1 package org.apache.maven.scm.provider.jazz.command.checkin;
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.util.List;
24
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.add.AddScmResult;
29 import org.apache.maven.scm.command.checkin.AbstractCheckInCommand;
30 import org.apache.maven.scm.command.checkin.CheckInScmResult;
31 import org.apache.maven.scm.provider.ScmProviderRepository;
32 import org.apache.maven.scm.provider.jazz.command.JazzConstants;
33 import org.apache.maven.scm.provider.jazz.command.JazzScmCommand;
34 import org.apache.maven.scm.provider.jazz.command.add.JazzAddCommand;
35 import org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer;
36 import org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer;
37 import org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository;
38 import org.codehaus.plexus.util.StringUtils;
39 import org.codehaus.plexus.util.cli.StreamConsumer;
40
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 public class JazzCheckInCommand
84 extends AbstractCheckInCommand
85 {
86
87
88
89
90 protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repository, ScmFileSet fileSet,
91 String message, ScmVersion scmVersion )
92 throws ScmException
93 {
94 if ( scmVersion != null && StringUtils.isNotEmpty( scmVersion.getName() ) )
95 {
96 throw new ScmException( "This provider command can't handle tags." );
97 }
98
99 if ( getLogger().isDebugEnabled() )
100 {
101 getLogger().debug( "Executing checkin command..." );
102 }
103
104
105
106 JazzScmCommand createChangesetCmd = createCreateChangesetCommand( repository, fileSet, message );
107 DebugLoggerConsumer outputConsumer = new DebugLoggerConsumer( getLogger() );
108 ErrorConsumer errConsumer = new ErrorConsumer( getLogger() );
109
110 int status = createChangesetCmd.execute( outputConsumer, errConsumer );
111 if ( status != 0 || errConsumer.hasBeenFed() )
112 {
113 return new CheckInScmResult( createChangesetCmd.getCommandString(),
114 "Error code for Jazz SCM create changeset command - " + status,
115 errConsumer.getOutput(), false );
116 }
117
118
119 return executeCheckInCommand( repository, fileSet, scmVersion );
120 }
121
122 protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repo, ScmFileSet fileSet,
123 ScmVersion scmVersion )
124 throws ScmException
125 {
126
127 JazzAddCommand addCommand = new JazzAddCommand();
128 addCommand.setLogger( getLogger() );
129 AddScmResult addResult = addCommand.executeAddCommand( repo, fileSet );
130
131
132 JazzScmProviderRepository jazzRepo = (JazzScmProviderRepository) repo;
133 if ( jazzRepo.isPushChangesAndHaveFlowTargets() )
134 {
135
136 JazzScmCommand deliverCmd = createDeliverCommand( (JazzScmProviderRepository) repo, fileSet );
137 StreamConsumer deliverConsumer =
138 new DebugLoggerConsumer( getLogger() );
139 ErrorConsumer errConsumer = new ErrorConsumer( getLogger() );
140
141 int status = deliverCmd.execute( deliverConsumer, errConsumer );
142 if ( status != 0 || errConsumer.hasBeenFed() )
143 {
144 return new CheckInScmResult( deliverCmd.getCommandString(),
145 "Error code for Jazz SCM deliver command - " + status,
146 errConsumer.getOutput(), false );
147 }
148 }
149
150
151 return new CheckInScmResult( addResult.getCommandLine(), addResult.getAddedFiles() );
152 }
153
154 public JazzScmCommand createCreateChangesetCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message )
155 {
156 JazzScmCommand command =
157 new JazzScmCommand( JazzConstants.CMD_CREATE, JazzConstants.CMD_SUB_CHANGESET, repo, false, fileSet,
158 getLogger() );
159 command.addArgument( message );
160
161 return command;
162 }
163
164 public JazzScmCommand createCheckInCommand( ScmProviderRepository repo, ScmFileSet fileSet )
165 {
166 JazzScmCommand command =
167 new JazzScmCommand( JazzConstants.CMD_CHECKIN, null, repo, false, fileSet, getLogger() );
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182 List<File> files = fileSet.getFileList();
183 if ( files != null && !files.isEmpty() )
184 {
185 for ( File file : files )
186 {
187 command.addArgument( file.getPath() );
188 }
189 }
190 else
191 {
192 command.addArgument( "." );
193 }
194
195 return command;
196 }
197
198
199
200 public JazzScmCommand createDeliverCommand( JazzScmProviderRepository repo, ScmFileSet fileSet )
201 {
202 JazzScmCommand command = new JazzScmCommand( JazzConstants.CMD_DELIVER, repo, fileSet, getLogger() );
203
204 if ( repo.getWorkspace() != null && !repo.getWorkspace().equals( "" ) )
205 {
206 command.addArgument( JazzConstants.ARG_DELIVER_SOURCE );
207 command.addArgument( repo.getWorkspace() );
208 }
209
210 if ( repo.getFlowTarget() != null && !repo.getFlowTarget().equals( "" ) )
211 {
212 command.addArgument( JazzConstants.ARG_DELIVER_TARGET );
213 command.addArgument( repo.getFlowTarget() );
214 }
215
216
217
218
219
220
221
222
223
224
225
226 command.addArgument( JazzConstants.ARG_OVERWRITE_UNCOMMITTED );
227
228 return command;
229 }
230 }