Skip to content

Commit

Permalink
#256 display initial version even when Maven upgrade proposed
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Jan 28, 2018
1 parent 3efd354 commit ed93a45
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 54 deletions.
12 changes: 9 additions & 3 deletions src/it/it-display-plugin-updates-002/verify.bsh
Original file line number Diff line number Diff line change
@@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/it/it-display-plugin-updates-008/verify.bsh
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,14 @@ public void execute()
Set<Plugin> plugins = getProjectPlugins( superPomPluginManagement, parentPlugins, parentBuildPlugins,
parentReportPlugins, pluginsWithVersionsSpecified );

List<String> updates = new ArrayList<>();
List<String> lockdowns = new ArrayList<>();
List<String> pluginUpdates = new ArrayList<>();
List<String> 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<plugin compact key, latest compatible plugin vesion>
Map<ArtifactVersion, Map<String, String>> upgrades = new TreeMap<>( new MavenVersionComparator() );
Map<ArtifactVersion, Map<String, String>> mavenUpgrades = new TreeMap<>( new MavenVersionComparator() );

for ( Plugin plugin : plugins )
{
Expand Down Expand Up @@ -456,16 +456,19 @@ public void execute()
// upgrade
if ( minRequires == null || compare( minRequires, pluginRequires ) > 0 )
{
Map<String, String> upgradePlugins = upgrades.get( pluginRequires );
Map<String, String> upgradePlugins = mavenUpgrades.get( pluginRequires );
if ( upgradePlugins == null )
{
upgrades.put( pluginRequires, upgradePlugins = new LinkedHashMap<String, String>() );
mavenUpgrades.put( pluginRequires,
upgradePlugins = new LinkedHashMap<String, String>() );
}

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;
}
Expand Down Expand Up @@ -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 )
Expand All @@ -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;
Expand Down Expand Up @@ -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<ArtifactVersion, Map<String, String>> mavenUpgrade : upgrades.entrySet() )

// updates if minimum Maven version is changed
for ( Map.Entry<ArtifactVersion, Map<String, String>> mavenUpgrade : mavenUpgrades.entrySet() )
{
ArtifactVersion mavenUpgradeVersion = mavenUpgrade.getKey();
Map<String, String> upgradePlugins = mavenUpgrade.getValue();
Expand All @@ -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<String, String> entry : upgradePlugins.entrySet() )
{
logLine( false, pad( entry.getKey(), INFO_PAD_SIZE, entry.getValue() ) );
logLine( false, entry.getValue() );
}
}
logLine( false, "" );
Expand Down
72 changes: 36 additions & 36 deletions src/site/apt/examples/display-plugin-updates.apt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -167,33 +167,33 @@ mvn versions:display-plugin-updates
[ERROR] </prerequisites>
[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
Expand Down Expand Up @@ -238,24 +238,24 @@ mvn versions:display-plugin-updates
[ERROR] </prerequisites>
[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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ed93a45

Please sign in to comment.