From 68d6174fd75a59db9348cc38e6039b0df40ff75a Mon Sep 17 00:00:00 2001 From: softphone Date: Wed, 30 Jan 2013 14:43:39 +0100 Subject: [PATCH] issue 47 --- .gitignore | 1 + .../AbstractAnnotationProcessorMojo.java | 51 ++++++++++++++----- .../MainAnnotationProcessorMojo.java | 26 ++++------ .../TestAnnotationProcessorMojo.java | 23 ++++----- .../maven/plugin/processor/ProcessorTest.java | 2 + 5 files changed, 60 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index 4082989..63fee9e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ sign-and-deploy.sh ======= /target/ >>>>>>> bf958dd87dd0dcd79c32815f3cdbafbfc8f350a5 +/issue47.txt \ No newline at end of file diff --git a/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java b/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java index 2fd178c..a7668e5 100644 --- a/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java +++ b/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java @@ -141,24 +141,31 @@ public abstract class AbstractAnnotationProcessorMojo extends AbstractMojo * additional source directories for the annotation processors. */ @Parameter - private File[] additionalSourceDirectories; + private java.util.List additionalSourceDirectories; - + + /** + * if true add to the source directory of the annotation processor all compile source roots detected int the project + * This is useful when we plan to use build-helper-maven-plugin + * + * @since 2.1.1 + */ + @Parameter(defaultValue = "false") + private boolean addCompileSourceRoots = false; + + + + /** + * for execution synchronization + */ private static final Lock syncExecutionLock = new ReentrantLock(); - public File[] getAdditionalSourceDirectories() { - if( additionalSourceDirectories == null ) { - additionalSourceDirectories = new File[0]; - } - return additionalSourceDirectories; - } - /** * * @return supported source directories */ - protected abstract java.util.Set getSourceDirectories(); + protected abstract java.util.Set getSourceDirectories( java.util.Set result ); /** * @@ -279,12 +286,28 @@ private void executeWithExceptionsHandled() throws Exception final String includesString = ( includes==null || includes.length==0) ? "**/*.java" : StringUtils.join(includes, ","); final String excludesString = ( excludes==null || excludes.length==0) ? null : StringUtils.join(excludes, ","); - java.util.Set sourceDirs = getSourceDirectories(); - if( sourceDirs == null ) throw new IllegalStateException("getSourceDirectories is null!"); + java.util.Set sourceDirs = getSourceDirectories(new java.util.HashSet( 5 )); - if( additionalSourceDirectories != null && additionalSourceDirectories.length>0) { - sourceDirs.addAll( Arrays.asList((File[])additionalSourceDirectories) ); + if( addCompileSourceRoots ) { + final java.util.List sourceRoots = project.getCompileSourceRoots(); + if( sourceRoots != null ) { + + for( String s : sourceRoots ) { + sourceDirs.add( new File(s) ); + } + } + } + + if( additionalSourceDirectories != null && !additionalSourceDirectories.isEmpty() ) { + sourceDirs.addAll( additionalSourceDirectories ); + } + + + if( sourceDirs == null ) { + throw new IllegalStateException("getSourceDirectories is null!"); + } + List files = new java.util.ArrayList(); diff --git a/src/main/java/org/bsc/maven/plugin/processor/MainAnnotationProcessorMojo.java b/src/main/java/org/bsc/maven/plugin/processor/MainAnnotationProcessorMojo.java index 675576e..a91c5ba 100644 --- a/src/main/java/org/bsc/maven/plugin/processor/MainAnnotationProcessorMojo.java +++ b/src/main/java/org/bsc/maven/plugin/processor/MainAnnotationProcessorMojo.java @@ -68,26 +68,13 @@ public class MainAnnotationProcessorMojo extends AbstractAnnotationProcessorMojo @Parameter( defaultValue="${project.build.outputDirectory}") private File outputClassDirectory; - @Override - public java.util.Set getSourceDirectories() - { - java.util.List sourceRoots = project.getCompileSourceRoots(); - java.util.Set result = new java.util.HashSet( sourceRoots.size() + 1); - - result.add( sourceDirectory ); - for( String s : sourceRoots ) { - result.add( new File(s) ); - } - - return result; - } - @Override protected File getOutputClassDirectory() { return outputClassDirectory; } + @Override protected void addCompileSourceRoot(MavenProject project, String dir) { project.addCompileSourceRoot(dir); @@ -99,10 +86,19 @@ public File getDefaultOutputDirectory() return defaultOutputDirectory; } + @Override + public java.util.Set getSourceDirectories( final java.util.Set result ) + { + result.add( sourceDirectory ); + + return result; + } + @Override @SuppressWarnings("unchecked") - protected java.util.Set getClasspathElements( java.util.Set result) + protected java.util.Set getClasspathElements( final java.util.Set result) { + List resources = project.getResources(); if( resources!=null ) { diff --git a/src/main/java/org/bsc/maven/plugin/processor/TestAnnotationProcessorMojo.java b/src/main/java/org/bsc/maven/plugin/processor/TestAnnotationProcessorMojo.java index 15c632f..8f06599 100644 --- a/src/main/java/org/bsc/maven/plugin/processor/TestAnnotationProcessorMojo.java +++ b/src/main/java/org/bsc/maven/plugin/processor/TestAnnotationProcessorMojo.java @@ -69,19 +69,6 @@ public class TestAnnotationProcessorMojo extends AbstractAnnotationProcessorMojo private File outputClassDirectory; @Override - public java.util.Set getSourceDirectories() - { - java.util.List sourceRoots = project.getCompileSourceRoots(); - java.util.Set result = new java.util.HashSet( sourceRoots.size() + 1); - - result.add( sourceDirectory ); - for( String s : sourceRoots ) { - result.add( new File(s) ); - } - - return result; - } - protected void addCompileSourceRoot(MavenProject project, String dir) { project.addTestCompileSourceRoot(dir); @@ -99,10 +86,18 @@ protected File getOutputClassDirectory() return outputClassDirectory; } + @Override + public java.util.Set getSourceDirectories( final java.util.Set result ) + { + result.add( sourceDirectory ); + + return result; + } + @SuppressWarnings("unchecked") @Override - protected java.util.Set getClasspathElements( java.util.Set result ) + protected java.util.Set getClasspathElements( final java.util.Set result ) { List resources = project.getTestResources(); diff --git a/src/test/java/org/bsc/maven/plugin/processor/ProcessorTest.java b/src/test/java/org/bsc/maven/plugin/processor/ProcessorTest.java index afe4c1a..1191e0c 100644 --- a/src/test/java/org/bsc/maven/plugin/processor/ProcessorTest.java +++ b/src/test/java/org/bsc/maven/plugin/processor/ProcessorTest.java @@ -4,6 +4,7 @@ */ package org.bsc.maven.plugin.processor; +import java.io.File; import org.junit.Assert; import org.junit.Test; import org.hamcrest.core.*; @@ -24,6 +25,7 @@ public void compareFile() { final java.io.File f3 = new java.io.File( "target/classes"); Assert.assertThat( f3.equals(f2), Is.is(true)); + } @Test