Skip to content

Commit

Permalink
Fixing mojohaus#670: allowSnapshots was disabled in PR mojohaus#665; …
Browse files Browse the repository at this point in the history
…usePluginRepositories was incorrectly enabled
  • Loading branch information
jarmoniuk committed Sep 6, 2022
1 parent e3beb05 commit 2be4fa6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
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
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 2be4fa6

Please sign in to comment.