View Javadoc
1   package org.apache.maven.scm.provider.hg.command.inventory;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  
24  import org.apache.maven.scm.ScmException;
25  import org.apache.maven.scm.ScmFileSet;
26  import org.apache.maven.scm.ScmResult;
27  import org.apache.maven.scm.ScmVersion;
28  import org.apache.maven.scm.command.Command;
29  import org.apache.maven.scm.command.list.AbstractListCommand;
30  import org.apache.maven.scm.command.list.ListScmResult;
31  import org.apache.maven.scm.provider.ScmProviderRepository;
32  import org.apache.maven.scm.provider.hg.HgUtils;
33  import org.apache.maven.scm.provider.hg.command.HgCommandConstants;
34  
35  /**
36   * Get a list of all files in the repository
37   *
38   * @author <a href="mailto:ryan@darksleep.com">ryan daum</a>
39   *
40   */
41  public class HgListCommand
42      extends AbstractListCommand
43      implements Command
44  {
45      /** {@inheritDoc} */
46      protected ListScmResult executeListCommand( ScmProviderRepository repository, ScmFileSet fileSet,
47                                                  boolean recursive, ScmVersion scmVersion )
48          throws ScmException
49      {
50  
51          //
52          File workingDir = fileSet.getBasedir();
53  
54          // build the command
55          String[] listCmd = new String[] { HgCommandConstants.INVENTORY_CMD };
56  
57          // keep the command about in string form for reporting
58          StringBuilder cmd = new StringBuilder();
59          for ( int i = 0; i < listCmd.length; i++ )
60          {
61              String s = listCmd[i];
62              cmd.append( s );
63              if ( i < listCmd.length - 1 )
64              {
65                  cmd.append( " " );
66              }
67          }
68  
69          HgListConsumer consumer = new HgListConsumer( getLogger() );
70  
71          ScmResult result = HgUtils.execute( consumer, getLogger(), workingDir, listCmd );
72  
73          if ( result.isSuccess() )
74          {
75              return new ListScmResult( consumer.getFiles(), result );
76          }
77          else
78          {
79              throw new ScmException( "Error while executing command " + cmd.toString() );
80          }
81      }
82  }