Coverage Report - org.apache.maven.plugin.CompilerMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
CompilerMojo
93%
27/29
66%
8/12
1.545
 
 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$
 39  
  * @since 2.0
 40  
  * @goal compile
 41  
  * @phase compile
 42  
  * @requiresDependencyResolution compile
 43  
  */
 44  9
 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<String> compileSourceRoots;
 55  
 
 56  
     /**
 57  
      * Project classpath.
 58  
      *
 59  
      * @parameter default-value="${project.compileClasspathElements}"
 60  
      * @required
 61  
      * @readonly
 62  
      */
 63  
     private List<String> 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  9
     private Set<String> includes = new HashSet<String>();
 90  
 
 91  
     /**
 92  
      * A list of exclusion filters for the compiler.
 93  
      *
 94  
      * @parameter
 95  
      */
 96  9
     private Set<String> excludes = new HashSet<String>();
 97  
 
 98  
     /**
 99  
      * <p>
 100  
      * Specify where to place generated source files created by annotation processing.
 101  
      * Only applies to JDK 1.6+
 102  
      * </p>
 103  
      * @parameter default-value="${project.build.directory}/generated-sources/annotations"
 104  
      * @since 2.2
 105  
      */
 106  
     private File generatedSourcesDirectory;
 107  
 
 108  
 
 109  
     protected List<String> getCompileSourceRoots()
 110  
     {
 111  27
         return compileSourceRoots;
 112  
     }
 113  
 
 114  
     protected List<String> getClasspathElements()
 115  
     {
 116  21
         return classpathElements;
 117  
     }
 118  
 
 119  
     protected File getOutputDirectory()
 120  
     {
 121  34
         return outputDirectory;
 122  
     }
 123  
 
 124  
     public void execute()
 125  
         throws MojoExecutionException, CompilationFailureException
 126  
     {
 127  9
         super.execute();
 128  
 
 129  8
         projectArtifact.setFile( outputDirectory );
 130  8
     }
 131  
 
 132  
     protected SourceInclusionScanner getSourceInclusionScanner( int staleMillis )
 133  
     {
 134  8
         SourceInclusionScanner scanner = null;
 135  
 
 136  8
         if ( includes.isEmpty() && excludes.isEmpty() )
 137  
         {
 138  6
             scanner = new StaleSourceScanner( staleMillis );
 139  
         }
 140  
         else
 141  
         {
 142  2
             if ( includes.isEmpty() )
 143  
             {
 144  0
                 includes.add( "**/*.java" );
 145  
             }
 146  2
             scanner = new StaleSourceScanner( staleMillis, includes, excludes );
 147  
         }
 148  
 
 149  8
         return scanner;
 150  
     }
 151  
 
 152  
     protected SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding )
 153  
     {
 154  5
         SourceInclusionScanner scanner = null;
 155  
 
 156  5
         if ( includes.isEmpty() && excludes.isEmpty() )
 157  
         {
 158  4
             includes = Collections.singleton( "**/*." + inputFileEnding );
 159  4
             scanner = new SimpleSourceInclusionScanner( includes, Collections.EMPTY_SET );
 160  
         }
 161  
         else
 162  
         {
 163  1
             if ( includes.isEmpty() )
 164  
             {
 165  0
                 includes.add( "**/*." + inputFileEnding );
 166  
             }
 167  1
             scanner = new SimpleSourceInclusionScanner( includes, excludes );
 168  
         }
 169  
 
 170  5
         return scanner;
 171  
     }
 172  
 
 173  
     protected String getSource()
 174  
     {
 175  8
       return source;
 176  
     }
 177  
 
 178  
     protected String getTarget()
 179  
     {
 180  8
       return target;
 181  
     }
 182  
 
 183  
     protected String getCompilerArgument()
 184  
     {
 185  8
       return compilerArgument;
 186  
     }
 187  
 
 188  
     protected Map<String, String> getCompilerArguments()
 189  
     {
 190  8
       return compilerArguments;
 191  
     }
 192  
 
 193  
     protected File getGeneratedSourcesDirectory()
 194  
     {
 195  8
         return generatedSourcesDirectory;
 196  
     }
 197  
 
 198  
 }