001: /*
002: * ====================================================================
003: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
004: *
005: * This software is licensed as described in the file COPYING, which
006: * you should have received as part of this distribution. The terms
007: * are also available at http://svnkit.com/license.html.
008: * If newer versions of this license are posted there, you may use a
009: * newer version instead, at your option.
010: * ====================================================================
011: */
012: package org.tmatesoft.svn.cli;
013:
014: import java.util.HashMap;
015: import java.util.HashSet;
016: import java.util.Map;
017: import java.util.Set;
018:
019: import org.tmatesoft.svn.core.SVNException;
020: import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
021: import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
022: import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
023: import org.tmatesoft.svn.util.SVNDebugLog;
024:
025: /**
026: * @version 1.1.1
027: * @author TMate Software Ltd.
028: * @since 1.1.1
029: */
030: public class SVNLook {
031: private static Set ourArguments;
032: private static Map ourCommands;
033:
034: static {
035: ourArguments = new HashSet();
036: ourArguments.add(SVNArgument.REVISION);
037: ourArguments.add(SVNArgument.TRANSACTION);
038: ourArguments.add(SVNArgument.COPY_INFO);
039: ourArguments.add(SVNArgument.NO_DIFF_DELETED);
040: ourArguments.add(SVNArgument.NO_DIFF_ADDED);
041: ourArguments.add(SVNArgument.DIFF_COPY_FROM);
042: ourArguments.add(SVNArgument.SHOW_IDS);
043: ourArguments.add(SVNArgument.REV_PROP);
044: ourArguments.add(SVNArgument.VERBOSE);
045: ourArguments.add(SVNArgument.FULL_PATHS);
046:
047: ourCommands = new HashMap();
048: ourCommands.put(new String[] { "author" },
049: "org.tmatesoft.svn.cli.command.SVNLookAuthorCommand");
050: ourCommands.put(new String[] { "cat" },
051: "org.tmatesoft.svn.cli.command.SVNLookCatCommand");
052: ourCommands.put(new String[] { "changed" },
053: "org.tmatesoft.svn.cli.command.SVNLookChangedCommand");
054: ourCommands.put(new String[] { "date" },
055: "org.tmatesoft.svn.cli.command.SVNLookDateCommand");
056: ourCommands.put(new String[] { "diff" },
057: "org.tmatesoft.svn.cli.command.SVNLookDiffCommand");
058: ourCommands
059: .put(new String[] { "dirs-changed" },
060: "org.tmatesoft.svn.cli.command.SVNLookDirsChangedCommand");
061: ourCommands.put(new String[] { "history" },
062: "org.tmatesoft.svn.cli.command.SVNLookHistoryCommand");
063: ourCommands.put(new String[] { "info" },
064: "org.tmatesoft.svn.cli.command.SVNLookInfoCommand");
065: ourCommands.put(new String[] { "lock" },
066: "org.tmatesoft.svn.cli.command.SVNLookLockCommand");
067: ourCommands.put(new String[] { "log" },
068: "org.tmatesoft.svn.cli.command.SVNLookLogCommand");
069: ourCommands.put(new String[] { "propget", "pget", "pg" },
070: "org.tmatesoft.svn.cli.command.SVNLookPropgetCommand");
071: ourCommands.put(new String[] { "proplist", "plist", "pl" },
072: "org.tmatesoft.svn.cli.command.SVNLookProplistCommand");
073: ourCommands.put(new String[] { "tree" },
074: "org.tmatesoft.svn.cli.command.SVNLookTreeCommand");
075: ourCommands.put(new String[] { "uuid" },
076: "org.tmatesoft.svn.cli.command.SVNLookUUIDCommand");
077: ourCommands.put(new String[] { "youngest" },
078: "org.tmatesoft.svn.cli.command.SVNLookYoungestCommand");
079: }
080:
081: public static void main(String[] args) {
082: if (args == null || args.length < 1) {
083: System.err
084: .println("general usage: jsvnlook SUBCOMMAND REPOS_PATH [ARGS & OPTIONS ...]");
085: System.exit(0);
086: }
087:
088: StringBuffer commandLineString = new StringBuffer();
089: for (int i = 0; i < args.length; i++) {
090: commandLineString.append(args[i]
091: + (i < args.length - 1 ? " " : ""));
092: }
093:
094: SVNCommandLine commandLine = null;
095: try {
096: try {
097: commandLine = new SVNCommandLine(args, ourArguments);
098: } catch (SVNException e) {
099: SVNDebugLog.getDefaultLog().info(e);
100: System.err.println(e.getMessage());
101: System.exit(1);
102: }
103: String commandName = commandLine.getCommandName();
104: SVNCommand command = SVNCommand.getCommand(commandName,
105: ourCommands);
106:
107: if (command != null) {
108: DAVRepositoryFactory.setup();
109: SVNRepositoryFactoryImpl.setup();
110: FSRepositoryFactory.setup();
111:
112: command.setCommandLine(commandLine);
113: boolean isSuccess = true;
114: try {
115: command.run(System.out, System.err);
116: } catch (SVNException e) {
117: isSuccess = false;
118: System.err.println(e.getMessage());
119: SVNDebugLog.getDefaultLog().info(e);
120: } finally {
121: if (command.getClientManager() != null) {
122: command.getClientManager().shutdownConnections(
123: true);
124: }
125: }
126: if (!isSuccess) {
127: System.exit(1);
128: }
129: } else {
130: System.err.println("error: unknown command name '"
131: + commandName + "'");
132: System.exit(1);
133: }
134: } catch (Throwable th) {
135: SVNDebugLog.getDefaultLog().info(th);
136: System.exit(-1);
137: }
138: System.exit(0);
139: }
140:
141: }
|