View Javadoc

1   /*
2   The MIT License
3   
4   Copyright (c) 2004, The Codehaus
5   
6   Permission is hereby granted, free of charge, to any person obtaining a copy of
7   this software and associated documentation files (the "Software"), to deal in
8   the Software without restriction, including without limitation the rights to
9   use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10  of the Software, and to permit persons to whom the Software is furnished to do
11  so, subject to the following conditions:
12  
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15  
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  SOFTWARE.
23   */
24  package org.codehaus.mojo.scmchangelog.scm.hg;
25  
26  import java.util.regex.Pattern;
27  import org.apache.maven.plugin.logging.Log;
28  import org.apache.maven.scm.CommandParameters;
29  import org.apache.maven.scm.ScmException;
30  import org.apache.maven.scm.ScmFileSet;
31  import org.apache.maven.scm.command.Command;
32  import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
33  import org.apache.maven.scm.command.list.ListScmResult;
34  import org.apache.maven.scm.log.ScmLogger;
35  import org.apache.maven.scm.provider.ScmProviderRepository;
36  import org.codehaus.mojo.scmchangelog.scm.util.MavenScmLogger;
37  import org.codehaus.mojo.scmchangelog.changelog.log.grammar.GrammarEnum;
38  import org.codehaus.mojo.scmchangelog.scm.hg.command.changelog.HgChangeLogCommand;
39  import org.codehaus.mojo.scmchangelog.scm.hg.command.list.HgListCommand;
40  
41  /**
42   * Wrapper over SvnExeScmProvider to use xml output from Subversion.
43   * @author ehsavoie
44   * @version $Id: HgScmProvider.java 9278 2009-03-26 08:32:14Z ehsavoie $
45   * @plexus.component role="org.apache.maven.scm.provider.ScmProvider" role-hint="svn"
46   * @see org.apache.maven.scm.provider.svn.svnexe.SvnExeScmProvider
47   */
48  public class HgScmProvider
49      extends org.apache.maven.scm.provider.hg.HgScmProvider
50  {
51    /**
52     * The scm logger.
53     */
54    private ScmLogger logger;
55  
56    /**
57     * The currentlogger.
58     * @return the logger
59     */
60    public ScmLogger getLogger()
61    {
62      return logger;
63    }
64  
65    /**
66     * The current logger to be used.
67     * @param log the maven logger to be wrapped as an ScmLogger.
68     */
69    public void setLogger( Log log )
70    {
71      this.logger = new MavenScmLogger( log );
72    }
73  
74  
75    /**
76     * The comment grammar to be used.
77     */
78    private GrammarEnum grammar;
79  
80    /**
81     * The filter on the tag names to be used.
82     */
83    private Pattern filter;
84  
85    /**
86     * Creates a new instance of SvnXmlExeScmProvider.
87     * @param commentGrammar the grammar tobe used.
88     * @param filter the filter on the tag names to be used.
89     */
90    public HgScmProvider( GrammarEnum commentGrammar , Pattern filter )
91    {
92      this.grammar = commentGrammar;
93      this.filter = filter;
94    }
95  
96    /**
97     * Returns a new instance of SvnCommand to execute a
98     * <code>svn list --xml</code> command.
99     * @return a SvnListCommand.
100    */
101   public HgListCommand getListCommand()
102   {
103     HgListCommand command = new HgListCommand( filter );
104     command.setLogger( getLogger() );
105     return command;
106   }
107 
108   /**
109    * Execute the list command for the Mercuial repository.
110    * @param repository the repository.
111    * @param fileSet the files.
112    * @param parameters the command parameters.
113    * @return a list of Tag.
114    * @throws org.apache.maven.scm.ScmException in case of an error with the scm command.
115    * @see org.codehaus.mojo.scmchangelog.tags.Tag
116    */
117   protected ListScmResult list( ScmProviderRepository repository,
118       ScmFileSet fileSet, CommandParameters parameters )
119       throws ScmException
120   {
121     Command command = getListCommand();
122     command.setLogger( getLogger() );
123     return ( ListScmResult ) command.execute( repository, fileSet, parameters );
124   }
125 
126   /**
127    * Execute the changelog command for the Mercuial repository.
128    * @param repository the repository
129    * @param fileSet the files.
130    * @param parameters the command parameters.
131    * @return a list of BetterChangeSet.
132    * @throws org.apache.maven.scm.ScmException  in case of an error with the scm command.
133    * @see org.apache.maven.scm.provider.AbstractScmProvider#changelog(org.apache.maven.scm.provider.ScmProviderRepository,org.apache.maven.scm.ScmFileSet,org.apache.maven.scm.CommandParameters)
134    * @see org.codehaus.mojo.scmchangelog.scm.hg.changelog.BetterChangeSet
135    */
136   public ChangeLogScmResult changelog( ScmProviderRepository repository,
137       ScmFileSet fileSet, CommandParameters parameters )
138       throws ScmException
139   {
140     HgChangeLogCommand command = new HgChangeLogCommand();
141     command.setLogger( getLogger() );
142     return ( ChangeLogScmResult ) command.execute( repository, fileSet,
143         parameters );
144   }
145 
146   /**
147    * Returns the String to be used as issue separator.
148    * @return the String to be used as issue separator.
149    */
150   public String getCommentSeparator()
151   {
152     return this.grammar.getIssueSeparator();
153   }
154 }