001package org.apache.maven.scm.manager;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.maven.scm.ScmBranch;
023import org.apache.maven.scm.ScmException;
024import org.apache.maven.scm.ScmFileSet;
025import org.apache.maven.scm.ScmVersion;
026import org.apache.maven.scm.command.add.AddScmResult;
027import org.apache.maven.scm.command.blame.BlameScmRequest;
028import org.apache.maven.scm.command.blame.BlameScmResult;
029import org.apache.maven.scm.command.branch.BranchScmResult;
030import org.apache.maven.scm.command.changelog.ChangeLogScmRequest;
031import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
032import org.apache.maven.scm.command.checkin.CheckInScmResult;
033import org.apache.maven.scm.command.checkout.CheckOutScmResult;
034import org.apache.maven.scm.command.diff.DiffScmResult;
035import org.apache.maven.scm.command.edit.EditScmResult;
036import org.apache.maven.scm.command.export.ExportScmResult;
037import org.apache.maven.scm.command.list.ListScmResult;
038import org.apache.maven.scm.command.mkdir.MkdirScmResult;
039import org.apache.maven.scm.command.remove.RemoveScmResult;
040import org.apache.maven.scm.command.status.StatusScmResult;
041import org.apache.maven.scm.command.tag.TagScmResult;
042import org.apache.maven.scm.command.unedit.UnEditScmResult;
043import org.apache.maven.scm.command.update.UpdateScmResult;
044import org.apache.maven.scm.provider.ScmProvider;
045import org.apache.maven.scm.provider.ScmProviderStub;
046import org.apache.maven.scm.repository.ScmRepository;
047import org.apache.maven.scm.repository.ScmRepositoryException;
048import org.apache.maven.scm.repository.ScmRepositoryStub;
049import org.apache.maven.scm.repository.UnknownRepositoryStructure;
050
051import java.io.File;
052import java.util.ArrayList;
053import java.util.Date;
054import java.util.List;
055
056/**
057 * Stub implementation of ScmManager for unit testing purposes.
058 * It allows setting the expected results that the different methods will return.
059 * More information about Stubs on
060 * <a href="http://martinfowler.com/bliki/TestDouble.html">Martin Fowler's TestDouble</a>
061 *
062 * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
063 *
064 */
065public class ScmManagerStub
066    implements ScmManager
067{
068
069    private ScmRepository scmRepository;
070
071    private ScmProvider scmProvider;
072
073    private List<String> messages;
074
075    /**
076     * Creates a new stub with stub repository and provider, and empty list of messages
077     */
078    public ScmManagerStub()
079    {
080        setScmRepository( new ScmRepositoryStub() );
081        setScmProvider( new ScmProviderStub() );
082        setMessages( new ArrayList<String>( 0 ) );
083    }
084
085    public void setScmProvider( ScmProvider scmProvider )
086    {
087        this.scmProvider = scmProvider;
088    }
089
090    public ScmProvider getScmProvider()
091    {
092        return scmProvider;
093    }
094
095    /**
096     * {@inheritDoc}
097     */
098    public void setScmProvider( String providerType, ScmProvider provider )
099    {
100        setScmProvider( provider );
101    }
102
103    /**
104     * {@inheritDoc}
105     */
106    public void setScmProviderImplementation( String providerType, String providerImplementation )
107    {
108        //Do nothing there
109    }
110
111    public void setScmRepository( ScmRepository scmRepository )
112    {
113        this.scmRepository = scmRepository;
114    }
115
116    public ScmRepository getScmRepository()
117    {
118        return scmRepository;
119    }
120
121    /**
122     * Set the messages to return in validateScmRepository
123     *
124     * @param messages <code>List</code> of <code>String</code> objects
125     */
126    public void setMessages( List<String> messages )
127    {
128        this.messages = messages;
129    }
130
131    /**
132     * Get the messages to return in validateScmRepository
133     *
134     * @return <code>List</code> of <code>String</code> objects
135     */
136    public List<String> getMessages()
137    {
138        return messages;
139    }
140
141    /**
142     * {@inheritDoc}
143     */
144    public ScmRepository makeScmRepository( String scmUrl )
145        throws ScmRepositoryException, NoSuchScmProviderException
146    {
147        return getScmRepository();
148    }
149
150    /**
151     * {@inheritDoc}
152     */
153    public ScmRepository makeProviderScmRepository( String providerType, File path )
154        throws ScmRepositoryException, UnknownRepositoryStructure, NoSuchScmProviderException
155    {
156        return getScmRepository();
157    }
158
159    /**
160     * Returns the same list as getMessages()
161     *
162     * @param scmUrl ignored
163     * @return <code>List</code> of <code>String</code> objects, the same list returned by getMessages()
164     */
165    public List<String> validateScmRepository( String scmUrl )
166    {
167        return getMessages();
168    }
169
170    /**
171     * {@inheritDoc}
172     */
173    public ScmProvider getProviderByUrl( String scmUrl )
174        throws ScmRepositoryException, NoSuchScmProviderException
175    {
176        return getScmProvider();
177    }
178
179    /**
180     * {@inheritDoc}
181     */
182    public ScmProvider getProviderByType( String providerType )
183        throws NoSuchScmProviderException
184    {
185        return getScmProvider();
186    }
187
188    /**
189     * {@inheritDoc}
190     */
191    public ScmProvider getProviderByRepository( ScmRepository repository )
192        throws NoSuchScmProviderException
193    {
194        return getScmProvider();
195    }
196
197    /**
198     * {@inheritDoc}
199     */
200    public AddScmResult add( ScmRepository repository, ScmFileSet fileSet )
201        throws ScmException
202    {
203        return this.getProviderByRepository( repository ).add( repository, fileSet );
204    }
205
206    /**
207     * {@inheritDoc}
208     */
209    public AddScmResult add( ScmRepository repository, ScmFileSet fileSet, String message )
210        throws ScmException
211    {
212        return this.getProviderByRepository( repository ).add( repository, fileSet, message );
213    }
214
215    /**
216     * {@inheritDoc}
217     */
218    @SuppressWarnings( "deprecation" )
219    public BranchScmResult branch( ScmRepository repository, ScmFileSet fileSet, String branchName )
220        throws ScmException
221    {
222        return this.getProviderByRepository( repository ).branch( repository, fileSet, branchName );
223    }
224
225    /**
226     * {@inheritDoc}
227     */
228    @SuppressWarnings( "deprecation" )
229    public BranchScmResult branch( ScmRepository repository, ScmFileSet fileSet, String branchName, String message )
230        throws ScmException
231    {
232        return this.getProviderByRepository( repository ).branch( repository, fileSet, branchName, message );
233    }
234
235    /**
236     * {@inheritDoc}
237     */
238    public ChangeLogScmResult changeLog( ScmRepository repository, ScmFileSet fileSet, Date startDate, Date endDate,
239                                         int numDays, ScmBranch branch )
240        throws ScmException
241    {
242        return this.getProviderByRepository( repository ).changeLog( repository, fileSet, startDate, endDate, numDays,
243                                                                     branch );
244    }
245
246    /**
247     * {@inheritDoc}
248     */
249    public ChangeLogScmResult changeLog( ScmRepository repository, ScmFileSet fileSet, Date startDate, Date endDate,
250                                         int numDays, ScmBranch branch, String datePattern )
251        throws ScmException
252    {
253        return this.getProviderByRepository( repository ).changeLog( repository, fileSet, startDate, endDate, numDays,
254                                                                     branch, datePattern );
255    }
256
257    /**
258     * {@inheritDoc}
259     */
260    public ChangeLogScmResult changeLog( ChangeLogScmRequest request )
261        throws ScmException
262    {
263        final ScmRepository repository = request.getScmRepository();
264        return this.getProviderByRepository( repository ).changeLog( request );
265    }
266
267    /**
268     * {@inheritDoc}
269     */
270    public ChangeLogScmResult changeLog( ScmRepository repository, ScmFileSet fileSet, ScmVersion startVersion,
271                                         ScmVersion endVersion )
272        throws ScmException
273    {
274        return this.getProviderByRepository( repository ).changeLog( repository, fileSet, startVersion, endVersion );
275    }
276
277    /**
278     * {@inheritDoc}
279     */
280    public ChangeLogScmResult changeLog( ScmRepository repository, ScmFileSet fileSet, ScmVersion startRevision,
281                                         ScmVersion endRevision, String datePattern )
282        throws ScmException
283    {
284        return this.getProviderByRepository( repository ).changeLog( repository, fileSet, startRevision, endRevision,
285                                                                     datePattern );
286    }
287
288    /**
289     * {@inheritDoc}
290     */
291    public CheckInScmResult checkIn( ScmRepository repository, ScmFileSet fileSet, String message )
292        throws ScmException
293    {
294        return this.getProviderByRepository( repository ).checkIn( repository, fileSet, message );
295    }
296
297    /**
298     * {@inheritDoc}
299     */
300    public CheckInScmResult checkIn( ScmRepository repository, ScmFileSet fileSet, ScmVersion revision, String message )
301        throws ScmException
302    {
303        return this.getProviderByRepository( repository ).checkIn( repository, fileSet, revision, message );
304    }
305
306    /**
307     * {@inheritDoc}
308     */
309    public CheckOutScmResult checkOut( ScmRepository repository, ScmFileSet fileSet )
310        throws ScmException
311    {
312        return this.getProviderByRepository( repository ).checkOut( repository, fileSet );
313    }
314
315    /**
316     * {@inheritDoc}
317     */
318    public CheckOutScmResult checkOut( ScmRepository repository, ScmFileSet fileSet, ScmVersion version )
319        throws ScmException
320    {
321        return this.getProviderByRepository( repository ).checkOut( repository, fileSet, version );
322    }
323
324    /**
325     * {@inheritDoc}
326     */
327    public CheckOutScmResult checkOut( ScmRepository repository, ScmFileSet fileSet, boolean recursive )
328        throws ScmException
329    {
330        return this.getProviderByRepository( repository ).checkOut( repository, fileSet, recursive );
331    }
332
333    /**
334     * {@inheritDoc}
335     */
336    public CheckOutScmResult checkOut( ScmRepository repository, ScmFileSet fileSet, ScmVersion version,
337                                       boolean recursive )
338        throws ScmException
339    {
340        return this.getProviderByRepository( repository ).checkOut( repository, fileSet, version, recursive );
341    }
342
343    /**
344     * {@inheritDoc}
345     */
346    public DiffScmResult diff( ScmRepository repository, ScmFileSet fileSet, ScmVersion startVersion,
347                               ScmVersion endVersion )
348        throws ScmException
349    {
350        return this.getProviderByRepository( repository ).diff( repository, fileSet, startVersion, endVersion );
351    }
352
353    /**
354     * {@inheritDoc}
355     */
356    public EditScmResult edit( ScmRepository repository, ScmFileSet fileSet )
357        throws ScmException
358    {
359        return this.getProviderByRepository( repository ).edit( repository, fileSet );
360    }
361
362    /**
363     * {@inheritDoc}
364     */
365    public ExportScmResult export( ScmRepository repository, ScmFileSet fileSet )
366        throws ScmException
367    {
368        return this.getProviderByRepository( repository ).export( repository, fileSet );
369    }
370
371    /**
372     * {@inheritDoc}
373     */
374    public ExportScmResult export( ScmRepository repository, ScmFileSet fileSet, ScmVersion version )
375        throws ScmException
376    {
377        return this.getProviderByRepository( repository ).export( repository, fileSet, version );
378    }
379
380    /**
381     * {@inheritDoc}
382     */
383    public ExportScmResult export( ScmRepository repository, ScmFileSet fileSet, String outputDirectory )
384        throws ScmException
385    {
386        return this.export( repository, fileSet, outputDirectory );
387    }
388
389    /**
390     * {@inheritDoc}
391     */
392    public ExportScmResult export( ScmRepository repository, ScmFileSet fileSet, ScmVersion version,
393                                   String outputDirectory )
394        throws ScmException
395    {
396        return this.getProviderByRepository( repository ).export( repository, fileSet, version, outputDirectory );
397    }
398
399    /**
400     * {@inheritDoc}
401     */
402    public ListScmResult list( ScmRepository repository, ScmFileSet fileSet, boolean recursive, ScmVersion version )
403        throws ScmException
404    {
405        return this.getProviderByRepository( repository ).list( repository, fileSet, recursive, version );
406    }
407
408    /**
409     * {@inheritDoc}
410     */
411    public RemoveScmResult remove( ScmRepository repository, ScmFileSet fileSet, String message )
412        throws ScmException
413    {
414        return this.getProviderByRepository( repository ).remove( repository, fileSet, message );
415    }
416
417    /**
418     * {@inheritDoc}
419     */
420    public StatusScmResult status( ScmRepository repository, ScmFileSet fileSet )
421        throws ScmException
422    {
423        return this.getProviderByRepository( repository ).status( repository, fileSet );
424    }
425
426    /**
427     * {@inheritDoc}
428     */
429    @SuppressWarnings( "deprecation" )
430    public TagScmResult tag( ScmRepository repository, ScmFileSet fileSet, String tagName )
431        throws ScmException
432    {
433        return this.getProviderByRepository( repository ).tag( repository, fileSet, tagName );
434    }
435
436    /**
437     * {@inheritDoc}
438     */
439    @SuppressWarnings( "deprecation" )
440    public TagScmResult tag( ScmRepository repository, ScmFileSet fileSet, String tagName, String message )
441        throws ScmException
442    {
443        return this.getProviderByRepository( repository ).tag( repository, fileSet, tagName, message );
444    }
445
446    /**
447     * {@inheritDoc}
448     */
449    public UnEditScmResult unedit( ScmRepository repository, ScmFileSet fileSet )
450        throws ScmException
451    {
452        return this.getProviderByRepository( repository ).unedit( repository, fileSet );
453    }
454
455    /**
456     * {@inheritDoc}
457     */
458    public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet )
459        throws ScmException
460    {
461        return this.getProviderByRepository( repository ).update( repository, fileSet );
462    }
463
464    /**
465     * {@inheritDoc}
466     */
467    public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, ScmVersion version )
468        throws ScmException
469    {
470        return this.getProviderByRepository( repository ).update( repository, fileSet, version );
471    }
472
473    /**
474     * {@inheritDoc}
475     */
476    public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, boolean runChangelog )
477        throws ScmException
478    {
479        return this.getProviderByRepository( repository ).update( repository, fileSet, runChangelog );
480    }
481
482    /**
483     * {@inheritDoc}
484     */
485    public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, ScmVersion version,
486                                   boolean runChangelog )
487        throws ScmException
488    {
489        return this.getProviderByRepository( repository ).update( repository, fileSet, version, runChangelog );
490    }
491
492    /**
493     * {@inheritDoc}
494     */
495    public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, String datePattern )
496        throws ScmException
497    {
498        return this.getProviderByRepository( repository ).update( repository, fileSet, (ScmVersion) null, datePattern );
499    }
500
501    /**
502     * {@inheritDoc}
503     */
504    public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, ScmVersion version,
505                                   String datePattern )
506        throws ScmException
507    {
508        return this.getProviderByRepository( repository ).update( repository, fileSet, version, datePattern );
509    }
510
511    /**
512     * {@inheritDoc}
513     */
514    public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, Date lastUpdate )
515        throws ScmException
516    {
517        return this.getProviderByRepository( repository ).update( repository, fileSet, (ScmVersion) null, lastUpdate );
518    }
519
520    /**
521     * {@inheritDoc}
522     */
523    public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, ScmVersion version, Date lastUpdate )
524        throws ScmException
525    {
526        return this.getProviderByRepository( repository ).update( repository, fileSet, version, lastUpdate );
527    }
528
529    /**
530     * {@inheritDoc}
531     */
532    public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, Date lastUpdate, String datePattern )
533        throws ScmException
534    {
535        return this.getProviderByRepository( repository ).update( repository, fileSet, (ScmVersion) null, lastUpdate,
536                                                                  datePattern );
537    }
538
539    /**
540     * {@inheritDoc}
541     */
542    public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, ScmVersion version, Date lastUpdate,
543                                   String datePattern )
544        throws ScmException
545    {
546        return this.getProviderByRepository( repository ).update( repository, fileSet, version, lastUpdate,
547                                                                  datePattern );
548    }
549
550    /**
551     * {@inheritDoc}
552     */
553    public BlameScmResult blame( ScmRepository repository, ScmFileSet fileSet, String filename )
554        throws ScmException
555    {
556        return this.getProviderByRepository( repository ).blame( repository, fileSet, filename );
557    }
558
559    public BlameScmResult blame( BlameScmRequest blameScmRequest )
560        throws ScmException
561    {
562        return this.getProviderByRepository( blameScmRequest.getScmRepository() ).blame( blameScmRequest );
563    }
564
565    /**
566     * {@inheritDoc}
567     */
568    public MkdirScmResult mkdir( ScmRepository repository, ScmFileSet fileSet, String message, boolean createInLocal )
569        throws ScmException
570    {
571        return this.getProviderByRepository( repository ).mkdir( repository, fileSet, message, createInLocal );
572    }
573}