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.IOException;
023
024import org.apache.maven.plugin.MojoExecutionException;
025import org.apache.maven.plugins.annotations.Mojo;
026import org.apache.maven.plugins.annotations.Parameter;
027import org.apache.maven.scm.ScmException;
028import org.apache.maven.scm.ScmFile;
029import org.apache.maven.scm.command.list.ListScmResult;
030import 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 */
037@Mojo( name = "list", aggregator = true )
038public class ListMojo
039    extends AbstractScmMojo
040{
041    /**
042     * The version type (branch/tag/revision) of scmVersion.
043     */
044    @Parameter( property = "scmVersionType" )
045    private String scmVersionType;
046
047    /**
048     * The version (revision number/branch name/tag name).
049     */
050    @Parameter( property = "scmVersion" )
051    private String scmVersion;
052
053    /**
054     * Use recursive mode.
055     */
056    @Parameter( property = "recursive", defaultValue = "true" )
057    private boolean recursive = true;
058
059    /** {@inheritDoc} */
060    public void execute()
061        throws MojoExecutionException
062    {
063        super.execute();
064
065        try
066        {
067            ScmRepository repository = getScmRepository();
068            ListScmResult result = getScmManager().list( repository, getFileSet(), recursive,
069                                                         getScmVersion( scmVersionType, scmVersion ) );
070
071            checkResult( result );
072
073            if ( result.getFiles() != null )
074            {
075                for ( ScmFile scmFile : result.getFiles() )
076                {
077                    getLog().info( scmFile.getPath() );
078                }
079            }
080        }
081        catch ( ScmException | IOException e )
082        {
083            throw new MojoExecutionException( "Cannot run list command : ", e );
084        }
085    }
086
087}
088