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 SVNAdmin {
031: private static Set ourArguments;
032: private static Map ourCommands;
033:
034: static {
035: ourArguments = new HashSet();
036: ourArguments.add(SVNArgument.CONFIG_DIR);
037: ourArguments.add(SVNArgument.FS_TYPE);
038: ourArguments.add(SVNArgument.PRE_14_COMPATIBLE);
039: ourArguments.add(SVNArgument.DELTAS);
040: ourArguments.add(SVNArgument.QUIET);
041: ourArguments.add(SVNArgument.REVISION);
042: ourArguments.add(SVNArgument.INCREMENTAL);
043: ourArguments.add(SVNArgument.IGNORE_UUID);
044: ourArguments.add(SVNArgument.FORCE_UUID);
045: ourArguments.add(SVNArgument.USE_POSTCOMMIT_HOOK);
046: ourArguments.add(SVNArgument.USE_PRECOMMIT_HOOK);
047: ourArguments.add(SVNArgument.PARENT_DIR);
048: ourArguments.add(SVNArgument.BDB_TXN_NOSYNC);
049: ourArguments.add(SVNArgument.BDB_LOG_KEEP);
050:
051: ourCommands = new HashMap();
052: ourCommands.put(new String[] { "create" },
053: "org.tmatesoft.svn.cli.command.SVNAdminCreateCommand");
054: ourCommands.put(new String[] { "dump" },
055: "org.tmatesoft.svn.cli.command.SVNAdminDumpCommand");
056: ourCommands.put(new String[] { "verify" },
057: "org.tmatesoft.svn.cli.command.SVNAdminVeirfyCommand");
058: ourCommands.put(new String[] { "load" },
059: "org.tmatesoft.svn.cli.command.SVNAdminLoadCommand");
060: ourCommands
061: .put(new String[] { "lstxns" },
062: "org.tmatesoft.svn.cli.command.SVNAdminListTransactionsCommand");
063: ourCommands
064: .put(new String[] { "rmtxns" },
065: "org.tmatesoft.svn.cli.command.SVNAdminRemoveTransactionsCommand");
066: ourCommands
067: .put(new String[] { "lslocks" },
068: "org.tmatesoft.svn.cli.command.SVNAdminListLocksCommand");
069: ourCommands
070: .put(new String[] { "rmlocks" },
071: "org.tmatesoft.svn.cli.command.SVNAdminRemoveLocksCommand");
072: }
073:
074: public static void main(String[] args) {
075: if (args == null || args.length < 1) {
076: System.err
077: .println("general usage: jsvnadmin SUBCOMMAND REPOS_PATH [ARGS & OPTIONS ...]");
078: System.exit(0);
079: }
080:
081: StringBuffer commandLineString = new StringBuffer();
082: for (int i = 0; i < args.length; i++) {
083: commandLineString.append(args[i]
084: + (i < args.length - 1 ? " " : ""));
085: }
086:
087: SVNCommandLine commandLine = null;
088: try {
089: try {
090: commandLine = new SVNCommandLine(args, ourArguments);
091: } catch (SVNException e) {
092: SVNDebugLog.getDefaultLog().info(e);
093: System.err.println(e.getMessage());
094: System.exit(1);
095: }
096: String commandName = commandLine.getCommandName();
097: SVNCommand command = SVNCommand.getCommand(commandName,
098: ourCommands);
099:
100: if (command != null) {
101: DAVRepositoryFactory.setup();
102: SVNRepositoryFactoryImpl.setup();
103: FSRepositoryFactory.setup();
104:
105: command.setCommandLine(commandLine);
106: boolean isSuccess = true;
107: try {
108: command.run(System.in, System.out, System.err);
109: } catch (SVNException e) {
110: isSuccess = false;
111: System.err.println(e.getMessage());
112: SVNDebugLog.getDefaultLog().info(e);
113: } finally {
114: if (command.getClientManager() != null) {
115: command.getClientManager().shutdownConnections(
116: true);
117: }
118: }
119: if (!isSuccess) {
120: System.exit(1);
121: }
122: } else {
123: System.err.println("error: unknown command name '"
124: + commandName + "'");
125: System.exit(1);
126: }
127: } catch (Throwable th) {
128: SVNDebugLog.getDefaultLog().info(th);
129: System.exit(-1);
130: }
131: System.exit(0);
132: }
133:
134: }
|