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