001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.scm.plugin;
020
021import java.io.IOException;
022
023import org.apache.maven.plugin.MojoExecutionException;
024import org.apache.maven.plugins.annotations.Mojo;
025import org.apache.maven.plugins.annotations.Parameter;
026import org.apache.maven.scm.ScmException;
027import org.apache.maven.scm.ScmFile;
028import org.apache.maven.scm.command.list.ListScmResult;
029import org.apache.maven.scm.repository.ScmRepository;
030
031/**
032 * Get the list of project files.
033 *
034 * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
035 */
036@Mojo(name = "list", aggregator = true)
037public class ListMojo extends AbstractScmMojo {
038    /**
039     * The version type (branch/tag/revision) of scmVersion.
040     */
041    @Parameter(property = "scmVersionType")
042    private String scmVersionType;
043
044    /**
045     * The version (revision number/branch name/tag name).
046     */
047    @Parameter(property = "scmVersion")
048    private String scmVersion;
049
050    /**
051     * Use recursive mode.
052     */
053    @Parameter(property = "recursive", defaultValue = "true")
054    private boolean recursive = true;
055
056    /** {@inheritDoc} */
057    public void execute() throws MojoExecutionException {
058        super.execute();
059
060        try {
061            ScmRepository repository = getScmRepository();
062            ListScmResult result = getScmManager()
063                    .list(repository, getFileSet(), recursive, getScmVersion(scmVersionType, scmVersion));
064
065            checkResult(result);
066
067            if (result.getFiles() != null) {
068                for (ScmFile scmFile : result.getFiles()) {
069                    getLog().info(scmFile.getPath());
070                }
071            }
072        } catch (ScmException | IOException e) {
073            throw new MojoExecutionException("Cannot run list command : ", e);
074        }
075    }
076}