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:
013: package org.tmatesoft.svn.cli.command;
014:
015: import java.io.File;
016: import java.io.InputStream;
017: import java.io.PrintStream;
018:
019: import org.tmatesoft.svn.cli.SVNArgument;
020: import org.tmatesoft.svn.cli.SVNCommand;
021: import org.tmatesoft.svn.core.SVNCommitInfo;
022: import org.tmatesoft.svn.core.SVNErrorCode;
023: import org.tmatesoft.svn.core.SVNErrorMessage;
024: import org.tmatesoft.svn.core.SVNException;
025: import org.tmatesoft.svn.core.SVNURL;
026: import org.tmatesoft.svn.core.wc.SVNCopyClient;
027: import org.tmatesoft.svn.core.wc.SVNRevision;
028:
029: /**
030: * @version 1.1.1
031: * @author TMate Software Ltd.
032: */
033: public class SVNMoveCommand extends SVNCommand {
034:
035: public void run(InputStream in, PrintStream out, PrintStream err)
036: throws SVNException {
037: run(out, err);
038: }
039:
040: public void run(PrintStream out, PrintStream err)
041: throws SVNException {
042: if (getCommandLine().hasPaths() && getCommandLine().hasURLs()) {
043: err.println("only URL->URL or WC->WC copy is supported");
044: return;
045: }
046: if (getCommandLine().hasURLs()) {
047: runRemote(out, err);
048: } else {
049: runLocally(out, err);
050: }
051: }
052:
053: private void runRemote(PrintStream out, PrintStream err)
054: throws SVNException {
055: if (getCommandLine().getURLCount() != 2) {
056: SVNErrorMessage msg = SVNErrorMessage.create(
057: SVNErrorCode.CL_INSUFFICIENT_ARGS,
058: "Please enter SRC and DST URLs");
059: throw new SVNException(msg);
060: }
061: String srcURL = getCommandLine().getURL(0);
062: SVNRevision srcRevision = SVNRevision
063: .parse((String) getCommandLine().getArgumentValue(
064: SVNArgument.REVISION));
065: String dstURL = getCommandLine().getURL(1);
066:
067: if (matchTabsInURL(srcURL, err) || matchTabsInURL(dstURL, err)) {
068: return;
069: }
070:
071: String commitMessage = (String) getCommandLine()
072: .getArgumentValue(SVNArgument.MESSAGE);
073: getClientManager().setEventHandler(
074: new SVNCommandEventProcessor(out, err, false));
075: SVNCopyClient updater = getClientManager().getCopyClient();
076: SVNCommitInfo result = updater.doCopy(SVNURL
077: .parseURIEncoded(srcURL), srcRevision, SVNURL
078: .parseURIDecoded(dstURL), true, commitMessage);
079: if (result != SVNCommitInfo.NULL) {
080: out.println();
081: out.println("Committed revision " + result.getNewRevision()
082: + ".");
083: }
084: }
085:
086: private void runLocally(final PrintStream out, PrintStream err)
087: throws SVNException {
088: if (getCommandLine().getPathCount() != 2) {
089: SVNErrorMessage msg = SVNErrorMessage.create(
090: SVNErrorCode.CL_INSUFFICIENT_ARGS,
091: "Please enter SRC and DST path");
092: throw new SVNException(msg);
093: }
094:
095: final String absoluteSrcPath = getCommandLine().getPathAt(0);
096: final String absoluteDstPath = getCommandLine().getPathAt(1);
097: if (matchTabsInPath(absoluteDstPath, err)
098: || matchTabsInPath(absoluteSrcPath, err)) {
099: return;
100: }
101: getClientManager().setEventHandler(
102: new SVNCommandEventProcessor(out, err, false));
103: SVNCopyClient updater = getClientManager().getCopyClient();
104: boolean force = getCommandLine().hasArgument(SVNArgument.FORCE);
105: updater.doCopy(new File(absoluteSrcPath), SVNRevision.WORKING,
106: new File(absoluteDstPath), force, true);
107: }
108: }
|