01: /*
02: * ====================================================================
03: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
04: *
05: * This software is licensed as described in the file COPYING, which
06: * you should have received as part of this distribution. The terms
07: * are also available at http://svnkit.com/license.html
08: * If newer versions of this license are posted there, you may use a
09: * newer version instead, at your option.
10: * ====================================================================
11: */
12:
13: package org.tmatesoft.svn.cli.command;
14:
15: import java.io.File;
16: import java.io.InputStream;
17: import java.io.PrintStream;
18:
19: import org.tmatesoft.svn.cli.SVNArgument;
20: import org.tmatesoft.svn.cli.SVNCommand;
21: import org.tmatesoft.svn.core.SVNException;
22: import org.tmatesoft.svn.core.SVNURL;
23: import org.tmatesoft.svn.core.internal.util.SVNPathUtil;
24: import org.tmatesoft.svn.core.wc.SVNRevision;
25: import org.tmatesoft.svn.core.wc.SVNUpdateClient;
26:
27: /**
28: * @version 1.1.1
29: * @author TMate Software Ltd.
30: */
31: public class SVNSwitchCommand extends SVNCommand {
32:
33: public void run(InputStream in, PrintStream out, PrintStream err)
34: throws SVNException {
35: run(out, err);
36: }
37:
38: public void run(final PrintStream out, final PrintStream err)
39: throws SVNException {
40: String url = getCommandLine().getURL(0);
41: String absolutePath;
42: if (getCommandLine().getPathCount() > 0) {
43: absolutePath = getCommandLine().getPathAt(0);
44: } else {
45: absolutePath = new File("").getAbsolutePath();
46: }
47:
48: SVNRevision revision = parseRevision(getCommandLine());
49: if (!revision.isValid()) {
50: revision = SVNRevision.HEAD;
51: }
52: getClientManager().setEventHandler(
53: new SVNCommandEventProcessor(out, err, false, false));
54: SVNUpdateClient updater = getClientManager().getUpdateClient();
55: try {
56: SVNURL switchURL = SVNURL.parseURIEncoded(url);
57:
58: if (getCommandLine().hasArgument(SVNArgument.RELOCATE)) {
59: SVNURL targetURL = SVNURL
60: .parseURIEncoded(getCommandLine().getURL(1));
61: File file = new File(absolutePath).getAbsoluteFile();
62: file = new File(SVNPathUtil.validateFilePath(file
63: .getAbsolutePath()));
64: updater.doRelocate(file, switchURL, targetURL,
65: !getCommandLine().hasArgument(
66: SVNArgument.NON_RECURSIVE));
67: } else {
68: File file = new File(absolutePath).getAbsoluteFile();
69: file = new File(SVNPathUtil.validateFilePath(file
70: .getAbsolutePath()));
71: updater.getDebugLog().info("switching path: " + file);
72: updater.doSwitch(file, switchURL, revision,
73: !getCommandLine().hasArgument(
74: SVNArgument.NON_RECURSIVE));
75: }
76: } catch (Throwable th) {
77: updater.getDebugLog().info(th);
78: println(err, th.getMessage());
79: println(err);
80: System.exit(1);
81: }
82: }
83: }
|