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