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

Resolves #978 - use-releases does not update parent #1007

Merged
merged 1 commit into from
Sep 12, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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