diff --git a/spring-boot-upgrade-30/src/test/java/org/openrewrite/java/spring/boot3/ConfigRecipeTestHelper.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/config/ConfigRecipeTestHelper.java similarity index 98% rename from spring-boot-upgrade-30/src/test/java/org/openrewrite/java/spring/boot3/ConfigRecipeTestHelper.java rename to components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/config/ConfigRecipeTestHelper.java index e9a9c4e4f..6d0837508 100644 --- a/spring-boot-upgrade-30/src/test/java/org/openrewrite/java/spring/boot3/ConfigRecipeTestHelper.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/config/ConfigRecipeTestHelper.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.openrewrite.java.spring.boot3; +package org.springframework.sbm.boot.upgrade_27_30.config; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; diff --git a/spring-boot-upgrade-30/src/test/java/org/openrewrite/java/spring/boot3/RemovedPropertyTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/config/RemovedPropertyTest.java similarity index 97% rename from spring-boot-upgrade-30/src/test/java/org/openrewrite/java/spring/boot3/RemovedPropertyTest.java rename to components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/config/RemovedPropertyTest.java index efe340c3b..d61d23179 100644 --- a/spring-boot-upgrade-30/src/test/java/org/openrewrite/java/spring/boot3/RemovedPropertyTest.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/config/RemovedPropertyTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.openrewrite.java.spring.boot3; +package org.springframework.sbm.boot.upgrade_27_30.config; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.params.ParameterizedTest; diff --git a/spring-boot-upgrade-30/src/test/java/org/openrewrite/java/spring/boot3/UpdatePropertyTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/config/UpdatePropertyTest.java similarity index 97% rename from spring-boot-upgrade-30/src/test/java/org/openrewrite/java/spring/boot3/UpdatePropertyTest.java rename to components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/config/UpdatePropertyTest.java index 4341c5b42..7abc1fb25 100644 --- a/spring-boot-upgrade-30/src/test/java/org/openrewrite/java/spring/boot3/UpdatePropertyTest.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/config/UpdatePropertyTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.openrewrite.java.spring.boot3; +package org.springframework.sbm.boot.upgrade_27_30.config; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.params.ParameterizedTest; diff --git a/spring-boot-upgrade-30/src/test/resources/META-INF/rewrite/recipie.yml b/components/sbm-recipes-boot-upgrade/src/test/resources/META-INF/rewrite/recipie.yml similarity index 93% rename from spring-boot-upgrade-30/src/test/resources/META-INF/rewrite/recipie.yml rename to components/sbm-recipes-boot-upgrade/src/test/resources/META-INF/rewrite/recipie.yml index f8671b4fe..b61c2d8d2 100644 --- a/spring-boot-upgrade-30/src/test/resources/META-INF/rewrite/recipie.yml +++ b/components/sbm-recipes-boot-upgrade/src/test/resources/META-INF/rewrite/recipie.yml @@ -1,47 +1,4 @@ type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.java.spring.boot3.data.TEST -displayName: Upgrade to Spring Data 3.0 -description: 'Upgrade to Spring Data to 3.0 from any prior version.' -recipeList: - - org.openrewrite.java.AddMavenRepository: - id: repository.spring.milestone - url: https://repo.spring.io/milestone - repositoryName: repository.spring.milestone - - org.openrewrite.maven.UpgradeParentVersion: - groupId: org.springframework.boot - artifactId: spring-boot-starter-parent - newVersion: 3.0.0-M3 - ---- -type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.java.spring.boot3.data.TEST2 -displayName: Upgrade to Spring Data 3.0 -description: 'Upgrade to Spring Data to 3.0 from any prior version.' -recipeList: - - org.openrewrite.java.AddMavenRepository: - id: repository.spring.milestone - url: https://repo.spring.io/milestone - repositoryName: repository.spring.milestone ---- -type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.java.spring.boot3.data.java.constructorbinding -displayName: Upgrade to Spring Data 3.0 -description: 'Handles @ConstructorBinding' -recipeList: - - org.openrewrite.java.ConstructorBinding: - id: repository.spring.milestone - url: https://repo.spring.io/milestone - repositoryName: repository.spring.milestone ---- -type: specs.openrewrite.org/v1beta/recipe -name: org.openrewrite.java.spring.boot3.SAMLRelyingPartyPropertyYAMLMove -displayName: Move SAML relying party identity provider property to asserting party -description: 'Renames spring.security.saml2.relyingparty.registration.(any).identityprovider to spring.security.saml2.relyingparty.registration.(any).assertingparty' -recipeList: - - org.openrewrite.java.spring.boot3.SAMLRelyingPartyPropertyYAMLMove - ---- -type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.spring.boot3.SpringBootPropertiesManual_2_7 displayName: Upgrade to Spring Data 3.0 description: 'Rename properties' diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-activemq.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-activemq.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-activemq.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-activemq.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-artemis.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-artemis.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-artemis.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-artemis.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-graphql.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-graphql.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-graphql.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-graphql.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-jta.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-jta.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-jta.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-jta.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-management.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-management.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-management.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-management.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-misc.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-misc.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-misc.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-properties-misc.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-activemq.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-activemq.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-activemq.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-activemq.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-artemis.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-artemis.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-artemis.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-artemis.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-graphql.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-graphql.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-graphql.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-graphql.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-jta.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-jta.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-jta.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-jta.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-management.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-management.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-management.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-management.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-misc.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-misc.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-misc.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-delete/spring-3_0-config-remove-yaml-misc.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-update/spring-3_0-config-refactor-properties-data.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-update/spring-3_0-config-refactor-properties-data.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-update/spring-3_0-config-refactor-properties-data.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-update/spring-3_0-config-refactor-properties-data.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-update/spring-3_0-config-refactor-properties-datasource.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-update/spring-3_0-config-refactor-properties-datasource.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-update/spring-3_0-config-refactor-properties-datasource.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-update/spring-3_0-config-refactor-properties-datasource.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-update/spring-3_0-config-refactor-properties-elasticsearch.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-update/spring-3_0-config-refactor-properties-elasticsearch.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-update/spring-3_0-config-refactor-properties-elasticsearch.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-update/spring-3_0-config-refactor-properties-elasticsearch.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-update/spring-3_0-config-refactor-properties-misc.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-update/spring-3_0-config-refactor-properties-misc.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-update/spring-3_0-config-refactor-properties-misc.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-update/spring-3_0-config-refactor-properties-misc.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-update/spring-3_0-config-refactor-yaml-data.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-update/spring-3_0-config-refactor-yaml-data.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-update/spring-3_0-config-refactor-yaml-data.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-update/spring-3_0-config-refactor-yaml-data.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-update/spring-3_0-config-refactor-yaml-datasource.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-update/spring-3_0-config-refactor-yaml-datasource.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-update/spring-3_0-config-refactor-yaml-datasource.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-update/spring-3_0-config-refactor-yaml-datasource.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-update/spring-3_0-config-refactor-yaml-elasticsearch.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-update/spring-3_0-config-refactor-yaml-elasticsearch.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-update/spring-3_0-config-refactor-yaml-elasticsearch.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-update/spring-3_0-config-refactor-yaml-elasticsearch.txt diff --git a/spring-boot-upgrade-30/src/test/resources/props-to-update/spring-3_0-config-refactor-yaml-misc.txt b/components/sbm-recipes-boot-upgrade/src/test/resources/props-to-update/spring-3_0-config-refactor-yaml-misc.txt similarity index 100% rename from spring-boot-upgrade-30/src/test/resources/props-to-update/spring-3_0-config-refactor-yaml-misc.txt rename to components/sbm-recipes-boot-upgrade/src/test/resources/props-to-update/spring-3_0-config-refactor-yaml-misc.txt diff --git a/spring-boot-upgrade-30/pom.xml b/spring-boot-upgrade-30/pom.xml deleted file mode 100644 index 07f2a8df2..000000000 --- a/spring-boot-upgrade-30/pom.xml +++ /dev/null @@ -1,113 +0,0 @@ - - - - - 4.0.0 - - org.springframework.sbm - spring-boot-upgrades-30 - 0.1.0-SNAPSHOT - jar - - - 17 - 17 - 7.26.0 - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M7 - - - org.apache.maven.plugins - maven-compiler-plugin - - 15 - 15 - - - - - - - - org.openrewrite - rewrite-java - ${openrewrite.version} - - - org.openrewrite - rewrite-maven - ${openrewrite.version} - - - org.openrewrite - rewrite-java-17 - ${openrewrite.version} - - - org.openrewrite - rewrite-java-11 - ${openrewrite.version} - - - org.openrewrite - rewrite-yaml - ${openrewrite.version} - - - org.projectlombok - lombok - 1.18.24 - provided - - - org.openrewrite - rewrite-test - ${openrewrite.version} - test - - - - - - - rewrite-snapshots - rewrite-snapshots - https://oss.sonatype.org/content/repositories/snapshots/ - - - jcenter - jcenter - https://jcenter.bintray.com - - - mavencentral - mavencentral - https://repo.maven.apache.org/maven2 - - - - jitpack.io - https://jitpack.io - - - diff --git a/spring-boot-upgrade-30/src/main/java/org/openrewrite/java/AddMavenRepository.java b/spring-boot-upgrade-30/src/main/java/org/openrewrite/java/AddMavenRepository.java deleted file mode 100644 index d16a6ae73..000000000 --- a/spring-boot-upgrade-30/src/main/java/org/openrewrite/java/AddMavenRepository.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright 2021 - 2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.java; - -import lombok.Getter; -import lombok.Setter; -import org.jetbrains.annotations.NotNull; -import org.openrewrite.*; -import org.openrewrite.internal.lang.Nullable; -import org.openrewrite.marker.SearchResult; -import org.openrewrite.maven.MavenIsoVisitor; -import org.openrewrite.xml.AddToTagVisitor; -import org.openrewrite.xml.tree.Xml; - -import java.util.Optional; -import java.util.UUID; - -@Getter -public class AddMavenRepository extends Recipe { - - @Option( - displayName = "id", - description = "The first part of a dependency coordinate 'org.springframework.boot:spring-boot-parent:VERSION'.", - example = "org.springframework.boot" - ) - private String id; - @Option( - displayName = "repositoryName", - description = "The first part of a dependency coordinate 'org.springframework.boot:spring-boot-parent:VERSION'.", - example = "org.springframework.boot" - ) - private String url; - @Option( - displayName = "repositoryName", - description = "The first part of a dependency coordinate 'org.springframework.boot:spring-boot-parent:VERSION'.", - example = "org.springframework.boot" - ) - private String repositoryName; - - @Option( - displayName = "layout", - description = "The first part of a dependency coordinate 'org.springframework.boot:spring-boot-parent:VERSION'.", - example = "org.springframework.boot" - ) - @Nullable - private String layout; - - @Option( - displayName = "snapshotsEnabled", - description = "The first part of a dependency coordinate 'org.springframework.boot:spring-boot-parent:VERSION'.", - example = "org.springframework.boot" - ) - @Nullable - private Boolean snapshotsEnabled; - - @Option( - displayName = "repositoryName", - description = "The first part of a dependency coordinate 'org.springframework.boot:spring-boot-parent:VERSION'.", - example = "org.springframework.boot" - ) - @Nullable - private String snapshotsChecksumPolicy; - - @Option( - displayName = "repositoryName", - description = "The first part of a dependency coordinate 'org.springframework.boot:spring-boot-parent:VERSION'.", - example = "org.springframework.boot" - ) - @Nullable - private String snapShotsUpdatePolicy; - - @Option( - displayName = "repositoryName", - description = "The first part of a dependency coordinate 'org.springframework.boot:spring-boot-parent:VERSION'.", - example = "org.springframework.boot" - ) - @Nullable - private Boolean releasesEnabled; - - @Option( - displayName = "repositoryName", - description = "The first part of a dependency coordinate 'org.springframework.boot:spring-boot-parent:VERSION'.", - example = "org.springframework.boot" - ) - @Nullable - private String releasesChecksumPolicy; - - @Option( - displayName = "repositoryName", - description = "The first part of a dependency coordinate 'org.springframework.boot:spring-boot-parent:VERSION'.", - example = "org.springframework.boot" - ) - @Nullable - private String releasesUpdatePolicy; - - public String getDisplayName() { - return "Upgrade Maven parent project version"; - } - - public String getDescription() { - return "Set the parent pom version number according to a node-style semver selector or to a specific version number."; - } - - @Override - protected TreeVisitor getVisitor() { - return new AddRepositoryVisitor(); - } - - private class AddRepositoryVisitor extends MavenIsoVisitor { - private AddRepositoryVisitor() { - } - - @Override - public Xml.Document visitDocument(Xml.Document document, ExecutionContext ctx) { - Xml.Tag parent = document.getRoot(); - Optional repositoriesTag = parent.getChild("repositories"); - if (repositoriesTag.isEmpty()) { - addRepositoriesTag(parent); - } else if(noRepositoryWithSameIdExists(repositoriesTag.get())){ - addRepositoryTag(repositoriesTag.get()); - } - return super.visitDocument(document, ctx); - } - - private boolean noRepositoryWithSameIdExists(Xml.Tag t) { - return t.getChildren().stream().anyMatch(repo -> repo.getChildren().stream().anyMatch(c -> c.getName().equals("id") && - false == c.getValue().get().equals(getId()))); - } - - private Xml.Tag addRepositoriesTag(Xml.Tag parent) { - Xml.Tag repositoriesTag = Xml.Tag.build( - "\n" + - renderRepositoryTag() + - "\n"); - this.doAfterVisit(new AddToTagVisitor(parent, repositoriesTag)); - return repositoriesTag; - } - - private void addRepositoryTag(Xml.Tag parent) { - AddToTagVisitor visitor = new AddToTagVisitor(parent, Xml.Tag.build(renderRepositoryTag())); - this.doAfterVisit(visitor); - } - - private String renderRepositoryTag() { - StringBuilder sb = new StringBuilder(); - sb.append("\n"); - sb.append("" + getId() + "\n"); - if(AddMavenRepository.this.getRepositoryName() != null) { - sb.append("").append(AddMavenRepository.this.getRepositoryName()).append("\n"); - } - if(getUrl() != null) { - sb.append("").append(getUrl()).append("\n"); - } - if(getReleasesEnabled() != null && getReleasesEnabled() == true) { - String releaseSection = renderSection("releases", getReleasesChecksumPolicy(), getReleasesUpdatePolicy()); - sb.append(releaseSection); - } - if(getSnapshotsEnabled() != null && getSnapshotsEnabled() == true) { - String snapshotsSection = renderSection("snapshots", getSnapshotsChecksumPolicy(), getSnapShotsUpdatePolicy()); - sb.append(snapshotsSection); - } - sb.append("\n"); - return sb.toString(); - } - - @NotNull - private String renderSection(String type, String checksum, String update) { - StringBuilder sb = new StringBuilder(); - - sb.append("<").append(type).append(">\n"); - sb.append("true\n"); - if (checksum != null) { - sb.append("").append(checksum).append("\n"); - } - if (update != null) { - sb.append("").append(update).append("\n"); - } - sb.append("\n"); - return sb.toString(); - } - - } -} diff --git a/spring-boot-upgrade-30/src/main/java/org/openrewrite/java/spring/boot3/ChangePropertyKey.java b/spring-boot-upgrade-30/src/main/java/org/openrewrite/java/spring/boot3/ChangePropertyKey.java deleted file mode 100644 index 45b006bc7..000000000 --- a/spring-boot-upgrade-30/src/main/java/org/openrewrite/java/spring/boot3/ChangePropertyKey.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright 2021 - 2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.java.spring.boot3; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import org.openrewrite.*; -import org.openrewrite.internal.ListUtils; -import org.openrewrite.internal.NameCaseConvention; -import org.openrewrite.internal.StringUtils; -import org.openrewrite.internal.lang.Nullable; -import org.openrewrite.marker.Markers; -import org.openrewrite.yaml.YamlIsoVisitor; -import org.openrewrite.yaml.YamlVisitor; -import org.openrewrite.yaml.tree.Yaml; - -import java.util.*; -import java.util.stream.Collectors; - -import static java.util.Spliterators.spliteratorUnknownSize; -import static java.util.stream.StreamSupport.stream; -import static org.openrewrite.Tree.randomId; - -/** - * Nested YAML mappings are interpreted as dot - * separated property names, e.g. as Spring Boot - * interprets application.yml files. - */ -@Getter -@Setter -@EqualsAndHashCode(callSuper = true) -public class ChangePropertyKey extends Recipe { - - @Option(displayName = "Old property key", - description = "The property key to rename. Supports glob", - example = "management.metrics.binders.*.enabled") - String oldPropertyKey; - - @Option(displayName = "New property key", - description = "The new name for the property key.", - example = "management.metrics.enable.process.files") - String newPropertyKey; - - @Incubating(since = "7.17.0") - @Option(displayName = "Use relaxed binding", - description = "Whether to match the `oldPropertyKey` using [relaxed binding](https://docs.spring.io/spring-boot/docs/2.5.6/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding) " + - "rules. Default is `true`. Set to `false` to use exact matching.", - required = false) - @Nullable - Boolean relaxedBinding; - - @Incubating(since = "7.8.0") - @Option(displayName = "Optional file matcher", - description = "Matching files will be modified. This is a glob expression.", - required = false, - example = "**/application-*.yml") - @Nullable - String fileMatcher; - - @Override - public String getDisplayName() { - return "Change property key"; - } - - @Override - public String getDescription() { - return "Change a YAML property key leaving the value intact. Nested YAML mappings are " + - "interpreted as dot separated property names, i.e. as Spring Boot interprets " + - "application.yml files."; - } - - @Override - protected TreeVisitor getSingleSourceApplicableTest() { - if (fileMatcher != null) { - return new HasSourcePath<>(fileMatcher); - } - return null; - } - - @Override - public YamlVisitor getVisitor() { - return new ChangePropertyKeyVisitor<>(); - } - - private class ChangePropertyKeyVisitor

