Skip to content

Commit

Permalink
Resolves #978
Browse files Browse the repository at this point in the history
- added an it testing against a plain (not timestamped) -SNAPSHOT
- added a unit test testing against a timestamped snapshot
- added another comparison for the base version if it exists
  • Loading branch information
andrzejj0 authored and slawekjaranowski committed Sep 12, 2023
1 parent 15d7a17 commit 1d03956
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:use-releases
invoker.mavenOpts = -DprocessParent=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<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-parent2</artifactId>
<version>3.0-SNAPSHOT</version>
</parent>

<artifactId>it-use-releases-issue-978-parent-snapshot</artifactId>
<version>1</version>
<packaging>pom</packaging>

<description>Test that parent is updated if it uses a snapshot version</description>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import groovy.xml.XmlSlurper

def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) )

assert project.parent.version == '3.0'
Original file line number Diff line number Diff line change
Expand Up @@ -509,28 +509,49 @@ protected boolean updateDependencyVersion(
boolean updated = false;
if (isProcessingParent()
&& getProject().getParent() != null
&& DependencyComparator.INSTANCE.compare(
dep,
DependencyBuilder.newBuilder()
.withGroupId(
getProject().getParentArtifact().getGroupId())
.withArtifactId(
getProject().getParentArtifact().getArtifactId())
.withVersion(
getProject().getParentArtifact().getVersion())
.build())
== 0
&& PomHelper.setProjectParentVersion(pom, newVersion)) {
if (getLog().isDebugEnabled()) {
getLog().debug("Made parent update from " + dep.getVersion() + " to " + newVersion);
&& (DependencyComparator.INSTANCE.compare(
dep,
DependencyBuilder.newBuilder()
.withGroupId(getProject()
.getParentArtifact()
.getGroupId())
.withArtifactId(getProject()
.getParentArtifact()
.getArtifactId())
.withVersion(getProject()
.getParentArtifact()
.getVersion())
.build())
== 0
|| getProject().getParentArtifact().getBaseVersion() != null
&& DependencyComparator.INSTANCE.compare(
dep,
DependencyBuilder.newBuilder()
.withGroupId(getProject()
.getParentArtifact()
.getGroupId())
.withArtifactId(getProject()
.getParentArtifact()
.getArtifactId())
.withVersion(getProject()
.getParentArtifact()
.getBaseVersion())
.build())
== 0)) {
if (PomHelper.setProjectParentVersion(pom, newVersion)) {
if (getLog().isDebugEnabled()) {
getLog().debug("Made parent update from " + dep.getVersion() + " to " + newVersion);
}
getChangeRecorder()
.recordChange(DefaultDependencyChangeRecord.builder()
.withKind(changeKind)
.withDependency(dep)
.withNewVersion(newVersion)
.build());
updated = true;
} else {
getLog().warn("Could not update parent: " + dep.toString() + " to " + newVersion);
}
getChangeRecorder()
.recordChange(DefaultDependencyChangeRecord.builder()
.withKind(changeKind)
.withDependency(dep)
.withNewVersion(newVersion)
.build());
updated = true;
}

if (PomHelper.setDependencyVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,49 @@ public void testProcessParent()
"1.0.0-SNAPSHOT", "1.0.0")));
}

@Test
public void testProcessTimestampedParent()
throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException,
VersionRetrievalException {
setVariableValueToObject(mojo, "processParent", true);
mojo.getProject().setParent(new MavenProject(new Model() {
{
setGroupId("default-group");
setArtifactId("artifactA");
setVersion("1.0.0-SNAPSHOT");
}
}));
mojo.getProject()
.setParentArtifact(
new DefaultArtifact(
"default-group",
"artifactA",
"1.0.0-20230912.080442-1",
SCOPE_COMPILE,
"pom",
"default",
null) {
{
setBaseVersion("1.0.0-SNAPSHOT");
}
});

try (MockedStatic<PomHelper> pomHelper = mockStatic(PomHelper.class)) {
pomHelper
.when(() -> PomHelper.setProjectParentVersion(any(), anyString()))
.thenReturn(true);
pomHelper
.when(() -> PomHelper.getRawModel(any(MavenProject.class)))
.thenReturn(mojo.getProject().getModel());
mojo.update(null);
}
assertThat(
changeRecorder.getChanges(),
hasItem(new DefaultDependencyVersionChange(
"default-group", "artifactA",
"1.0.0-SNAPSHOT", "1.0.0")));
}

@Test
public void testReplaceSnapshotWithRelease()
throws MojoExecutionException, XMLStreamException, MojoFailureException, VersionRetrievalException {
Expand Down

0 comments on commit 1d03956

Please sign in to comment.