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