You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2014/10/03 23:06:59 UTC
svn commit: r1629322 - in /maven/plugins/trunk/maven-compiler-plugin/src:
it/MCOMPILER-157/ it/MCOMPILER-157/annotation-processor/
it/MCOMPILER-157/annotation-processor/src/
it/MCOMPILER-157/annotation-processor/src/main/
it/MCOMPILER-157/annotation-pr...
Author: jdcasey
Date: Fri Oct 3 21:06:58 2014
New Revision: 1629322
URL: http://svn.apache.org/r1629322
Log:
[MCOMPILER-157] Add generated sources directory as compile/testCompile source root after annotation processor runs. This includes an integration test that uses a custom annotation processor to generate text files based on annotated classes, and a custom plugin to verify that these text files are available via project.getCompileSourceRoots() / project.getTestCompileSourceRoots().
Added:
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/pom.xml
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/src/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/src/main/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/src/main/java/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/src/main/java/org/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/src/main/java/org/issue/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/src/main/java/org/issue/SimpleAnnotation.java
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/src/main/java/org/issue/SimpleAnnotationProcessor.java
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/pom.xml
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/main/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/main/java/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/main/java/org/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/main/java/org/issue/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/main/java/org/issue/SimpleObject.java
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/test/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/test/java/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/test/java/org/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/test/java/org/issue/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/test/java/org/issue/SimpleTestObject.java
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-verify/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-verify/pom.xml
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-verify/src/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-verify/src/main/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-verify/src/main/java/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-verify/src/main/java/org/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-verify/src/main/java/org/issue/
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-verify/src/main/java/org/issue/SourcePathReadGoal.java
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/invoker.properties
maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/pom.xml (with props)
Modified:
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java
Added: maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/pom.xml?rev=1629322&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/pom.xml (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/pom.xml Fri Oct 3 21:06:58 2014
@@ -0,0 +1,13 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+
+ <parent>
+ <groupId>org.issue</groupId>
+ <artifactId>compiler-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>annotation-processor</artifactId>
+</project>
\ No newline at end of file
Added: maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/src/main/java/org/issue/SimpleAnnotation.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/src/main/java/org/issue/SimpleAnnotation.java?rev=1629322&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/src/main/java/org/issue/SimpleAnnotation.java (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/src/main/java/org/issue/SimpleAnnotation.java Fri Oct 3 21:06:58 2014
@@ -0,0 +1,12 @@
+package org.issue;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.SOURCE)
+public @interface SimpleAnnotation {
+
+}
Added: maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/src/main/java/org/issue/SimpleAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/src/main/java/org/issue/SimpleAnnotationProcessor.java?rev=1629322&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/src/main/java/org/issue/SimpleAnnotationProcessor.java (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-processor/src/main/java/org/issue/SimpleAnnotationProcessor.java Fri Oct 3 21:06:58 2014
@@ -0,0 +1,52 @@
+package org.issue;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Set;
+
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.Filer;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.Name;
+import javax.lang.model.element.PackageElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.util.Elements;
+import javax.tools.FileObject;
+import javax.tools.StandardLocation;
+
+@SupportedSourceVersion(SourceVersion.RELEASE_6)
+@SupportedAnnotationTypes("org.issue.SimpleAnnotation")
+public class SimpleAnnotationProcessor extends AbstractProcessor {
+
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ Filer filer = processingEnv.getFiler();
+
+ Elements elementUtils = processingEnv.getElementUtils();
+
+ Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(SimpleAnnotation.class);
+
+ for (Element element : elements) {
+ Name name = element.getSimpleName();
+
+ PackageElement packageElement = elementUtils.getPackageOf(element);
+
+ try {
+ FileObject resource = filer.createResource(StandardLocation.SOURCE_OUTPUT, packageElement.getQualifiedName(), name + ".txt", element);
+
+ Writer writer = resource.openWriter();
+ writer.write(name.toString());
+ writer.close();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ return !elements.isEmpty();
+ }
+
+}
Added: maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/pom.xml?rev=1629322&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/pom.xml (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/pom.xml Fri Oct 3 21:06:58 2014
@@ -0,0 +1,60 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.issue</groupId>
+ <artifactId>compiler-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>annotation-user</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.issue</groupId>
+ <artifactId>annotation-processor</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <annotationProcessors>
+ <annotationProcessor>org.issue.SimpleAnnotationProcessor</annotationProcessor>
+ </annotationProcessors>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.issue</groupId>
+ <artifactId>annotation-verify</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <id>verify-annotations</id>
+ <goals>
+ <goal>read-source</goal>
+ </goals>
+ <configuration>
+ <sourceClass>org.issue.SimpleObject</sourceClass>
+ <testSourceClass>org.issue.SimpleTestObject</testSourceClass>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Added: maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/main/java/org/issue/SimpleObject.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/main/java/org/issue/SimpleObject.java?rev=1629322&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/main/java/org/issue/SimpleObject.java (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/main/java/org/issue/SimpleObject.java Fri Oct 3 21:06:58 2014
@@ -0,0 +1,6 @@
+package org.issue;
+
+@SimpleAnnotation
+public class SimpleObject {
+
+}
Added: maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/test/java/org/issue/SimpleTestObject.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/test/java/org/issue/SimpleTestObject.java?rev=1629322&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/test/java/org/issue/SimpleTestObject.java (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-user/src/test/java/org/issue/SimpleTestObject.java Fri Oct 3 21:06:58 2014
@@ -0,0 +1,6 @@
+package org.issue;
+
+@SimpleAnnotation
+public class SimpleTestObject {
+
+}
Added: maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-verify/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-verify/pom.xml?rev=1629322&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-verify/pom.xml (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-verify/pom.xml Fri Oct 3 21:06:58 2014
@@ -0,0 +1,109 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.issue</groupId>
+ <artifactId>compiler-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>annotation-verify</artifactId>
+ <packaging>maven-plugin</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.issue</groupId>
+ <artifactId>annotation-processor</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <version>3.3</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>@mavenVersion@</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>@mavenVersion@</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>@mavenVersion@</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.maven.reporting</groupId>
+ <artifactId>maven-reporting-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-file</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-http-lightweight</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-ssh</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-ssh-external</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>classworlds</groupId>
+ <artifactId>classworlds</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-interactivity-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-shared-utils</artifactId>
+ <version>0.1</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>@mavenPluginPluginVersion@</version>
+ <configuration>
+ <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+ </configuration>
+ <executions>
+ <execution>
+ <id>mojo-descriptor</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>descriptor</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Added: maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-verify/src/main/java/org/issue/SourcePathReadGoal.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-verify/src/main/java/org/issue/SourcePathReadGoal.java?rev=1629322&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-verify/src/main/java/org/issue/SourcePathReadGoal.java (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/annotation-verify/src/main/java/org/issue/SourcePathReadGoal.java Fri Oct 3 21:06:58 2014
@@ -0,0 +1,88 @@
+package org.issue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.utils.StringUtils;
+import org.apache.maven.shared.utils.io.FileUtils;
+
+@Mojo( name = "read-source", defaultPhase = LifecyclePhase.PROCESS_TEST_CLASSES )
+public class SourcePathReadGoal
+ extends AbstractMojo
+{
+
+ @Parameter
+ protected String sourceClass;
+
+ @Parameter
+ protected String testSourceClass;
+
+ @Parameter( defaultValue = "${project}" )
+ protected MavenProject project;
+
+ @SuppressWarnings( "unchecked" )
+ public void execute()
+ throws MojoExecutionException, MojoFailureException
+ {
+ if ( sourceClass != null )
+ {
+ getLog().info( "Checking compile source roots for: '" + sourceClass + "'" );
+ assertGeneratedSourceFileFor( sourceClass, project.getCompileSourceRoots() );
+ }
+
+ if ( testSourceClass != null )
+ {
+ getLog().info( "Checking test-compile source roots for: '" + testSourceClass + "'" );
+ assertGeneratedSourceFileFor( testSourceClass, project.getTestCompileSourceRoots() );
+ }
+ }
+
+ private void assertGeneratedSourceFileFor( String sourceClass, List<String> sourceRoots )
+ throws MojoFailureException, MojoExecutionException
+ {
+ String sourceFile = sourceClass.replace( '.', '/' )
+ .concat( ".txt" );
+
+ boolean found = false;
+ for ( String root : sourceRoots )
+ {
+ File f = new File( root, sourceFile );
+ getLog().info( "Looking for: " + f );
+ if ( f.exists() )
+ {
+ try
+ {
+ String[] nameParts = sourceClass.split( "\\." );
+ String content = FileUtils.fileRead( f );
+ if ( !nameParts[nameParts.length-1].equals( content ) )
+ {
+ throw new MojoFailureException( "Non-matching content in: " + f + "\n expected: '"
+ + sourceClass + "'\n found: '" + content + "'" );
+ }
+
+ found = true;
+ break;
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Cannot read contents of: " + f, e );
+ }
+ }
+ }
+
+ if ( !found )
+ {
+ throw new MojoFailureException( "Cannot find generated source file: " + sourceFile + " in:\n "
+ + StringUtils.join( sourceRoots.iterator(), "\n " ) );
+ }
+ }
+
+}
Added: maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/invoker.properties?rev=1629322&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/invoker.properties (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/invoker.properties Fri Oct 3 21:06:58 2014
@@ -0,0 +1 @@
+invoker.goals=clean process-test-classes
\ No newline at end of file
Added: maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/pom.xml?rev=1629322&view=auto
==============================================================================
Binary file - no diff available.
Propchange: maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-157/pom.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Modified: maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java?rev=1629322&r1=1629321&r2=1629322&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java (original)
+++ maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java Fri Oct 3 21:06:58 2014
@@ -25,6 +25,7 @@ import org.apache.maven.plugin.MojoExecu
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.incremental.IncrementalBuildHelper;
import org.apache.maven.shared.incremental.IncrementalBuildHelperRequest;
import org.apache.maven.shared.utils.ReaderFactory;
@@ -72,6 +73,7 @@ import java.util.Set;
public abstract class AbstractCompilerMojo
extends AbstractMojo
{
+
// ----------------------------------------------------------------------
// Configurables
// ----------------------------------------------------------------------
@@ -324,6 +326,12 @@ public abstract class AbstractCompilerMo
private MavenSession session;
/**
+ * The current project instance. This is used for propagating generated-sources paths as compile/testCompile source roots.
+ */
+ @Parameter( defaultValue = "${project}", readonly = true, required = true )
+ private MavenProject project;
+
+ /**
* Strategy to re use javacc class created:
* <ul>
* <li><code>reuseCreated</code> (default): will reuse already created but in case of multi-threaded builds,
@@ -464,8 +472,6 @@ public abstract class AbstractCompilerMo
compilerConfiguration.setClasspathEntries( getClasspathElements() );
- compilerConfiguration.setSourceLocations( compileSourceRoots );
-
compilerConfiguration.setOptimize( optimize );
compilerConfiguration.setDebug( debug );
@@ -473,7 +479,8 @@ public abstract class AbstractCompilerMo
if ( debug && StringUtils.isNotEmpty( debuglevel ) )
{
String[] split = StringUtils.split( debuglevel, "," );
- for (String aSplit : split) {
+ for ( String aSplit : split )
+ {
if (!(aSplit.equalsIgnoreCase("none") || aSplit.equalsIgnoreCase("lines")
|| aSplit.equalsIgnoreCase("vars") || aSplit.equalsIgnoreCase("source"))) {
throw new IllegalArgumentException("The specified debug level: '" + aSplit + "' is unsupported. "
@@ -495,7 +502,41 @@ public abstract class AbstractCompilerMo
compilerConfiguration.setProc( proc );
- compilerConfiguration.setGeneratedSourcesDirectory( getGeneratedSourcesDirectory() );
+ File generatedSourcesDirectory = getGeneratedSourcesDirectory();
+ compilerConfiguration.setGeneratedSourcesDirectory( generatedSourcesDirectory );
+
+ if ( generatedSourcesDirectory != null )
+ {
+ String generatedSourcesPath = generatedSourcesDirectory.getAbsolutePath();
+
+ compileSourceRoots.add( generatedSourcesPath );
+
+ if ( isTestCompile() )
+ {
+ getLog().debug( "Adding " + generatedSourcesPath + " to test-compile source roots:\n "
+ + StringUtils.join( project.getTestCompileSourceRoots()
+ .iterator(), "\n " ) );
+
+ project.addTestCompileSourceRoot( generatedSourcesPath );
+
+ getLog().debug( "New test-compile source roots:\n "
+ + StringUtils.join( project.getTestCompileSourceRoots()
+ .iterator(), "\n " ) );
+ }
+ else
+ {
+ getLog().debug( "Adding " + generatedSourcesPath + " to compile source roots:\n "
+ + StringUtils.join( project.getCompileSourceRoots()
+ .iterator(), "\n " ) );
+
+ project.addCompileSourceRoot( generatedSourcesPath );
+
+ getLog().debug( "New compile source roots:\n " + StringUtils.join( project.getCompileSourceRoots()
+ .iterator(), "\n " ) );
+ }
+ }
+
+ compilerConfiguration.setSourceLocations( compileSourceRoots );
compilerConfiguration.setAnnotationProcessors( annotationProcessors );
@@ -890,6 +931,11 @@ public abstract class AbstractCompilerMo
}
}
+ protected boolean isTestCompile()
+ {
+ return false;
+ }
+
protected CompilerResult convertToCompilerResult( List<CompilerError> compilerErrors )
{
if ( compilerErrors == null )
@@ -1224,4 +1270,5 @@ public abstract class AbstractCompilerMo
return false;
}
+
}
Modified: maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java?rev=1629322&r1=1629321&r2=1629322&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java (original)
+++ maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java Fri Oct 3 21:06:58 2014
@@ -237,4 +237,10 @@ public class TestCompilerMojo
return generatedTestSourcesDirectory;
}
+ @Override
+ protected boolean isTestCompile()
+ {
+ return true;
+ }
+
}
Modified: maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java?rev=1629322&r1=1629321&r2=1629322&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java (original)
+++ maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java Fri Oct 3 21:06:58 2014
@@ -303,6 +303,7 @@ public class CompilerMojoTestCase
setVariableValueToObject( mojo, "projectArtifact", new ArtifactStub() );
setVariableValueToObject( mojo, "classpathElements", Collections.EMPTY_LIST );
setVariableValueToObject( mojo, "session", getMockMavenSession() );
+ setVariableValueToObject( mojo, "project", getMockMavenProject() );
setVariableValueToObject( mojo, "mojoExecution", getMockMojoExecution() );
assertNotNull( mojo );