From 4cfb8787fdbaf8fd1875823208efd3be585e7f3e Mon Sep 17 00:00:00 2001 From: Andrzej Jarmoniuk Date: Tue, 6 Sep 2022 13:36:47 +0200 Subject: [PATCH] Fixing #670: allowSnapshots was disabled in PR #665 --- .../mojo/versions/UpdateParentMojo.java | 2 +- .../mojo/versions/UpdateParentMojoTest.java | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java b/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java index 68893603f3..311ad837eb 100644 --- a/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java @@ -134,7 +134,7 @@ protected void update( ModifiedPomXMLEventReader pom ) ArtifactVersion artifactVersion; try { - artifactVersion = findLatestVersion( artifact, versionRange, false, true, + artifactVersion = findLatestVersion( artifact, versionRange, allowSnapshots, true, allowDowngrade ); } catch ( ArtifactMetadataRetrievalException e ) diff --git a/src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java b/src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java index 0faeec3993..aca23440e2 100644 --- a/src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java +++ b/src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java @@ -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(); @@ -236,4 +241,27 @@ public void testParentDowngradeForbiddenWithRange() } assertThat( changeRecorder.getChanges(), is( empty() ) ); } + + @Test + public void testParentDowngradeForbiddenWithSnapshots() + 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 = 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" ) ) ); + } }