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: import java.util.ArrayList;
019: import java.util.Collection;
020: import java.util.Iterator;
021:
022: import org.tmatesoft.svn.cli.SVNArgument;
023: import org.tmatesoft.svn.cli.SVNCommand;
024: import org.tmatesoft.svn.core.SVNCommitInfo;
025: import org.tmatesoft.svn.core.SVNErrorCode;
026: import org.tmatesoft.svn.core.SVNErrorMessage;
027: import org.tmatesoft.svn.core.SVNException;
028: import org.tmatesoft.svn.core.SVNURL;
029: import org.tmatesoft.svn.core.wc.SVNCommitClient;
030: import org.tmatesoft.svn.core.wc.SVNWCClient;
031:
032: /**
033: * @version 1.1.1
034: * @author TMate Software Ltd.
035: */
036: public class SVNMkDirCommand extends SVNCommand {
037:
038: public void run(InputStream in, PrintStream out, PrintStream err)
039: throws SVNException {
040: run(out, err);
041: }
042:
043: public final void run(final PrintStream out, PrintStream err)
044: throws SVNException {
045: if (!getCommandLine().hasURLs()) {
046: if (getCommandLine().getArgumentValue(SVNArgument.MESSAGE) != null) {
047: SVNErrorMessage msg = SVNErrorMessage
048: .create(
049: SVNErrorCode.CL_UNNECESSARY_LOG_MESSAGE,
050: "Local, non-commit operations do not take a log message.");
051: throw new SVNException(msg);
052: }
053: createLocalDirectories(out, err);
054: } else {
055: createRemoteDirectories(out, err);
056: }
057: }
058:
059: private void createLocalDirectories(final PrintStream out,
060: PrintStream err) {
061: final Collection paths = new ArrayList();
062: for (int i = 0; i < getCommandLine().getPathCount(); i++) {
063: if (matchTabsInPath(getCommandLine().getPathAt(i), err)) {
064: continue;
065: }
066: paths.add(new File(getCommandLine().getPathAt(i)));
067: }
068: if (paths.isEmpty()) {
069: return;
070: }
071: getClientManager().setEventHandler(
072: new SVNCommandEventProcessor(out, err, false));
073: SVNWCClient wcClient = getClientManager().getWCClient();
074: boolean recursive = !getCommandLine().hasArgument(
075: SVNArgument.NON_RECURSIVE);
076: for (Iterator files = paths.iterator(); files.hasNext();) {
077: File file = (File) files.next();
078: try {
079: wcClient.doAdd(file, false, true, false, recursive,
080: false);
081: } catch (SVNException e) {
082: err.println(e.getMessage());
083: }
084: }
085: }
086:
087: private void createRemoteDirectories(final PrintStream out,
088: PrintStream err) throws SVNException {
089: final Collection urls = new ArrayList();
090: for (int i = 0; i < getCommandLine().getURLCount(); i++) {
091: if (matchTabsInURL(getCommandLine().getURL(i), err)) {
092: continue;
093: }
094: urls.add(getCommandLine().getURL(i));
095: }
096: if (urls.isEmpty()) {
097: return;
098: }
099: String message = (String) getCommandLine().getArgumentValue(
100: SVNArgument.MESSAGE);
101: getClientManager().setEventHandler(
102: new SVNCommandEventProcessor(out, err, false));
103: SVNCommitClient client = getClientManager().getCommitClient();
104: String[] paths = (String[]) urls
105: .toArray(new String[urls.size()]);
106: SVNURL[] svnURLs = new SVNURL[paths.length];
107: for (int i = 0; i < svnURLs.length; i++) {
108: svnURLs[i] = SVNURL.parseURIEncoded(paths[i]);
109: }
110: SVNCommitInfo info = client.doMkDir(svnURLs,
111: message == null ? "" : message);
112: if (info != SVNCommitInfo.NULL) {
113: out.println();
114: out.println("Committed revision " + info.getNewRevision()
115: + ".");
116: }
117: }
118: }
|