1 package org.apache.maven.scm.provider.jazz;
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.CommandParameters;
23 import org.apache.maven.scm.ScmException;
24 import org.apache.maven.scm.ScmFileSet;
25 import org.apache.maven.scm.command.add.AddScmResult;
26 import org.apache.maven.scm.command.blame.BlameScmResult;
27 import org.apache.maven.scm.command.branch.BranchScmResult;
28 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
29 import org.apache.maven.scm.command.checkin.CheckInScmResult;
30 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
31 import org.apache.maven.scm.command.diff.DiffScmResult;
32 import org.apache.maven.scm.command.edit.EditScmResult;
33 import org.apache.maven.scm.command.export.ExportScmResult;
34 import org.apache.maven.scm.command.list.ListScmResult;
35 import org.apache.maven.scm.command.status.StatusScmResult;
36 import org.apache.maven.scm.command.tag.TagScmResult;
37 import org.apache.maven.scm.command.unedit.UnEditScmResult;
38 import org.apache.maven.scm.command.update.UpdateScmResult;
39 import org.apache.maven.scm.provider.AbstractScmProvider;
40 import org.apache.maven.scm.provider.ScmProviderRepository;
41 import org.apache.maven.scm.provider.jazz.command.JazzConstants;
42 import org.apache.maven.scm.provider.jazz.command.add.JazzAddCommand;
43 import org.apache.maven.scm.provider.jazz.command.blame.JazzBlameCommand;
44 import org.apache.maven.scm.provider.jazz.command.branch.JazzBranchCommand;
45 import org.apache.maven.scm.provider.jazz.command.changelog.JazzChangeLogCommand;
46 import org.apache.maven.scm.provider.jazz.command.checkin.JazzCheckInCommand;
47 import org.apache.maven.scm.provider.jazz.command.checkout.JazzCheckOutCommand;
48 import org.apache.maven.scm.provider.jazz.command.diff.JazzDiffCommand;
49 import org.apache.maven.scm.provider.jazz.command.edit.JazzEditCommand;
50 import org.apache.maven.scm.provider.jazz.command.list.JazzListCommand;
51 import org.apache.maven.scm.provider.jazz.command.status.JazzStatusCommand;
52 import org.apache.maven.scm.provider.jazz.command.tag.JazzTagCommand;
53 import org.apache.maven.scm.provider.jazz.command.unedit.JazzUnEditCommand;
54 import org.apache.maven.scm.provider.jazz.command.update.JazzUpdateCommand;
55 import org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository;
56 import org.apache.maven.scm.repository.ScmRepositoryException;
57
58 import java.net.URI;
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76 public class JazzScmProvider
77 extends AbstractScmProvider
78 {
79
80
81 public static final String JAZZ_URL_FORMAT =
82 "scm:jazz:[username[;password]@]http[s]://server_name[:port]/contextRoot:repositoryWorkspace";
83
84
85
86
87
88 public String getScmType()
89 {
90 return JazzConstants.SCM_TYPE;
91 }
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108 public ScmProviderRepository makeProviderScmRepository( String scmUrl, char delimiter )
109 throws ScmRepositoryException
110 {
111
112
113
114 getLogger().debug( "JazzScmProvider:makeProviderScmRepository" );
115 getLogger().debug( "Provided scm url - " + scmUrl );
116 getLogger().debug( "Provided delimiter - '" + delimiter + "'" );
117
118 String jazzUrlAndWorkspace = null;
119 String usernameAndPassword = null;
120
121
122
123 int lastAtPosition = scmUrl.lastIndexOf( '@' );
124 if ( lastAtPosition == -1 )
125 {
126
127 jazzUrlAndWorkspace = scmUrl;
128 }
129 else
130 {
131
132 jazzUrlAndWorkspace = ( lastAtPosition < 0 ) ? scmUrl : scmUrl.substring( lastAtPosition + 1 );
133 usernameAndPassword = ( lastAtPosition < 0 ) ? null : scmUrl.substring( 0, lastAtPosition );
134 }
135
136
137
138
139
140 String username = null;
141 String password = null;
142
143 if ( usernameAndPassword != null )
144 {
145
146
147
148 int delimPosition = usernameAndPassword.indexOf( ';' );
149 username = delimPosition >= 0 ? usernameAndPassword.substring( 0, delimPosition ) : usernameAndPassword;
150 password = delimPosition >= 0 ? usernameAndPassword.substring( delimPosition + 1 ) : null;
151 }
152
153
154
155
156 int colonsCounted = 0;
157 int colonIndex = 0;
158 while ( colonIndex != -1 )
159 {
160 colonIndex = jazzUrlAndWorkspace.indexOf( ":", colonIndex + 1 );
161 if ( colonIndex != -1 )
162 {
163 colonsCounted++;
164 }
165 }
166
167 boolean havePort = colonsCounted == 3;
168
169
170 int repositoryWorkspacePosition = jazzUrlAndWorkspace.lastIndexOf( delimiter );
171 String repositoryWorkspace = jazzUrlAndWorkspace.substring( repositoryWorkspacePosition + 1 );
172 String jazzUrl = jazzUrlAndWorkspace.substring( 0, repositoryWorkspacePosition );
173
174
175 try
176 {
177
178 URI jazzUri = URI.create( jazzUrl );
179 String scheme = jazzUri.getScheme();
180 getLogger().debug( "Scheme - " + scheme );
181 if ( scheme == null || !( scheme.equalsIgnoreCase( "http" ) || scheme.equalsIgnoreCase( "https" ) ) )
182 {
183 throw new ScmRepositoryException(
184 "Jazz Url \"" + jazzUrl + "\" is not a valid URL. The Jazz Url syntax is " + JAZZ_URL_FORMAT );
185 }
186 }
187 catch ( IllegalArgumentException e )
188 {
189 throw new ScmRepositoryException(
190 "Jazz Url \"" + jazzUrl + "\" is not a valid URL. The Jazz Url syntax is " + JAZZ_URL_FORMAT );
191 }
192
193
194
195 String hostname = null;
196 int port = 0;
197
198 if ( havePort )
199 {
200
201
202 int protocolIndex = jazzUrl.indexOf( ":" ) + 3;
203 int portIndex = jazzUrl.indexOf( ":", protocolIndex + 1 );
204 hostname = jazzUrl.substring( protocolIndex, portIndex );
205 int pathIndex = jazzUrl.indexOf( "/", portIndex + 1 );
206 String portNo = jazzUrl.substring( portIndex + 1, pathIndex );
207 try
208 {
209 port = Integer.parseInt( portNo );
210 }
211 catch ( NumberFormatException nfe )
212 {
213 throw new ScmRepositoryException(
214 "Jazz Url \"" + jazzUrl + "\" is not a valid URL. The Jazz Url syntax is " + JAZZ_URL_FORMAT );
215 }
216 }
217 else
218 {
219
220
221
222 int protocolIndex = jazzUrl.indexOf( ":" ) + 3;
223 int pathIndex = jazzUrl.indexOf( "/", protocolIndex + 1 );
224 if ( ( protocolIndex != -1 ) && ( pathIndex != -1 ) )
225 {
226 hostname = jazzUrl.substring( protocolIndex, pathIndex );
227 }
228 else
229 {
230 throw new ScmRepositoryException(
231 "Jazz Url \"" + jazzUrl + "\" is not a valid URL. The Jazz Url syntax is " + JAZZ_URL_FORMAT );
232 }
233 }
234
235 getLogger().debug( "Creating JazzScmProviderRepository with the following values:" );
236 getLogger().debug( "jazzUrl - " + jazzUrl );
237 getLogger().debug( "username - " + username );
238 getLogger().debug( "password - " + password );
239 getLogger().debug( "hostname - " + hostname );
240 getLogger().debug( "port - " + port );
241 getLogger().debug( "repositoryWorkspace - " + repositoryWorkspace );
242
243 return new JazzScmProviderRepository( jazzUrl, username, password, hostname, port, repositoryWorkspace );
244 }
245
246
247
248
249 public AddScmResult add( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
250 throws ScmException
251 {
252 JazzAddCommand command = new JazzAddCommand();
253 command.setLogger( getLogger() );
254 return (AddScmResult) command.execute( repository, fileSet, parameters );
255 }
256
257
258
259
260 protected BranchScmResult branch( ScmProviderRepository repository, ScmFileSet fileSet,
261 CommandParameters parameters )
262 throws ScmException
263 {
264 JazzBranchCommand command = new JazzBranchCommand();
265 command.setLogger( getLogger() );
266 return (BranchScmResult) command.execute( repository, fileSet, parameters );
267 }
268
269
270
271
272 protected BlameScmResult blame( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
273 throws ScmException
274 {
275 JazzBlameCommand command = new JazzBlameCommand();
276 command.setLogger( getLogger() );
277 return (BlameScmResult) command.execute( repository, fileSet, parameters );
278 }
279
280
281
282
283 protected ChangeLogScmResult changelog( ScmProviderRepository repository, ScmFileSet fileSet,
284 CommandParameters parameters )
285 throws ScmException
286 {
287
288
289
290 JazzStatusCommand statusCommand = new JazzStatusCommand();
291 statusCommand.setLogger( getLogger() );
292 statusCommand.execute( repository, fileSet, parameters );
293
294 JazzChangeLogCommand command = new JazzChangeLogCommand();
295 command.setLogger( getLogger() );
296 return (ChangeLogScmResult) command.execute( repository, fileSet, parameters );
297 }
298
299
300
301
302 protected CheckInScmResult checkin( ScmProviderRepository repository, ScmFileSet fileSet,
303 CommandParameters parameters )
304 throws ScmException
305 {
306 JazzCheckInCommand command = new JazzCheckInCommand();
307 command.setLogger( getLogger() );
308 return (CheckInScmResult) command.execute( repository, fileSet, parameters );
309 }
310
311
312
313
314 protected CheckOutScmResult checkout( ScmProviderRepository repository, ScmFileSet fileSet,
315 CommandParameters parameters )
316 throws ScmException
317 {
318 JazzCheckOutCommand command = new JazzCheckOutCommand();
319 command.setLogger( getLogger() );
320 return (CheckOutScmResult) command.execute( repository, fileSet, parameters );
321 }
322
323
324
325
326 protected DiffScmResult diff( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
327 throws ScmException
328 {
329 JazzDiffCommand command = new JazzDiffCommand();
330 command.setLogger( getLogger() );
331 return (DiffScmResult) command.execute( repository, fileSet, parameters );
332 }
333
334
335
336
337 protected EditScmResult edit( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
338 throws ScmException
339 {
340 JazzEditCommand command = new JazzEditCommand();
341 command.setLogger( getLogger() );
342 return (EditScmResult) command.execute( repository, fileSet, parameters );
343 }
344
345
346
347
348 protected ExportScmResult export( ScmProviderRepository repository, ScmFileSet fileSet,
349 CommandParameters parameters )
350 throws ScmException
351 {
352
353 return super.export( repository, fileSet, parameters );
354 }
355
356
357
358
359 protected ListScmResult list( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
360 throws ScmException
361 {
362
363
364 JazzStatusCommand statusCommand = new JazzStatusCommand();
365 statusCommand.setLogger( getLogger() );
366 statusCommand.execute( repository, fileSet, parameters );
367
368 JazzListCommand command = new JazzListCommand();
369 command.setLogger( getLogger() );
370 return (ListScmResult) command.execute( repository, fileSet, parameters );
371 }
372
373
374
375
376 protected StatusScmResult status( ScmProviderRepository repository, ScmFileSet fileSet,
377 CommandParameters parameters )
378 throws ScmException
379 {
380 JazzStatusCommand command = new JazzStatusCommand();
381 command.setLogger( getLogger() );
382 return (StatusScmResult) command.execute( repository, fileSet, parameters );
383 }
384
385
386
387
388 protected TagScmResult tag( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
389 throws ScmException
390 {
391
392
393 JazzStatusCommand statusCommand = new JazzStatusCommand();
394 statusCommand.setLogger( getLogger() );
395 statusCommand.execute( repository, fileSet, parameters );
396
397 JazzTagCommand command = new JazzTagCommand();
398 command.setLogger( getLogger() );
399 return (TagScmResult) command.execute( repository, fileSet, parameters );
400 }
401
402
403
404
405 protected UpdateScmResult update( ScmProviderRepository repository, ScmFileSet fileSet,
406 CommandParameters parameters )
407 throws ScmException
408 {
409 JazzUpdateCommand command = new JazzUpdateCommand();
410 command.setLogger( getLogger() );
411 return (UpdateScmResult) command.execute( repository, fileSet, parameters );
412 }
413
414
415
416
417 protected UnEditScmResult unedit( ScmProviderRepository repository, ScmFileSet fileSet,
418 CommandParameters parameters )
419 throws ScmException
420 {
421 JazzUnEditCommand command = new JazzUnEditCommand();
422 command.setLogger( getLogger() );
423 return (UnEditScmResult) command.execute( repository, fileSet, parameters );
424 }
425
426
427
428
429 public String getScmSpecificFilename()
430 {
431 return JazzConstants.SCM_META_DATA_FOLDER;
432 }
433
434 }