diff --git a/src/it/it-display-plugin-updates-002/verify.bsh b/src/it/it-display-plugin-updates-002/verify.bsh index 726b272e71..9a7aaf6045 100644 --- a/src/it/it-display-plugin-updates-002/verify.bsh +++ b/src/it/it-display-plugin-updates-002/verify.bsh @@ -1,16 +1,22 @@ import java.io.*; import org.codehaus.plexus.util.FileUtils; -import java.util.regex.Pattern; +import java.util.regex.*; try { File file = new File( basedir, "build.log" ); String buf = FileUtils.fileRead( file ); - if (Pattern.compile( "\\Qlocalhost:dummy-maven-plugin\\E\\s*\\.*\\s*+3\\.0\\s+->\\s+[0-9\\.]+" ) - .matcher( buf.toString() ).find() ) + Pattern p1 = Pattern.compile( "\\QRequire Maven 2.0.9 to use the following plugin updates:\\E" ); + Matcher m1 = p1.matcher( buf.toString() ); + Pattern p2 = Pattern.compile( "\\Qlocalhost:dummy-maven-plugin\\E \\.* \\Q3.0 -> \\E[0-9\\.]+" ); + Matcher m2 = p1.matcher( buf.toString() ); + + if ( m1.find() && m2.find() && m1.start() > m2.start() ) { System.out.println( "Suggested updating dummy-maven-plugin from version 3.0" ); + System.out.println( m1.group( 0 ) ); + System.out.println( m2.group( 0 ) ); return false; } } diff --git a/src/it/it-display-plugin-updates-008/verify.bsh b/src/it/it-display-plugin-updates-008/verify.bsh index 9f50e722a2..d0f1c821b1 100644 --- a/src/it/it-display-plugin-updates-008/verify.bsh +++ b/src/it/it-display-plugin-updates-008/verify.bsh @@ -9,7 +9,7 @@ try Pattern p1 = Pattern.compile( "\\QRequire Maven 2.0.9 to use the following plugin updates:\\E" ); Matcher m1 = p1.matcher( buf.toString() ); - Pattern p2 = Pattern.compile( "\\Qlocalhost:dummy-maven-plugin\\E\\s*\\.*\\s*3\\.1" ); + Pattern p2 = Pattern.compile( "\\Qlocalhost:dummy-maven-plugin\\E\\s*\\.*\\s*\\Q1.0 -> 3.1\\E" ); Matcher m2 = p2.matcher( buf.toString() ); if ( !m1.find() || !m2.find() || m2.start() < m1.start() ) { diff --git a/src/main/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java b/src/main/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java index 12b911a2b0..9c3979d815 100644 --- a/src/main/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java @@ -381,14 +381,14 @@ public void execute() Set plugins = getProjectPlugins( superPomPluginManagement, parentPlugins, parentBuildPlugins, parentReportPlugins, pluginsWithVersionsSpecified ); - List updates = new ArrayList<>(); - List lockdowns = new ArrayList<>(); + List pluginUpdates = new ArrayList<>(); + List pluginLockdowns = new ArrayList<>(); ArtifactVersion curMavenVersion = runtimeInformation.getApplicationVersion(); ArtifactVersion specMavenVersion = new DefaultArtifactVersion( getRequiredMavenVersion( getProject(), "2.0" ) ); ArtifactVersion minMavenVersion = null; boolean superPomDrivingMinVersion = false; // if Maven prerequisite upgraded to a version, Map - Map> upgrades = new TreeMap<>( new MavenVersionComparator() ); + Map> mavenUpgrades = new TreeMap<>( new MavenVersionComparator() ); for ( Plugin plugin : plugins ) { @@ -456,16 +456,19 @@ public void execute() // upgrade if ( minRequires == null || compare( minRequires, pluginRequires ) > 0 ) { - Map upgradePlugins = upgrades.get( pluginRequires ); + Map upgradePlugins = mavenUpgrades.get( pluginRequires ); if ( upgradePlugins == null ) { - upgrades.put( pluginRequires, upgradePlugins = new LinkedHashMap() ); + mavenUpgrades.put( pluginRequires, + upgradePlugins = new LinkedHashMap() ); } String upgradePluginKey = compactKey( groupId, artifactId ); if ( !upgradePlugins.containsKey( upgradePluginKey ) ) { - upgradePlugins.put( upgradePluginKey, newerVersions[j].toString() ); + upgradePlugins.put( upgradePluginKey, + pad( upgradePluginKey, INFO_PAD_SIZE, + effectiveVersion, " -> ", newerVersions[j].toString() ) ); } minRequires = pluginRequires; } @@ -534,7 +537,7 @@ public void execute() superPomDrivingMinVersion = true; } - lockdowns.add( pad( compactKey( groupId, artifactId ), WARN_PAD_SIZE, + pluginLockdowns.add( pad( compactKey( groupId, artifactId ), WARN_PAD_SIZE, superPomDrivingMinVersion ? FROM_SUPER_POM : "", newVersion ) ); } else if ( artifactVersion != null ) @@ -548,37 +551,46 @@ else if ( artifactVersion != null ) if ( version != null && artifactVersion != null && newVersion != null && effectiveVersion != null && new DefaultArtifactVersion( effectiveVersion ).compareTo( new DefaultArtifactVersion( newVersion ) ) < 0 ) { - updates.add( pad( compactKey( groupId, artifactId ), INFO_PAD_SIZE, + pluginUpdates.add( pad( compactKey( groupId, artifactId ), INFO_PAD_SIZE, effectiveVersion, " -> ", newVersion ) ); } } + + // info on each plugin gathered: now it's time to display the result! + // logLine( false, "" ); - if ( updates.isEmpty() ) + + // updates keeping currently defined Maven version minimum + if ( pluginUpdates.isEmpty() ) { logLine( false, "All plugins with a version specified are using the latest versions." ); } else { logLine( false, "The following plugin updates are available:" ); - for ( String update : updates ) + for ( String update : pluginUpdates ) { logLine( false, update ); } } logLine( false, "" ); - if ( lockdowns.isEmpty() ) + + // has every plugin a specified version? + if ( pluginLockdowns.isEmpty() ) { logLine( false, "All plugins have a version specified." ); } else { getLog().warn( "The following plugins do not have their version specified:" ); - for ( String lockdown : lockdowns ) + for ( String lockdown : pluginLockdowns ) { getLog().warn( lockdown ); } } logLine( false, "" ); + + // information on minimum Maven version boolean noMavenMinVersion = getRequiredMavenVersion( getProject(), null ) == null; boolean noExplicitMavenMinVersion = getProject().getPrerequisites() == null || getProject().getPrerequisites().getMaven() == null; @@ -662,7 +674,9 @@ else if ( minMavenVersion != null && compare( specMavenVersion, minMavenVersion logLine( false, "No plugins require a newer version of Maven than specified by the pom." ); } } - for ( Map.Entry> mavenUpgrade : upgrades.entrySet() ) + + // updates if minimum Maven version is changed + for ( Map.Entry> mavenUpgrade : mavenUpgrades.entrySet() ) { ArtifactVersion mavenUpgradeVersion = mavenUpgrade.getKey(); Map upgradePlugins = mavenUpgrade.getValue(); @@ -674,7 +688,7 @@ else if ( minMavenVersion != null && compare( specMavenVersion, minMavenVersion logLine( false, "Require Maven " + mavenUpgradeVersion + " to use the following plugin updates:" ); for ( Map.Entry entry : upgradePlugins.entrySet() ) { - logLine( false, pad( entry.getKey(), INFO_PAD_SIZE, entry.getValue() ) ); + logLine( false, entry.getValue() ); } } logLine( false, "" ); diff --git a/src/site/apt/examples/display-plugin-updates.apt b/src/site/apt/examples/display-plugin-updates.apt index f7057251d3..17960db3b7 100644 --- a/src/site/apt/examples/display-plugin-updates.apt +++ b/src/site/apt/examples/display-plugin-updates.apt @@ -65,17 +65,17 @@ mvn versions:display-plugin-updates [WARNING] enforce that the correct version of Maven is used to build this plugin. [INFO] [INFO] Require Maven 2.0.9 to use the following plugin updates: -[INFO] maven-compiler-plugin ......................................... 2.3.2 -[INFO] maven-surefire-plugin .......................................... 2.10 +[INFO] maven-compiler-plugin ................................ 2.3 6 -> 2.3.2 +[INFO] maven-surefire-plugin ................................... 2.9 -> 2.10 [INFO] [INFO] Require Maven 2.1.0 to use the following plugin updates: -[INFO] maven-site-plugin ............................................. 2.1.1 +[INFO] maven-site-plugin ..................... ${sitePluginVersion} -> 2.1.1 [INFO] [INFO] Require Maven 2.2.0 to use the following plugin updates: -[INFO] maven-site-plugin ............................................... 3.0 +[INFO] maven-site-plugin ....................... ${sitePluginVersion} -> 3.0 [INFO] [INFO] Require Maven 2.2.1 to use the following plugin updates: -[INFO] maven-changes-plugin ............................................ 2.5 +[INFO] maven-changes-plugin ..................................... 2.0 -> 2.5 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL @@ -167,33 +167,33 @@ mvn versions:display-plugin-updates [ERROR] [INFO] [INFO] Require Maven 2.0.2 to use the following plugin updates: -[INFO] maven-checkstyle-plugin ......................................... 2.1 -[INFO] maven-javadoc-plugin ............................................ 2.2 -[INFO] maven-site-plugin ........................................ 2.0-beta-7 -[INFO] org.codehaus.mojo:build-helper-maven-plugin ..................... 1.5 +[INFO] maven-checkstyle-plugin .................................. 2.0 -> 2.1 +[INFO] maven-javadoc-plugin ..................................... 2.0 -> 2.2 +[INFO] maven-site-plugin .......................... 2.0-beta-4 -> 2.0-beta-7 +[INFO] org.codehaus.mojo:build-helper-maven-plugin .............. 1.0 -> 1.5 [INFO] [INFO] Require Maven 2.0.6 to use the following plugin updates: -[INFO] maven-checkstyle-plugin ......................................... 2.8 -[INFO] maven-clean-plugin ............................................ 2.4.1 -[INFO] maven-deploy-plugin ............................................. 2.7 -[INFO] maven-install-plugin .......................................... 2.3.1 -[INFO] maven-javadoc-plugin ............................................ 2.3 -[INFO] maven-site-plugin ............................................. 2.0.1 -[INFO] org.codehaus.mojo:build-helper-maven-plugin ..................... 1.7 -[INFO] org.codehaus.mojo:versions-maven-plugin ......................... 1.2 +[INFO] maven-checkstyle-plugin .................................. 2.0 -> 2.8 +[INFO] maven-clean-plugin ..................................... 2.1 -> 2.4.1 +[INFO] maven-deploy-plugin ...................................... 2.4 -> 2.7 +[INFO] maven-install-plugin ................................... 2.2 -> 2.3.1 +[INFO] maven-javadoc-plugin ..................................... 2.0 -> 2.3 +[INFO] maven-site-plugin ............................... 2.0-beta-4 -> 2.0.1 +[INFO] org.codehaus.mojo:build-helper-maven-plugin .............. 1.0 -> 1.7 +[INFO] org.codehaus.mojo:versions-maven-plugin .................. 1.0 -> 1.2 [INFO] [INFO] Require Maven 2.0.8 to use the following plugin updates: -[INFO] maven-javadoc-plugin ............................................ 2.4 +[INFO] maven-javadoc-plugin ..................................... 2.0 -> 2.4 [INFO] [INFO] Require Maven 2.0.9 to use the following plugin updates: -[INFO] maven-compiler-plugin ......................................... 2.3.2 -[INFO] maven-javadoc-plugin ............................................ 2.8 +[INFO] maven-compiler-plugin ................................ 2.0.2 -> 2.3.2 +[INFO] maven-javadoc-plugin ..................................... 2.0 -> 2.8 [INFO] [INFO] Require Maven 2.1.0 to use the following plugin updates: -[INFO] maven-site-plugin ............................................. 2.1.1 +[INFO] maven-site-plugin ............................... 2.0-beta-4 -> 2.1.1 [INFO] [INFO] Require Maven 2.2.0 to use the following plugin updates: -[INFO] maven-site-plugin ............................................... 3.0 +[INFO] maven-site-plugin ................................. 2.0-beta-4 -> 3.0 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL @@ -238,24 +238,24 @@ mvn versions:display-plugin-updates [ERROR] [INFO] [INFO] Require Maven 2.0.2 to use the following plugin updates: -[INFO] maven-checkstyle-plugin ......................................... 2.1 -[INFO] maven-site-plugin ........................................ 2.0-beta-7 -[INFO] org.codehaus.mojo:build-helper-maven-plugin ..................... 1.5 +[INFO] maven-checkstyle-plugin .................................. 2.0 -> 2.1 +[INFO] maven-site-plugin .......................... 2.0-beta-4 -> 2.0-beta-7 +[INFO] org.codehaus.mojo:build-helper-maven-plugin .............. 1.0 -> 1.5 [INFO] [INFO] Require Maven 2.0.6 to use the following plugin updates: -[INFO] maven-checkstyle-plugin ......................................... 2.8 -[INFO] maven-clean-plugin ............................................ 2.4.1 -[INFO] maven-deploy-plugin ............................................. 2.7 -[INFO] maven-install-plugin .......................................... 2.3.1 -[INFO] maven-site-plugin ............................................. 2.0.1 -[INFO] org.codehaus.mojo:build-helper-maven-plugin ..................... 1.7 -[INFO] org.codehaus.mojo:versions-maven-plugin ......................... 1.2 +[INFO] maven-checkstyle-plugin .................................. 2.0 -> 2.8 +[INFO] maven-clean-plugin ..................................... 2.3 -> 2.4.1 +[INFO] maven-deploy-plugin ...................................... 2.4 -> 2.7 +[INFO] maven-install-plugin ................................... 2.2 -> 2.3.1 +[INFO] maven-site-plugin ............................... 2.0-beta-4 -> 2.0.1 +[INFO] org.codehaus.mojo:build-helper-maven-plugin .............. 1.0 -> 1.7 +[INFO] org.codehaus.mojo:versions-maven-plugin .................. 1.0 -> 1.2 [INFO] [INFO] Require Maven 2.1.0 to use the following plugin updates: -[INFO] maven-site-plugin ............................................. 2.1.1 +[INFO] maven-site-plugin ............................... 2.0-beta-4 -> 2.1.1 [INFO] [INFO] Require Maven 2.2.0 to use the following plugin updates: -[INFO] maven-site-plugin ............................................... 3.0 +[INFO] maven-site-plugin ................................. 2.0-beta-4 -> 3.0 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL @@ -339,10 +339,10 @@ mvn versions:display-plugin-updates [INFO] maven-javadoc-plugin ............................................ 2.8 [INFO] [INFO] Require Maven 2.1.0 to use the following plugin updates: -[INFO] maven-site-plugin ............................................. 2.1.1 +[INFO] maven-site-plugin ...................................... 2.0 -> 2.1.1 [INFO] [INFO] Require Maven 2.2.0 to use the following plugin updates: -[INFO] maven-site-plugin ............................................... 3.0 +[INFO] maven-site-plugin ........................................ 2.0 -> 3.0 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL