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.command.list;
25
26 import java.io.File;
27
28 import java.util.regex.Pattern;
29 import org.apache.maven.scm.ScmException;
30 import org.apache.maven.scm.ScmFileSet;
31 import org.apache.maven.scm.ScmResult;
32 import org.apache.maven.scm.ScmVersion;
33 import org.apache.maven.scm.command.list.AbstractListCommand;
34 import org.apache.maven.scm.command.list.ListScmResult;
35 import org.apache.maven.scm.provider.ScmProviderRepository;
36 import org.apache.maven.scm.provider.hg.HgUtils;
37
38 /**
39 * List command for Mercurial : the command used is: <code>hg tags --verbose path</code.>
40 * @author ehsavoie
41 * @version $Id: HgListCommand.java 8980 2009-02-04 09:55:20Z ehsavoie $
42 */
43 public class HgListCommand
44 extends AbstractListCommand
45 {
46
47 /**
48 * The name of the Tag tag in Mercurial.
49 */
50 public static final String TAGS_CMD = "tags";
51
52 /**
53 * The name of the Trunk/HEAD tag in Mercurial.
54 */
55 public static final String TRUNK_TAG = "tip";
56
57 /**
58 * The filter on the tag names to be used.
59 */
60 private Pattern filter;
61
62 /**
63 * Creates a new instance of HgListCommand.
64 * @param filter the filter on the tag names to be used.
65 */
66 public HgListCommand( Pattern filter )
67 {
68 this.filter = filter;
69 }
70
71 /**
72 * Executes a <code>hg tags --verbose path</code> command.
73 * @param repository the mercurial repository.
74 * @param fileSet the list of files.
75 * @param recursive true if we want a recursive list command - false otherwise.
76 * @param version the version target (branch, tags, trunk).
77 * @return a ListScmResult containing a List>Tag<.
78 * @throws org.apache.maven.scm.ScmException in case of an error with the scm command.
79 */
80 protected ListScmResult executeListCommand( ScmProviderRepository repository,
81 ScmFileSet fileSet, boolean recursive, ScmVersion version )
82 throws ScmException
83 {
84 String[] tagsCmd = new String[]
85 {
86 TAGS_CMD
87 };
88 File workingDir = fileSet.getBasedir();
89 HgTagsConsumer consumer = new HgTagsConsumer( getLogger() , filter );
90 ScmResult result = HgUtils.execute( consumer, getLogger(), workingDir,
91 tagsCmd );
92
93 return new ListScmResult( consumer.getStatus(), result );
94 }
95 }