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 javax.inject.Inject;
022
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.command.list.ListScmResult;
031import org.apache.maven.scm.manager.ScmManager;
032import org.apache.maven.scm.repository.ScmRepository;
033import org.apache.maven.settings.crypto.SettingsDecrypter;
034
035/**
036 * Get the list of project files.
037 *
038 * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
039 */
040@Mojo(name = "list", aggregator = true)
041public class ListMojo extends AbstractScmMojo {
042    /**
043     * The version type (branch/tag/revision) of scmVersion.
044     */
045    @Parameter(property = "scmVersionType")
046    private String scmVersionType;
047
048    /**
049     * The version (revision number/branch name/tag name).
050     */
051    @Parameter(property = "scmVersion")
052    private String scmVersion;
053
054    /**
055     * Use recursive mode.
056     */
057    @Parameter(property = "recursive", defaultValue = "true")
058    private boolean recursive = true;
059
060    @Inject
061    public ListMojo(ScmManager manager, SettingsDecrypter settingsDecrypter) {
062        super(manager, settingsDecrypter);
063    }
064
065    /** {@inheritDoc} */
066    public void execute() throws MojoExecutionException {
067        super.execute();
068
069        try {
070            ScmRepository repository = getScmRepository();
071            ListScmResult result = getScmManager()
072                    .list(repository, getFileSet(), recursive, getScmVersion(scmVersionType, scmVersion));
073
074            checkResult(result);
075
076            if (result.getFiles() != null) {
077                for (ScmFile scmFile : result.getFiles()) {
078                    getLog().info(scmFile.getPath());
079                }
080            }
081        } catch (ScmException | IOException e) {
082            throw new MojoExecutionException("Cannot run list command : ", e);
083        }
084    }
085}