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.SVNEncodingUtil;
24: import org.tmatesoft.svn.core.internal.util.SVNPathUtil;
25: import org.tmatesoft.svn.core.wc.SVNRevision;
26: import org.tmatesoft.svn.core.wc.SVNUpdateClient;
27:
28: /**
29: * @version 1.1.1
30: * @author TMate Software Ltd.
31: */
32: public class SVNCheckoutCommand extends SVNCommand {
33:
34: public void run(InputStream in, PrintStream out, PrintStream err)
35: throws SVNException {
36: run(out, err);
37: }
38:
39: public void run(final PrintStream out, final PrintStream err)
40: throws SVNException {
41: final String url = getCommandLine().getURL(0);
42:
43: String path;
44: if (getCommandLine().getPathCount() > 0) {
45: path = getCommandLine().getPathAt(0);
46: } else {
47: path = new File(".", SVNEncodingUtil.uriDecode(SVNPathUtil
48: .tail(url))).getAbsolutePath();
49: }
50:
51: SVNRevision revision = parseRevision(getCommandLine());
52: getClientManager().setEventHandler(
53: new SVNCommandEventProcessor(out, err, true));
54: SVNUpdateClient updater = getClientManager().getUpdateClient();
55: if (getCommandLine().getURLCount() == 1) {
56: SVNRevision pegRevision = getCommandLine()
57: .getPegRevision(0);
58: updater.doCheckout(SVNURL.parseURIEncoded(url), new File(
59: path), pegRevision, revision, !getCommandLine()
60: .hasArgument(SVNArgument.NON_RECURSIVE));
61: } else {
62: for (int i = 0; i < getCommandLine().getURLCount(); i++) {
63: String curl = getCommandLine().getURL(i);
64: File dstPath = new File(path, SVNEncodingUtil
65: .uriDecode(SVNPathUtil.tail(curl)));
66: SVNRevision pegRevision = getCommandLine()
67: .getPegRevision(i);
68: updater.doCheckout(SVNURL.parseURIEncoded(url),
69: dstPath, pegRevision, revision,
70: !getCommandLine().hasArgument(
71: SVNArgument.NON_RECURSIVE));
72: }
73: }
74: }
75: }
|