Skip to content

Commit 30ceb33

Browse files
committed
Strip -Dtest=... from the original mvnOpts, if specified.
This helps in test isolation if -Dtest=**something** is used to filter tests in a specific package.
1 parent d327735 commit 30ceb33

File tree

2 files changed

+49
-41
lines changed

2 files changed

+49
-41
lines changed

pom.xml

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

77
<groupId>com.clevertap</groupId>
88
<artifactId>supertest-maven-plugin</artifactId>
99
<packaging>maven-plugin</packaging>
10-
<version>1.8</version>
11-
<description>A wrapper for Maven's Surefire Plugin, with advanced re-run capabilities.</description>
12-
<name>supertest-maven-plugin</name>
13-
<url>https://github.com/CleverTap/supertest-maven-plugin</url>
10+
<version>1.10</version>
11+
<description>A wrapper for Maven's Surefire Plugin, with advanced re-run capabilities.
12+
</description>
13+
<name>supertest-maven-plugin</name>
14+
<url>https://github.com/CleverTap/supertest-maven-plugin</url>
1415

1516
<properties>
1617
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -133,33 +134,33 @@
133134
</plugins>
134135
</build>
135136
</profile>
136-
<profile>
137-
<id>gpg_verify</id>
138-
<build>
139-
<plugins>
140-
<plugin>
141-
<groupId>org.apache.maven.plugins</groupId>
142-
<artifactId>maven-gpg-plugin</artifactId>
143-
<version>1.5</version>
144-
<configuration>
145-
<gpgArguments>
146-
<arg>--pinentry-mode</arg>
147-
<arg>loopback</arg>
148-
</gpgArguments>
149-
</configuration>
150-
<executions>
151-
<execution>
152-
<id>sign-artifacts</id>
153-
<phase>verify</phase>
154-
<goals>
155-
<goal>sign</goal>
156-
</goals>
157-
</execution>
158-
</executions>
159-
</plugin>
160-
</plugins>
161-
</build>
162-
</profile>
137+
<profile>
138+
<id>gpg_verify</id>
139+
<build>
140+
<plugins>
141+
<plugin>
142+
<groupId>org.apache.maven.plugins</groupId>
143+
<artifactId>maven-gpg-plugin</artifactId>
144+
<version>1.5</version>
145+
<configuration>
146+
<gpgArguments>
147+
<arg>--pinentry-mode</arg>
148+
<arg>loopback</arg>
149+
</gpgArguments>
150+
</configuration>
151+
<executions>
152+
<execution>
153+
<id>sign-artifacts</id>
154+
<phase>verify</phase>
155+
<goals>
156+
<goal>sign</goal>
157+
</goals>
158+
</execution>
159+
</executions>
160+
</plugin>
161+
</plugins>
162+
</build>
163+
</profile>
163164
</profiles>
164165

165166
<developers>

src/main/java/com/clevertap/maven/plugins/supertest/SuperTestMavenPlugin.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,8 @@ public void execute() throws MojoExecutionException {
5050
final String artifactId = project.getArtifactId();
5151
final String groupId = project.getGroupId();
5252

53-
final StringBuilder processedMvnTestOpts = new StringBuilder(" ");
54-
processedMvnTestOpts.append(mvnTestOpts);
55-
processedMvnTestOpts.append(" -pl ").append(groupId);
56-
processedMvnTestOpts.append(":").append(artifactId);
57-
5853
int exitCode;
59-
final String command = "mvn test " + processedMvnTestOpts;
54+
final String command = "mvn test " + buildProcessedMvnTestOpts(artifactId, groupId);
6055
try {
6156
exitCode = runShellCommand(command, "supertest run#1");
6257
} catch (IOException | InterruptedException e) {
@@ -67,7 +62,10 @@ public void execute() throws MojoExecutionException {
6762
return;
6863
}
6964

70-
for (int retryRunNumber = 1; retryRunNumber <= retryRunCount.intValue(); retryRunNumber++) {
65+
// Strip -Dtest=... from the Maven opts if specified, since these were valid for the very first run only.
66+
mvnTestOpts = mvnTestOpts.replaceAll("-Dtest=(.*?)(\\s|$)", "");
67+
68+
for (int retryRunNumber = 1; retryRunNumber <= retryRunCount; retryRunNumber++) {
7169
final File[] xmlFileList = getXmlFileList(baseDir);
7270
final Map<String, List<String>> classnameToTestcaseList = new HashMap<>();
7371
for (File file : xmlFileList) {
@@ -84,7 +82,7 @@ public void execute() throws MojoExecutionException {
8482

8583
final String runCommand = createRerunCommand(classnameToTestcaseList);
8684
final StringBuilder rerunCommand = new StringBuilder(runCommand);
87-
rerunCommand.append(processedMvnTestOpts);
85+
rerunCommand.append(buildProcessedMvnTestOpts(artifactId, groupId));
8886
if (rerunProfile != null) {
8987
String trimmedRerunProfile = rerunProfile.replaceAll("\"", "");
9088
rerunCommand.append(" -P ").append(trimmedRerunProfile);
@@ -108,12 +106,21 @@ public void execute() throws MojoExecutionException {
108106
}
109107
}
110108

109+
private StringBuilder buildProcessedMvnTestOpts(String artifactId, String groupId) {
110+
final StringBuilder processedMvnTestOpts = new StringBuilder(" ");
111+
processedMvnTestOpts.append(mvnTestOpts);
112+
processedMvnTestOpts.append(" -pl ").append(groupId);
113+
processedMvnTestOpts.append(":").append(artifactId);
114+
return processedMvnTestOpts;
115+
}
116+
111117
/**
112118
* @param command shell command to be executed
113119
* @return process exit value, returns 1 if failure
114120
*/
115121
public int runShellCommand(final String command, final String commandDescriptor)
116122
throws IOException, InterruptedException {
123+
getLog().info("Running " + command);
117124
Process proc = Runtime.getRuntime().exec(command);
118125
InputStream inputStream = proc.getInputStream();
119126
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);

0 commit comments

Comments
 (0)