1 package org.apache.maven.scm.provider.vss.commands.tag;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.ScmException;
23 import org.apache.maven.scm.ScmFileSet;
24 import org.apache.maven.scm.ScmResult;
25 import org.apache.maven.scm.ScmTagParameters;
26 import org.apache.maven.scm.command.tag.AbstractTagCommand;
27 import org.apache.maven.scm.command.tag.TagScmResult;
28 import org.apache.maven.scm.provider.ScmProviderRepository;
29 import org.apache.maven.scm.provider.vss.commands.VssCommandLineUtils;
30 import org.apache.maven.scm.provider.vss.commands.VssConstants;
31 import org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository;
32 import org.codehaus.plexus.util.cli.CommandLineUtils;
33 import org.codehaus.plexus.util.cli.Commandline;
34
35
36
37
38
39 public class VssTagCommand
40 extends AbstractTagCommand
41 {
42
43 protected ScmResult executeTagCommand( ScmProviderRepository repository, ScmFileSet fileSet, String tagName,
44 ScmTagParameters scmTagParameters )
45 throws ScmException
46 {
47 return executeTagCommand( repository, fileSet, tagName, scmTagParameters == null ? "" : scmTagParameters
48 .getMessage() );
49 }
50
51
52
53
54
55 protected ScmResult executeTagCommand( ScmProviderRepository repository, ScmFileSet fileSet, String tagName,
56 String message )
57 throws ScmException
58 {
59 if ( getLogger().isDebugEnabled() )
60 {
61 getLogger().debug( "executing tag command..." );
62 }
63
64 VssScmProviderRepository repo = (VssScmProviderRepository) repository;
65
66 Commandline cl = buildCmdLine( repo, fileSet, tagName, message );
67
68 VssTagConsumer consumer = new VssTagConsumer( repo, getLogger() );
69
70
71 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
72
73 int exitCode;
74
75 if ( getLogger().isDebugEnabled() )
76 {
77 getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() );
78 }
79
80 exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
81
82 if ( exitCode != 0 )
83 {
84 String error = stderr.getOutput();
85
86 if ( getLogger().isDebugEnabled() )
87 {
88 getLogger().debug( "VSS returns error: [" + error + "] return code: [" + exitCode + "]" );
89 }
90 if ( error.indexOf( "A writable copy of" ) < 0 )
91 {
92 return new TagScmResult( cl.toString(), "The vss command failed.", error, false );
93 }
94
95 if ( getLogger().isWarnEnabled() )
96 {
97 getLogger().warn( error );
98 }
99 }
100
101 return new TagScmResult( cl.toString(), consumer.getUpdatedFiles() );
102 }
103
104 public Commandline buildCmdLine( VssScmProviderRepository repo, ScmFileSet fileSet, String tagName, String message )
105 throws ScmException
106 {
107
108 Commandline command = new Commandline();
109
110 command.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() );
111
112 try
113 {
114 command.addSystemEnvironment();
115 }
116 catch ( Exception e )
117 {
118 throw new ScmException( "Can't add system environment.", e );
119 }
120
121 command.addEnvironment( "SSDIR", repo.getVssdir() );
122
123 String ssDir = VssCommandLineUtils.getSsDir();
124
125 command.setExecutable( ssDir + VssConstants.SS_EXE );
126
127 command.createArg().setValue( VssConstants.COMMAND_LABEL );
128
129 command.createArg().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() );
130
131
132 if ( repo.getUserPassword() != null )
133 {
134 command.createArg().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() );
135 }
136
137
138 command.createArg().setValue( VssConstants.FLAG_AUTORESPONSE_DEF );
139
140 command.createArg().setValue( VssConstants.FLAG_LABEL + tagName );
141
142 return command;
143 }
144
145 }