Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run all tests for unsupported surefire versions #101

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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";

Expand Down
23 changes: 10 additions & 13 deletions starts-core/src/main/java/edu/illinois/starts/helpers/PomUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -54,20 +52,19 @@ public static List<String> 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) {
Expand Down
15 changes: 12 additions & 3 deletions starts-plugin/src/main/java/edu/illinois/starts/jdeps/RunMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -96,14 +99,20 @@ public void execute() throws MojoExecutionException {
protected void run() throws MojoExecutionException {
String cpString = Writer.pathToString(getSureFireClassPath().getClassPath());
List<String> 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<String>());
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<String>());
// 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();
Expand Down