mirror of https://github.com/apache/maven.git
o Adding support for selecting the Plexus compiler implementation. Configure
the compiler plugin with <compilerId>, both "javac" and "eclipse" will work. The default value is still "javac" so this shouldn't break anything. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@227494 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b69490b828
commit
b1b01a6c94
|
@ -17,10 +17,23 @@
|
|||
<artifactId>plexus-compiler-api</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>plexus</groupId>
|
||||
<artifactId>plexus-compiler-manager</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>plexus</groupId>
|
||||
<artifactId>plexus-compiler-javac</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>plexus</groupId>
|
||||
<artifactId>plexus-compiler-eclipse</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
|
|
|
@ -19,7 +19,8 @@ package org.apache.maven.plugin;
|
|||
import org.codehaus.plexus.compiler.Compiler;
|
||||
import org.codehaus.plexus.compiler.CompilerConfiguration;
|
||||
import org.codehaus.plexus.compiler.CompilerError;
|
||||
import org.codehaus.plexus.compiler.javac.JavacCompiler;
|
||||
import org.codehaus.plexus.compiler.manager.CompilerManager;
|
||||
import org.codehaus.plexus.compiler.manager.NoSuchCompilerException;
|
||||
import org.codehaus.plexus.compiler.util.scan.InclusionScanException;
|
||||
import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner;
|
||||
import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
|
||||
|
@ -35,46 +36,55 @@ import java.util.Set;
|
|||
public abstract class AbstractCompilerMojo
|
||||
extends AbstractMojo
|
||||
{
|
||||
|
||||
private Compiler compiler = new JavacCompiler();
|
||||
|
||||
/**
|
||||
* Whether to include debugging information in the compiled class files.
|
||||
* The default value is true.
|
||||
*
|
||||
*
|
||||
* @parameter expression="${maven.compiler.debug}" default-value="true"
|
||||
*/
|
||||
private boolean debug;
|
||||
|
||||
|
||||
/**
|
||||
* The -source argument for the Java compiler
|
||||
*
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
private String source;
|
||||
|
||||
|
||||
/**
|
||||
* The -target argument for the Java compiler
|
||||
*
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
private String target;
|
||||
|
||||
|
||||
/**
|
||||
* The -encoding argument for the Java compiler
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
private String encoding;
|
||||
|
||||
|
||||
/**
|
||||
* The granularity in milliseconds of the last modification
|
||||
* date for testing whether a source needs recompilation
|
||||
*
|
||||
*
|
||||
* @parameter expression="${lastModGranularityMs}" default-value="0"
|
||||
*/
|
||||
private int staleMillis;
|
||||
|
||||
|
||||
/**
|
||||
* @parameter default-value="javac"
|
||||
*/
|
||||
private String compilerId;
|
||||
|
||||
/**
|
||||
* @parameter expression="${component.org.codehaus.plexus.compiler.manager.CompilerManager}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
private CompilerManager compilerManager;
|
||||
|
||||
protected abstract List getClasspathElements();
|
||||
|
||||
protected abstract List getCompileSourceRoots();
|
||||
|
@ -95,10 +105,16 @@ public abstract class AbstractCompilerMojo
|
|||
return;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Create the compiler configuration
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
|
||||
|
||||
compilerConfiguration.setOutputLocation( getOutputDirectory().getAbsolutePath() );
|
||||
|
||||
compilerConfiguration.setClasspathEntries( getClasspathElements() );
|
||||
|
||||
compilerConfiguration.setSourceLocations( compileSourceRoots );
|
||||
|
||||
// TODO: have an option to always compile (without need to clean)
|
||||
|
@ -128,10 +144,53 @@ public abstract class AbstractCompilerMojo
|
|||
{
|
||||
compilerConfiguration.addCompilerOption( "-encoding" , encoding );
|
||||
}
|
||||
|
||||
|
||||
compilerConfiguration.setDebug( debug );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Dump configuration
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
if ( getLog().isDebugEnabled() )
|
||||
{
|
||||
getLog().debug( "Classpath:" );
|
||||
|
||||
for ( Iterator it = getClasspathElements().iterator(); it.hasNext(); )
|
||||
{
|
||||
String s = (String) it.next();
|
||||
|
||||
getLog().debug( " " + s );
|
||||
}
|
||||
|
||||
getLog().debug( "Source roots:" );
|
||||
|
||||
for ( Iterator it = getCompileSourceRoots().iterator(); it.hasNext(); )
|
||||
{
|
||||
String root = (String) it.next();
|
||||
|
||||
getLog().debug( " " + root );
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Compile!
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
List messages;
|
||||
|
||||
Compiler compiler;
|
||||
|
||||
try
|
||||
{
|
||||
compiler = compilerManager.getCompiler( compilerId );
|
||||
}
|
||||
catch ( NoSuchCompilerException e )
|
||||
{
|
||||
throw new MojoExecutionException( "No such compiler '" + e.getCompilerId() + "'." );
|
||||
}
|
||||
|
||||
getLog().info( "Using compiler '" + compilerId + "'." );
|
||||
|
||||
try
|
||||
{
|
||||
messages = compiler.compile( compilerConfiguration );
|
||||
|
|
|
@ -1,5 +1,21 @@
|
|||
package org.apache.maven.plugin;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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.codehaus.plexus.compiler.CompilerError;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
|
|
@ -2,16 +2,18 @@ package org.apache.maven.plugin;
|
|||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
* Licensed 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;
|
||||
|
@ -27,7 +29,6 @@ import java.io.File;
|
|||
* @requiresDependencyResolution compile
|
||||
* @description Compiles application sources
|
||||
*/
|
||||
|
||||
public class CompilerMojo
|
||||
extends AbstractCompilerMojo
|
||||
{
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package org.apache.maven.plugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.io.File;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
|
@ -19,6 +16,9 @@ import java.io.File;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
|
|
Loading…
Reference in New Issue