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 org.tmatesoft.svn.cli.SVNArgument;
16: import org.tmatesoft.svn.cli.SVNCommand;
17: import org.tmatesoft.svn.core.SVNCommitInfo;
18: import org.tmatesoft.svn.core.SVNErrorCode;
19: import org.tmatesoft.svn.core.SVNErrorMessage;
20: import org.tmatesoft.svn.core.SVNException;
21: import org.tmatesoft.svn.core.wc.SVNCommitClient;
22:
23: import java.io.File;
24: import java.io.InputStream;
25: import java.io.PrintStream;
26:
27: /**
28: * @version 1.1.1
29: * @author TMate Software Ltd.
30: */
31: public class SVNCommitCommand 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, PrintStream err)
39: throws SVNException {
40: checkEditorCommand();
41: final boolean recursive = !getCommandLine().hasArgument(
42: SVNArgument.NON_RECURSIVE);
43: boolean keepLocks = getCommandLine().hasArgument(
44: SVNArgument.NO_UNLOCK);
45: final String message = getCommitMessage();
46:
47: File[] localPaths = new File[getCommandLine().getPathCount()];
48: for (int i = 0; i < getCommandLine().getPathCount(); i++) {
49: matchTabsInPath(getCommandLine().getPathAt(i), err);
50: localPaths[i] = new File(getCommandLine().getPathAt(i));
51: }
52: getClientManager().setEventHandler(
53: new SVNCommandEventProcessor(out, err, false));
54: SVNCommitClient client = getClientManager().getCommitClient();
55: SVNCommitInfo result = client.doCommit(localPaths, keepLocks,
56: message, false, recursive);
57: if (result != SVNCommitInfo.NULL) {
58: out.println();
59: out.println("Committed revision " + result.getNewRevision()
60: + ".");
61: }
62: if (result.getErrorMessage() != null
63: && result.getErrorMessage().getErrorCode() == SVNErrorCode.REPOS_POST_COMMIT_HOOK_FAILED) {
64: out.println();
65: out.println(result.getErrorMessage());
66: }
67: }
68:
69: private void checkEditorCommand() throws SVNException {
70: final String editorCommand = (String) getCommandLine()
71: .getArgumentValue(SVNArgument.EDITOR_CMD);
72: if (editorCommand == null) {
73: return;
74: }
75: SVNErrorMessage err = SVNErrorMessage.create(
76: SVNErrorCode.CL_NO_EXTERNAL_EDITOR,
77: "Commit failed. Can''t handle external editor "
78: + editorCommand);
79: throw new SVNException(err);
80: }
81: }
|