1 package org.apache.maven.scm.provider.svn.svnexe.command.untag;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
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
52 @Override
53 public ScmResult executeUntagCommand( ScmProviderRepository repo, ScmFileSet fileSet,
54 ScmUntagParameters scmUntagParameters ) throws ScmException
55 {
56 String tag = scmUntagParameters.getTag();
57 if ( tag == null || tag.trim().isEmpty() )
58 {
59 throw new ScmException( "tag must be specified" );
60 }
61
62 SvnScmProviderRepository repository = (SvnScmProviderRepository) repo;
63
64 File messageFile = FileUtils.createTempFile( "maven-scm-", ".commit", null );
65
66 String message = scmUntagParameters.getMessage();
67 try
68 {
69 FileUtils.fileWrite( messageFile.getAbsolutePath(), "UTF-8", message );
70 }
71 catch ( IOException ex )
72 {
73 return new UntagScmResult( null, "Error while making a temporary file for the commit message: "
74 + ex.getMessage(), null, false );
75 }
76
77 Commandline cl = createCommandline( repository, fileSet, tag, messageFile );
78
79 CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
80
81 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
82
83 if ( getLogger().isInfoEnabled() )
84 {
85 getLogger().info( "Executing: " + SvnCommandLineUtils.cryptPassword( cl ) );
86
87 if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
88 {
89 getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
90 }
91 }
92
93 int exitCode;
94
95 try
96 {
97 exitCode = SvnCommandLineUtils.execute( cl, stdout, stderr, getLogger() );
98 }
99 catch ( CommandLineException ex )
100 {
101 throw new ScmException( "Error while executing svn remove command.", ex );
102 }
103 finally
104 {
105 try
106 {
107 FileUtils.forceDelete( messageFile );
108 }
109 catch ( IOException ex )
110 {
111
112 }
113 }
114
115 if ( exitCode == 0 )
116 {
117 return new UntagScmResult( cl.toString(), "The svn remove command was successful.",
118 stderr.getOutput(), true );
119 }
120 else
121 {
122 return new UntagScmResult( cl.toString(), "The svn remove command failed.", stderr.getOutput(), false );
123 }
124
125 }
126
127
128
129
130
131
132
133
134
135
136 Commandline createCommandline( SvnScmProviderRepository repo, ScmFileSet fileSet, String tag, File messageFile )
137 {
138 Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine( fileSet.getBasedir(), repo );
139
140 cl.createArg().setValue( "--file" );
141
142 cl.createArg().setValue( messageFile.getAbsolutePath() );
143
144 cl.createArg().setValue( "remove" );
145
146 String tagUrl = SvnTagBranchUtils.resolveTagUrl( repo, new ScmTag( tag ) );
147 tagUrl = SvnCommandUtils.fixUrl( tagUrl, repo.getUser() );
148 cl.createArg().setValue( tagUrl + "@" );
149
150 return cl;
151 }
152
153 }