extends YamlIsoVisitor

{ - @Override - public Yaml.Mapping.Entry visitMappingEntry(Yaml.Mapping.Entry entry, P p) { - Yaml.Mapping.Entry e = super.visitMappingEntry(entry, p); - if (getCursor().firstEnclosing(Yaml.Sequence.class) != null) { - return e; - } - Deque propertyEntries = getCursor().getPathAsStream() - .filter(Yaml.Mapping.Entry.class::isInstance) - .map(Yaml.Mapping.Entry.class::cast) - .collect(Collectors.toCollection(ArrayDeque::new)); - - String prop = stream(spliteratorUnknownSize(propertyEntries.descendingIterator(), 0), false) - .map(e2 -> e2.getKey().getValue()) - .collect(Collectors.joining(".")); - - String propertyToTest = newPropertyKey; - if (!Boolean.FALSE.equals(relaxedBinding) ? - NameCaseConvention.matchesRelaxedBinding(prop, oldPropertyKey) : - StringUtils.matchesGlob(prop, oldPropertyKey)) { - Iterator propertyEntriesLeftToRight = propertyEntries.descendingIterator(); - while (propertyEntriesLeftToRight.hasNext()) { - Yaml.Mapping.Entry propertyEntry = propertyEntriesLeftToRight.next(); - String value = propertyEntry.getKey().getValue() + "."; - - if (!propertyToTest.startsWith(value ) || (propertyToTest.startsWith(value) && !propertyEntriesLeftToRight.hasNext())) { - doAfterVisit(new InsertSubpropertyVisitor<>( - propertyEntry, - propertyToTest, - entry - )); - break; - } - propertyToTest = propertyToTest.substring(value.length()); - } - } - - return e; - } - } - - private static class InsertSubpropertyVisitor

