Skip to content

Commit

Permalink
Fixing #604: npe in DependencyVersionChanger if artifact version is null
Browse files Browse the repository at this point in the history
  • Loading branch information
jarmoniuk committed Aug 27, 2022
1 parent d96c746 commit 4a6c2d3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
13 changes: 13 additions & 0 deletions src/it/it-set-024-versionless-dependency/child/pom.xml
@@ -0,0 +1,13 @@
<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>test-artifact</artifactId>
<version>1.0</version>
</parent>

<artifactId>child</artifactId>

</project>
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:set -DprocessDependencies=true, -DartifactId=child -DoldVersion=1.0 -DnewVersion=2.0
22 changes: 22 additions & 0 deletions src/it/it-set-024-versionless-dependency/pom.xml
@@ -0,0 +1,22 @@
<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>test-artifact</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
</dependencyManagement>

<modules>
<module>child</module>
</modules>
</project>
20 changes: 9 additions & 11 deletions src/main/java/org/codehaus/mojo/versions/SetMojo.java
Expand Up @@ -342,27 +342,25 @@ public void execute() throws MojoExecutionException, MojoFailureException

getLog().info(
"Processing change of " + groupId + ":" + artifactId + ":" + oldVersion + " -> " + newVersion );
Pattern groupIdRegex =
Pattern.compile( RegexUtils.convertWildcardsToRegex( fixNullOrEmpty( groupId, "*" ), true ) );
Pattern artifactIdRegex =
Pattern.compile( RegexUtils.convertWildcardsToRegex( fixNullOrEmpty( artifactId, "*" ), true ) );
Pattern oldVersionIdRegex =
Pattern.compile( RegexUtils.convertWildcardsToRegex( fixNullOrEmpty( oldVersion, "*" ), true ) );
Pattern groupIdRegex = Pattern.compile( fixNullOrEmpty( groupId, ".*" ) );
Pattern artifactIdRegex = Pattern.compile( fixNullOrEmpty( artifactId, ".*" ) );
Pattern oldVersionIdRegex = Pattern.compile( fixNullOrEmpty( oldVersion, ".*" ) );
boolean found = false;
for ( Model m : reactor.values() )
{
final String mGroupId = PomHelper.getGroupId( m );
final String mArtifactId = PomHelper.getArtifactId( m );
final String mVersion = PomHelper.getVersion( m );
if ( ( ( groupIdRegex.matcher( mGroupId ).matches() && artifactIdRegex.matcher( mArtifactId )
.matches() ) //
|| ( processAllModules ) ) //
&& oldVersionIdRegex.matcher( mVersion ).matches() && !newVersion.equals( mVersion ) )
if ( ( processAllModules
|| groupIdRegex.matcher( mGroupId ).matches()
&& artifactIdRegex.matcher( mArtifactId ).matches() )
&& oldVersionIdRegex.matcher( mVersion ).matches()
&& !newVersion.equals( mVersion ) )
{
found = true;
// if the change is not one we have swept up already
applyChange( project, reactor, files, mGroupId, m.getArtifactId(),
StringUtils.isBlank( oldVersion ) || "*".equals( oldVersion ) ? "" : m.getVersion() );
StringUtils.isBlank( oldVersion ) || "*".equals( oldVersion ) ? "" : mVersion );
}
}
if ( !found && RegexUtils.getWildcardScore( groupId ) == 0 && RegexUtils.getWildcardScore( artifactId ) == 0
Expand Down

0 comments on commit 4a6c2d3

Please sign in to comment.