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.untag;
20
21 import java.io.File;
22 import java.io.IOException;
23
24 import org.apache.maven.scm.ScmException;
25 import org.apache.maven.scm.ScmFileSet;
26 import org.apache.maven.scm.ScmResult;
27 import org.apache.maven.scm.ScmTag;
28 import org.apache.maven.scm.ScmUntagParameters;
29 import org.apache.maven.scm.command.untag.AbstractUntagCommand;
30 import org.apache.maven.scm.command.untag.UntagScmResult;
31 import org.apache.maven.scm.provider.ScmProviderRepository;
32 import org.apache.maven.scm.provider.svn.SvnCommandUtils;
33 import org.apache.maven.scm.provider.svn.SvnTagBranchUtils;
34 import org.apache.maven.scm.provider.svn.command.SvnCommand;
35 import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
36 import org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils;
37 import org.codehaus.plexus.util.FileUtils;
38 import org.codehaus.plexus.util.Os;
39 import org.codehaus.plexus.util.cli.CommandLineException;
40 import org.codehaus.plexus.util.cli.CommandLineUtils;
41 import org.codehaus.plexus.util.cli.Commandline;
42
43
44
45
46
47
48 public class SvnUntagCommand extends AbstractUntagCommand implements SvnCommand {
49
50
51 @Override
52 public ScmResult executeUntagCommand(
53 ScmProviderRepository repo, ScmFileSet fileSet, ScmUntagParameters scmUntagParameters) throws ScmException {
54 String tag = scmUntagParameters.getTag();
55 if (tag == null || tag.trim().isEmpty()) {
56 throw new ScmException("tag must be specified");
57 }
58
59 SvnScmProviderRepository repository = (SvnScmProviderRepository) repo;
60
61 File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
62
63 String message = scmUntagParameters.getMessage();
64 try {
65 FileUtils.fileWrite(messageFile.getAbsolutePath(), "UTF-8", message);
66 } catch (IOException ex) {
67 return new UntagScmResult(
68 null,
69 "Error while making a temporary file for the commit message: " + ex.getMessage(),
70 null,
71 false);
72 }
73
74 Commandline cl = createCommandline(repository, fileSet, tag, messageFile);
75
76 CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
77
78 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
79
80 if (logger.isInfoEnabled()) {
81 logger.info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
82
83 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
84 logger.info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
85 }
86 }
87
88 int exitCode;
89
90 try {
91 exitCode = SvnCommandLineUtils.execute(cl, stdout, stderr);
92 } catch (CommandLineException ex) {
93 throw new ScmException("Error while executing svn remove command.", ex);
94 } finally {
95 try {
96 FileUtils.forceDelete(messageFile);
97 } catch (IOException ex) {
98
99 }
100 }
101
102 if (exitCode == 0) {
103 return new UntagScmResult(
104 cl.toString(), "The svn remove command was successful.", stderr.getOutput(), true);
105 } else {
106 return new UntagScmResult(cl.toString(), "The svn remove command failed.", stderr.getOutput(), false);
107 }
108 }
109
110
111
112
113
114
115
116
117
118
119 Commandline createCommandline(SvnScmProviderRepository repo, ScmFileSet fileSet, String tag, File messageFile) {
120 Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(fileSet.getBasedir(), repo);
121
122 cl.createArg().setValue("--file");
123
124 cl.createArg().setValue(messageFile.getAbsolutePath());
125
126 cl.createArg().setValue("remove");
127
128 String tagUrl = SvnTagBranchUtils.resolveTagUrl(repo, new ScmTag(tag));
129 tagUrl = SvnCommandUtils.fixUrl(tagUrl, repo.getUser());
130 cl.createArg().setValue(tagUrl + "@");
131
132 return cl;
133 }
134 }