001package org.apache.maven.scm.plugin;
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;
023import java.io.IOException;
024
025import org.apache.maven.plugin.MojoExecutionException;
026import org.apache.maven.plugins.annotations.Mojo;
027import org.apache.maven.plugins.annotations.Parameter;
028import org.apache.maven.scm.ScmException;
029import org.apache.maven.scm.ScmFile;
030import org.apache.maven.scm.ScmFileSet;
031import org.apache.maven.scm.command.list.ListScmResult;
032import org.apache.maven.scm.repository.ScmRepository;
033
034/**
035 * Get the list of project files.
036 *
037 * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
038 */
039@Mojo( name = "list", aggregator = true )
040public class ListMojo
041    extends AbstractScmMojo
042{
043    /**
044     * The version type (branch/tag/revision) of scmVersion.
045     */
046    @Parameter( property = "scmVersionType" )
047    private String scmVersionType;
048
049    /**
050     * The version (revision number/branch name/tag name).
051     */
052    @Parameter( property = "scmVersion" )
053    private String scmVersion;
054
055    /**
056     * Use recursive mode.
057     */
058    @Parameter( property = "recursive", defaultValue = "true" )
059    private boolean recursive = true;
060
061    /** {@inheritDoc} */
062    public void execute()
063        throws MojoExecutionException
064    {
065        super.execute();
066
067        try
068        {
069            ScmRepository repository = getScmRepository();
070            ListScmResult result = getScmManager().list( repository, getFileSet(), recursive,
071                                                         getScmVersion( scmVersionType, scmVersion ) );
072
073            checkResult( result );
074
075            if ( result.getFiles() != null )
076            {
077                for ( ScmFile scmFile : result.getFiles() )
078                {
079                    getLog().info( scmFile.getPath() );
080                }
081            }
082        }
083        catch ( ScmException e )
084        {
085            throw new MojoExecutionException( "Cannot run list command : ", e );
086        }
087        catch ( IOException e )
088        {
089            throw new MojoExecutionException( "Cannot run list command : ", e );
090        }
091    }
092
093    public ScmFileSet getFileSet()
094        throws IOException
095    {
096        if ( getIncludes() != null || getExcludes() != null )
097        {
098            return new ScmFileSet( getWorkingDirectory(), getIncludes(), getExcludes() );
099        }
100        else
101        {
102            return new ScmFileSet( getWorkingDirectory(), new File( "." ) );
103        }
104    }
105
106}
107