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 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,3 @@
pom = new File( basedir, "pom.xml" ).text

assert pom =~ /<version>71-SNAPSHOT<\/version>/
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 8395718

Please sign in to comment.