From e65e9dc0493517f50b72f9e14f01673714a1dc4e Mon Sep 17 00:00:00 2001 From: Benjamin Shen Date: Sun, 30 Oct 2022 21:06:48 -0400 Subject: [PATCH 1/3] run all tests if project uses invalid surefire version --- .../starts/constants/StartsConstants.java | 1 + .../edu/illinois/starts/helpers/PomUtil.java | 23 ++++++++----------- .../edu/illinois/starts/jdeps/RunMojo.java | 10 +++++++- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/starts-core/src/main/java/edu/illinois/starts/constants/StartsConstants.java b/starts-core/src/main/java/edu/illinois/starts/constants/StartsConstants.java index fdd963b3..49e84400 100644 --- a/starts-core/src/main/java/edu/illinois/starts/constants/StartsConstants.java +++ b/starts-core/src/main/java/edu/illinois/starts/constants/StartsConstants.java @@ -11,6 +11,7 @@ */ public interface StartsConstants { String STARTS_DIRECTORY_PATH = ".starts" + File.separator; + String MIN_SUREFIRE_VERSION = "2.13"; String SUREFIRE_PLUGIN_VM = "org/apache/maven/plugin/surefire/SurefirePlugin"; String SUREFIRE_PLUGIN_BIN = "org.apache.maven.plugin.surefire.SurefirePlugin"; diff --git a/starts-core/src/main/java/edu/illinois/starts/helpers/PomUtil.java b/starts-core/src/main/java/edu/illinois/starts/helpers/PomUtil.java index 612894fe..00895224 100644 --- a/starts-core/src/main/java/edu/illinois/starts/helpers/PomUtil.java +++ b/starts-core/src/main/java/edu/illinois/starts/helpers/PomUtil.java @@ -20,9 +20,7 @@ /** * Utility methods for manipulating pom.xml files. */ -public class PomUtil { - static final String MIN_SUREFIRE_VERSION = "2.13"; - +public class PomUtil implements StartsConstants { public static String extractParamValue(Plugin plugin, String elem) throws MojoExecutionException { String value = null; Xpp3Dom dom = (Xpp3Dom) plugin.getConfiguration(); @@ -54,20 +52,19 @@ public static List extractIncludeExcludes(Plugin plugin, String elem) th public static Plugin getSfPlugin(MavenProject project) throws MojoExecutionException { Plugin sfPlugin = lookupPlugin("org.apache.maven.plugins:maven-surefire-plugin", project); - checkSFVersion(sfPlugin); - return sfPlugin; - } - - public static void checkSFVersion(Plugin sfPlugin) throws MojoExecutionException { if (sfPlugin == null) { throw new MojoExecutionException("Surefire plugin not available"); } + return sfPlugin; + } - String version = sfPlugin.getVersion(); - if (MIN_SUREFIRE_VERSION.compareTo(version) > 0) { - throw new MojoExecutionException("Unsupported Surefire version: " + version - + ". Use version " + MIN_SUREFIRE_VERSION + " and above."); - } + public static String getSfVersion(MavenProject project) throws MojoExecutionException { + return getSfPlugin(project).getVersion(); + } + + public static boolean invalidSfVersion(MavenProject project) throws MojoExecutionException { + String version = getSfVersion(project); + return MIN_SUREFIRE_VERSION.compareTo(version) > 0; } public static Plugin lookupPlugin(String name, MavenProject project) { diff --git a/starts-plugin/src/main/java/edu/illinois/starts/jdeps/RunMojo.java b/starts-plugin/src/main/java/edu/illinois/starts/jdeps/RunMojo.java index e8d21b92..15d62049 100644 --- a/starts-plugin/src/main/java/edu/illinois/starts/jdeps/RunMojo.java +++ b/starts-plugin/src/main/java/edu/illinois/starts/jdeps/RunMojo.java @@ -4,6 +4,9 @@ package edu.illinois.starts.jdeps; +import static edu.illinois.starts.helpers.PomUtil.getSfVersion; +import static edu.illinois.starts.helpers.PomUtil.invalidSfVersion; + import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -96,7 +99,12 @@ public void execute() throws MojoExecutionException { protected void run() throws MojoExecutionException { String cpString = Writer.pathToString(getSureFireClassPath().getClassPath()); List sfPathElements = getCleanClassPath(cpString); - if (!isSameClassPath(sfPathElements) || !hasSameJarChecksum(sfPathElements)) { + if (invalidSfVersion(getProject())) { + logger.log(Level.WARNING, "Unsupported Surefire version: " + getSfVersion(getProject()) + + ". Use version " + MIN_SUREFIRE_VERSION + " and above. Running all tests."); + // Run all tests + dynamicallyUpdateExcludes(new ArrayList()); + } else if (!isSameClassPath(sfPathElements) || !hasSameJarChecksum(sfPathElements)) { // Force retestAll because classpath changed since last run // don't compute changed and non-affected classes dynamicallyUpdateExcludes(new ArrayList()); From 046ef03400b74ef778726f7c114394a89a2da79a Mon Sep 17 00:00:00 2001 From: Benjamin Shen Date: Sun, 30 Oct 2022 21:30:38 -0400 Subject: [PATCH 2/3] fix npe --- .../src/main/java/edu/illinois/starts/jdeps/RunMojo.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/starts-plugin/src/main/java/edu/illinois/starts/jdeps/RunMojo.java b/starts-plugin/src/main/java/edu/illinois/starts/jdeps/RunMojo.java index 15d62049..ac464ba0 100644 --- a/starts-plugin/src/main/java/edu/illinois/starts/jdeps/RunMojo.java +++ b/starts-plugin/src/main/java/edu/illinois/starts/jdeps/RunMojo.java @@ -104,14 +104,15 @@ protected void run() throws MojoExecutionException { + ". Use version " + MIN_SUREFIRE_VERSION + " and above. Running all tests."); // Run all tests dynamicallyUpdateExcludes(new ArrayList()); + nonAffectedTests = new HashSet<>(); } else if (!isSameClassPath(sfPathElements) || !hasSameJarChecksum(sfPathElements)) { // Force retestAll because classpath changed since last run // don't compute changed and non-affected classes dynamicallyUpdateExcludes(new ArrayList()); // Make nonAffected empty so dependencies can be updated nonAffectedTests = new HashSet<>(); - Writer.writeClassPath(cpString, artifactsDir); - Writer.writeJarChecksums(sfPathElements, artifactsDir, jarCheckSums); + Writer.writeClassPath(cpString, getArtifactsDir()); + Writer.writeJarChecksums(sfPathElements, getArtifactsDir(), jarCheckSums); } else if (retestAll) { // Force retestAll but compute changes and affected tests setChangedAndNonaffected(); From 5ab2ec1cf29fb2bf60da02219da729eb0d8792d1 Mon Sep 17 00:00:00 2001 From: Benjamin Shen Date: Sun, 30 Oct 2022 21:32:29 -0400 Subject: [PATCH 3/3] spacing --- .../java/edu/illinois/starts/constants/StartsConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starts-core/src/main/java/edu/illinois/starts/constants/StartsConstants.java b/starts-core/src/main/java/edu/illinois/starts/constants/StartsConstants.java index 49e84400..467ed926 100644 --- a/starts-core/src/main/java/edu/illinois/starts/constants/StartsConstants.java +++ b/starts-core/src/main/java/edu/illinois/starts/constants/StartsConstants.java @@ -11,8 +11,8 @@ */ public interface StartsConstants { String STARTS_DIRECTORY_PATH = ".starts" + File.separator; - String MIN_SUREFIRE_VERSION = "2.13"; + String MIN_SUREFIRE_VERSION = "2.13"; String SUREFIRE_PLUGIN_VM = "org/apache/maven/plugin/surefire/SurefirePlugin"; String SUREFIRE_PLUGIN_BIN = "org.apache.maven.plugin.surefire.SurefirePlugin";