View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.scm.provider;
20  
21  import java.io.File;
22  import java.util.ArrayList;
23  import java.util.Date;
24  import java.util.List;
25  
26  import org.apache.maven.scm.CommandParameter;
27  import org.apache.maven.scm.CommandParameters;
28  import org.apache.maven.scm.NoSuchCommandScmException;
29  import org.apache.maven.scm.ScmBranch;
30  import org.apache.maven.scm.ScmBranchParameters;
31  import org.apache.maven.scm.ScmException;
32  import org.apache.maven.scm.ScmFileSet;
33  import org.apache.maven.scm.ScmRevision;
34  import org.apache.maven.scm.ScmTagParameters;
35  import org.apache.maven.scm.ScmVersion;
36  import org.apache.maven.scm.command.add.AddScmResult;
37  import org.apache.maven.scm.command.blame.BlameScmRequest;
38  import org.apache.maven.scm.command.blame.BlameScmResult;
39  import org.apache.maven.scm.command.branch.BranchScmResult;
40  import org.apache.maven.scm.command.changelog.ChangeLogScmRequest;
41  import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
42  import org.apache.maven.scm.command.checkin.CheckInScmResult;
43  import org.apache.maven.scm.command.checkout.CheckOutScmResult;
44  import org.apache.maven.scm.command.diff.DiffScmResult;
45  import org.apache.maven.scm.command.edit.EditScmResult;
46  import org.apache.maven.scm.command.export.ExportScmResult;
47  import org.apache.maven.scm.command.info.InfoScmResult;
48  import org.apache.maven.scm.command.list.ListScmResult;
49  import org.apache.maven.scm.command.login.LoginScmResult;
50  import org.apache.maven.scm.command.mkdir.MkdirScmResult;
51  import org.apache.maven.scm.command.remoteinfo.RemoteInfoScmResult;
52  import org.apache.maven.scm.command.remove.RemoveScmResult;
53  import org.apache.maven.scm.command.status.StatusScmResult;
54  import org.apache.maven.scm.command.tag.TagScmResult;
55  import org.apache.maven.scm.command.unedit.UnEditScmResult;
56  import org.apache.maven.scm.command.untag.UntagScmResult;
57  import org.apache.maven.scm.command.update.UpdateScmResult;
58  import org.apache.maven.scm.repository.ScmRepository;
59  import org.apache.maven.scm.repository.ScmRepositoryException;
60  import org.apache.maven.scm.repository.UnknownRepositoryStructure;
61  import org.codehaus.plexus.util.StringUtils;
62  import org.slf4j.Logger;
63  import org.slf4j.LoggerFactory;
64  
65  /**
66   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
67   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
68   * @author Olivier Lamy
69   *
70   */
71  public abstract class AbstractScmProvider implements ScmProvider {
72      protected final Logger logger = LoggerFactory.getLogger(getClass());
73  
74      // ----------------------------------------------------------------------
75      //
76      // ----------------------------------------------------------------------
77  
78      /**
79       * {@inheritDoc}
80       */
81      @Override
82      public String getScmSpecificFilename() {
83          return null;
84      }
85  
86      /**
87       * {@inheritDoc}
88       */
89      @Override
90      public String sanitizeTagName(String tag) {
91          /* by default, we assume all tags are valid. */
92          return tag;
93      }
94  
95      /**
96       * {@inheritDoc}
97       */
98      @Override
99      public boolean validateTagName(String tag) {
100         /* by default, we assume all tags are valid. */
101         return true;
102     }
103 
104     /**
105      * {@inheritDoc}
106      */
107     @Override
108     public List<String> validateScmUrl(String scmSpecificUrl, char delimiter) {
109         List<String> messages = new ArrayList<String>();
110 
111         try {
112             makeProviderScmRepository(scmSpecificUrl, delimiter);
113         } catch (ScmRepositoryException e) {
114             messages.add(e.getMessage());
115         }
116 
117         return messages;
118     }
119 
120     /**
121      * {@inheritDoc}
122      */
123     @Override
124     public boolean requiresEditMode() {
125         return false;
126     }
127 
128     // ----------------------------------------------------------------------
129     // Scm Implementation
130     // ----------------------------------------------------------------------
131 
132     /**
133      * {@inheritDoc}
134      */
135     @Override
136     public AddScmResult add(ScmRepository repository, ScmFileSet fileSet) throws ScmException {
137         return add(repository, fileSet, (String) null);
138     }
139 
140     /**
141      * {@inheritDoc}
142      */
143     @Override
144     public AddScmResult add(ScmRepository repository, ScmFileSet fileSet, String message) throws ScmException {
145         login(repository, fileSet);
146 
147         CommandParameters parameters = new CommandParameters();
148 
149         parameters.setString(CommandParameter.MESSAGE, message == null ? "" : message);
150 
151         // TODO: binary may be dependant on particular files though
152         // TODO: set boolean?
153         parameters.setString(CommandParameter.BINARY, "false");
154 
155         return add(repository.getProviderRepository(), fileSet, parameters);
156     }
157 
158     @Override
159     public AddScmResult add(ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters)
160             throws ScmException {
161         login(repository, fileSet);
162 
163         if (parameters.getString(CommandParameter.BINARY, null) == null) {
164             // TODO: binary may be dependant on particular files though
165             // TODO: set boolean?
166             parameters.setString(CommandParameter.BINARY, "false");
167         }
168 
169         return add(repository.getProviderRepository(), fileSet, parameters);
170     }
171 
172     /**
173      * TODO: why public? This should be protected, no?
174      */
175     public AddScmResult add(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
176             throws ScmException {
177         throw new NoSuchCommandScmException("add");
178     }
179 
180     /**
181      * {@inheritDoc}
182      */
183     @Override
184     public BranchScmResult branch(ScmRepository repository, ScmFileSet fileSet, String branchName) throws ScmException {
185         return branch(repository, fileSet, branchName, new ScmBranchParameters());
186     }
187 
188     /**
189      * {@inheritDoc}
190      */
191     @Override
192     public BranchScmResult branch(ScmRepository repository, ScmFileSet fileSet, String branchName, String message)
193             throws ScmException {
194         ScmBranchParameters scmBranchParameters = new ScmBranchParameters();
195 
196         if (StringUtils.isNotEmpty(message)) {
197             scmBranchParameters.setMessage(message);
198         }
199 
200         return branch(repository, fileSet, branchName, scmBranchParameters);
201     }
202 
203     @Override
204     public BranchScmResult branch(
205             ScmRepository repository, ScmFileSet fileSet, String branchName, ScmBranchParameters scmBranchParameters)
206             throws ScmException {
207         login(repository, fileSet);
208 
209         CommandParameters parameters = new CommandParameters();
210 
211         parameters.setString(CommandParameter.BRANCH_NAME, branchName);
212 
213         parameters.setScmBranchParameters(CommandParameter.SCM_BRANCH_PARAMETERS, scmBranchParameters);
214 
215         return branch(repository.getProviderRepository(), fileSet, parameters);
216     }
217 
218     protected BranchScmResult branch(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
219             throws ScmException {
220         throw new NoSuchCommandScmException("branch");
221     }
222 
223     /**
224      * {@inheritDoc}
225      *
226      * @deprecated
227      */
228     @Deprecated
229     @Override
230     public ChangeLogScmResult changeLog(
231             ScmRepository repository, ScmFileSet fileSet, Date startDate, Date endDate, int numDays, String branch)
232             throws ScmException {
233         return changeLog(repository, fileSet, startDate, endDate, numDays, branch, null);
234     }
235 
236     /**
237      * {@inheritDoc}
238      *
239      * @deprecated
240      */
241     @Deprecated
242     @Override
243     public ChangeLogScmResult changeLog(
244             ScmRepository repository,
245             ScmFileSet fileSet,
246             Date startDate,
247             Date endDate,
248             int numDays,
249             String branch,
250             String datePattern)
251             throws ScmException {
252         ScmBranch scmBranch = null;
253 
254         if (StringUtils.isNotEmpty(branch)) {
255             scmBranch = new ScmBranch(branch);
256         }
257         return changeLog(repository, fileSet, startDate, endDate, numDays, scmBranch, null);
258     }
259 
260     /**
261      * {@inheritDoc}
262      */
263     @Override
264     public ChangeLogScmResult changeLog(
265             ScmRepository repository, ScmFileSet fileSet, Date startDate, Date endDate, int numDays, ScmBranch branch)
266             throws ScmException {
267         return changeLog(repository, fileSet, startDate, endDate, numDays, branch, null);
268     }
269 
270     /**
271      * {@inheritDoc}
272      */
273     @Override
274     public ChangeLogScmResult changeLog(
275             ScmRepository repository,
276             ScmFileSet fileSet,
277             Date startDate,
278             Date endDate,
279             int numDays,
280             ScmBranch branch,
281             String datePattern)
282             throws ScmException {
283         final ChangeLogScmRequest request = new ChangeLogScmRequest(repository, fileSet);
284         request.setDateRange(startDate, endDate);
285         request.setNumDays(numDays);
286         request.setScmBranch(branch);
287         request.setDatePattern(datePattern);
288         return changeLog(request);
289     }
290 
291     /**
292      * {@inheritDoc}
293      */
294     @Override
295     public ChangeLogScmResult changeLog(ChangeLogScmRequest request) throws ScmException {
296         final ScmRepository scmRepository = request.getScmRepository();
297         final ScmFileSet scmFileSet = request.getScmFileSet();
298         login(scmRepository, scmFileSet);
299         return changelog(scmRepository.getProviderRepository(), scmFileSet, request.getCommandParameters());
300     }
301 
302     /**
303      * {@inheritDoc}
304      *
305      * @deprecated
306      */
307     @Deprecated
308     @Override
309     public ChangeLogScmResult changeLog(ScmRepository repository, ScmFileSet fileSet, String startTag, String endTag)
310             throws ScmException {
311         return changeLog(repository, fileSet, startTag, endTag, null);
312     }
313 
314     /**
315      * {@inheritDoc}
316      *
317      * @deprecated
318      */
319     @Deprecated
320     @Override
321     public ChangeLogScmResult changeLog(
322             ScmRepository repository, ScmFileSet fileSet, String startTag, String endTag, String datePattern)
323             throws ScmException {
324         ScmVersion startRevision = null;
325         ScmVersion endRevision = null;
326 
327         if (StringUtils.isNotEmpty(startTag)) {
328             startRevision = new ScmRevision(startTag);
329         }
330 
331         if (StringUtils.isNotEmpty(endTag)) {
332             endRevision = new ScmRevision(endTag);
333         }
334 
335         return changeLog(repository, fileSet, startRevision, endRevision, null);
336     }
337 
338     /**
339      * {@inheritDoc}
340      */
341     @Override
342     public ChangeLogScmResult changeLog(
343             ScmRepository repository, ScmFileSet fileSet, ScmVersion startVersion, ScmVersion endVersion)
344             throws ScmException {
345         return changeLog(repository, fileSet, startVersion, endVersion, null);
346     }
347 
348     /**
349      * {@inheritDoc}
350      */
351     @Override
352     public ChangeLogScmResult changeLog(
353             ScmRepository repository,
354             ScmFileSet fileSet,
355             ScmVersion startVersion,
356             ScmVersion endVersion,
357             String datePattern)
358             throws ScmException {
359         login(repository, fileSet);
360 
361         CommandParameters parameters = new CommandParameters();
362 
363         parameters.setScmVersion(CommandParameter.START_SCM_VERSION, startVersion);
364 
365         parameters.setScmVersion(CommandParameter.END_SCM_VERSION, endVersion);
366 
367         parameters.setString(CommandParameter.CHANGELOG_DATE_PATTERN, datePattern);
368 
369         return changelog(repository.getProviderRepository(), fileSet, parameters);
370     }
371 
372     protected ChangeLogScmResult changelog(
373             ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
374         throw new NoSuchCommandScmException("changelog");
375     }
376 
377     /**
378      * {@inheritDoc}
379      *
380      * @deprecated
381      */
382     @Deprecated
383     @Override
384     public CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, String tag, String message)
385             throws ScmException {
386         ScmVersion scmVersion = null;
387 
388         if (StringUtils.isNotEmpty(tag)) {
389             scmVersion = new ScmBranch(tag);
390         }
391 
392         return checkIn(repository, fileSet, scmVersion, message);
393     }
394 
395     /**
396      * {@inheritDoc}
397      */
398     @Override
399     public CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, String message) throws ScmException {
400         return checkIn(repository, fileSet, (ScmVersion) null, message);
401     }
402 
403     /**
404      * {@inheritDoc}
405      */
406     @Override
407     public CheckInScmResult checkIn(ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, String message)
408             throws ScmException {
409         login(repository, fileSet);
410 
411         CommandParameters parameters = new CommandParameters();
412 
413         parameters.setScmVersion(CommandParameter.SCM_VERSION, scmVersion);
414 
415         parameters.setString(CommandParameter.MESSAGE, message);
416 
417         return checkin(repository.getProviderRepository(), fileSet, parameters);
418     }
419 
420     protected CheckInScmResult checkin(
421             ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
422         throw new NoSuchCommandScmException("checkin");
423     }
424 
425     /**
426      * {@inheritDoc}
427      *
428      * @deprecated
429      */
430     @Deprecated
431     @Override
432     public CheckOutScmResult checkOut(ScmRepository repository, ScmFileSet fileSet, String tag) throws ScmException {
433         return checkOut(repository, fileSet, tag, true);
434     }
435 
436     /**
437      * {@inheritDoc}
438      *
439      * @deprecated
440      */
441     @Deprecated
442     @Override
443     public CheckOutScmResult checkOut(ScmRepository repository, ScmFileSet fileSet, String tag, boolean recursive)
444             throws ScmException {
445         ScmVersion scmVersion = null;
446 
447         if (StringUtils.isNotEmpty(tag)) {
448             scmVersion = new ScmBranch(tag);
449         }
450 
451         return checkOut(repository, fileSet, scmVersion, recursive);
452     }
453 
454     /**
455      * {@inheritDoc}
456      */
457     @Override
458     public CheckOutScmResult checkOut(ScmRepository repository, ScmFileSet fileSet) throws ScmException {
459         return checkOut(repository, fileSet, (ScmVersion) null, true);
460     }
461 
462     /**
463      * {@inheritDoc}
464      */
465     @Override
466     public CheckOutScmResult checkOut(ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion)
467             throws ScmException {
468         return checkOut(repository, fileSet, scmVersion, true);
469     }
470 
471     /**
472      * {@inheritDoc}
473      */
474     @Override
475     public CheckOutScmResult checkOut(ScmRepository repository, ScmFileSet fileSet, boolean recursive)
476             throws ScmException {
477         return checkOut(repository, fileSet, (ScmVersion) null, recursive);
478     }
479 
480     /**
481      * {@inheritDoc}
482      */
483     @Override
484     public CheckOutScmResult checkOut(
485             ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, boolean recursive)
486             throws ScmException {
487         login(repository, fileSet);
488 
489         CommandParameters parameters = new CommandParameters();
490 
491         parameters.setScmVersion(CommandParameter.SCM_VERSION, scmVersion);
492 
493         parameters.setString(CommandParameter.RECURSIVE, Boolean.toString(recursive));
494 
495         return checkout(repository.getProviderRepository(), fileSet, parameters);
496     }
497 
498     @Override
499     public CheckOutScmResult checkOut(
500             ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, CommandParameters commandParameters)
501             throws ScmException {
502         login(repository, fileSet);
503         if (scmVersion != null && commandParameters.getScmVersion(CommandParameter.SCM_VERSION, null) == null) {
504             commandParameters.setScmVersion(CommandParameter.SCM_VERSION, scmVersion);
505         }
506 
507         return checkout(repository.getProviderRepository(), fileSet, commandParameters);
508     }
509 
510     protected CheckOutScmResult checkout(
511             ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
512         throw new NoSuchCommandScmException("checkout");
513     }
514 
515     /**
516      * {@inheritDoc}
517      *
518      * @deprecated
519      */
520     @Deprecated
521     @Override
522     public DiffScmResult diff(ScmRepository repository, ScmFileSet fileSet, String startRevision, String endRevision)
523             throws ScmException {
524         ScmVersion startVersion = null;
525         ScmVersion endVersion = null;
526 
527         if (StringUtils.isNotEmpty(startRevision)) {
528             startVersion = new ScmRevision(startRevision);
529         }
530 
531         if (StringUtils.isNotEmpty(endRevision)) {
532             endVersion = new ScmRevision(endRevision);
533         }
534 
535         return diff(repository, fileSet, startVersion, endVersion);
536     }
537 
538     /**
539      * {@inheritDoc}
540      */
541     @Override
542     public DiffScmResult diff(
543             ScmRepository repository, ScmFileSet fileSet, ScmVersion startVersion, ScmVersion endVersion)
544             throws ScmException {
545         login(repository, fileSet);
546 
547         CommandParameters parameters = new CommandParameters();
548 
549         parameters.setScmVersion(CommandParameter.START_SCM_VERSION, startVersion);
550 
551         parameters.setScmVersion(CommandParameter.END_SCM_VERSION, endVersion);
552 
553         return diff(repository.getProviderRepository(), fileSet, parameters);
554     }
555 
556     protected DiffScmResult diff(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
557             throws ScmException {
558         throw new NoSuchCommandScmException("diff");
559     }
560 
561     /**
562      * {@inheritDoc}
563      */
564     @Override
565     public EditScmResult edit(ScmRepository repository, ScmFileSet fileSet) throws ScmException {
566         login(repository, fileSet);
567 
568         CommandParameters parameters = new CommandParameters();
569 
570         return edit(repository.getProviderRepository(), fileSet, parameters);
571     }
572 
573     protected EditScmResult edit(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
574             throws ScmException {
575         if (logger.isWarnEnabled()) {
576             logger.warn("Provider " + this.getScmType() + " does not support edit operation.");
577         }
578 
579         return new EditScmResult("", null, null, true);
580     }
581 
582     /**
583      * {@inheritDoc}
584      *
585      * @deprecated
586      */
587     @Deprecated
588     @Override
589     public ExportScmResult export(ScmRepository repository, ScmFileSet fileSet, String tag) throws ScmException {
590         return export(repository, fileSet, tag, null);
591     }
592 
593     /**
594      * {@inheritDoc}
595      *
596      * @deprecated
597      */
598     @Deprecated
599     @Override
600     public ExportScmResult export(ScmRepository repository, ScmFileSet fileSet, String tag, String outputDirectory)
601             throws ScmException {
602         ScmVersion scmVersion = null;
603 
604         if (StringUtils.isNotEmpty(tag)) {
605             scmVersion = new ScmRevision(tag);
606         }
607 
608         return export(repository, fileSet, scmVersion, outputDirectory);
609     }
610 
611     /**
612      * {@inheritDoc}
613      */
614     @Override
615     public ExportScmResult export(ScmRepository repository, ScmFileSet fileSet) throws ScmException {
616         return export(repository, fileSet, (ScmVersion) null, null);
617     }
618 
619     /**
620      * {@inheritDoc}
621      */
622     @Override
623     public ExportScmResult export(ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion)
624             throws ScmException {
625         return export(repository, fileSet, scmVersion, null);
626     }
627 
628     /**
629      * {@inheritDoc}
630      */
631     @Override
632     public ExportScmResult export(
633             ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, String outputDirectory)
634             throws ScmException {
635         login(repository, fileSet);
636 
637         CommandParameters parameters = new CommandParameters();
638 
639         parameters.setScmVersion(CommandParameter.SCM_VERSION, scmVersion);
640 
641         parameters.setString(CommandParameter.OUTPUT_DIRECTORY, outputDirectory);
642 
643         return export(repository.getProviderRepository(), fileSet, parameters);
644     }
645 
646     protected ExportScmResult export(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
647             throws ScmException {
648         throw new NoSuchCommandScmException("export");
649     }
650 
651     /**
652      * {@inheritDoc}
653      */
654     @Override
655     public ListScmResult list(ScmRepository repository, ScmFileSet fileSet, boolean recursive, String tag)
656             throws ScmException {
657         ScmVersion scmVersion = null;
658 
659         if (StringUtils.isNotEmpty(tag)) {
660             scmVersion = new ScmRevision(tag);
661         }
662 
663         return list(repository, fileSet, recursive, scmVersion);
664     }
665 
666     /**
667      * {@inheritDoc}
668      */
669     @Override
670     public ListScmResult list(ScmRepository repository, ScmFileSet fileSet, boolean recursive, ScmVersion scmVersion)
671             throws ScmException {
672         login(repository, fileSet);
673 
674         CommandParameters parameters = new CommandParameters();
675 
676         parameters.setString(CommandParameter.RECURSIVE, Boolean.toString(recursive));
677 
678         if (scmVersion != null) {
679             parameters.setScmVersion(CommandParameter.SCM_VERSION, scmVersion);
680         }
681 
682         return list(repository.getProviderRepository(), fileSet, parameters);
683     }
684 
685     /**
686      * List each element (files and directories) of <B>fileSet</B> as they exist in the repository.
687      *
688      * @param repository the source control system
689      * @param fileSet    the files to list
690      * @param parameters TODO
691      * @return The list of files in the repository
692      * @throws NoSuchCommandScmException unless overriden by subclass
693      * @throws ScmException              if any
694      */
695     protected ListScmResult list(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
696             throws ScmException {
697         throw new NoSuchCommandScmException("list");
698     }
699 
700     /**
701      * {@inheritDoc}
702      */
703     @Override
704     public MkdirScmResult mkdir(ScmRepository repository, ScmFileSet fileSet, String message, boolean createInLocal)
705             throws ScmException {
706         login(repository, fileSet);
707 
708         CommandParameters parameters = new CommandParameters();
709 
710         if (message == null) {
711             message = "";
712             if (!createInLocal) {
713                 logger.warn("Commit message is empty!");
714             }
715         }
716 
717         parameters.setString(CommandParameter.MESSAGE, message);
718 
719         parameters.setString(CommandParameter.SCM_MKDIR_CREATE_IN_LOCAL, Boolean.toString(createInLocal));
720 
721         return mkdir(repository.getProviderRepository(), fileSet, parameters);
722     }
723 
724     /**
725      * Create directory/directories in the repository.
726      *
727      * @param repository TODO
728      * @param fileSet TODO
729      * @param parameters TODO
730      * @return TODO
731      * @throws ScmException if any
732      */
733     protected MkdirScmResult mkdir(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
734             throws ScmException {
735         throw new NoSuchCommandScmException("mkdir");
736     }
737 
738     private void login(ScmRepository repository, ScmFileSet fileSet) throws ScmException {
739         LoginScmResult result = login(repository.getProviderRepository(), fileSet, new CommandParameters());
740 
741         if (!result.isSuccess()) {
742             throw new ScmException("Can't login.\n" + result.getCommandOutput());
743         }
744     }
745 
746     protected LoginScmResult login(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
747             throws ScmException {
748         return new LoginScmResult(null, null, null, true);
749     }
750 
751     /**
752      * {@inheritDoc}
753      */
754     @Override
755     public RemoveScmResult remove(ScmRepository repository, ScmFileSet fileSet, String message) throws ScmException {
756         login(repository, fileSet);
757 
758         CommandParameters parameters = new CommandParameters();
759 
760         parameters.setString(CommandParameter.MESSAGE, message == null ? "" : message);
761 
762         return remove(repository.getProviderRepository(), fileSet, parameters);
763     }
764 
765     protected RemoveScmResult remove(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
766             throws ScmException {
767         throw new NoSuchCommandScmException("remove");
768     }
769 
770     /**
771      * {@inheritDoc}
772      */
773     @Override
774     public StatusScmResult status(ScmRepository repository, ScmFileSet fileSet) throws ScmException {
775         login(repository, fileSet);
776 
777         CommandParameters parameters = new CommandParameters();
778 
779         return status(repository.getProviderRepository(), fileSet, parameters);
780     }
781 
782     protected StatusScmResult status(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
783             throws ScmException {
784         throw new NoSuchCommandScmException("status");
785     }
786 
787     /**
788      * {@inheritDoc}
789      */
790     @Override
791     public TagScmResult tag(ScmRepository repository, ScmFileSet fileSet, String tagName) throws ScmException {
792         return tag(repository, fileSet, tagName, new ScmTagParameters());
793     }
794 
795     /**
796      * {@inheritDoc}
797      */
798     @Override
799     public TagScmResult tag(ScmRepository repository, ScmFileSet fileSet, String tagName, String message)
800             throws ScmException {
801         login(repository, fileSet);
802 
803         CommandParameters parameters = new CommandParameters();
804 
805         parameters.setString(CommandParameter.TAG_NAME, tagName);
806 
807         if (StringUtils.isNotEmpty(message)) {
808             parameters.setString(CommandParameter.MESSAGE, message);
809         }
810 
811         ScmTagParameters scmTagParameters = new ScmTagParameters(message);
812 
813         parameters.setScmTagParameters(CommandParameter.SCM_TAG_PARAMETERS, scmTagParameters);
814 
815         return tag(repository.getProviderRepository(), fileSet, parameters);
816     }
817 
818     /**
819      * {@inheritDoc}
820      */
821     @Override
822     public TagScmResult tag(
823             ScmRepository repository, ScmFileSet fileSet, String tagName, ScmTagParameters scmTagParameters)
824             throws ScmException {
825         login(repository, fileSet);
826 
827         CommandParameters parameters = new CommandParameters();
828 
829         parameters.setString(CommandParameter.TAG_NAME, tagName);
830 
831         parameters.setScmTagParameters(CommandParameter.SCM_TAG_PARAMETERS, scmTagParameters);
832 
833         return tag(repository.getProviderRepository(), fileSet, parameters);
834     }
835 
836     protected TagScmResult tag(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
837             throws ScmException {
838         throw new NoSuchCommandScmException("tag");
839     }
840 
841     /**
842      * {@inheritDoc}
843      */
844     @Override
845     public UnEditScmResult unedit(ScmRepository repository, ScmFileSet fileSet) throws ScmException {
846         login(repository, fileSet);
847 
848         CommandParameters parameters = new CommandParameters();
849 
850         return unedit(repository.getProviderRepository(), fileSet, parameters);
851     }
852 
853     protected UnEditScmResult unedit(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
854             throws ScmException {
855         if (logger.isWarnEnabled()) {
856             logger.warn("Provider " + this.getScmType() + " does not support unedit operation.");
857         }
858 
859         return new UnEditScmResult("", null, null, true);
860     }
861 
862     /**
863      * {@inheritDoc}
864      */
865     @Override
866     public UntagScmResult untag(ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters)
867             throws ScmException {
868         logger.warn("Provider " + this.getScmType() + " does not support untag operation.");
869         return new UntagScmResult("", null, null, true);
870     }
871 
872     /**
873      * {@inheritDoc}
874      *
875      * @deprecated
876      */
877     @Deprecated
878     @Override
879     public UpdateScmResult update(ScmRepository repository, ScmFileSet fileSet, String tag) throws ScmException {
880         return update(repository, fileSet, tag, true);
881     }
882 
883     /**
884      * {@inheritDoc}
885      *
886      * @deprecated
887      */
888     @Deprecated
889     @Override
890     public UpdateScmResult update(ScmRepository repository, ScmFileSet fileSet, String tag, boolean runChangelog)
891             throws ScmException {
892         return update(repository, fileSet, tag, "", runChangelog);
893     }
894 
895     /**
896      * {@inheritDoc}
897      */
898     @Override
899     public UpdateScmResult update(ScmRepository repository, ScmFileSet fileSet) throws ScmException {
900         return update(repository, fileSet, (ScmVersion) null, true);
901     }
902 
903     /**
904      * {@inheritDoc}
905      */
906     @Override
907     public UpdateScmResult update(ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion)
908             throws ScmException {
909         return update(repository, fileSet, scmVersion, true);
910     }
911 
912     /**
913      * {@inheritDoc}
914      */
915     @Override
916     public UpdateScmResult update(ScmRepository repository, ScmFileSet fileSet, boolean runChangelog)
917             throws ScmException {
918         return update(repository, fileSet, (ScmVersion) null, "", runChangelog);
919     }
920 
921     /**
922      * {@inheritDoc}
923      */
924     @Override
925     public UpdateScmResult update(
926             ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, boolean runChangelog)
927             throws ScmException {
928         return update(repository, fileSet, scmVersion, "", runChangelog);
929     }
930 
931     /**
932      * {@inheritDoc}
933      *
934      * @deprecated
935      */
936     @Override
937     public UpdateScmResult update(ScmRepository repository, ScmFileSet fileSet, String tag, String datePattern)
938             throws ScmException {
939         return update(repository, fileSet, tag, datePattern, true);
940     }
941 
942     /**
943      * {@inheritDoc}
944      */
945     @Override
946     public UpdateScmResult update(
947             ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, String datePattern)
948             throws ScmException {
949         return update(repository, fileSet, scmVersion, datePattern, true);
950     }
951 
952     /**
953      * @deprecated
954      */
955     private UpdateScmResult update(
956             ScmRepository repository, ScmFileSet fileSet, String tag, String datePattern, boolean runChangelog)
957             throws ScmException {
958         ScmBranch scmBranch = null;
959 
960         if (StringUtils.isNotEmpty(tag)) {
961             scmBranch = new ScmBranch(tag);
962         }
963 
964         return update(repository, fileSet, scmBranch, datePattern, runChangelog);
965     }
966 
967     private UpdateScmResult update(
968             ScmRepository repository,
969             ScmFileSet fileSet,
970             ScmVersion scmVersion,
971             String datePattern,
972             boolean runChangelog)
973             throws ScmException {
974         login(repository, fileSet);
975 
976         CommandParameters parameters = new CommandParameters();
977 
978         parameters.setScmVersion(CommandParameter.SCM_VERSION, scmVersion);
979 
980         parameters.setString(CommandParameter.CHANGELOG_DATE_PATTERN, datePattern);
981 
982         parameters.setString(CommandParameter.RUN_CHANGELOG_WITH_UPDATE, String.valueOf(runChangelog));
983 
984         return update(repository.getProviderRepository(), fileSet, parameters);
985     }
986 
987     /**
988      * {@inheritDoc}
989      *
990      * @deprecated
991      */
992     @Deprecated
993     @Override
994     public UpdateScmResult update(ScmRepository repository, ScmFileSet fileSet, String tag, Date lastUpdate)
995             throws ScmException {
996         return update(repository, fileSet, tag, lastUpdate, null);
997     }
998 
999     /**
1000      * {@inheritDoc}
1001      */
1002     @Override
1003     public UpdateScmResult update(ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, Date lastUpdate)
1004             throws ScmException {
1005         return update(repository, fileSet, scmVersion, lastUpdate, null);
1006     }
1007 
1008     /**
1009      * {@inheritDoc}
1010      *
1011      * @deprecated
1012      */
1013     @Deprecated
1014     @Override
1015     public UpdateScmResult update(
1016             ScmRepository repository, ScmFileSet fileSet, String tag, Date lastUpdate, String datePattern)
1017             throws ScmException {
1018         ScmBranch scmBranch = null;
1019 
1020         if (StringUtils.isNotEmpty(tag)) {
1021             scmBranch = new ScmBranch(tag);
1022         }
1023 
1024         return update(repository, fileSet, scmBranch, lastUpdate, datePattern);
1025     }
1026 
1027     /**
1028      * {@inheritDoc}
1029      */
1030     @Override
1031     public UpdateScmResult update(
1032             ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, Date lastUpdate, String datePattern)
1033             throws ScmException {
1034         login(repository, fileSet);
1035 
1036         CommandParameters parameters = new CommandParameters();
1037 
1038         parameters.setScmVersion(CommandParameter.SCM_VERSION, scmVersion);
1039 
1040         if (lastUpdate != null) {
1041             parameters.setDate(CommandParameter.START_DATE, lastUpdate);
1042         }
1043 
1044         parameters.setString(CommandParameter.CHANGELOG_DATE_PATTERN, datePattern);
1045 
1046         parameters.setString(CommandParameter.RUN_CHANGELOG_WITH_UPDATE, "true");
1047 
1048         return update(repository.getProviderRepository(), fileSet, parameters);
1049     }
1050 
1051     protected UpdateScmResult update(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
1052             throws ScmException {
1053         throw new NoSuchCommandScmException("update");
1054     }
1055 
1056     /**
1057      * {@inheritDoc}
1058      */
1059     @Override
1060     public BlameScmResult blame(ScmRepository repository, ScmFileSet fileSet, String filename) throws ScmException {
1061         login(repository, fileSet);
1062 
1063         CommandParameters parameters = new CommandParameters();
1064 
1065         parameters.setString(CommandParameter.FILE, filename);
1066 
1067         return blame(repository.getProviderRepository(), fileSet, parameters);
1068     }
1069 
1070     protected BlameScmResult blame(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
1071             throws ScmException {
1072         throw new NoSuchCommandScmException("blame");
1073     }
1074 
1075     @Override
1076     public BlameScmResult blame(BlameScmRequest blameScmRequest) throws ScmException {
1077         return blame(
1078                 blameScmRequest.getScmRepository().getProviderRepository(),
1079                 blameScmRequest.getScmFileSet(),
1080                 blameScmRequest.getCommandParameters());
1081     }
1082 
1083     @Override
1084     public InfoScmResult info(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters)
1085             throws ScmException {
1086         return null;
1087     }
1088 
1089     @Override
1090     public RemoteInfoScmResult remoteInfo(
1091             ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
1092         return null;
1093     }
1094 
1095     /**
1096      * {@inheritDoc}
1097      */
1098     @Override
1099     public ScmProviderRepository makeProviderScmRepository(File path)
1100             throws ScmRepositoryException, UnknownRepositoryStructure {
1101         throw new UnknownRepositoryStructure();
1102     }
1103 }