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:
021: import org.tmatesoft.svn.cli.SVNArgument;
022: import org.tmatesoft.svn.cli.SVNCommand;
023: import org.tmatesoft.svn.core.SVNCommitInfo;
024: import org.tmatesoft.svn.core.SVNErrorCode;
025: import org.tmatesoft.svn.core.SVNErrorMessage;
026: import org.tmatesoft.svn.core.SVNException;
027: import org.tmatesoft.svn.core.SVNURL;
028: import org.tmatesoft.svn.core.wc.SVNCommitClient;
029: import org.tmatesoft.svn.core.wc.SVNWCClient;
030:
031: /**
032: * @version 1.1.1
033: * @author TMate Software Ltd.
034: */
035: public class SVNDeleteCommand extends SVNCommand {
036:
037: public void run(InputStream in, PrintStream out, PrintStream err)
038: throws SVNException {
039: run(out, err);
040: }
041:
042: public void run(PrintStream out, PrintStream err)
043: throws SVNException {
044: if (getCommandLine().hasURLs()) {
045: runRemote(out);
046: } else {
047: if (getCommandLine().getArgumentValue(SVNArgument.MESSAGE) != null) {
048: SVNErrorMessage msg = SVNErrorMessage
049: .create(
050: SVNErrorCode.CL_UNNECESSARY_LOG_MESSAGE,
051: "Local, non-commit operations do not take a log message.");
052: throw new SVNException(msg);
053: }
054: runLocally(out, err);
055: }
056: }
057:
058: private void runRemote(PrintStream out) throws SVNException {
059: final String commitMessage = (String) getCommandLine()
060: .getArgumentValue(SVNArgument.MESSAGE);
061:
062: SVNCommitClient client = getClientManager().getCommitClient();
063: Collection urls = new ArrayList(getCommandLine().getURLCount());
064: for (int i = 0; i < getCommandLine().getURLCount(); i++) {
065: urls.add(getCommandLine().getURL(i));
066: }
067: String[] urlsArray = (String[]) urls.toArray(new String[urls
068: .size()]);
069: SVNURL[] svnUrls = new SVNURL[urlsArray.length];
070: for (int i = 0; i < svnUrls.length; i++) {
071: svnUrls[i] = SVNURL.parseURIEncoded(urlsArray[i]);
072: }
073: SVNCommitInfo info = client.doDelete(svnUrls, commitMessage);
074: if (info != SVNCommitInfo.NULL) {
075: out.println();
076: out.println("Committed revision " + info.getNewRevision()
077: + ".");
078: }
079: }
080:
081: private void runLocally(final PrintStream out, PrintStream err) {
082: boolean force = getCommandLine().hasArgument(SVNArgument.FORCE);
083:
084: getClientManager().setEventHandler(
085: new SVNCommandEventProcessor(out, err, false));
086:
087: SVNWCClient client = getClientManager().getWCClient();
088: boolean error = false;
089: for (int i = 0; i < getCommandLine().getPathCount(); i++) {
090: final String absolutePath = getCommandLine().getPathAt(i);
091: try {
092: client.doDelete(new File(absolutePath), force, false);
093: } catch (SVNException e) {
094: err.println(e.getMessage());
095: error = true;
096: }
097: }
098: if (error) {
099: System.exit(1);
100: }
101: }
102: }
|