View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.scm.plugin;
20  
21  import java.io.IOException;
22  
23  import org.apache.maven.plugin.MojoExecutionException;
24  import org.apache.maven.plugins.annotations.Mojo;
25  import org.apache.maven.plugins.annotations.Parameter;
26  import org.apache.maven.scm.ScmException;
27  import org.apache.maven.scm.ScmFile;
28  import org.apache.maven.scm.command.list.ListScmResult;
29  import org.apache.maven.scm.repository.ScmRepository;
30  
31  /**
32   * Get the list of project files.
33   *
34   * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
35   */
36  @Mojo(name = "list", aggregator = true)
37  public class ListMojo extends AbstractScmMojo {
38      /**
39       * The version type (branch/tag/revision) of scmVersion.
40       */
41      @Parameter(property = "scmVersionType")
42      private String scmVersionType;
43  
44      /**
45       * The version (revision number/branch name/tag name).
46       */
47      @Parameter(property = "scmVersion")
48      private String scmVersion;
49  
50      /**
51       * Use recursive mode.
52       */
53      @Parameter(property = "recursive", defaultValue = "true")
54      private boolean recursive = true;
55  
56      /** {@inheritDoc} */
57      public void execute() throws MojoExecutionException {
58          super.execute();
59  
60          try {
61              ScmRepository repository = getScmRepository();
62              ListScmResult result = getScmManager()
63                      .list(repository, getFileSet(), recursive, getScmVersion(scmVersionType, scmVersion));
64  
65              checkResult(result);
66  
67              if (result.getFiles() != null) {
68                  for (ScmFile scmFile : result.getFiles()) {
69                      getLog().info(scmFile.getPath());
70                  }
71              }
72          } catch (ScmException | IOException e) {
73              throw new MojoExecutionException("Cannot run list command : ", e);
74          }
75      }
76  }