Skip to content

Commit

Permalink
Resolves #995: Minimum version required for Versions Maven Plugin sho…
Browse files Browse the repository at this point in the history
…uld is not the minimum version for the project
  • Loading branch information
jarmoniuk authored and slawekjaranowski committed Aug 20, 2023
1 parent 1cfdb54 commit 220c4ef
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 50 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 @@ -124,8 +124,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 @@ -345,8 +343,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 @@ -472,10 +469,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 @@ -488,7 +483,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 @@ -507,7 +502,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 @@ -528,7 +523,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 @@ -816,7 +811,7 @@ private ArtifactVersion getPrerequisitesMavenVersion(MavenProject pluginProject)
return ofNullable(pluginProject.getPrerequisites())
.map(Prerequisites::getMaven)
.map(DefaultArtifactVersionCache::of)
.orElse(DefaultArtifactVersionCache.of(DEFAULT_MVN_VERSION));
.orElse(null);
}

/**
Expand Down Expand Up @@ -1159,7 +1154,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 @@ -39,14 +39,11 @@ static Optional<ArtifactVersion> getGreatestVersion(ArtifactVersion... v) {
});
}

static ArtifactVersion find(MavenProject mavenProject, String defaultMavenVersion, Log log) {
static ArtifactVersion find(MavenProject mavenProject, Log log) {
return getGreatestVersion(
getEnforcerMavenVersion(mavenProject, log),
ofNullable(mavenProject.getPrerequisites())
.map(Prerequisites::getMaven)
.map(DefaultArtifactVersionCache::of)
.orElse(null),
ofNullable(defaultMavenVersion)
.map(DefaultArtifactVersionCache::of)
.orElse(null))
.orElse(null);
Expand Down

0 comments on commit 220c4ef

Please sign in to comment.