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.scm.ScmException;
27 import org.apache.maven.scm.ScmFile;
28 import org.apache.maven.scm.ScmFileSet;
29 import org.apache.maven.scm.command.list.ListScmResult;
30 import org.apache.maven.scm.repository.ScmRepository;
31
32 /**
33 * Get the list of project files.
34 *
35 * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
36 * @version $Id: ListMojo.java 1055646 2011-01-05 21:22:58Z olamy $
37 * @goal list
38 * @aggregator
39 */
40 public class ListMojo
41 extends AbstractScmMojo
42 {
43 /**
44 * The version type (branch/tag/revision) of scmVersion.
45 *
46 * @parameter expression="${scmVersionType}"
47 */
48 private String scmVersionType;
49
50 /**
51 * The version (revision number/branch name/tag name).
52 *
53 * @parameter expression="${scmVersion}"
54 */
55 private String scmVersion;
56
57 /**
58 * Use recursive mode.
59 *
60 * @parameter expression="${recursive}" default-value="true"
61 */
62 private boolean recursive = true;
63
64 /** {@inheritDoc} */
65 public void execute()
66 throws MojoExecutionException
67 {
68 super.execute();
69
70 try
71 {
72 ScmRepository repository = getScmRepository();
73 ListScmResult result = getScmManager().list( repository, getFileSet(), recursive,
74 getScmVersion( scmVersionType, scmVersion ) );
75
76 checkResult( result );
77
78 if ( result.getFiles() != null )
79 {
80 for ( ScmFile scmFile : result.getFiles() )
81 {
82 getLog().info( scmFile.getPath() );
83 }
84 }
85 }
86 catch ( ScmException e )
87 {
88 throw new MojoExecutionException( "Cannot run list command : ", e );
89 }
90 catch ( IOException e )
91 {
92 throw new MojoExecutionException( "Cannot run list command : ", e );
93 }
94 }
95
96 public ScmFileSet getFileSet()
97 throws IOException
98 {
99 if ( getIncludes() != null || getExcludes() != null )
100 {
101 return new ScmFileSet( getWorkingDirectory(), getIncludes(), getExcludes() );
102 }
103 else
104 {
105 return new ScmFileSet( getWorkingDirectory(), new File( "." ) );
106 }
107 }
108
109 }
110