Skip to content

Commit

Permalink
Resolves mojohaus#995: Minimum version required for Versions Maven Pl…
Browse files Browse the repository at this point in the history
…ugin should is not the minimum version for the project
  • Loading branch information
jarmoniuk committed Jul 30, 2023
1 parent 6cd759c commit e573b6e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:display-plugin-updates
invoker.mavenOpts = -Dversions.outputFile=./output.txt -DoutputEncoding=UTF-8

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
output = new File(basedir, "output.txt").text
assert output =~ /\Qmaven-deploy-plugin\E\s*\.*\s*\Q2.3 ->\E/
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@

assert new File(basedir, 'output.txt').text
.replaceAll('\r', '')
.contains('The following plugin updates are available:\n'
+ ' maven-jar-plugin ................................... 3.0.0 -> 3.3.0')
.contains('Require Maven 3.2.5 to use the following plugin updates:\n' +
' maven-jar-plugin ................................... 3.0.0 -> 3.3.0')
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ public class DisplayPluginUpdatesMojo extends AbstractVersionsDisplayMojo {
*/
private static final String FROM_SUPER_POM = "(from super-pom) ";

public static final String DEFAULT_MVN_VERSION = "3.2.5";

/**
* @since 1.0-alpha-1
*/
Expand Down Expand Up @@ -346,8 +344,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
List<String> pluginUpdates = new ArrayList<>();
List<String> pluginLockdowns = new ArrayList<>();
ArtifactVersion curMavenVersion = DefaultArtifactVersionCache.of(runtimeInformation.getMavenVersion());
ArtifactVersion specMavenVersion =
MinimalMavenBuildVersionFinder.find(getProject(), DEFAULT_MVN_VERSION, getLog());
ArtifactVersion specMavenVersion = MinimalMavenBuildVersionFinder.find(getProject(), getLog());
ArtifactVersion minMavenVersion = null;
boolean superPomDrivingMinVersion = false;
// if Maven prerequisite upgraded to a version, Map<plugin compact key, latest compatible plugin vesion>
Expand Down Expand Up @@ -473,10 +470,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
logLine(false, "");

// information on minimum Maven version
boolean noMavenMinVersion = MinimalMavenBuildVersionFinder.find(getProject(), null, getLog()) == null;
if (noMavenMinVersion) {
getLog().warn("Project does not define minimum Maven version required for build, default is: "
+ DEFAULT_MVN_VERSION);
if (specMavenVersion == null) {
getLog().warn("Project does not define minimum Maven version required for build");
} else {
logLine(false, "Project requires minimum Maven version for build of: " + specMavenVersion);
}
Expand All @@ -489,7 +484,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
logLine(false, "");

if (isMavenPluginProject()) {
if (noMavenMinVersion) {
if (specMavenVersion == null) {
getLog().warn("Project (which is a Maven plugin) does not define required minimum version of Maven.");
getLog().warn("Update the pom.xml to contain");
getLog().warn(" <prerequisites>");
Expand All @@ -508,7 +503,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
logLine(false, "No plugins require a newer version of Maven than specified by the pom.");
}
} else {
if (noMavenMinVersion) {
if (specMavenVersion == null) {
logLine(true, "Project does not define required minimum version of Maven.");
logLine(true, "Update the pom.xml to contain maven-enforcer-plugin to");
logLine(true, "force the Maven version which is needed to build this project.");
Expand All @@ -529,7 +524,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
for (Map.Entry<ArtifactVersion, Map<String, String>> mavenUpgrade : mavenUpgrades.entrySet()) {
ArtifactVersion mavenUpgradeVersion = mavenUpgrade.getKey();
Map<String, String> upgradePlugins = mavenUpgrade.getValue();
if (upgradePlugins.isEmpty() || compare(specMavenVersion, mavenUpgradeVersion) >= 0) {
if (upgradePlugins.isEmpty() || compare(mavenUpgradeVersion, specMavenVersion) < 0) {
continue;
}
logLine(false, "");
Expand Down Expand Up @@ -817,7 +812,7 @@ private ArtifactVersion getPrerequisitesMavenVersion(MavenProject pluginProject)
return ofNullable(pluginProject.getPrerequisites())
.map(Prerequisites::getMaven)
.map(DefaultArtifactVersion::new)
.orElse(DefaultArtifactVersionCache.of(DEFAULT_MVN_VERSION));
.orElse(null);
}

/**
Expand Down Expand Up @@ -1160,7 +1155,7 @@ protected void update(ModifiedPomXMLEventReader pom) {
}

private static int compare(ArtifactVersion a, ArtifactVersion b) {
return a.compareTo(b);
return a == null ? b == null ? 0 : -1 : b == null ? 1 : a.compareTo(b);
}

private static class IgnoringModelProblemCollector implements ModelProblemCollector {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ private MinimalMavenBuildVersionFinder() {
// not supposed to be created, static methods only
}

static ArtifactVersion find(MavenProject mavenProject, String defaultVersion, Log log) {
ArtifactVersion version = getEnforcerMavenVersion(mavenProject, log);
if (version == null && defaultVersion != null) {
version = DefaultArtifactVersionCache.of(defaultVersion);
}
return version;
static ArtifactVersion find(MavenProject mavenProject, Log log) {
return getEnforcerMavenVersion(mavenProject, log);
}

private static ArtifactVersion getEnforcerMavenVersion(MavenProject mavenProject, Log log) {
Expand Down

0 comments on commit e573b6e

Please sign in to comment.