diff --git a/src/main/java/org/openrewrite/java/spring/SeparateApplicationPropertiesByProfile.java b/src/main/java/org/openrewrite/java/spring/SeparateApplicationPropertiesByProfile.java index 5cf31a637..96524c70b 100644 --- a/src/main/java/org/openrewrite/java/spring/SeparateApplicationPropertiesByProfile.java +++ b/src/main/java/org/openrewrite/java/spring/SeparateApplicationPropertiesByProfile.java @@ -17,8 +17,8 @@ import lombok.EqualsAndHashCode; import lombok.Value; -import org.openrewrite.*; import org.jspecify.annotations.Nullable; +import org.openrewrite.*; import org.openrewrite.properties.CreatePropertiesFile; import org.openrewrite.properties.PropertiesVisitor; import org.openrewrite.properties.tree.Properties; @@ -60,12 +60,12 @@ public TreeVisitor getScanner(Accumulator acc) { String sourcePath = PathUtils.separatorsToUnix(propertyFile.getSourcePath().toString()); String[] pathArray = sourcePath.split("/"); - if (sourcePath.matches("(?:.*/)?application.properties")) { + if (propertyFile.getSourcePath().endsWith("application.properties")) { acc.pathToApplicationProperties = getPathToApplicationProperties(pathArray); acc.propertyFileContent = getNewApplicationPropertyFileInfo(propertyFile.getContent()); } - if (sourcePath.matches("(?:.*/)?application-[^/]+\\.properties")) { + if (propertyFile.getSourcePath().getFileName().toString().matches("application-[^/]+\\.properties")) { acc.fileNameToFilePath.put(pathArray[pathArray.length - 1], sourcePath); } diff --git a/src/testWithSpringBoot_2_4/java/org/openrewrite/java/spring/SeparateApplicationPropertiesByProfileTest.java b/src/testWithSpringBoot_2_4/java/org/openrewrite/java/spring/SeparateApplicationPropertiesByProfileTest.java index ad170e5d6..abfff84e3 100644 --- a/src/testWithSpringBoot_2_4/java/org/openrewrite/java/spring/SeparateApplicationPropertiesByProfileTest.java +++ b/src/testWithSpringBoot_2_4/java/org/openrewrite/java/spring/SeparateApplicationPropertiesByProfileTest.java @@ -40,7 +40,6 @@ void noApplicationProperties() { base-url.PR-services=http://my.url.com exchange-token=1234567890 exchange-tokens=${base-url.PR-services}/exchange-token - """, sourceSpecs -> sourceSpecs.path("application-dev.properties")) ); @@ -58,7 +57,6 @@ void noSeparateProfile() { base-url.PR-services=http://my.url.com exchange-token=1234567890 exchange-tokens=${base-url.PR-services}/exchange-token - """, sourceSpecs -> sourceSpecs.path("application.properties")) );