From 847804059e1b568026a155cb17f3e732ad2fe6be Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 13 Dec 2023 20:41:29 +0100 Subject: [PATCH] Fix SeparateApplicationYamlByProfile --- .../spring/SeparateApplicationYamlByProfile.java | 9 +++++---- .../SeparateApplicationYamlByProfileTest.java | 13 ++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/openrewrite/java/spring/SeparateApplicationYamlByProfile.java b/src/main/java/org/openrewrite/java/spring/SeparateApplicationYamlByProfile.java index e7c66a6dd..7b8184d11 100644 --- a/src/main/java/org/openrewrite/java/spring/SeparateApplicationYamlByProfile.java +++ b/src/main/java/org/openrewrite/java/spring/SeparateApplicationYamlByProfile.java @@ -48,8 +48,7 @@ public TreeVisitor getScanner(ApplicationProfiles acc) { return new YamlIsoVisitor() { @Override public Yaml.Documents visitDocuments(Yaml.Documents yaml, ExecutionContext ctx) { - if (PathUtils.matchesGlob(yaml.getSourcePath(), "application.yml")) { - + if (PathUtils.matchesGlob(yaml.getSourcePath(), "**/application.yml")) { Set profiles = new HashSet<>(yaml.getDocuments().size()); //noinspection unchecked @@ -65,7 +64,9 @@ public Yaml.Documents visitDocuments(Yaml.Documents yaml, ExecutionContext ctx) Yaml.Document profileDoc = (Yaml.Document) new DeleteProperty("spring.config.activate.on-profile", true, true) .getVisitor().visit(doc, ctx, new Cursor(null, yaml)); assert profileDoc != null; - profiles.add(yaml.withDocuments(Collections.singletonList(profileDoc.withExplicit(false))) + profiles.add(yaml + .withId(Tree.randomId()) + .withDocuments(Collections.singletonList(profileDoc.withExplicit(false))) .withSourcePath(yaml.getSourcePath().resolveSibling("application-" + profileName + ".yml"))); return null; } @@ -99,7 +100,7 @@ public Yaml.Documents visitDocuments(Yaml.Documents yaml, ExecutionContext ctx) } @Value - static class ApplicationProfiles { + public static class ApplicationProfiles { Map modifiedMainProfileFiles = new HashMap<>(); Set newProfileFiles = new HashSet<>(); } diff --git a/src/testWithSpringBoot_2_4/java/org/openrewrite/java/spring/SeparateApplicationYamlByProfileTest.java b/src/testWithSpringBoot_2_4/java/org/openrewrite/java/spring/SeparateApplicationYamlByProfileTest.java index 74b693ad8..925b735e8 100644 --- a/src/testWithSpringBoot_2_4/java/org/openrewrite/java/spring/SeparateApplicationYamlByProfileTest.java +++ b/src/testWithSpringBoot_2_4/java/org/openrewrite/java/spring/SeparateApplicationYamlByProfileTest.java @@ -15,7 +15,6 @@ */ package org.openrewrite.java.spring; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -23,9 +22,7 @@ import static org.openrewrite.java.Assertions.srcMainResources; import static org.openrewrite.yaml.Assertions.yaml; -@Disabled class SeparateApplicationYamlByProfileTest implements RewriteTest { - @Override public void defaults(RecipeSpec spec) { spec.recipe(new SeparateApplicationYamlByProfile()); @@ -46,13 +43,15 @@ void separateProfile() { on-profile: test name: test """, - "name: main", - spec -> spec.path("application.yaml") + """ + name: main + """, + spec -> spec.path("application.yml").noTrim() ), yaml( null, "name: test", - spec -> spec.path("application-test.yaml") + spec -> spec.path("application-test.yml") ) ) ); @@ -71,7 +70,7 @@ void leaveProfileExpressionsAlone() { on-profile: !test name: test """, - spec -> spec.path("application.yaml") + spec -> spec.path("application.yml") ) ) );