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