From fc2c4b4f3618c8464220cd33fb0dfe470bcc98a6 Mon Sep 17 00:00:00 2001 From: Sam Snyder Date: Sun, 28 Jul 2024 20:46:24 -0700 Subject: [PATCH] Make AddToTagVisitor more targeted in its formatting. Previously it would sometimes format tags that came before the tag being inserted. --- .../org/openrewrite/maven/tree/Scope.java | 3 + .../maven/ChangeDependencyClassifierTest.java | 212 +++++++++--------- .../org/openrewrite/xml/AddToTagVisitor.java | 8 +- 3 files changed, 112 insertions(+), 111 deletions(-) diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Scope.java b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Scope.java index fb50ce0259c..249a6b1f000 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Scope.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Scope.java @@ -24,6 +24,7 @@ public enum Scope { Runtime, Test, System, + Import, Invalid; /** @@ -110,6 +111,8 @@ public static Scope fromName(@Nullable String scope) { return Test; case "system": return System; + case "import": + return Import; default: return Invalid; } diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyClassifierTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyClassifierTest.java index 285b0c3acfb..be97c47383c 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyClassifierTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyClassifierTest.java @@ -40,7 +40,7 @@ void noClassifierToClassifier() { com.mycompany.app my-app 1 - + org.ehcache @@ -48,7 +48,7 @@ void noClassifierToClassifier() { 3.10.0 - + @@ -67,7 +67,7 @@ void noClassifierToClassifier() { com.mycompany.app my-app 1 - + org.ehcache @@ -76,7 +76,7 @@ void noClassifierToClassifier() { jakarta - + @@ -103,11 +103,11 @@ void noClassifierToClassifierManagedDependency() { """ 4.0.0 - + com.mycompany.app my-app 1 - + org.ehcache @@ -115,7 +115,7 @@ void noClassifierToClassifierManagedDependency() { 3.10.0 - + @@ -130,11 +130,11 @@ void noClassifierToClassifierManagedDependency() { """ 4.0.0 - + com.mycompany.app my-app 1 - + org.ehcache @@ -143,7 +143,7 @@ void noClassifierToClassifierManagedDependency() { jakarta - + @@ -170,11 +170,11 @@ void addClassifierUsingGlobsExpressions() { """ 4.0.0 - + com.mycompany.app my-app 1 - + org.ehcache @@ -187,7 +187,7 @@ void addClassifierUsingGlobsExpressions() { 3.10.0 - + @@ -207,11 +207,11 @@ void addClassifierUsingGlobsExpressions() { """ 4.0.0 - + com.mycompany.app my-app 1 - + org.ehcache @@ -226,7 +226,7 @@ void addClassifierUsingGlobsExpressions() { jakarta - + @@ -256,80 +256,80 @@ void addClassifierUsingGlobsExpressionsManagedDependency() { pomXml( """ - 4.0.0 - - com.mycompany.app - my-app - 1 - - - - org.ehcache - ehcache - 3.10.0 - - - org.ehcache - ehcache-transactions - 3.10.0 - - - - + 4.0.0 + + com.mycompany.app + my-app + 1 + - - org.ehcache - ehcache - 3.10.0 - - - org.ehcache - ehcache-transactions - 3.10.0 - + + org.ehcache + ehcache + 3.10.0 + + + org.ehcache + ehcache-transactions + 3.10.0 + - + + + + + org.ehcache + ehcache + 3.10.0 + + + org.ehcache + ehcache-transactions + 3.10.0 + + + """, """ - 4.0.0 - - com.mycompany.app - my-app - 1 - - - - org.ehcache - ehcache - 3.10.0 - jakarta - - - org.ehcache - ehcache-transactions - 3.10.0 - jakarta - - - - + 4.0.0 + + com.mycompany.app + my-app + 1 + - - org.ehcache - ehcache - 3.10.0 - jakarta - - - org.ehcache - ehcache-transactions - 3.10.0 - jakarta - + + org.ehcache + ehcache + 3.10.0 + jakarta + + + org.ehcache + ehcache-transactions + 3.10.0 + jakarta + - + + + + + org.ehcache + ehcache + 3.10.0 + jakarta + + + org.ehcache + ehcache-transactions + 3.10.0 + jakarta + + + """ ) @@ -343,11 +343,11 @@ void classifierToClassifier() { """ 4.0.0 - + com.mycompany.app my-app 1 - + org.ehcache @@ -356,7 +356,7 @@ void classifierToClassifier() { javax - + @@ -372,11 +372,11 @@ void classifierToClassifier() { """ 4.0.0 - + com.mycompany.app my-app 1 - + org.ehcache @@ -385,7 +385,7 @@ void classifierToClassifier() { jakarta - + @@ -412,11 +412,11 @@ void classifierToClassifierManagedDependency() { """ 4.0.0 - + com.mycompany.app my-app 1 - + org.ehcache @@ -425,7 +425,7 @@ void classifierToClassifierManagedDependency() { javax - + @@ -441,11 +441,11 @@ void classifierToClassifierManagedDependency() { """ 4.0.0 - + com.mycompany.app my-app 1 - + org.ehcache @@ -454,7 +454,7 @@ void classifierToClassifierManagedDependency() { jakarta - + @@ -479,11 +479,11 @@ void classifierToNoClassifier() { """ 4.0.0 - + com.mycompany.app my-app 1 - + org.ehcache @@ -492,7 +492,7 @@ void classifierToNoClassifier() { jakarta - + @@ -508,11 +508,11 @@ void classifierToNoClassifier() { """ 4.0.0 - + com.mycompany.app my-app 1 - + org.ehcache @@ -520,7 +520,7 @@ void classifierToNoClassifier() { 3.10.0 - + @@ -545,11 +545,11 @@ void classifierToNoClassifierManagedDependency() { """ 4.0.0 - + com.mycompany.app my-app 1 - + org.ehcache @@ -558,7 +558,7 @@ void classifierToNoClassifierManagedDependency() { jakarta - + @@ -574,11 +574,11 @@ void classifierToNoClassifierManagedDependency() { """ 4.0.0 - + com.mycompany.app my-app 1 - + org.ehcache @@ -586,7 +586,7 @@ void classifierToNoClassifierManagedDependency() { 3.10.0 - + diff --git a/rewrite-xml/src/main/java/org/openrewrite/xml/AddToTagVisitor.java b/rewrite-xml/src/main/java/org/openrewrite/xml/AddToTagVisitor.java index b7645ca09a0..e5e4c97c679 100755 --- a/rewrite-xml/src/main/java/org/openrewrite/xml/AddToTagVisitor.java +++ b/rewrite-xml/src/main/java/org/openrewrite/xml/AddToTagVisitor.java @@ -46,13 +46,11 @@ public AddToTagVisitor(Xml.Tag scope, Xml.Tag tagToAdd, @Nullable Comparator content = t.getContent() == null ? new ArrayList<>() : new ArrayList<>(t.getContent()); if (tagComparator != null) { @@ -82,7 +81,6 @@ public Xml visitTag(Xml.Tag t, P p) { } t = t.withContent(content); - t = autoFormat(t, formatParent ? null : formattedTagToAdd, p, getCursor().getParent()); } return super.visitTag(t, p);