Skip to content

Commit

Permalink
#550 ignore plugins which have not version in current POM but in pare…
Browse files Browse the repository at this point in the history
…nt POM
  • Loading branch information
stefanseifert committed Mar 9, 2022
1 parent 50e624a commit 65fa0ee
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:display-plugin-updates
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>localhost</groupId>
<artifactId>it-101-parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>display-plugin-updates-parent</name>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>localhost</groupId>
<artifactId>dummy-maven-plugin</artifactId>
<version>1.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>localhost</groupId>
<artifactId>it-101-parent</artifactId>
<version>1.0</version>
<relativePath>parent/pom.xml</relativePath>
</parent>

<groupId>localhost</groupId>
<artifactId>it-101</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>display-plugin-updates</name>

<description>Ignore plugin used in this POM without version, which has a version defined in a parent POM.</description>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>localhost</groupId>
<artifactId>dummy-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import java.io.*;
import org.codehaus.plexus.util.FileUtils;
import java.util.regex.*;

try
{
File file = new File( basedir, "build.log" );
String buf = FileUtils.fileRead( file );

// output should not contain any message like 'localhost:dummy-maven-plugin .....' because this plugin should be ignored due to its version defined in parent POM
Pattern p = Pattern.compile( "\\Qlocalhost:dummy-maven-plugin\\E\\s*\\.+" );
Matcher m = p.matcher( buf.toString() );
if ( m.find() )
{
System.out.println( "dummy-maven-plugin should not be listed in output, version is defined in Parent POM" );
return false;
}
}
catch( Throwable t )
{
t.printStackTrace();
return false;
}

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,13 @@ public void execute()
{
version = parentPlugins.get( coords );
}

boolean versionSpecifiedInCurrentPom = pluginsWithVersionsSpecified.contains( coords );
if ( !versionSpecifiedInCurrentPom && parentPlugins.containsKey( coords ) ) {
getLog().debug( "Skip " + coords + ", version " + version + " is defined in parent POM." );
continue;
}

getLog().debug( "Checking " + coords + " for updates newer than " + version );
String effectiveVersion = version;

Expand Down Expand Up @@ -515,7 +522,7 @@ public void execute()

String newVersion;

if ( version == null && pluginsWithVersionsSpecified.contains( coords ) )
if ( version == null && versionSpecifiedInCurrentPom )
{
// Hack ALERT!
//
Expand All @@ -530,8 +537,8 @@ public void execute()
getLog().debug( "[" + coords + "].version=" + version );
getLog().debug( "[" + coords + "].artifactVersion=" + artifactVersion );
getLog().debug( "[" + coords + "].effectiveVersion=" + effectiveVersion );
getLog().debug( "[" + coords + "].specified=" + pluginsWithVersionsSpecified.contains( coords ) );
if ( version == null || !pluginsWithVersionsSpecified.contains( coords ) )
getLog().debug( "[" + coords + "].specified=" + versionSpecifiedInCurrentPom );
if ( version == null || !versionSpecifiedInCurrentPom )
{
version = superPomPluginManagement.get( coords );
getLog().debug( "[" + coords + "].superPom.version=" + version );
Expand Down

0 comments on commit 65fa0ee

Please sign in to comment.