001package org.apache.maven.scm.provider.hg.command.inventory;
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 java.io.File;
023
024import org.apache.maven.scm.ScmException;
025import org.apache.maven.scm.ScmFileSet;
026import org.apache.maven.scm.ScmResult;
027import org.apache.maven.scm.ScmVersion;
028import org.apache.maven.scm.command.Command;
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.hg.HgUtils;
033import org.apache.maven.scm.provider.hg.command.HgCommandConstants;
034
035/**
036 * Get a list of all files in the repository
037 *
038 * @author <a href="mailto:ryan@darksleep.com">ryan daum</a>
039 *
040 */
041public class HgListCommand
042    extends AbstractListCommand
043    implements Command
044{
045    /** {@inheritDoc} */
046    protected ListScmResult executeListCommand( ScmProviderRepository repository, ScmFileSet fileSet,
047                                                boolean recursive, ScmVersion scmVersion )
048        throws ScmException
049    {
050
051        //
052        File workingDir = fileSet.getBasedir();
053
054        // build the command
055        String[] listCmd = new String[] { HgCommandConstants.INVENTORY_CMD };
056
057        // keep the command about in string form for reporting
058        StringBuilder cmd = new StringBuilder();
059        for ( int i = 0; i < listCmd.length; i++ )
060        {
061            String s = listCmd[i];
062            cmd.append( s );
063            if ( i < listCmd.length - 1 )
064            {
065                cmd.append( " " );
066            }
067        }
068
069        HgListConsumer consumer = new HgListConsumer( getLogger() );
070
071        ScmResult result = HgUtils.execute( consumer, getLogger(), workingDir, listCmd );
072
073        if ( result.isSuccess() )
074        {
075            return new ListScmResult( consumer.getFiles(), result );
076        }
077        else
078        {
079            throw new ScmException( "Error while executing command " + cmd.toString() );
080        }
081    }
082}