org.apache.maven.plugin.compiler.CompilerMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maven-compiler-plugin Show documentation
Show all versions of maven-compiler-plugin Show documentation
The Compiler Plugin is used to compile the sources of your project.
package org.apache.maven.plugin.compiler;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner;
import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner;
import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
import java.io.File;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Compiles application sources
*
* @author Jason van Zyl
* @version $Id: CompilerMojo.java 1441990 2013-02-03 23:41:24Z olamy $
* @since 2.0
*/
@org.apache.maven.plugins.annotations.Mojo( name = "compile", defaultPhase = LifecyclePhase.COMPILE, threadSafe = true,
requiresDependencyResolution = ResolutionScope.COMPILE )
public class CompilerMojo
extends AbstractCompilerMojo
{
/**
* The source directories containing the sources to be compiled.
*/
@Parameter( defaultValue = "${project.compileSourceRoots}", readonly = true, required = true )
private List compileSourceRoots;
/**
* Project classpath.
*/
@Parameter( defaultValue = "${project.compileClasspathElements}", readonly = true, required = true )
private List classpathElements;
/**
* The directory for compiled classes.
*/
@Parameter( defaultValue = "${project.build.outputDirectory}", required = true, readonly = true )
private File outputDirectory;
/**
* Projects main artifact.
*
* @todo this is an export variable, really
*/
@Parameter( defaultValue = "${project.artifact}", readonly = true, required = true )
private Artifact projectArtifact;
/**
* A list of inclusion filters for the compiler.
*/
@Parameter
private Set includes = new HashSet();
/**
* A list of exclusion filters for the compiler.
*/
@Parameter
private Set excludes = new HashSet();
/**
*
* Specify where to place generated source files created by annotation processing.
* Only applies to JDK 1.6+
*
*
* @since 2.2
*/
@Parameter( defaultValue = "${project.build.directory}/generated-sources/annotations" )
private File generatedSourcesDirectory;
/**
* Set this to 'true' to bypass compilation of main sources.
* Its use is NOT RECOMMENDED, but quite convenient on occasion.
*/
@Parameter ( property = "maven.main.skip" )
private boolean skipMain;
protected List getCompileSourceRoots()
{
return compileSourceRoots;
}
protected List getClasspathElements()
{
return classpathElements;
}
protected File getOutputDirectory()
{
return outputDirectory;
}
public void execute()
throws MojoExecutionException, CompilationFailureException
{
if ( skipMain )
{
getLog().info( "Not compiling main sources" );
return;
}
super.execute();
if ( outputDirectory.isDirectory() )
{
projectArtifact.setFile( outputDirectory );
}
}
protected SourceInclusionScanner getSourceInclusionScanner( int staleMillis )
{
SourceInclusionScanner scanner = null;
if ( includes.isEmpty() && excludes.isEmpty() )
{
scanner = new StaleSourceScanner( staleMillis );
}
else
{
if ( includes.isEmpty() )
{
includes.add( "**/*.java" );
}
scanner = new StaleSourceScanner( staleMillis, includes, excludes );
}
return scanner;
}
protected SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding )
{
SourceInclusionScanner scanner = null;
// it's not defined if we get the ending with or without the dot '.'
String defaultIncludePattern = "**/*" + ( inputFileEnding.startsWith( "." ) ? "" : "." ) + inputFileEnding;
if ( includes.isEmpty() && excludes.isEmpty() )
{
includes = Collections.singleton( defaultIncludePattern );
scanner = new SimpleSourceInclusionScanner( includes, Collections.emptySet() );
}
else
{
if ( includes.isEmpty() )
{
includes.add( defaultIncludePattern );
}
scanner = new SimpleSourceInclusionScanner( includes, excludes );
}
return scanner;
}
protected String getSource()
{
return source;
}
protected String getTarget()
{
return target;
}
protected String getCompilerArgument()
{
return compilerArgument;
}
protected Map getCompilerArguments()
{
return compilerArguments;
}
protected File getGeneratedSourcesDirectory()
{
return generatedSourcesDirectory;
}
}