View Javadoc

1   package org.apache.maven.scm.provider.integrity.command.list;
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 com.mks.api.response.APIException;
23  import org.apache.maven.scm.ScmException;
24  import org.apache.maven.scm.ScmFile;
25  import org.apache.maven.scm.ScmFileSet;
26  import org.apache.maven.scm.ScmFileStatus;
27  import org.apache.maven.scm.ScmResult;
28  import org.apache.maven.scm.ScmVersion;
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.integrity.ExceptionHandler;
33  import org.apache.maven.scm.provider.integrity.Member;
34  import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
35  
36  import java.util.ArrayList;
37  import java.util.Iterator;
38  import java.util.List;
39  
40  /**
41   * MKS Integrity implementation for Maven's AbstractListCommand
42   * <br>This command will a 'si viewproject' command listing all the files in the project
43   *
44   * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
45   * @version $Id: IntegrityListCommand.java 1.4 2011/08/22 13:06:30EDT Cletus D'Souza (dsouza) Exp  $
46   * @since 1.6
47   */
48  public class IntegrityListCommand
49      extends AbstractListCommand
50  {
51      /**
52       * {@inheritDoc}
53       */
54      @Override
55      public ListScmResult executeListCommand( ScmProviderRepository repository, ScmFileSet fileSet, boolean recursive,
56                                               ScmVersion scmVersion )
57          throws ScmException
58      {
59          ListScmResult result;
60          IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
61          getLogger().info( "Listing all files in project " + iRepo.getConfigruationPath() );
62          try
63          {
64              // Get a listing for all the members in the project...
65              List<Member> projectMembers = iRepo.getProject().listFiles( fileSet.getBasedir().getAbsolutePath() );
66              // Initialize the list of ScmFile objects for the ListScmResult
67              List<ScmFile> scmFileList = new ArrayList<ScmFile>();
68              for ( Iterator<Member> it = projectMembers.iterator(); it.hasNext(); )
69              {
70                  Member siMember = it.next();
71                  scmFileList.add( new ScmFile( siMember.getTargetFilePath(), ScmFileStatus.UNKNOWN ) );
72              }
73              result = new ListScmResult( scmFileList, new ScmResult( "si viewproject", "", "", true ) );
74  
75          }
76          catch ( APIException aex )
77          {
78              ExceptionHandler eh = new ExceptionHandler( aex );
79              getLogger().error( "MKS API Exception: " + eh.getMessage() );
80              getLogger().debug( eh.getCommand() + " exited with return code " + eh.getExitCode() );
81              result = new ListScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
82          }
83  
84          return result;
85      }
86  
87  }