Skip to content

Commit

Permalink
Fix SeparateApplicationYamlByProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Dec 13, 2023
1 parent 67815f7 commit 8478040
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public TreeVisitor<?, ExecutionContext> getScanner(ApplicationProfiles acc) {
return new YamlIsoVisitor<ExecutionContext>() {
@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<Yaml.Documents> profiles = new HashSet<>(yaml.getDocuments().size());

//noinspection unchecked
Expand All @@ -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;
}
Expand Down Expand Up @@ -99,7 +100,7 @@ public Yaml.Documents visitDocuments(Yaml.Documents yaml, ExecutionContext ctx)
}

@Value
static class ApplicationProfiles {
public static class ApplicationProfiles {
Map<Path, Yaml.Documents> modifiedMainProfileFiles = new HashMap<>();
Set<SourceFile> newProfileFiles = new HashSet<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@
*/
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;

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());
Expand All @@ -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")
)
)
);
Expand All @@ -71,7 +70,7 @@ void leaveProfileExpressionsAlone() {
on-profile: !test
name: test
""",
spec -> spec.path("application.yaml")
spec -> spec.path("application.yml")
)
)
);
Expand Down

0 comments on commit 8478040

Please sign in to comment.