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