1 package org.apache.maven.scm.provider.jazz.command.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.ScmFile;
24 import org.apache.maven.scm.ScmFileSet;
25 import org.apache.maven.scm.ScmFileStatus;
26 import org.apache.maven.scm.ScmResult;
27 import org.apache.maven.scm.ScmTagParameters;
28 import org.apache.maven.scm.command.tag.AbstractTagCommand;
29 import org.apache.maven.scm.command.tag.TagScmResult;
30 import org.apache.maven.scm.provider.ScmProviderRepository;
31 import org.apache.maven.scm.provider.jazz.command.JazzConstants;
32 import org.apache.maven.scm.provider.jazz.command.JazzScmCommand;
33 import org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer;
34 import org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer;
35 import org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository;
36 import org.codehaus.plexus.util.cli.StreamConsumer;
37
38 import java.io.File;
39 import java.util.ArrayList;
40 import java.util.List;
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 public class JazzTagCommand
68 extends AbstractTagCommand
69 {
70
71
72
73 protected ScmResult executeTagCommand( ScmProviderRepository repo, ScmFileSet fileSet, String tag,
74 ScmTagParameters scmTagParameters )
75 throws ScmException
76 {
77 if ( getLogger().isDebugEnabled() )
78 {
79 getLogger().debug( "Executing tag command..." );
80 }
81
82 JazzScmProviderRepository jazzRepo = (JazzScmProviderRepository) repo;
83
84 getLogger().debug( "Creating Snapshot..." );
85 StreamConsumer tagConsumer =
86 new DebugLoggerConsumer( getLogger() );
87 ErrorConsumer errConsumer = new ErrorConsumer( getLogger() );
88 JazzScmCommand tagCreateSnapshotCmd =
89 createTagCreateSnapshotCommand( jazzRepo, fileSet, tag, scmTagParameters );
90 int status = tagCreateSnapshotCmd.execute( tagConsumer, errConsumer );
91
92 if ( status != 0 || errConsumer.hasBeenFed() )
93 {
94 return new TagScmResult( tagCreateSnapshotCmd.getCommandString(),
95 "Error code for Jazz SCM tag (SNAPSHOT) command - " + status,
96 errConsumer.getOutput(), false );
97 }
98
99
100
101
102 getLogger().debug( "Creating Workspace from Snapshot..." );
103 JazzScmCommand tagCreateWorkspaceCmd = createTagCreateWorkspaceCommand( jazzRepo, fileSet, tag );
104 errConsumer = new ErrorConsumer( getLogger() );
105 status = tagCreateWorkspaceCmd.execute( tagConsumer, errConsumer );
106
107 if ( status != 0 || errConsumer.hasBeenFed() )
108 {
109 return new TagScmResult( tagCreateWorkspaceCmd.getCommandString(),
110 "Error code for Jazz SCM tag (WORKSPACE) command - " + status,
111 errConsumer.getOutput(), false );
112 }
113
114
115 if ( jazzRepo.isPushChangesAndHaveFlowTargets() )
116 {
117
118 getLogger().debug( "Promoting and delivering..." );
119
120
121 getLogger().debug( "Delivering..." );
122 JazzScmCommand tagDeliverCommand = createTagDeliverCommand( jazzRepo, fileSet, tag );
123 errConsumer = new ErrorConsumer( getLogger() );
124 status = tagDeliverCommand.execute( tagConsumer, errConsumer );
125 if ( status != 0 || errConsumer.hasBeenFed() )
126 {
127 return new TagScmResult( tagDeliverCommand.getCommandString(),
128 "Error code for Jazz SCM deliver command - " + status, errConsumer.getOutput(),
129 false );
130 }
131
132
133 getLogger().debug( "Promoting snapshot..." );
134 JazzScmCommand tagSnapshotPromoteCommand = createTagSnapshotPromoteCommand( jazzRepo, fileSet, tag );
135 errConsumer = new ErrorConsumer( getLogger() );
136 status = tagSnapshotPromoteCommand.execute( tagConsumer, errConsumer );
137 if ( status != 0 || errConsumer.hasBeenFed() )
138 {
139 return new TagScmResult( tagSnapshotPromoteCommand.getCommandString(),
140 "Error code for Jazz SCM snapshot promote command - " + status,
141 errConsumer.getOutput(), false );
142 }
143 }
144
145
146 List<ScmFile> taggedFiles = new ArrayList<ScmFile>( fileSet.getFileList().size() );
147 for ( File f : fileSet.getFileList() )
148 {
149 taggedFiles.add( new ScmFile( f.getPath(), ScmFileStatus.TAGGED ) );
150 }
151
152
153
154
155 return new TagScmResult( tagCreateSnapshotCmd.getCommandString(), taggedFiles );
156 }
157
158
159
160 public JazzScmCommand createTagCreateSnapshotCommand( JazzScmProviderRepository repo, ScmFileSet fileSet,
161 String tag, ScmTagParameters scmTagParameters )
162 {
163 JazzScmCommand command =
164 new JazzScmCommand( JazzConstants.CMD_CREATE, JazzConstants.CMD_SUB_SNAPSHOT, repo, fileSet, getLogger() );
165
166 if ( tag != null && !tag.trim().equals( "" ) )
167 {
168 command.addArgument( JazzConstants.ARG_SNAPSHOT_NAME );
169 command.addArgument( tag );
170 }
171
172 String message = scmTagParameters.getMessage();
173 if ( message != null && !message.trim().equals( "" ) )
174 {
175 command.addArgument( JazzConstants.ARG_SNAPSHOT_DESCRIPTION );
176 command.addArgument( message );
177 }
178
179 command.addArgument( repo.getRepositoryWorkspace() );
180
181 return command;
182 }
183
184
185
186 public JazzScmCommand createTagSnapshotPromoteCommand( JazzScmProviderRepository repo, ScmFileSet fileSet,
187 String tag )
188 {
189 JazzScmCommand command =
190 new JazzScmCommand( JazzConstants.CMD_SNAPSHOT, JazzConstants.CMD_SUB_PROMOTE, repo, fileSet, getLogger() );
191
192 if ( repo.getFlowTarget() != null && !repo.getFlowTarget().equals( "" ) )
193 {
194 command.addArgument( repo.getFlowTarget() );
195 }
196 if ( tag != null && !tag.trim().equals( "" ) )
197 {
198 command.addArgument( tag );
199 }
200
201 return command;
202 }
203
204
205
206 public JazzScmCommand createTagDeliverCommand( JazzScmProviderRepository repo, ScmFileSet fileSet, String tag )
207 {
208 JazzScmCommand command = new JazzScmCommand( JazzConstants.CMD_DELIVER, repo, fileSet, getLogger() );
209
210 if ( repo.getWorkspace() != null && !repo.getWorkspace().equals( "" ) )
211 {
212
213
214 command.addArgument( JazzConstants.ARG_DELIVER_SOURCE );
215 command.addArgument( tag );
216 }
217
218 if ( repo.getFlowTarget() != null && !repo.getFlowTarget().equals( "" ) )
219 {
220 command.addArgument( JazzConstants.ARG_DELIVER_TARGET );
221 command.addArgument( repo.getFlowTarget() );
222 }
223
224 return command;
225 }
226
227
228
229 public JazzScmCommand createTagCreateWorkspaceCommand( JazzScmProviderRepository repo, ScmFileSet fileSet,
230 String tag )
231 {
232 JazzScmCommand command =
233 new JazzScmCommand( JazzConstants.CMD_CREATE, JazzConstants.CMD_SUB_WORKSPACE, repo, fileSet, getLogger() );
234
235 if ( tag != null && !tag.trim().equals( "" ) )
236 {
237 command.addArgument( tag );
238 command.addArgument( JazzConstants.ARG_WORKSPACE_SNAPSHOT );
239 command.addArgument( tag );
240 }
241
242 return command;
243 }
244
245 }