extends YamlIsoVisitor

{ - private final Yaml.Mapping.Entry scope; - private final String subproperty; - private final Yaml.Mapping.Entry entryToReplace; - - private InsertSubpropertyVisitor(Yaml.Mapping.Entry scope, String subproperty, Yaml.Mapping.Entry entryToReplace) { - this.scope = scope; - this.subproperty = subproperty; - this.entryToReplace = entryToReplace; - } - - @Override - public Yaml.Mapping visitMapping(Yaml.Mapping mapping, P p) { - Yaml.Mapping m = super.visitMapping(mapping, p); - if (m.getEntries().contains(scope)) { - String newEntryPrefix = scope.getPrefix(); - Yaml.Mapping.Entry newEntry = new Yaml.Mapping.Entry(randomId(), - newEntryPrefix, - Markers.EMPTY, - new Yaml.Scalar(randomId(), "", Markers.EMPTY, - Yaml.Scalar.Style.PLAIN, null, subproperty), - scope.getBeforeMappingValueIndicator(), - entryToReplace.getValue().copyPaste()); - - if (m.getEntries().contains(entryToReplace)) { - m = m.withEntries(ListUtils.map(m.getEntries(), e -> { - if (e.equals(entryToReplace)) { - return newEntry.withPrefix(e.getPrefix()); - } - return e; - })); - } else { - m = (Yaml.Mapping) new DeletePropertyVisitor<>(entryToReplace).visitNonNull(m, p); - m = maybeAutoFormat(m, m.withEntries(ListUtils.concat(m.getEntries(), newEntry)), p, getCursor().getParentOrThrow()); - } - } - - return m; - } - } - private static class DeletePropertyVisitor

