Skip to content

Commit

Permalink
ChangeDependencyGroupIdAndArtifactId - fixed issue described by `mana…
Browse files Browse the repository at this point in the history
…gedToUnmanagedExternalizedDepMgmt` test… (#3998)

* fixed issue described by `managedToUnmanagedExternalizedDepMgmt` test; previously, the changed dep would erroneously have no version (and one or more "No version provided" markers) after recipe execution

* shifting RemoveRedundantDependencyVersions call to be conditional on ChangeManagedDependencyGroupIdAndArtifactId making a change, to fix test failures with `multipleRetainVersions` on `UpgradeDependencyVersionTest` and `ChangeParentPomTest`
  • Loading branch information
nmck257 authored Feb 14, 2024
1 parent becbfc0 commit 194c106
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) {
// Otherwise, change the version to the new value.
t = changeChildTagValue(t, "version", resolvedNewVersion, ctx);
}
} else if (configuredToOverrideManageVersion || !newDependencyManaged && !(oldDependencyManaged && configuredToChangeManagedDependency)) {
} else if (configuredToOverrideManageVersion || !newDependencyManaged) {
//If the version is not present, add the version if we are explicitly overriding a managed version or if no managed version exists.
Xml.Tag newVersionTag = Xml.Tag.build("<version>" + resolvedNewVersion + "</version>");
//noinspection ConstantConditions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) {
}
if (changed) {
maybeUpdateModel();
doAfterVisit(new RemoveRedundantDependencyVersions(null, null, null, null).getVisitor());
}
}
return t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,71 @@ void managedToUnmanagedWithoutChangeManagedDependency() {
);
}

@Test
void managedToUnmanagedExternalizedDepMgmt() {
rewriteRun(
spec -> spec.recipe(new ChangeDependencyGroupIdAndArtifactId(
"org.springframework.cloud",
"spring-cloud-starter-sleuth",
"io.micrometer",
"micrometer-tracing-bridge-brave",
"1.0.12",
null
)),
pomXml(
"""
<project>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2021.0.0</version>
<type>bom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<groupId>com.mycompany.app</groupId>
<artifactId>sample</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
</dependencies>
</project>
""",
"""
<project>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2021.0.0</version>
<type>bom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<groupId>com.mycompany.app</groupId>
<artifactId>sample</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
<version>1.0.12</version>
</dependency>
</dependencies>
</project>
"""
)
);
}

@Test
void unmanagedToManaged() {
rewriteRun(
Expand Down Expand Up @@ -573,6 +638,71 @@ void unmanagedToManagedWithOverrideManagedVersionNull() {
);
}

@Test
void unmanagedToManagedExternalizedDepMgmt() {
rewriteRun(
spec -> spec.recipe(new ChangeDependencyGroupIdAndArtifactId(
"io.micrometer",
"micrometer-tracing-bridge-brave",
"org.springframework.cloud",
"spring-cloud-starter-sleuth",
"2021.0.0",
null
)),
pomXml(
"""
<project>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2021.0.0</version>
<type>bom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<groupId>com.mycompany.app</groupId>
<artifactId>sample</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
<version>1.0.12</version>
</dependency>
</dependencies>
</project>
""",
"""
<project>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2021.0.0</version>
<type>bom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<groupId>com.mycompany.app</groupId>
<artifactId>sample</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
</dependencies>
</project>
"""
)
);
}

@Test
void changeOnlyArtifactId() {
rewriteRun(
Expand Down

0 comments on commit 194c106

Please sign in to comment.