mirror of
https://github.com/apache/maven.git
synced 2025-02-08 02:59:22 +00:00
Resolving: MNG-643
o Added includes/excludes for compile and testCompile o added integration tests for single execution of compile and testCompile with excludes o Added integration test for multiple execution of compile in different phases per Dan Tran's request The bulk of this commit is KrisBravo's work (I think that's who Corridor Software Developer is??). Thanks for the help. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@239272 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5bebfb8ad0
commit
78bd69c44c
@ -153,6 +153,12 @@ it0053: Test that attached artifacts have the same buildnumber and timestamp
|
||||
it0054: Test that locally defined repositories override those from the super
|
||||
POM. This is from MNG-479.
|
||||
|
||||
it0055: Test that source includes/excludes with in the compiler plugin config.
|
||||
This will test excludes and testExcludes...
|
||||
|
||||
it0056: Test that multiple executions of the compile goal with different
|
||||
includes/excludes will succeed.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
- generated sources
|
||||
|
@ -1,4 +1,7 @@
|
||||
it0056
|
||||
it0055
|
||||
it0054
|
||||
it0053
|
||||
it0052
|
||||
it0051
|
||||
it0050
|
||||
|
4
maven-core-it/it0055/expected-results.txt
Normal file
4
maven-core-it/it0055/expected-results.txt
Normal file
@ -0,0 +1,4 @@
|
||||
target/classes/org/apache/maven/it0001/Person.class
|
||||
target/test-classes/org/apache/maven/it0001/PersonTest.class
|
||||
!target/classes/org/apache/maven/it0001/PersonTwo.class
|
||||
!target/test-classes/org/apache/maven/it0001/PersonTwoTest.class
|
1
maven-core-it/it0055/goals.txt
Normal file
1
maven-core-it/it0055/goals.txt
Normal file
@ -0,0 +1 @@
|
||||
test-compile
|
33
maven-core-it/it0055/pom.xml
Normal file
33
maven-core-it/it0055/pom.xml
Normal file
@ -0,0 +1,33 @@
|
||||
<model>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core-it0055</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude implementation="java.lang.String">**/PersonTwo.java</exclude>
|
||||
</excludes>
|
||||
<testExcludes>
|
||||
<testExclude implementation="java.lang.String">**/PersonTwoTest.java</testExclude>
|
||||
</testExcludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</model>
|
@ -0,0 +1,16 @@
|
||||
package org.apache.maven.it0001;
|
||||
|
||||
public class Person
|
||||
{
|
||||
private String name;
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package org.apache.maven.it0001;
|
||||
|
||||
public class PersonTwo
|
||||
{
|
||||
private String name;
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
name = jason
|
@ -0,0 +1,16 @@
|
||||
package org.apache.maven.it0001;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PersonTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testPerson()
|
||||
{
|
||||
Person person = new Person();
|
||||
|
||||
person.setName( "foo" );
|
||||
|
||||
assertEquals( "foo", person.getName() );
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package org.apache.maven.it0001;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PersonTwoTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testPerson()
|
||||
{
|
||||
Person person = new Person();
|
||||
|
||||
person.setName( "foo" );
|
||||
|
||||
assertEquals( "foo", person.getName() );
|
||||
}
|
||||
}
|
6
maven-core-it/it0056/expected-results.txt
Normal file
6
maven-core-it/it0056/expected-results.txt
Normal file
@ -0,0 +1,6 @@
|
||||
target/classes/org/apache/maven/it0001/Person.class
|
||||
target/classes/org/apache/maven/it0001/PersonTwo.class
|
||||
target/classes/org/apache/maven/it0001/PersonThree.class
|
||||
target/test-classes/org/apache/maven/it0001/PersonTest.class
|
||||
target/test-classes/org/apache/maven/it0001/PersonTwoTest.class
|
||||
target/test-classes/org/apache/maven/it0001/PersonThreeTest.class
|
1
maven-core-it/it0056/goals.txt
Normal file
1
maven-core-it/it0056/goals.txt
Normal file
@ -0,0 +1 @@
|
||||
test-compile
|
42
maven-core-it/it0056/pom.xml
Normal file
42
maven-core-it/it0056/pom.xml
Normal file
@ -0,0 +1,42 @@
|
||||
<model>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core-it0056</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>validation-phase-execution</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude implementation="java.lang.String">**/PersonTwo.java</exclude>
|
||||
</excludes>
|
||||
<testExcludes>
|
||||
<testExclude implementation="java.lang.String">**/PersonTwoTest.java</testExclude>
|
||||
</testExcludes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</model>
|
@ -0,0 +1,16 @@
|
||||
package org.apache.maven.it0001;
|
||||
|
||||
public class Person
|
||||
{
|
||||
private String name;
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package org.apache.maven.it0001;
|
||||
|
||||
public class PersonThree
|
||||
{
|
||||
private String name;
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package org.apache.maven.it0001;
|
||||
|
||||
public class PersonTwo
|
||||
{
|
||||
private String name;
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
name = jason
|
@ -0,0 +1,16 @@
|
||||
package org.apache.maven.it0001;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PersonTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testPerson()
|
||||
{
|
||||
Person person = new Person();
|
||||
|
||||
person.setName( "foo" );
|
||||
|
||||
assertEquals( "foo", person.getName() );
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package org.apache.maven.it0001;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PersonThreeTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testPerson()
|
||||
{
|
||||
Person person = new Person();
|
||||
|
||||
person.setName( "foo" );
|
||||
|
||||
assertEquals( "foo", person.getName() );
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package org.apache.maven.it0001;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PersonTwoTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testPerson()
|
||||
{
|
||||
Person person = new Person();
|
||||
|
||||
person.setName( "foo" );
|
||||
|
||||
assertEquals( "foo", person.getName() );
|
||||
}
|
||||
}
|
@ -27,7 +27,6 @@
|
||||
<artifactId>plexus-compiler-javac</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>plexus</groupId>
|
||||
|
@ -24,16 +24,13 @@
|
||||
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.SimpleSourceInclusionScanner;
|
||||
import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner;
|
||||
import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
|
||||
import org.codehaus.plexus.compiler.util.scan.mapping.SingleTargetSourceMapping;
|
||||
import org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping;
|
||||
import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -113,13 +110,6 @@ public abstract class AbstractCompilerMojo
|
||||
*/
|
||||
private String compilerId;
|
||||
|
||||
/**
|
||||
* Version of the compiler to use, ex. "1.3", "1.5"
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
private String compilerVersion;
|
||||
|
||||
/**
|
||||
* Runs the compiler in a separate process.
|
||||
* <p/>
|
||||
@ -183,6 +173,10 @@ public abstract class AbstractCompilerMojo
|
||||
*/
|
||||
private CompilerManager compilerManager;
|
||||
|
||||
protected abstract SourceInclusionScanner getSourceInclusionScanner( int staleMillis );
|
||||
|
||||
protected abstract SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding );
|
||||
|
||||
protected abstract List getClasspathElements();
|
||||
|
||||
protected abstract List getCompileSourceRoots();
|
||||
@ -267,24 +261,19 @@ public void execute()
|
||||
|
||||
try
|
||||
{
|
||||
staleSources = computeStaleSources( compilerConfiguration,
|
||||
compiler,
|
||||
new StaleSourceScanner( staleMillis ) );
|
||||
staleSources = computeStaleSources( compilerConfiguration, compiler, getSourceInclusionScanner( staleMillis ) );
|
||||
|
||||
canUpdateTarget = compiler.canUpdateTarget( compilerConfiguration );
|
||||
|
||||
if ( compiler.getCompilerOutputStyle() == CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES &&
|
||||
!canUpdateTarget )
|
||||
if ( compiler.getCompilerOutputStyle() == CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES
|
||||
&& !canUpdateTarget )
|
||||
{
|
||||
getLog().info( "RESCANNING!" );
|
||||
// TODO: This second scan for source files is sub-optimal
|
||||
String inputFileEnding = compiler.getInputFileEnding( compilerConfiguration );
|
||||
|
||||
Set includes = Collections.singleton( "**/*." + inputFileEnding );
|
||||
|
||||
Set sources = computeStaleSources( compilerConfiguration,
|
||||
compiler,
|
||||
new SimpleSourceInclusionScanner( includes, Collections.EMPTY_SET ));
|
||||
Set sources = computeStaleSources( compilerConfiguration, compiler,
|
||||
getSourceInclusionScanner( inputFileEnding ) );
|
||||
|
||||
compilerConfiguration.setSourceFiles( sources );
|
||||
}
|
||||
@ -364,9 +353,8 @@ public void execute()
|
||||
}
|
||||
}
|
||||
|
||||
private Set computeStaleSources( CompilerConfiguration compilerConfiguration,
|
||||
Compiler compiler,
|
||||
SourceInclusionScanner scanner )
|
||||
private Set computeStaleSources( CompilerConfiguration compilerConfiguration, Compiler compiler,
|
||||
SourceInclusionScanner scanner )
|
||||
throws MojoExecutionException, CompilerException
|
||||
{
|
||||
CompilerOutputStyle outputStyle = compiler.getCompilerOutputStyle();
|
||||
@ -377,15 +365,15 @@ private Set computeStaleSources( CompilerConfiguration compilerConfiguration,
|
||||
|
||||
if ( outputStyle == CompilerOutputStyle.ONE_OUTPUT_FILE_PER_INPUT_FILE )
|
||||
{
|
||||
mapping = new SuffixMapping( compiler.getInputFileEnding( compilerConfiguration ),
|
||||
compiler.getOutputFileEnding( compilerConfiguration ) );
|
||||
mapping = new SuffixMapping( compiler.getInputFileEnding( compilerConfiguration ), compiler
|
||||
.getOutputFileEnding( compilerConfiguration ) );
|
||||
|
||||
outputDirectory = getOutputDirectory();
|
||||
}
|
||||
else if ( outputStyle == CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES )
|
||||
{
|
||||
mapping = new SingleTargetSourceMapping( compiler.getInputFileEnding( compilerConfiguration ),
|
||||
compiler.getOutputFile( compilerConfiguration ) );
|
||||
mapping = new SingleTargetSourceMapping( compiler.getInputFileEnding( compilerConfiguration ), compiler
|
||||
.getOutputFile( compilerConfiguration ) );
|
||||
|
||||
outputDirectory = buildDirectory;
|
||||
}
|
||||
@ -415,8 +403,8 @@ else if ( outputStyle == CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES
|
||||
}
|
||||
catch ( InclusionScanException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Error scanning source root: \'" + sourceRoot + "\' " +
|
||||
"for stale files to recompile.", e );
|
||||
throw new MojoExecutionException( "Error scanning source root: \'" + sourceRoot + "\' "
|
||||
+ "for stale files to recompile.", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,14 @@
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner;
|
||||
import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner;
|
||||
import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
@ -61,6 +67,18 @@ public class CompilerMojo
|
||||
*/
|
||||
private Artifact projectArtifact;
|
||||
|
||||
/**
|
||||
* A list of inclusion filters for the compiler.
|
||||
* @parameter
|
||||
*/
|
||||
private Set includes = new HashSet();
|
||||
|
||||
/**
|
||||
* A list of exclusion filters for the compiler.
|
||||
* @parameter
|
||||
*/
|
||||
private Set excludes = new HashSet();
|
||||
|
||||
protected List getCompileSourceRoots()
|
||||
{
|
||||
return compileSourceRoots;
|
||||
@ -83,4 +101,46 @@ public void execute()
|
||||
|
||||
projectArtifact.setFile( outputDirectory );
|
||||
}
|
||||
|
||||
protected SourceInclusionScanner getSourceInclusionScanner( int staleMillis )
|
||||
{
|
||||
SourceInclusionScanner scanner = null;
|
||||
|
||||
if ( includes.isEmpty() && excludes.isEmpty() )
|
||||
{
|
||||
scanner = new StaleSourceScanner( staleMillis );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( includes.isEmpty() )
|
||||
{
|
||||
includes.add( "**/*.java" );
|
||||
}
|
||||
scanner = new StaleSourceScanner( staleMillis, includes, excludes );
|
||||
}
|
||||
|
||||
return scanner;
|
||||
}
|
||||
|
||||
protected SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding )
|
||||
{
|
||||
SourceInclusionScanner scanner = null;
|
||||
|
||||
if ( includes.isEmpty() && excludes.isEmpty() )
|
||||
{
|
||||
includes = Collections.singleton( "**/*." + inputFileEnding );
|
||||
scanner = new SimpleSourceInclusionScanner( includes, Collections.EMPTY_SET );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( includes.isEmpty() )
|
||||
{
|
||||
includes.add( "**/*." + inputFileEnding );
|
||||
}
|
||||
scanner = new SimpleSourceInclusionScanner( excludes, excludes );
|
||||
}
|
||||
|
||||
return scanner;
|
||||
}
|
||||
|
||||
}
|
@ -16,7 +16,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner;
|
||||
import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner;
|
||||
import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
@ -51,6 +58,18 @@ public class TestCompilerMojo
|
||||
*/
|
||||
private File outputDirectory;
|
||||
|
||||
/**
|
||||
* A list of inclusion filters for the compiler.
|
||||
* @parameter
|
||||
*/
|
||||
private Set testIncludes = new HashSet();
|
||||
|
||||
/**
|
||||
* A list of exclusion filters for the compiler.
|
||||
* @parameter
|
||||
*/
|
||||
private Set testExcludes = new HashSet();
|
||||
|
||||
protected List getCompileSourceRoots()
|
||||
{
|
||||
return compileSourceRoots;
|
||||
@ -66,4 +85,45 @@ protected File getOutputDirectory()
|
||||
return outputDirectory;
|
||||
}
|
||||
|
||||
protected SourceInclusionScanner getSourceInclusionScanner( int staleMillis )
|
||||
{
|
||||
SourceInclusionScanner scanner = null;
|
||||
|
||||
if ( testIncludes.isEmpty() && testExcludes.isEmpty() )
|
||||
{
|
||||
scanner = new StaleSourceScanner( staleMillis );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( testIncludes.isEmpty() )
|
||||
{
|
||||
testIncludes.add( "**/*.java" );
|
||||
}
|
||||
scanner = new StaleSourceScanner( staleMillis, testIncludes, testExcludes );
|
||||
}
|
||||
|
||||
return scanner;
|
||||
}
|
||||
|
||||
protected SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding )
|
||||
{
|
||||
SourceInclusionScanner scanner = null;
|
||||
|
||||
if ( testIncludes.isEmpty() && testExcludes.isEmpty() )
|
||||
{
|
||||
testIncludes = Collections.singleton( "**/*." + inputFileEnding );
|
||||
scanner = new SimpleSourceInclusionScanner( testIncludes, Collections.EMPTY_SET );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( testIncludes.isEmpty() )
|
||||
{
|
||||
testIncludes.add( "**/*." + inputFileEnding );
|
||||
}
|
||||
scanner = new SimpleSourceInclusionScanner( testExcludes, testExcludes );
|
||||
}
|
||||
|
||||
return scanner;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user