extends YamlIsoVisitor

{ - private final Yaml.Mapping.Entry scope; - - private DeletePropertyVisitor(Yaml.Mapping.Entry scope) { - this.scope = scope; - } - - @Override - public Yaml.Mapping visitMapping(Yaml.Mapping mapping, P p) { - Yaml.Mapping m = super.visitMapping(mapping, p); - - boolean changed = false; - List entries = new ArrayList<>(); - for (Yaml.Mapping.Entry entry : m.getEntries()) { - if (entry == scope || (entry.getValue() instanceof Yaml.Mapping && ((Yaml.Mapping) entry.getValue()).getEntries().isEmpty())) { - changed = true; - } else { - entries.add(entry); - } - } - - if (entries.size() == 1) { - entries = ListUtils.map(entries, e -> e.withPrefix("")); - } - - if (changed) { - m = m.withEntries(entries); - - if (getCursor().getParentOrThrow().getValue() instanceof Yaml.Document) { - Yaml.Document document = getCursor().getParentOrThrow().getValue(); - if (!document.isExplicit()) { - m = m.withEntries(m.getEntries()); - } - } - } - return m; - } - } -} diff --git a/spring-boot-upgrade-30/src/test/java/org/openrewrite/java/spring/boot3/UpdateMicrometerPackageTest.java b/spring-boot-upgrade-30/src/test/java/org/openrewrite/java/spring/boot3/UpdateMicrometerPackageTest.java deleted file mode 100644 index fbbc4720d..000000000 --- a/spring-boot-upgrade-30/src/test/java/org/openrewrite/java/spring/boot3/UpdateMicrometerPackageTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2021 - 2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.java.spring.boot3; - -import org.junit.jupiter.api.Test; -import org.openrewrite.Result; -import org.openrewrite.java.JavaParser; -import org.openrewrite.java.tree.J; -import org.openrewrite.test.RewriteTest; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -public class UpdateMicrometerPackageTest { - - @Test - void shouldUpdatePackage() { - JavaParser javaParser = JavaParser.fromJavaVersion().build(); - String javaDependsOn = """ - package io.micrometer.core.instrument.binder; - public class Abc { - }""".stripIndent(); - String javaCode = """ - package a; - import io.micrometer.core.instrument.binder.*; - class A { - Abc method() { - return null; - } - }""".stripIndent(); - List parse = javaParser.parse(javaDependsOn, javaCode); - String recipeName = "org.openrewrite.java.spring.boot3.Micrometer_3_0"; - List results = RewriteTest.fromRuntimeClasspath(recipeName) - .run(parse); - assertThat(results).hasSize(2); - - assertThat(results.get(1).getAfter().printAll()).isEqualTo(""" - package a; - import io.micrometer.binder.*; - class A { - Abc method() { - return null; - } - }""".stripIndent()); - } -}