View Javadoc

1   package org.apache.maven.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 org.apache.maven.artifact.Artifact;
23  import org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner;
24  import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner;
25  import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
26  
27  import java.io.File;
28  import java.util.Collections;
29  import java.util.HashSet;
30  import java.util.List;
31  import java.util.Map;
32  import java.util.Set;
33  
34  /**
35   * Compiles application sources
36   *
37   * @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
38   * @version $Id: CompilerMojo.html 816611 2012-05-08 13:04:26Z hboutemy $
39   * @since 2.0
40   * @goal compile
41   * @phase compile
42   * @requiresDependencyResolution compile
43   */
44  public class CompilerMojo
45      extends AbstractCompilerMojo
46  {
47      /**
48       * The source directories containing the sources to be compiled.
49       *
50       * @parameter default-value="${project.compileSourceRoots}"
51       * @required
52       * @readonly
53       */
54      private List compileSourceRoots;
55  
56      /**
57       * Project classpath.
58       *
59       * @parameter default-value="${project.compileClasspathElements}"
60       * @required
61       * @readonly
62       */
63      private List classpathElements;
64  
65      /**
66       * The directory for compiled classes.
67       *
68       * @parameter default-value="${project.build.outputDirectory}"
69       * @required
70       * @readonly
71       */
72      private File outputDirectory;
73  
74      /**
75       * Project artifacts.
76       *
77       * @parameter default-value="${project.artifact}"
78       * @required
79       * @readonly
80       * @todo this is an export variable, really
81       */
82      private Artifact projectArtifact;
83  
84      /**
85       * A list of inclusion filters for the compiler.
86       *
87       * @parameter
88       */
89      private Set includes = new HashSet();
90  
91      /**
92       * A list of exclusion filters for the compiler.
93       *
94       * @parameter
95       */
96      private Set excludes = new HashSet();
97  
98      protected List getCompileSourceRoots()
99      {
100         return compileSourceRoots;
101     }
102 
103     protected List getClasspathElements()
104     {
105         return classpathElements;
106     }
107 
108     protected File getOutputDirectory()
109     {
110         return outputDirectory;
111     }
112 
113     public void execute()
114         throws MojoExecutionException, CompilationFailureException
115     {
116         super.execute();
117 
118         projectArtifact.setFile( outputDirectory );
119     }
120 
121     protected SourceInclusionScanner getSourceInclusionScanner( int staleMillis )
122     {
123         SourceInclusionScanner scanner = null;
124 
125         if ( includes.isEmpty() && excludes.isEmpty() )
126         {
127             scanner = new StaleSourceScanner( staleMillis );
128         }
129         else
130         {
131             if ( includes.isEmpty() )
132             {
133                 includes.add( "**/*.java" );
134             }
135             scanner = new StaleSourceScanner( staleMillis, includes, excludes );
136         }
137 
138         return scanner;
139     }
140 
141     protected SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding )
142     {
143         SourceInclusionScanner scanner = null;
144 
145         if ( includes.isEmpty() && excludes.isEmpty() )
146         {
147             includes = Collections.singleton( "**/*." + inputFileEnding );
148             scanner = new SimpleSourceInclusionScanner( includes, Collections.EMPTY_SET );
149         }
150         else
151         {
152             if ( includes.isEmpty() )
153             {
154                 includes.add( "**/*." + inputFileEnding );
155             }
156             scanner = new SimpleSourceInclusionScanner( includes, excludes );
157         }
158 
159         return scanner;
160     }
161 
162     protected String getSource()
163     {
164       return source;
165     }
166 
167     protected String getTarget()
168     {
169       return target;
170     }
171 
172     protected String getCompilerArgument()
173     {
174       return compilerArgument;
175     }
176 
177     protected Map getCompilerArguments()
178     {
179       return compilerArguments;
180     }
181 
182 }