Skip to content

Commit

Permalink
Merge pull request #423 from stefanseifert/issue/422-plugin-updates-p…
Browse files Browse the repository at this point in the history
…arent-npe

Fixes #422 Avoid NPE when non-local parent POM is present
  • Loading branch information
mfriedenhagen committed Aug 9, 2020
2 parents 979e363 + 29b368d commit f4b555b
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 2 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
52 changes: 52 additions & 0 deletions src/it/it-display-plugin-updates-009-issue-422/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<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>org.apache</groupId>
<artifactId>apache</artifactId>
<version>23</version>
<relativePath/>
</parent>

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

<description>Make sure display-plugin-updates works if a non-local parent is referenced.</description>

<prerequisites>
<maven>2.0.6</maven>
</prerequisites>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>localhost</groupId>
<artifactId>dummy-maven-plugin</artifactId>
<version>1.0</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.3</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>
25 changes: 25 additions & 0 deletions src/it/it-display-plugin-updates-009-issue-422/verify.bsh
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 );

Pattern p = Pattern.compile( "\\Qlocalhost:dummy-maven-plugin\\E\\s*\\.*\\s*1\\.0\\s+->\\s+3\\.1" );
Matcher m = p.matcher( buf.toString() );
if ( !m.find() )
{
System.out.println( "Did not suggest updating dummy-maven-plugin to version 3.1" );
return false;
}
System.out.println( m.group( 0 ) );
}
catch( Throwable t )
{
t.printStackTrace();
return false;
}

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent;

import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.io.StringWriter;
Expand Down Expand Up @@ -769,7 +771,7 @@ private Map<String, String> getParentsPlugins( List<MavenProject> parents )
try
{
Set<String> withVersionSpecified =
findPluginsWithVersionsSpecified( new StringBuilder( writer.toString() ), parentProject.getFile().getAbsolutePath() );
findPluginsWithVersionsSpecified( new StringBuilder( writer.toString() ), getSafeProjectPathInfo(parentProject) );

Map<String, String> map = getPluginManagement( interpolatedModel );
map.keySet().retainAll( withVersionSpecified );
Expand Down Expand Up @@ -797,6 +799,17 @@ private Map<String, String> getParentsPlugins( List<MavenProject> parents )
}
return parentPlugins;
}

private String getSafeProjectPathInfo(MavenProject project) {
File file = project.getFile();
if (file != null) {
return file.getAbsolutePath();
}
else {
// path is used only as information in error message, we can fallback to project artifact info here
return project.toString();
}
}

private boolean isMavenPluginProject()
{
Expand Down Expand Up @@ -850,7 +863,7 @@ public String toString()
private Set<String> findPluginsWithVersionsSpecified( MavenProject project )
throws IOException, XMLStreamException
{
return findPluginsWithVersionsSpecified( PomHelper.readXmlFile( project.getFile() ), project.getFile().getAbsolutePath() );
return findPluginsWithVersionsSpecified( PomHelper.readXmlFile( project.getFile() ), getSafeProjectPathInfo(project) );
}

/**
Expand Down

0 comments on commit f4b555b

Please sign in to comment.