Skip to content

Commit 769ca50

Browse files
committed
Only ignore test-source/resource folder if all executions are skipped
Fixes #1338
1 parent 885d674 commit 769ca50

File tree

8 files changed

+91
-10
lines changed

8 files changed

+91
-10
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>foo.bar</groupId>
7+
<artifactId>skip-none</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<build>
10+
<pluginManagement>
11+
<plugins>
12+
<plugin>
13+
<groupId>org.apache.maven.plugins</groupId>
14+
<artifactId>maven-compiler-plugin</artifactId>
15+
<version>3.10.1</version>
16+
</plugin>
17+
</plugins>
18+
</pluginManagement>
19+
</build>
20+
</project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import java.io.Serializable;
2+
3+
class A {
4+
5+
}

org.eclipse.m2e.jdt.tests/projects/skipNone/src/test/resources/A.properties

Whitespace-only changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>foo.bar</groupId>
7+
<artifactId>skip-one-of-multiple</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<build>
10+
<plugins>
11+
<plugin>
12+
<groupId>org.apache.maven.plugins</groupId>
13+
<artifactId>maven-compiler-plugin</artifactId>
14+
<version>3.10.1</version>
15+
<executions>
16+
<execution>
17+
<id>default-testCompile</id>
18+
<phase>test-compile</phase>
19+
<goals>
20+
<goal>testCompile</goal>
21+
</goals>
22+
</execution>
23+
<execution>
24+
<id>compile-generated-specs</id>
25+
<phase>process-test-classes</phase>
26+
<goals>
27+
<goal>testCompile</goal>
28+
</goals>
29+
<configuration>
30+
<skip>true</skip>
31+
</configuration>
32+
</execution>
33+
</executions>
34+
</plugin>
35+
</plugins>
36+
</build>
37+
</project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import java.io.Serializable;
2+
3+
class A {
4+
5+
}

org.eclipse.m2e.jdt.tests/projects/skipOnlyOneOfMultipleExecutions/src/test/resources/A.properties

Whitespace-only changes.

org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/JavaConfigurationTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,20 @@ public void testSkipTestResources() throws CoreException, IOException, Interrupt
9292
assertEquals(0, classpathEntriesCount(project, TEST_RESOURCES));
9393
}
9494

95+
@Test
96+
public void testSkipOnlyOneOfMultipleExecutions() throws CoreException, IOException, InterruptedException {
97+
IJavaProject project = importResourceProject("/projects/skipOnlyOneOfMultipleExecutions/pom.xml");
98+
assertEquals(1, classpathEntriesCount(project, TEST_SOURCES));
99+
assertEquals(1, classpathEntriesCount(project, TEST_RESOURCES));
100+
}
101+
102+
@Test
103+
public void testSkipNone() throws CoreException, IOException, InterruptedException {
104+
IJavaProject project = importResourceProject("/projects/skipNone/pom.xml");
105+
assertEquals(1, classpathEntriesCount(project, TEST_SOURCES));
106+
assertEquals(1, classpathEntriesCount(project, TEST_RESOURCES));
107+
}
108+
95109
// --- utility methods ---
96110

97111
private static final Predicate<IClasspathEntry> TEST_SOURCES = cp -> cp.isTest()

org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ protected void addProjectSourceFolders(IClasspathDescriptor classpath, Map<Strin
300300
String mainResourcesEncoding = null;
301301
String testResourcesEncoding = null;
302302

303-
boolean isTestCompilationSkipped = false;
304-
boolean isTestResourcesSkipped = false;
303+
List<Boolean> isTestCompilationSkipped = new ArrayList<>();
304+
List<Boolean> isTestResourcesSkipped = new ArrayList<>();
305305

306306
List<MojoExecution> executions = getCompilerMojoExecutions(request, mon.newChild(1));
307307
for(MojoExecution compile : executions) {
@@ -338,10 +338,10 @@ protected void addProjectSourceFolders(IClasspathDescriptor classpath, Map<Strin
338338
log.error("Failed to determine compiler test exclusions, assuming defaults", ex);
339339
}
340340
try {
341-
isTestCompilationSkipped = Boolean.TRUE
342-
.equals(maven.getMojoParameterValue(mavenProject, compile, "skip", Boolean.class, monitor)); //$NON-NLS-1$
341+
isTestCompilationSkipped
342+
.add(maven.getMojoParameterValue(mavenProject, compile, "skip", Boolean.class, monitor));
343343
} catch(Exception ex) {
344-
//ignore
344+
isTestCompilationSkipped.add(Boolean.FALSE);
345345
}
346346
}
347347
}
@@ -355,10 +355,10 @@ protected void addProjectSourceFolders(IClasspathDescriptor classpath, Map<Strin
355355
RESOURCES_PLUGIN_ARTIFACT_ID, mon.newChild(1), GOAL_TESTRESOURCES)) {
356356
testResourcesEncoding = maven.getMojoParameterValue(mavenProject, resources, "encoding", String.class, monitor); //$NON-NLS-1$
357357
try {
358-
isTestResourcesSkipped = Boolean.TRUE
359-
.equals(maven.getMojoParameterValue(mavenProject, resources, "skip", Boolean.class, monitor)); //$NON-NLS-1$
358+
isTestResourcesSkipped
359+
.add(maven.getMojoParameterValue(mavenProject, resources, "skip", Boolean.class, monitor));
360360
} catch(Exception ex) {
361-
//ignore
361+
isTestResourcesSkipped.add(Boolean.FALSE);
362362
}
363363
}
364364
addSourceDirs(classpath, project, mavenProject.getCompileSourceRoots(), classes.getFullPath(), inclusion,
@@ -368,11 +368,11 @@ protected void addProjectSourceFolders(IClasspathDescriptor classpath, Map<Strin
368368

369369
//If the project properties contain m2e.disableTestClasspathFlag=true, then the test flag must not be set
370370
boolean addTestFlag = !MavenClasspathHelpers.hasTestFlagDisabled(mavenProject);
371-
if(!isTestCompilationSkipped) {
371+
if(isTestCompilationSkipped.isEmpty() || !isTestCompilationSkipped.stream().allMatch(Boolean.TRUE::equals)) {
372372
addSourceDirs(classpath, project, mavenProject.getTestCompileSourceRoots(), testClasses.getFullPath(),
373373
inclusionTest, exclusionTest, testSourceEncoding, mon.newChild(1), addTestFlag);
374374
}
375-
if(!isTestResourcesSkipped) {
375+
if(isTestResourcesSkipped.isEmpty() || !isTestResourcesSkipped.stream().allMatch(Boolean.TRUE::equals)) {
376376
addResourceDirs(classpath, project, mavenProject, mavenProject.getBuild().getTestResources(),
377377
testClasses.getFullPath(), testResourcesEncoding, mon.newChild(1), addTestFlag);
378378
}

0 commit comments

Comments
 (0)