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.0
029: */
030: public class SVNSync {
031: private static Set ourArguments;
032: private static Map ourCommands;
033:
034: static {
035: ourArguments = new HashSet();
036: ourArguments.add(SVNArgument.NON_INTERACTIVE);
037: ourArguments.add(SVNArgument.NO_AUTH_CACHE);
038: ourArguments.add(SVNArgument.PASSWORD);
039: ourArguments.add(SVNArgument.USERNAME);
040: ourArguments.add(SVNArgument.CONFIG_DIR);
041:
042: ourCommands = new HashMap();
043: ourCommands.put(new String[] { "initialize", "init" },
044: "org.tmatesoft.svn.cli.command.SVNSyncInitCommand");
045: ourCommands
046: .put(new String[] { "synchronize", "sync" },
047: "org.tmatesoft.svn.cli.command.SVNSyncSynchronizeCommand");
048: ourCommands
049: .put(new String[] { "copy-revprops" },
050: "org.tmatesoft.svn.cli.command.SVNSyncCopyRevpropsCommand");
051: }
052:
053: public static void main(String[] args) {
054: if (args == null || args.length < 1) {
055: System.err
056: .println("general usage: jsvnsync SUBCOMMAND DEST_URL [ARGS & OPTIONS ...]\n");
057: System.exit(0);
058: }
059:
060: StringBuffer commandLineString = new StringBuffer();
061: for (int i = 0; i < args.length; i++) {
062: commandLineString.append(args[i]
063: + (i < args.length - 1 ? " " : ""));
064: }
065:
066: SVNCommandLine commandLine = null;
067: try {
068: try {
069: commandLine = new SVNCommandLine(args, ourArguments);
070: } catch (SVNException e) {
071: SVNDebugLog.getDefaultLog().info(e);
072: System.err.println(e.getMessage());
073: System.exit(1);
074: }
075: String commandName = commandLine.getCommandName();
076: SVNCommand command = SVNCommand.getCommand(commandName,
077: ourCommands);
078:
079: if (command != null) {
080: DAVRepositoryFactory.setup();
081: SVNRepositoryFactoryImpl.setup();
082: FSRepositoryFactory.setup();
083:
084: command.setCommandLine(commandLine);
085: boolean isSuccess = true;
086: try {
087: command.run(System.out, System.err);
088: } catch (SVNException e) {
089: isSuccess = false;
090: System.err.println(e.getMessage());
091: SVNDebugLog.getDefaultLog().info(e);
092: } finally {
093: if (command.getClientManager() != null) {
094: command.getClientManager().shutdownConnections(
095: true);
096: }
097: }
098: if (!isSuccess) {
099: System.exit(1);
100: }
101: } else {
102: System.err.println("error: unknown command name '"
103: + commandName + "'");
104: System.exit(1);
105: }
106: } catch (Throwable th) {
107: SVNDebugLog.getDefaultLog().info(th);
108: System.exit(-1);
109: }
110: System.exit(0);
111:
112: }
113: }
|