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
andrzejj0 committed Aug 27, 2022
1 parent d96c746 commit ae7d32b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/it/it-set-024-versionless-dependency/child/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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>
11 changes: 6 additions & 5 deletions src/main/java/org/codehaus/mojo/versions/SetMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,16 @@ public void execute() throws MojoExecutionException, MojoFailureException
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 ae7d32b

Please sign in to comment.