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 * @version $Id: IntegrityListCommand.java 1.4 2011/08/22 13:06:30EDT Cletus D'Souza (dsouza) Exp  $
046 * @since 1.6
047 */
048public class IntegrityListCommand
049    extends AbstractListCommand
050{
051    /**
052     * {@inheritDoc}
053     */
054    @Override
055    public ListScmResult executeListCommand( ScmProviderRepository repository, ScmFileSet fileSet, boolean recursive,
056                                             ScmVersion scmVersion )
057        throws ScmException
058    {
059        ListScmResult result;
060        IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
061        getLogger().info( "Listing all files in project " + iRepo.getConfigruationPath() );
062        try
063        {
064            // Get a listing for all the members in the project...
065            List<Member> projectMembers = iRepo.getProject().listFiles( fileSet.getBasedir().getAbsolutePath() );
066            // Initialize the list of ScmFile objects for the ListScmResult
067            List<ScmFile> scmFileList = new ArrayList<ScmFile>();
068            for ( Iterator<Member> it = projectMembers.iterator(); it.hasNext(); )
069            {
070                Member siMember = it.next();
071                scmFileList.add( new ScmFile( siMember.getTargetFilePath(), ScmFileStatus.UNKNOWN ) );
072            }
073            result = new ListScmResult( scmFileList, new ScmResult( "si viewproject", "", "", true ) );
074
075        }
076        catch ( APIException aex )
077        {
078            ExceptionHandler eh = new ExceptionHandler( aex );
079            getLogger().error( "MKS API Exception: " + eh.getMessage() );
080            getLogger().debug( eh.getCommand() + " exited with return code " + eh.getExitCode() );
081            result = new ListScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
082        }
083
084        return result;
085    }
086
087}