001package org.apache.maven.scm.provider.integrity.command.list; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import com.mks.api.response.APIException; 023import org.apache.maven.scm.ScmException; 024import org.apache.maven.scm.ScmFile; 025import org.apache.maven.scm.ScmFileSet; 026import org.apache.maven.scm.ScmFileStatus; 027import org.apache.maven.scm.ScmResult; 028import org.apache.maven.scm.ScmVersion; 029import org.apache.maven.scm.command.list.AbstractListCommand; 030import org.apache.maven.scm.command.list.ListScmResult; 031import org.apache.maven.scm.provider.ScmProviderRepository; 032import org.apache.maven.scm.provider.integrity.ExceptionHandler; 033import org.apache.maven.scm.provider.integrity.Member; 034import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository; 035 036import java.util.ArrayList; 037import java.util.Iterator; 038import java.util.List; 039 040/** 041 * MKS Integrity implementation for Maven's AbstractListCommand 042 * <br>This command will a 'si viewproject' command listing all the files in the project 043 * 044 * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a> 045 * @since 1.6 046 */ 047public class IntegrityListCommand 048 extends AbstractListCommand 049{ 050 /** 051 * {@inheritDoc} 052 */ 053 @Override 054 public ListScmResult executeListCommand( ScmProviderRepository repository, ScmFileSet fileSet, boolean recursive, 055 ScmVersion scmVersion ) 056 throws ScmException 057 { 058 ListScmResult result; 059 IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository; 060 getLogger().info( "Listing all files in project " + iRepo.getConfigruationPath() ); 061 try 062 { 063 // Get a listing for all the members in the project... 064 List<Member> projectMembers = iRepo.getProject().listFiles( fileSet.getBasedir().getAbsolutePath() ); 065 // Initialize the list of ScmFile objects for the ListScmResult 066 List<ScmFile> scmFileList = new ArrayList<ScmFile>(); 067 for ( Iterator<Member> it = projectMembers.iterator(); it.hasNext(); ) 068 { 069 Member siMember = it.next(); 070 scmFileList.add( new ScmFile( siMember.getTargetFilePath(), ScmFileStatus.UNKNOWN ) ); 071 } 072 result = new ListScmResult( scmFileList, new ScmResult( "si viewproject", "", "", true ) ); 073 074 } 075 catch ( APIException aex ) 076 { 077 ExceptionHandler eh = new ExceptionHandler( aex ); 078 getLogger().error( "MKS API Exception: " + eh.getMessage() ); 079 getLogger().debug( eh.getCommand() + " exited with return code " + eh.getExitCode() ); 080 result = new ListScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false ); 081 } 082 083 return result; 084 } 085 086}