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 javax.inject.Inject;
22  
23  import java.io.IOException;
24  
25  import org.apache.maven.plugin.MojoExecutionException;
26  import org.apache.maven.plugins.annotations.Mojo;
27  import org.apache.maven.plugins.annotations.Parameter;
28  import org.apache.maven.scm.ScmException;
29  import org.apache.maven.scm.ScmFile;
30  import org.apache.maven.scm.command.list.ListScmResult;
31  import org.apache.maven.scm.manager.ScmManager;
32  import org.apache.maven.scm.repository.ScmRepository;
33  import org.apache.maven.settings.crypto.SettingsDecrypter;
34  
35  /**
36   * Get the list of project files.
37   *
38   * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
39   */
40  @Mojo(name = "list", aggregator = true)
41  public class ListMojo extends AbstractScmMojo {
42      /**
43       * The version type (branch/tag/revision) of scmVersion.
44       */
45      @Parameter(property = "scmVersionType")
46      private String scmVersionType;
47  
48      /**
49       * The version (revision number/branch name/tag name).
50       */
51      @Parameter(property = "scmVersion")
52      private String scmVersion;
53  
54      /**
55       * Use recursive mode.
56       */
57      @Parameter(property = "recursive", defaultValue = "true")
58      private boolean recursive = true;
59  
60      @Inject
61      public ListMojo(ScmManager manager, SettingsDecrypter settingsDecrypter) {
62          super(manager, settingsDecrypter);
63      }
64  
65      /**
66       * {@inheritDoc}
67       */
68      public void execute() throws MojoExecutionException {
69          super.execute();
70  
71          try {
72              ScmRepository repository = getScmRepository();
73              ListScmResult result = getScmManager()
74                      .list(repository, getFileSet(), recursive, getScmVersion(scmVersionType, scmVersion));
75  
76              checkResult(result);
77  
78              if (result.getFiles() != null) {
79                  for (ScmFile scmFile : result.getFiles()) {
80                      getLog().info(scmFile.getPath());
81                  }
82              }
83          } catch (ScmException | IOException e) {
84              throw new MojoExecutionException("Cannot run list command : ", e);
85          }
86      }
87  }