Skip to content
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
Expand Up @@ -154,8 +154,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
@Override
public Xml visitDocument(Xml.Document document, ExecutionContext ctx) {
isNewDependencyPresent = checkIfNewDependencyPresents(newGroupId, newArtifactId, newVersion);
// Any managed dependency change is unlikely to use the same version, so only update selectively.
if ((changeManagedDependency == null || changeManagedDependency) && newVersion != null || versionPattern != null) {
if (changeManagedDependency == null || changeManagedDependency) {
doAfterVisit(new ChangeManagedDependencyGroupIdAndArtifactId(
oldGroupId, oldArtifactId,
Optional.ofNullable(newGroupId).orElse(oldGroupId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ void changeDependencyGroupIdAndArtifactId() {
"jakarta.activation",
"jakarta.activation-api",
null,
null
null,
false,
false
Comment on lines +40 to +41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What has me slightly worried is that we're changing these values here from what they were (implied false, true), to now explicitly setting the second to false to keep the test passing. That to me signals that we're changing the behavior in a way that might surprise folks using the explicit constructor, as we for instance do here:
https://github.com/openrewrite/rewrite-migrate-java/blob/05fa3e0a9e228a4d5568702e36ac62ee0d4cf889/src/main/java/org/openrewrite/java/migrate/javax/AddJaxbRuntime.java#L221-L224

Can you explain why this change in default is needed, and what changes we should be making downstream as a result?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I'm mostly trying to look out for is that we don't inadvertently start to see more changes that we hadn't anticipated or desired following this change; and that's hard to say with just a single test added and the defaults flipped on three more. Just trying to make sure we can move forward with this with confidence.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from what it looks like we're only sparsely using that recipe from Yaml; with no changes there expected (version was already used)
https://github.com/search?q=org%3Aopenrewrite+ChangeDependencyGroupIdAndArtifactId+language%3AYAML&type=code&l=YAML

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is the only downstream usage of the outdated constructor:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What has me slightly worried is that we're changing these values here from what they were (implied false, true), to now explicitly setting the second to false to keep the test passing.

Yes I can explain this. The tests that I changed do not take managed dependencies into account. Thus by setting these managed properties to explicit false, the behaviour stays the same. This is in line with the thing I mentioned in the starting post:

As the managed dependencies will now also be changed when no version is given, running recipes that use ChangeDependencyGroupIdAndArtifactId / ChangeDependency without a newVersion or versionPattern will behave a little differently, which could lead to a different outcome.

)),
pomXml(
"""
Expand Down Expand Up @@ -326,7 +328,9 @@ void shouldNotAddNewIfDependencyAlreadyExistsManaged() {
"jakarta.activation",
"jakarta.activation-api",
null,
null
null,
false,
false
)),
pomXml(
"""
Expand Down Expand Up @@ -466,7 +470,56 @@ void shouldNotAddNewIfDependencyAlreadyExistsManagedWithVersion() {
}

@Test
void changeManagedDependencyGroupIdAndArtifactId() {
void changeManagedDependencyArtifactId() {
rewriteRun(
spec -> spec.recipe(new ChangeDependencyGroupIdAndArtifactId(
"io.swagger.core.v3",
"swagger-annotations",
null,
"swagger-annotations-jakarta",
null,
null)),
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.1.10</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
""",
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations-jakarta</artifactId>
<version>2.1.10</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
"""
)
);
}

@Test
void changeManagedDependencyGroupIdAndArtifactIdAndVersion() {
rewriteRun(
spec -> spec.recipe(new ChangeDependencyGroupIdAndArtifactId(
"javax.activation",
Expand Down Expand Up @@ -1395,7 +1448,9 @@ void changeDependencyGroupIdAndArtifactIdWithDependencyManagementScopeTest() {
"io.quarkus",
"quarkus-arc",
null,
null
null,
false,
false
)),
pomXml(
"""
Expand Down