Skip to content

Commit 7429cd2

Browse files
cperkkkdarko-marinov
authored andcommitted
fix: respect surefire execution
1 parent 9aa673e commit 7429cd2

File tree

5 files changed

+218
-21
lines changed

5 files changed

+218
-21
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>nondex.plugin.it</groupId>
7+
<artifactId>simple-it</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
10+
<description>A simple IT verifying the basic use case.</description>
11+
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
</properties>
15+
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<groupId>org.apache.maven.plugins</groupId>
20+
<artifactId>maven-compiler-plugin</artifactId>
21+
<version>3.8.1</version>
22+
<configuration>
23+
<source>1.8</source>
24+
<target>1.8</target>
25+
</configuration>
26+
</plugin>
27+
<plugin>
28+
<groupId>@project.groupId@</groupId>
29+
<artifactId>@project.artifactId@</artifactId>
30+
<version>@project.version@</version>
31+
</plugin>
32+
<plugin>
33+
<groupId>org.apache.maven.plugins</groupId>
34+
<artifactId>maven-surefire-plugin</artifactId>
35+
<version>2.22.2</version>
36+
<configuration>
37+
<rerunFailingTestsCount>2</rerunFailingTestsCount>
38+
<systemPropertyVariables>
39+
<!-- originally one -->
40+
<env.flag>1</env.flag>
41+
</systemPropertyVariables>
42+
</configuration>
43+
<executions>
44+
<execution>
45+
<id>default-test</id>
46+
<configuration>
47+
<skip>true</skip>
48+
</configuration>
49+
</execution>
50+
<execution>
51+
<id>test-execution-1</id>
52+
<goals>
53+
<goal>test</goal>
54+
</goals>
55+
<configuration>
56+
<systemPropertyVariables>
57+
<!-- modify to two -->
58+
<env.flag>2</env.flag>
59+
</systemPropertyVariables>
60+
<includes>
61+
<include>**/AppExec1Test.java</include>
62+
</includes>
63+
</configuration>
64+
</execution>
65+
<execution>
66+
<id>test-execution-2</id>
67+
<goals>
68+
<goal>test</goal>
69+
</goals>
70+
<configuration>
71+
<!-- will derive some config from root -->
72+
<includes>
73+
<include>**/AppExec2Test.java</include>
74+
</includes>
75+
</configuration>
76+
</execution>
77+
</executions>
78+
</plugin>
79+
</plugins>
80+
</build>
81+
82+
<dependencies>
83+
<dependency>
84+
<groupId>junit</groupId>
85+
<artifactId>junit</artifactId>
86+
<version>4.13.2</version>
87+
<scope>test</scope>
88+
</dependency>
89+
<dependency>
90+
<groupId>@project.groupId@</groupId>
91+
<artifactId>nondex-common</artifactId>
92+
<version>@project.version@</version>
93+
</dependency>
94+
</dependencies>
95+
</project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
The MIT License (MIT)
3+
Copyright (c) 2025 Steven Kusuman
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
*/
24+
25+
package edu.illinois.nondex.it;
26+
27+
import org.junit.Test;
28+
import static org.junit.Assert.assertEquals;
29+
30+
public class AppExec1Test
31+
{
32+
@Test
33+
public void testFlag1() {
34+
assertEquals("2", System.getProperty("env.flag"));
35+
}
36+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
The MIT License (MIT)
3+
Copyright (c) 2025 Steven Kusuman
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
*/
24+
25+
package edu.illinois.nondex.it;
26+
27+
import org.junit.Test;
28+
import org.junit.experimental.categories.Category;
29+
import static org.junit.Assert.assertEquals;
30+
31+
public class AppExec2Test
32+
{
33+
@Test
34+
public void testFlag2() {
35+
assertEquals("1", System.getProperty("env.flag"));
36+
}
37+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
File nondexDirectory = new File( basedir, ".nondex" );
2+
3+
sleep(3000)
4+
assert nondexDirectory.isDirectory();
5+
6+
// 3 execution adds 12 directories (1 clean / 3 shuffled). 3 other overhead files
7+
assert (nondexDirectory.list().length - 3) == 12;

nondex-maven-plugin/src/main/java/edu/illinois/nondex/plugin/NonDexMojo.java

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ a copy of this software and associated documentation files (the
5454
import edu.illinois.nondex.common.Logger;
5555
import edu.illinois.nondex.common.Utils;
5656

57+
import org.apache.maven.model.PluginExecution;
5758
import org.apache.maven.plugin.MojoExecutionException;
5859
import org.apache.maven.plugin.MojoFailureException;
5960
import org.apache.maven.plugins.annotations.LifecyclePhase;
6061
import org.apache.maven.plugins.annotations.Mojo;
6162
import org.apache.maven.plugins.annotations.ResolutionScope;
63+
import org.codehaus.plexus.util.xml.Xpp3Dom;
6264

6365
@Mojo(name = "nondex", defaultPhase = LifecyclePhase.TEST, requiresDependencyResolution = ResolutionScope.TEST)
6466
public class NonDexMojo extends AbstractNonDexMojo {
@@ -80,28 +82,22 @@ public void execute() throws MojoExecutionException, MojoFailureException {
8082

8183
// If we add clean exceptions to allExceptions then the build fails if anything fails without nondex.
8284
// Everything in nondex-test is expected to fail without nondex so we throw away the result here.
83-
for (int j = 0; j < this.numRunsWithoutShuffling; j++) {
84-
CleanSurefireExecution cleanExec = new CleanSurefireExecution(
85-
this.surefire, this.originalArgLine, this.mavenProject,
86-
this.mavenSession, this.pluginManager,
87-
Paths.get(this.baseDir.getAbsolutePath(), ConfigurationDefaults.DEFAULT_NONDEX_DIR).toString());
88-
this.executeSurefireExecution(allExceptions, cleanExec);
89-
this.executionsWithoutShuffling.add(cleanExec);
90-
}
9185

92-
for (int i = 0; i < this.numRuns; i++) {
93-
NonDexSurefireExecution execution =
94-
new NonDexSurefireExecution(this.mode, this.computeIthSeed(i),
95-
Pattern.compile(this.filter), this.start, this.end,
96-
Paths.get(this.baseDir.getAbsolutePath(), ConfigurationDefaults.DEFAULT_NONDEX_DIR).toString(),
97-
Paths.get(this.baseDir.getAbsolutePath(), ConfigurationDefaults.DEFAULT_NONDEX_JAR_DIR)
98-
.toString(),
99-
this.surefire, this.originalArgLine, this.mavenProject,
100-
this.mavenSession, this.pluginManager);
101-
setFilePath(execution.getConfiguration().getRunFilePath());
102-
this.executions.add(execution);
103-
allExceptions = this.executeSurefireExecution(allExceptions, execution);
104-
this.writeCurrentRunInfo(execution);
86+
if (this.surefire.getExecutions() != null && !this.surefire.getExecutions().isEmpty()) {
87+
// We need to do this because Xpp3Dom doesn't accept null yet setConfiguration accepts null.
88+
Xpp3Dom origNode = null;
89+
if (this.surefire.getConfiguration() != null) {
90+
origNode = (Xpp3Dom) this.surefire.getConfiguration();
91+
}
92+
for (PluginExecution exec: this.surefire.getExecutions()) {
93+
if (exec.getConfiguration() != null) {
94+
this.surefire.setConfiguration((Xpp3Dom) exec.getConfiguration());
95+
}
96+
allExceptions = this.runExecutions(allExceptions);
97+
this.surefire.setConfiguration(origNode);
98+
}
99+
} else {
100+
allExceptions = this.runExecutions(allExceptions);
105101
}
106102

107103
for (CleanSurefireExecution cleanExec : this.executionsWithoutShuffling) {
@@ -123,7 +119,33 @@ public void execute() throws MojoExecutionException, MojoFailureException {
123119
if (allExceptions != null) {
124120
throw allExceptions;
125121
}
122+
}
126123

124+
private MojoExecutionException runExecutions(MojoExecutionException allExceptions) {
125+
for (int j = 0; j < this.numRunsWithoutShuffling; j++) {
126+
CleanSurefireExecution cleanExec = new CleanSurefireExecution(
127+
this.surefire, this.originalArgLine, this.mavenProject,
128+
this.mavenSession, this.pluginManager,
129+
Paths.get(this.baseDir.getAbsolutePath(), ConfigurationDefaults.DEFAULT_NONDEX_DIR).toString());
130+
this.executeSurefireExecution(allExceptions, cleanExec);
131+
this.executionsWithoutShuffling.add(cleanExec);
132+
}
133+
for (int i = 0; i < this.numRuns; i++) {
134+
NonDexSurefireExecution execution =
135+
new NonDexSurefireExecution(this.mode, this.computeIthSeed(i),
136+
Pattern.compile(this.filter), this.start, this.end,
137+
Paths.get(this.baseDir.getAbsolutePath(), ConfigurationDefaults.DEFAULT_NONDEX_DIR)
138+
.toString(),
139+
Paths.get(this.baseDir.getAbsolutePath(), ConfigurationDefaults.DEFAULT_NONDEX_JAR_DIR)
140+
.toString(),
141+
this.surefire, this.originalArgLine, this.mavenProject,
142+
this.mavenSession, this.pluginManager);
143+
setFilePath(execution.getConfiguration().getRunFilePath());
144+
this.executions.add(execution);
145+
allExceptions = this.executeSurefireExecution(allExceptions, execution);
146+
this.writeCurrentRunInfo(execution);
147+
}
148+
return allExceptions;
127149
}
128150

129151
private void postProcessExecutions(CleanSurefireExecution cleanExec) {

0 commit comments

Comments
 (0)