Skip to content

Commit

Permalink
issue 47
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Jan 30, 2013
1 parent e29da4c commit 68d6174
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ sign-and-deploy.sh
=======
/target/
>>>>>>> bf958dd87dd0dcd79c32815f3cdbafbfc8f350a5
/issue47.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<File> 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<File> getSourceDirectories();
protected abstract java.util.Set<File> getSourceDirectories( java.util.Set<File> result );

/**
*
Expand Down Expand Up @@ -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<File> sourceDirs = getSourceDirectories();
if( sourceDirs == null ) throw new IllegalStateException("getSourceDirectories is null!");
java.util.Set<File> sourceDirs = getSourceDirectories(new java.util.HashSet<File>( 5 ));

if( additionalSourceDirectories != null && additionalSourceDirectories.length>0) {
sourceDirs.addAll( Arrays.asList((File[])additionalSourceDirectories) );
if( addCompileSourceRoots ) {
final java.util.List<String> 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<File> files = new java.util.ArrayList<File>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,13 @@ public class MainAnnotationProcessorMojo extends AbstractAnnotationProcessorMojo
@Parameter( defaultValue="${project.build.outputDirectory}")
private File outputClassDirectory;

@Override
public java.util.Set<File> getSourceDirectories()
{
java.util.List<String> sourceRoots = project.getCompileSourceRoots();
java.util.Set<File> result = new java.util.HashSet<File>( 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);
Expand All @@ -99,10 +86,19 @@ public File getDefaultOutputDirectory()
return defaultOutputDirectory;
}

@Override
public java.util.Set<File> getSourceDirectories( final java.util.Set<File> result )
{
result.add( sourceDirectory );

return result;
}

@Override
@SuppressWarnings("unchecked")
protected java.util.Set<String> getClasspathElements( java.util.Set<String> result)
protected java.util.Set<String> getClasspathElements( final java.util.Set<String> result)
{

List<Resource> resources = project.getResources();

if( resources!=null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,6 @@ public class TestAnnotationProcessorMojo extends AbstractAnnotationProcessorMojo
private File outputClassDirectory;

@Override
public java.util.Set<File> getSourceDirectories()
{
java.util.List<String> sourceRoots = project.getCompileSourceRoots();
java.util.Set<File> result = new java.util.HashSet<File>( 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);
Expand All @@ -99,10 +86,18 @@ protected File getOutputClassDirectory()
return outputClassDirectory;
}

@Override
public java.util.Set<File> getSourceDirectories( final java.util.Set<File> result )
{
result.add( sourceDirectory );

return result;
}


@SuppressWarnings("unchecked")
@Override
protected java.util.Set<String> getClasspathElements( java.util.Set<String> result )
protected java.util.Set<String> getClasspathElements( final java.util.Set<String> result )
{
List<Resource> resources = project.getTestResources();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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
Expand Down

0 comments on commit 68d6174

Please sign in to comment.