1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm.provider.svn.svnexe.command.checkin;
20
21 import java.io.File;
22 import java.io.IOException;
23
24 import org.apache.commons.lang3.StringUtils;
25 import org.apache.maven.scm.ScmException;
26 import org.apache.maven.scm.ScmFileSet;
27 import org.apache.maven.scm.ScmVersion;
28 import org.apache.maven.scm.command.checkin.AbstractCheckInCommand;
29 import org.apache.maven.scm.command.checkin.CheckInScmResult;
30 import org.apache.maven.scm.provider.ScmProviderRepository;
31 import org.apache.maven.scm.provider.svn.command.SvnCommand;
32 import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
33 import org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils;
34 import org.codehaus.plexus.util.FileUtils;
35 import org.codehaus.plexus.util.Os;
36 import org.codehaus.plexus.util.cli.CommandLineException;
37 import org.codehaus.plexus.util.cli.CommandLineUtils;
38 import org.codehaus.plexus.util.cli.Commandline;
39
40
41
42
43
44
45 public class SvnCheckInCommand extends AbstractCheckInCommand implements SvnCommand {
46
47 protected CheckInScmResult executeCheckInCommand(
48 ScmProviderRepository repo, ScmFileSet fileSet, String message, ScmVersion version) throws ScmException {
49 if (version != null && StringUtils.isNotEmpty(version.getName())) {
50 throw new ScmException("This provider command can't handle tags.");
51 }
52
53 File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
54
55 try {
56 FileUtils.fileWrite(messageFile.getAbsolutePath(), "UTF-8", message);
57 } catch (IOException ex) {
58 return new CheckInScmResult(
59 null,
60 "Error while making a temporary file for the commit message: " + ex.getMessage(),
61 null,
62 false);
63 }
64
65 Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet, messageFile);
66
67 SvnCheckInConsumer consumer = new SvnCheckInConsumer(fileSet.getBasedir());
68
69 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
70
71 if (logger.isInfoEnabled()) {
72 logger.info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
73
74 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
75 logger.info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
76 }
77 }
78
79 int exitCode;
80
81 try {
82 exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr);
83 } catch (CommandLineException ex) {
84 throw new ScmException("Error while executing command.", ex);
85 } finally {
86 try {
87 FileUtils.forceDelete(messageFile);
88 } catch (IOException ex) {
89
90 }
91 }
92
93 if (exitCode != 0) {
94 return new CheckInScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
95 }
96
97 return new CheckInScmResult(
98 cl.toString(), consumer.getCheckedInFiles(), Integer.toString(consumer.getRevision()));
99 }
100
101
102
103
104
105 public static Commandline createCommandLine(
106 SvnScmProviderRepository repository, ScmFileSet fileSet, File messageFile) throws ScmException {
107 Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(fileSet.getBasedir(), repository);
108
109 cl.createArg().setValue("commit");
110
111 cl.createArg().setValue("--file");
112
113 cl.createArg().setValue(messageFile.getAbsolutePath());
114
115 cl.createArg().setValue("--encoding");
116
117 cl.createArg().setValue("UTF-8");
118
119 try {
120 SvnCommandLineUtils.addTarget(cl, fileSet.getFileList());
121 } catch (IOException e) {
122 throw new ScmException("Can't create the targets file", e);
123 }
124
125 return cl;
126 }
127 }