Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing #670: restoring allowSnapshots which was disabled in PR #665 #671

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 );
jarmoniuk marked this conversation as resolved.
Show resolved Hide resolved
}
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" ) ) );
}
}