Skip to content

Commit

Permalink
Fixing #670: allowSnapshots was disabled in PR #665; usePluginReposit…
Browse files Browse the repository at this point in the history
…ories was incorrectly enabled
  • Loading branch information
andrzejj0 committed Sep 6, 2022
1 parent e3beb05 commit 8395718
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/it-repo/dummy-parent4-70.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<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>dummy-parent4</artifactId>
<version>70</version>
<packaging>pom</packaging>
</project>
9 changes: 9 additions & 0 deletions src/it-repo/dummy-parent4-71-SNAPSHOT.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<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>dummy-parent4</artifactId>
<version>71-SNAPSHOT</version>
<packaging>pom</packaging>
</project>
1 change: 1 addition & 0 deletions src/it/it-update-parent-005-issue-670/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:update-parent -DparentVersion=71-SNAPSHOT -DallowSnapshots
16 changes: 16 additions & 0 deletions src/it/it-update-parent-005-issue-670/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>dummy-parent4</artifactId>
<version>70</version>
</parent>

<groupId>localhsot</groupId>
<artifactId>issue-670</artifactId>
<version>0.31-SNAPSHOT</version>
<packaging>pom</packaging>

</project>
3 changes: 3 additions & 0 deletions src/it/it-update-parent-005-issue-670/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pom = new File( basedir, "pom.xml" ).text

assert pom =~ /<version>71-SNAPSHOT<\/version>/
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,13 @@ protected void update( ModifiedPomXMLEventReader pom )
ArtifactVersion artifactVersion;
try
{
artifactVersion = findLatestVersion( artifact, versionRange, false, true,
allowDowngrade );
artifactVersion = findLatestVersion( artifact, versionRange, null, false, allowDowngrade );
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}


if ( !shouldApplyUpdate( artifact, currentVersion, artifactVersion, forceUpdate ) )
{
return;
Expand Down
52 changes: 52 additions & 0 deletions src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ private static ArtifactMetadataSource mockArtifactMetaDataSource() throws Artifa
new DefaultArtifactVersion( "1.0.0" ),
new DefaultArtifactVersion( "0.9.0" ) );
}
else if ( "issue-670-artifact".equals( artifact.getArtifactId() ) )
{
return Arrays.asList( new DefaultArtifactVersion( "0.0.1-1" ),
new DefaultArtifactVersion( "0.0.1-1-impl-SNAPSHOT" ) );
}
else if ( "unknown-artifact".equals( artifact.getArtifactId() ) )
{
return Collections.emptyList();
Expand Down Expand Up @@ -236,4 +241,51 @@ public void testParentDowngradeForbiddenWithRange()
}
assertThat( changeRecorder.getChanges(), is( empty() ) );
}

@Test
public void testAllowSnapshots()
throws MojoExecutionException, XMLStreamException, MojoFailureException
{
mojo.allowSnapshots = true;
mojo.getProject().setParent( new MavenProject()
{{
setGroupId( "default-group" );
setArtifactId( "issue-670-artifact" );
setVersion( "0.0.1-1" );
}} );

try ( MockedStatic<PomHelper> pomHelper = mockStatic( PomHelper.class ) )
{
pomHelper.when( () -> PomHelper.setProjectParentVersion( any(), any() ) )
.thenReturn( true );
mojo.update( null );
}
assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group",
"issue-670-artifact", "0.0.1-1",
"0.0.1-1-impl-SNAPSHOT" ) ) );
}

@Test
public void testAllowSnapshotsWithParentVersion()
throws MojoExecutionException, XMLStreamException, MojoFailureException
{
mojo.allowSnapshots = true;
mojo.parentVersion = "0.0.1-1-impl-SNAPSHOT";
mojo.getProject().setParent( new MavenProject()
{{
setGroupId( "default-group" );
setArtifactId( "issue-670-artifact" );
setVersion( "0.0.1-1" );
}} );

try ( MockedStatic<PomHelper> pomHelper = mockStatic( PomHelper.class ) )
{
pomHelper.when( () -> PomHelper.setProjectParentVersion( any(), any() ) )
.thenReturn( true );
mojo.update( null );
}
assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group",
"issue-670-artifact", "0.0.1-1",
"0.0.1-1-impl-SNAPSHOT" ) ) );
}
}

0 comments on commit 8395718

Please sign in to comment.