View Javadoc

1   package org.apache.maven.scm.manager;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.scm.ScmBranch;
23  import org.apache.maven.scm.ScmException;
24  import org.apache.maven.scm.ScmFileSet;
25  import org.apache.maven.scm.ScmVersion;
26  import org.apache.maven.scm.command.add.AddScmResult;
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.remove.RemoveScmResult;
36  import org.apache.maven.scm.command.status.StatusScmResult;
37  import org.apache.maven.scm.command.tag.TagScmResult;
38  import org.apache.maven.scm.command.unedit.UnEditScmResult;
39  import org.apache.maven.scm.command.update.UpdateScmResult;
40  import org.apache.maven.scm.provider.ScmProvider;
41  import org.apache.maven.scm.provider.ScmProviderStub;
42  import org.apache.maven.scm.repository.ScmRepository;
43  import org.apache.maven.scm.repository.ScmRepositoryException;
44  import org.apache.maven.scm.repository.ScmRepositoryStub;
45  import org.apache.maven.scm.repository.UnknownRepositoryStructure;
46  
47  import java.io.File;
48  import java.util.ArrayList;
49  import java.util.Date;
50  import java.util.List;
51  
52  /**
53   * Stub implementation of ScmManager for unit testing purposes. It allows setting the expected results that the different methods will return.
54   * More information about Stubs on <a href="http://martinfowler.com/bliki/TestDouble.html">Martin Fowler's TestDouble</a>
55   *
56   * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
57   * @version $Id: ScmManagerStub.java 540587 2007-05-22 14:00:13Z evenisse $
58   */
59  public class ScmManagerStub
60      implements ScmManager
61  {
62  
63      private ScmRepository scmRepository;
64  
65      private ScmProvider scmProvider;
66  
67      private List messages;
68  
69      /**
70       * Creates a new stub with stub repository and provider, and empty list of messages
71       */
72      public ScmManagerStub()
73      {
74          setScmRepository( new ScmRepositoryStub() );
75          setScmProvider( new ScmProviderStub() );
76          setMessages( new ArrayList( 0 ) );
77      }
78  
79      public void setScmProvider( ScmProvider scmProvider )
80      {
81          this.scmProvider = scmProvider;
82      }
83  
84      public ScmProvider getScmProvider()
85      {
86          return scmProvider;
87      }
88  
89      public void setScmProvider( String providerType, ScmProvider provider )
90      {
91          setScmProvider( provider );
92      }
93  
94      public void setScmProviderImplementation( String providerType, String providerImplementation )
95      {
96          //Do nothing there
97      }
98  
99      public void setScmRepository( ScmRepository scmRepository )
100     {
101         this.scmRepository = scmRepository;
102     }
103 
104     public ScmRepository getScmRepository()
105     {
106         return scmRepository;
107     }
108 
109     /**
110      * Set the messages to return in validateScmRepository
111      *
112      * @param messages <code>List</code> of <code>String</code> objects
113      */
114     public void setMessages( List messages )
115     {
116         this.messages = messages;
117     }
118 
119     /**
120      * Get the messages to return in validateScmRepository
121      *
122      * @return <code>List</code> of <code>String</code> objects
123      */
124     public List getMessages()
125     {
126         return messages;
127     }
128 
129     /**
130      * @return getScmRepository()
131      */
132     public ScmRepository makeScmRepository( String scmUrl )
133         throws ScmRepositoryException, NoSuchScmProviderException
134     {
135         return getScmRepository();
136     }
137 
138     /**
139      * @return getScmRepository()
140      */
141     public ScmRepository makeProviderScmRepository( String providerType, File path )
142         throws ScmRepositoryException, UnknownRepositoryStructure, NoSuchScmProviderException
143     {
144         return getScmRepository();
145     }
146 
147     /**
148      * Returns the same list as getMessages()
149      *
150      * @param scmUrl ignored
151      * @return <code>List</code> of <code>String</code> objects, the same list returned by getMessages()
152      */
153     public List validateScmRepository( String scmUrl )
154     {
155         return getMessages();
156     }
157 
158     /**
159      * @return getScmProvider()
160      */
161     public ScmProvider getProviderByUrl( String scmUrl )
162         throws ScmRepositoryException, NoSuchScmProviderException
163     {
164         return getScmProvider();
165     }
166 
167     /**
168      * @return getScmProvider()
169      */
170     public ScmProvider getProviderByType( String providerType )
171         throws NoSuchScmProviderException
172     {
173         return getScmProvider();
174     }
175 
176     /**
177      * @return getScmProvider()
178      */
179     public ScmProvider getProviderByRepository( ScmRepository repository )
180         throws NoSuchScmProviderException
181     {
182         return getScmProvider();
183     }
184 
185     /**
186      *
187      */
188     public AddScmResult add( ScmRepository repository, ScmFileSet fileSet )
189         throws ScmException
190     {
191         return this.getProviderByRepository( repository ).add( repository, fileSet );
192     }
193 
194     /**
195      *
196      */
197     public AddScmResult add( ScmRepository repository, ScmFileSet fileSet, String message )
198         throws ScmException
199     {
200         return this.getProviderByRepository( repository ).add( repository, fileSet, message );
201     }
202 
203     /**
204      *
205      */
206     public BranchScmResult branch( ScmRepository repository, ScmFileSet fileSet, String branchName )
207         throws ScmException
208     {
209         return this.getProviderByRepository( repository ).branch( repository, fileSet, branchName );
210     }
211 
212     /**
213      *
214      */
215     public BranchScmResult branch( ScmRepository repository, ScmFileSet fileSet, String branchName, String message )
216         throws ScmException
217     {
218         return this.getProviderByRepository( repository ).branch( repository, fileSet, branchName, message );
219     }
220 
221     /**
222      *
223      */
224     public ChangeLogScmResult changeLog( ScmRepository repository, ScmFileSet fileSet, Date startDate, Date endDate,
225                                          int numDays, ScmBranch branch )
226         throws ScmException
227     {
228         return this.getProviderByRepository( repository ).changeLog( repository, fileSet, startDate, endDate, numDays,
229                                                                      branch );
230     }
231 
232     /**
233      *
234      */
235     public ChangeLogScmResult changeLog( ScmRepository repository, ScmFileSet fileSet, Date startDate, Date endDate,
236                                          int numDays, ScmBranch branch, String datePattern )
237         throws ScmException
238     {
239         return this.getProviderByRepository( repository ).changeLog( repository, fileSet, startDate, endDate, numDays,
240                                                                      branch, datePattern );
241     }
242 
243     /**
244      *
245      */
246     public ChangeLogScmResult changeLog( ScmRepository repository, ScmFileSet fileSet, ScmVersion startVersion,
247                                          ScmVersion endVersion )
248         throws ScmException
249     {
250         return this.getProviderByRepository( repository ).changeLog( repository, fileSet, startVersion, endVersion );
251     }
252 
253     /**
254      *
255      */
256     public ChangeLogScmResult changeLog( ScmRepository repository, ScmFileSet fileSet, ScmVersion startRevision,
257                                          ScmVersion endRevision, String datePattern )
258         throws ScmException
259     {
260         return this.getProviderByRepository( repository ).changeLog( repository, fileSet, startRevision, endRevision,
261                                                                      datePattern );
262     }
263 
264     /**
265      *
266      */
267     public CheckInScmResult checkIn( ScmRepository repository, ScmFileSet fileSet, String message )
268         throws ScmException
269     {
270         return this.getProviderByRepository( repository ).checkIn( repository, fileSet, message );
271     }
272 
273     /**
274      *
275      */
276     public CheckInScmResult checkIn( ScmRepository repository, ScmFileSet fileSet, ScmVersion revision, String message )
277         throws ScmException
278     {
279         return this.getProviderByRepository( repository ).checkIn( repository, fileSet, revision, message );
280     }
281 
282     /**
283      *
284      */
285     public CheckOutScmResult checkOut( ScmRepository repository, ScmFileSet fileSet )
286         throws ScmException
287     {
288         return this.getProviderByRepository( repository ).checkOut( repository, fileSet );
289     }
290 
291     /**
292      *
293      */
294     public CheckOutScmResult checkOut( ScmRepository repository, ScmFileSet fileSet, ScmVersion version )
295         throws ScmException
296     {
297         return this.getProviderByRepository( repository ).checkOut( repository, fileSet, version );
298     }
299 
300     /**
301      *
302      */
303     public CheckOutScmResult checkOut( ScmRepository repository, ScmFileSet fileSet, boolean recursive )
304         throws ScmException
305     {
306         return this.getProviderByRepository( repository ).checkOut( repository, fileSet, recursive );
307     }
308 
309     /**
310      *
311      */
312     public CheckOutScmResult checkOut( ScmRepository repository, ScmFileSet fileSet, ScmVersion version,
313                                        boolean recursive )
314         throws ScmException
315     {
316         return this.getProviderByRepository( repository ).checkOut( repository, fileSet, version, recursive );
317     }
318 
319     /**
320      *
321      */
322     public DiffScmResult diff( ScmRepository repository, ScmFileSet fileSet, ScmVersion startVersion,
323                                ScmVersion endVersion )
324         throws ScmException
325     {
326         return this.getProviderByRepository( repository ).diff( repository, fileSet, startVersion, endVersion );
327     }
328 
329     /**
330      *
331      */
332     public EditScmResult edit( ScmRepository repository, ScmFileSet fileSet )
333         throws ScmException
334     {
335         return this.getProviderByRepository( repository ).edit( repository, fileSet );
336     }
337 
338     /**
339      *
340      */
341     public ExportScmResult export( ScmRepository repository, ScmFileSet fileSet )
342         throws ScmException
343     {
344         return this.getProviderByRepository( repository ).export( repository, fileSet );
345     }
346 
347     /**
348      *
349      */
350     public ExportScmResult export( ScmRepository repository, ScmFileSet fileSet, ScmVersion version )
351         throws ScmException
352     {
353         return this.getProviderByRepository( repository ).export( repository, fileSet, version );
354     }
355 
356     /**
357      *
358      */
359     public ExportScmResult export( ScmRepository repository, ScmFileSet fileSet, String outputDirectory )
360         throws ScmException
361     {
362         return this.export( repository, fileSet, outputDirectory );
363     }
364 
365     /**
366      *
367      */
368     public ExportScmResult export( ScmRepository repository, ScmFileSet fileSet, ScmVersion version,
369                                    String outputDirectory )
370         throws ScmException
371     {
372         return this.getProviderByRepository( repository ).export( repository, fileSet, version, outputDirectory );
373     }
374 
375     /**
376      *
377      */
378     public ListScmResult list( ScmRepository repository, ScmFileSet fileSet, boolean recursive, ScmVersion version )
379         throws ScmException
380     {
381         return this.getProviderByRepository( repository ).list( repository, fileSet, recursive, version );
382     }
383 
384     /**
385      *
386      */
387     public RemoveScmResult remove( ScmRepository repository, ScmFileSet fileSet, String message )
388         throws ScmException
389     {
390         return this.getProviderByRepository( repository ).remove( repository, fileSet, message );
391     }
392 
393     /**
394      *
395      */
396     public StatusScmResult status( ScmRepository repository, ScmFileSet fileSet )
397         throws ScmException
398     {
399         return this.getProviderByRepository( repository ).status( repository, fileSet );
400     }
401 
402     /**
403      *
404      */
405     public TagScmResult tag( ScmRepository repository, ScmFileSet fileSet, String tagName )
406         throws ScmException
407     {
408         return this.getProviderByRepository( repository ).tag( repository, fileSet, tagName );
409     }
410 
411     /**
412      *
413      */
414     public TagScmResult tag( ScmRepository repository, ScmFileSet fileSet, String tagName, String message )
415         throws ScmException
416     {
417         return this.getProviderByRepository( repository ).tag( repository, fileSet, tagName, message );
418     }
419 
420     /**
421      *
422      */
423     public UnEditScmResult unedit( ScmRepository repository, ScmFileSet fileSet )
424         throws ScmException
425     {
426         return this.getProviderByRepository( repository ).unedit( repository, fileSet );
427     }
428 
429     /**
430      *
431      */
432     public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet )
433         throws ScmException
434     {
435         return this.getProviderByRepository( repository ).update( repository, fileSet );
436     }
437 
438     /**
439      *
440      */
441     public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, ScmVersion version )
442         throws ScmException
443     {
444         return this.getProviderByRepository( repository ).update( repository, fileSet, version );
445     }
446 
447     /**
448      *
449      */
450     public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, boolean runChangelog )
451         throws ScmException
452     {
453         return this.getProviderByRepository( repository ).update( repository, fileSet, runChangelog );
454     }
455 
456     /**
457      *
458      */
459     public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, ScmVersion version,
460                                    boolean runChangelog )
461         throws ScmException
462     {
463         return this.getProviderByRepository( repository ).update( repository, fileSet, version, runChangelog );
464     }
465 
466     /**
467      *
468      */
469     public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, String datePattern )
470         throws ScmException
471     {
472         return this.getProviderByRepository( repository ).update( repository, fileSet, (ScmVersion) null, datePattern );
473     }
474 
475     /**
476      *
477      */
478     public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, ScmVersion version,
479                                    String datePattern )
480         throws ScmException
481     {
482         return this.getProviderByRepository( repository ).update( repository, fileSet, version, datePattern );
483     }
484 
485     /**
486      *
487      */
488     public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, Date lastUpdate )
489         throws ScmException
490     {
491         return this.getProviderByRepository( repository ).update( repository, fileSet, (ScmVersion) null, lastUpdate );
492     }
493 
494     /**
495      *
496      */
497     public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, ScmVersion version, Date lastUpdate )
498         throws ScmException
499     {
500         return this.getProviderByRepository( repository ).update( repository, fileSet, version, lastUpdate );
501     }
502 
503     /**
504      *
505      */
506     public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, Date lastUpdate, String datePattern )
507         throws ScmException
508     {
509         return this.getProviderByRepository( repository ).update( repository, fileSet, (ScmVersion) null, lastUpdate,
510                                                                   datePattern );
511     }
512 
513     /**
514      *
515      */
516     public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, ScmVersion version, Date lastUpdate,
517                                    String datePattern )
518         throws ScmException
519     {
520         return this.getProviderByRepository( repository ).update( repository, fileSet, version, lastUpdate,
521                                                                   datePattern );
522     }
523 }