From 30ceb334f62ab3cb887276039aa89071bce1f9bf Mon Sep 17 00:00:00 2001 From: Jude Pereira Date: Thu, 13 Oct 2022 17:04:35 +0200 Subject: [PATCH] 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. --- pom.xml | 67 ++++++++++--------- .../supertest/SuperTestMavenPlugin.java | 23 ++++--- 2 files changed, 49 insertions(+), 41 deletions(-) diff --git a/pom.xml b/pom.xml index e47782d..9e740da 100644 --- a/pom.xml +++ b/pom.xml @@ -1,16 +1,17 @@ + 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"> 4.0.0 com.clevertap supertest-maven-plugin maven-plugin - 1.8 - A wrapper for Maven's Surefire Plugin, with advanced re-run capabilities. - supertest-maven-plugin - https://github.com/CleverTap/supertest-maven-plugin + 1.10 + A wrapper for Maven's Surefire Plugin, with advanced re-run capabilities. + + supertest-maven-plugin + https://github.com/CleverTap/supertest-maven-plugin UTF-8 @@ -133,33 +134,33 @@ - - gpg_verify - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - --pinentry-mode - loopback - - - - - sign-artifacts - verify - - sign - - - - - - - + + gpg_verify + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + --pinentry-mode + loopback + + + + + sign-artifacts + verify + + sign + + + + + + + diff --git a/src/main/java/com/clevertap/maven/plugins/supertest/SuperTestMavenPlugin.java b/src/main/java/com/clevertap/maven/plugins/supertest/SuperTestMavenPlugin.java index 4745555..d17cf8c 100644 --- a/src/main/java/com/clevertap/maven/plugins/supertest/SuperTestMavenPlugin.java +++ b/src/main/java/com/clevertap/maven/plugins/supertest/SuperTestMavenPlugin.java @@ -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) { @@ -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> classnameToTestcaseList = new HashMap<>(); for (File file : xmlFileList) { @@ -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); @@ -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);