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   * @since 1.6
46   */
47  public class IntegrityListCommand
48      extends AbstractListCommand
49  {
50      /**
51       * {@inheritDoc}
52       */
53      @Override
54      public ListScmResult executeListCommand( ScmProviderRepository repository, ScmFileSet fileSet, boolean recursive,
55                                               ScmVersion scmVersion )
56          throws ScmException
57      {
58          ListScmResult result;
59          IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
60          getLogger().info( "Listing all files in project " + iRepo.getConfigruationPath() );
61          try
62          {
63              // Get a listing for all the members in the project...
64              List<Member> projectMembers = iRepo.getProject().listFiles( fileSet.getBasedir().getAbsolutePath() );
65              // Initialize the list of ScmFile objects for the ListScmResult
66              List<ScmFile> scmFileList = new ArrayList<ScmFile>();
67              for ( Iterator<Member> it = projectMembers.iterator(); it.hasNext(); )
68              {
69                  Member siMember = it.next();
70                  scmFileList.add( new ScmFile( siMember.getTargetFilePath(), ScmFileStatus.UNKNOWN ) );
71              }
72              result = new ListScmResult( scmFileList, new ScmResult( "si viewproject", "", "", true ) );
73  
74          }
75          catch ( APIException aex )
76          {
77              ExceptionHandler eh = new ExceptionHandler( aex );
78              getLogger().error( "MKS API Exception: " + eh.getMessage() );
79              getLogger().debug( eh.getCommand() + " exited with return code " + eh.getExitCode() );
80              result = new ListScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
81          }
82  
83          return result;
84      }
85  
86  }