Index: org/apache/maven/plugin/TestCompilerMojo.java =================================================================== --- org/apache/maven/plugin/TestCompilerMojo.java (.../branches/maven-compiler-plugin-2.0.2/src/main/java) (revision 72911) +++ org/apache/maven/plugin/TestCompilerMojo.java (.../maven-compiler-plugin/tags/maven-compiler-plugin-2.0.2.SP1/src/main/java) (revision 72919) @@ -23,7 +23,10 @@ import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner; import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; +import java.io.IOException; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -33,6 +36,7 @@ * Compiles application test sources * * @author Jason van Zyl + * @author Thomas Diesler * @version $Id$ * @goal testCompile * @phase test-compile @@ -90,6 +94,20 @@ */ private Set testExcludes = new HashSet(); + /** + * A file of exclusion filters for the compiler. + * + * @parameter + */ + private File testExcludeFile; + + /** + * A file of inclusion filters for the compiler. + * + * @parameter + */ + private File testIncludeFile; + public void execute() throws MojoExecutionException, CompilationFailureException { @@ -122,17 +140,19 @@ { SourceInclusionScanner scanner = null; - if ( testIncludes.isEmpty() && testExcludes.isEmpty() ) + Set effectiveIncludes = getEffectiveIncludes(); + Set effectiveExcludes = getEffectiveExcludes(); + if ( effectiveIncludes.isEmpty() && effectiveExcludes.isEmpty() ) { scanner = new StaleSourceScanner( staleMillis ); } else { - if ( testIncludes.isEmpty() ) + if ( effectiveIncludes.isEmpty() ) { - testIncludes.add( "**/*.java" ); + effectiveIncludes.add( "**/*.java" ); } - scanner = new StaleSourceScanner( staleMillis, testIncludes, testExcludes ); + scanner = new StaleSourceScanner( staleMillis, effectiveIncludes, effectiveExcludes ); } return scanner; @@ -142,21 +162,84 @@ { SourceInclusionScanner scanner = null; - if ( testIncludes.isEmpty() && testExcludes.isEmpty() ) + Set effectiveIncludes = getEffectiveIncludes(); + Set effectiveExcludes = getEffectiveExcludes(); + if ( effectiveIncludes.isEmpty() && effectiveExcludes.isEmpty() ) { - testIncludes = Collections.singleton( "**/*." + inputFileEnding ); - scanner = new SimpleSourceInclusionScanner( testIncludes, Collections.EMPTY_SET ); + effectiveIncludes = Collections.singleton( "**/*." + inputFileEnding ); + scanner = new SimpleSourceInclusionScanner( effectiveIncludes, Collections.EMPTY_SET ); } else { - if ( testIncludes.isEmpty() ) + if ( effectiveIncludes.isEmpty() ) { - testIncludes.add( "**/*." + inputFileEnding ); + effectiveIncludes.add( "**/*." + inputFileEnding ); } - scanner = new SimpleSourceInclusionScanner( testIncludes, testExcludes ); + scanner = new SimpleSourceInclusionScanner( effectiveIncludes, effectiveExcludes ); } return scanner; } + protected Set getEffectiveIncludes() + { + Set effectiveIncludes = new HashSet(testIncludes); + if (testIncludeFile != null) + { + if (testIncludeFile.exists() == false) + throw new IllegalArgumentException("Cannot find: " + testIncludeFile); + + try + { + BufferedReader br = new BufferedReader(new FileReader(testIncludeFile)); + String line = br.readLine(); + while (line != null) + { + if (line.length() > 0 && !line.startsWith("#")) + { + getLog().debug("Add include: " + line); + effectiveIncludes.add(line); + } + line = br.readLine(); + } + br.close(); + } + catch (IOException ex) + { + throw new IllegalArgumentException("Cannot process: " + testIncludeFile, ex); + } + } + return effectiveIncludes; + } + + protected Set getEffectiveExcludes() + { + Set effectiveExcludes = new HashSet(testExcludes); + if (testExcludeFile != null) + { + if (testExcludeFile.exists() == false) + throw new IllegalArgumentException("Cannot find: " + testExcludeFile); + + try + { + BufferedReader br = new BufferedReader(new FileReader(testExcludeFile)); + String line = br.readLine(); + while (line != null) + { + if (line.length() > 0 && !line.startsWith("#")) + { + getLog().debug("Add exclude: " + line); + effectiveExcludes.add(line); + } + line = br.readLine(); + } + br.close(); + } + catch (IOException ex) + { + throw new IllegalArgumentException("Cannot process: " + testExcludeFile, ex); + } + } + return effectiveExcludes; + } }