Skip to content

Commit

Permalink
Strip -Dtest=... from the original mvnOpts, if specified.
Browse files Browse the repository at this point in the history
This helps in test isolation if -Dtest=**something** is used to filter tests in a specific package.
  • Loading branch information
judepereira committed Oct 13, 2022
1 parent d327735 commit 30ceb33
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 41 deletions.
67 changes: 34 additions & 33 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.clevertap</groupId>
<artifactId>supertest-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.8</version>
<description>A wrapper for Maven's Surefire Plugin, with advanced re-run capabilities.</description>
<name>supertest-maven-plugin</name>
<url>https://github.com/CleverTap/supertest-maven-plugin</url>
<version>1.10</version>
<description>A wrapper for Maven's Surefire Plugin, with advanced re-run capabilities.
</description>
<name>supertest-maven-plugin</name>
<url>https://github.com/CleverTap/supertest-maven-plugin</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -133,33 +134,33 @@
</plugins>
</build>
</profile>
<profile>
<id>gpg_verify</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>gpg_verify</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<developers>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,8 @@ public void execute() throws MojoExecutionException {
final String artifactId = project.getArtifactId();
final String groupId = project.getGroupId();

final StringBuilder processedMvnTestOpts = new StringBuilder(" ");
processedMvnTestOpts.append(mvnTestOpts);
processedMvnTestOpts.append(" -pl ").append(groupId);
processedMvnTestOpts.append(":").append(artifactId);

int exitCode;
final String command = "mvn test " + processedMvnTestOpts;
final String command = "mvn test " + buildProcessedMvnTestOpts(artifactId, groupId);
try {
exitCode = runShellCommand(command, "supertest run#1");
} catch (IOException | InterruptedException e) {
Expand All @@ -67,7 +62,10 @@ public void execute() throws MojoExecutionException {
return;
}

for (int retryRunNumber = 1; retryRunNumber <= retryRunCount.intValue(); retryRunNumber++) {
// Strip -Dtest=... from the Maven opts if specified, since these were valid for the very first run only.
mvnTestOpts = mvnTestOpts.replaceAll("-Dtest=(.*?)(\\s|$)", "");

for (int retryRunNumber = 1; retryRunNumber <= retryRunCount; retryRunNumber++) {
final File[] xmlFileList = getXmlFileList(baseDir);
final Map<String, List<String>> classnameToTestcaseList = new HashMap<>();
for (File file : xmlFileList) {
Expand All @@ -84,7 +82,7 @@ public void execute() throws MojoExecutionException {

final String runCommand = createRerunCommand(classnameToTestcaseList);
final StringBuilder rerunCommand = new StringBuilder(runCommand);
rerunCommand.append(processedMvnTestOpts);
rerunCommand.append(buildProcessedMvnTestOpts(artifactId, groupId));
if (rerunProfile != null) {
String trimmedRerunProfile = rerunProfile.replaceAll("\"", "");
rerunCommand.append(" -P ").append(trimmedRerunProfile);
Expand All @@ -108,12 +106,21 @@ public void execute() throws MojoExecutionException {
}
}

private StringBuilder buildProcessedMvnTestOpts(String artifactId, String groupId) {
final StringBuilder processedMvnTestOpts = new StringBuilder(" ");
processedMvnTestOpts.append(mvnTestOpts);
processedMvnTestOpts.append(" -pl ").append(groupId);
processedMvnTestOpts.append(":").append(artifactId);
return processedMvnTestOpts;
}

/**
* @param command shell command to be executed
* @return process exit value, returns 1 if failure
*/
public int runShellCommand(final String command, final String commandDescriptor)
throws IOException, InterruptedException {
getLog().info("Running " + command);
Process proc = Runtime.getRuntime().exec(command);
InputStream inputStream = proc.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
Expand Down

0 comments on commit 30ceb33

Please sign in to comment.