From 84343282ba818008f44bfd4d335f5e75ba52e502 Mon Sep 17 00:00:00 2001 From: Andrei Shakirin Date: Thu, 18 Aug 2022 18:17:59 +0200 Subject: [PATCH 01/23] Updated test container dependency --- applications/spring-shell/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/spring-shell/pom.xml b/applications/spring-shell/pom.xml index cc8911851..f6bae19cd 100644 --- a/applications/spring-shell/pom.xml +++ b/applications/spring-shell/pom.xml @@ -79,7 +79,7 @@ test - com.github.testcontainers.testcontainers-java + org.testcontainers testcontainers ${testcontainers.version} test diff --git a/pom.xml b/pom.xml index 66a3b9dc1..651080e8c 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ 1.9.1 2.7.2 0.9.3 - 9baedef17589ff70f7a585c809e0b1beb27eff62 + 1.17.3 3.2.0 3.1.4 1.18.24 From c6624e4371c28b89609255832556b12103fdf7fa Mon Sep 17 00:00:00 2001 From: Andrei Shakirin Date: Thu, 18 Aug 2022 19:18:42 +0200 Subject: [PATCH 02/23] Revert "Updated test container dependency" This reverts commit 84343282ba818008f44bfd4d335f5e75ba52e502. --- applications/spring-shell/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/spring-shell/pom.xml b/applications/spring-shell/pom.xml index f6bae19cd..cc8911851 100644 --- a/applications/spring-shell/pom.xml +++ b/applications/spring-shell/pom.xml @@ -79,7 +79,7 @@ test - org.testcontainers + com.github.testcontainers.testcontainers-java testcontainers ${testcontainers.version} test diff --git a/pom.xml b/pom.xml index 651080e8c..66a3b9dc1 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ 1.9.1 2.7.2 0.9.3 - 1.17.3 + 9baedef17589ff70f7a585c809e0b1beb27eff62 3.2.0 3.1.4 1.18.24 From 49e851cf1a8458092c4b77523cfe5194a9741b49 Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Mon, 22 Aug 2022 16:33:14 +0100 Subject: [PATCH 03/23] Multi Module example project --- .../README.md | 8 + .../boot-migration-27-30-multi-module/pom.xml | 48 ++++++ .../spring-app/pom.xml | 75 +++++++++ .../main/java/com/hello/GreetingConfig.java | 13 ++ .../example/ehcache/EventLogger.java | 11 ++ .../upgrade/BootUpgrade2730Application.java | 12 ++ .../upgrade/ConstructorBindingConfig.java | 14 ++ .../example/upgrade/RepositoryController.java | 19 +++ .../springboot/example/upgrade/Student.java | 11 ++ .../upgrade/StudentRepoPagingAndSorting.java | 6 + .../main/resources/META-INF/spring.factories | 1 + .../src/main/resources/application.properties | 121 ++++++++++++++ .../src/main/resources/application.yaml | 158 ++++++++++++++++++ 13 files changed, 497 insertions(+) create mode 100644 applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/README.md create mode 100644 applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/pom.xml create mode 100644 applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/pom.xml create mode 100644 applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/com/hello/GreetingConfig.java create mode 100644 applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/ehcache/EventLogger.java create mode 100644 applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/BootUpgrade2730Application.java create mode 100644 applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/ConstructorBindingConfig.java create mode 100644 applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/RepositoryController.java create mode 100644 applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/Student.java create mode 100644 applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/StudentRepoPagingAndSorting.java create mode 100644 applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/resources/META-INF/spring.factories create mode 100644 applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/resources/application.properties create mode 100644 applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/resources/application.yaml diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/README.md b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/README.md new file mode 100644 index 000000000..500c74c90 --- /dev/null +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/README.md @@ -0,0 +1,8 @@ +**Features used in the current project** + +* ehcache in pom is mentioned this helps validate our migration to spring 3 where ehcache classifier has to be used to resolve version. +* Uses Constructor binding on classes which will be removed when migrating to Spring 3 +* Uses PagingAndSortingRepo interface where CrudRepo has been removed. +* Uses properties that will be removed/moved on spring 3 migration +* Uses micrometer packages which are moved to a new structure. + diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/pom.xml b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/pom.xml new file mode 100644 index 000000000..b000ab18f --- /dev/null +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + pom + + spring-app + + + + org.springframework.boot + spring-boot-starter-parent + 2.7.1 + + com.example + boot-upgrade-27_30 + 0.0.1-SNAPSHOT + boot-upgrade-27_30 + boot-upgrade-27_30 + + 17 + + + + + + spring-snapshot + https://repo.spring.io/snapshot + + false + + + + spring-milestone + https://repo.spring.io/milestone + + false + + + + spring-release + https://repo.spring.io/release + + false + + + + diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/pom.xml b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/pom.xml new file mode 100644 index 000000000..17bbc4385 --- /dev/null +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/pom.xml @@ -0,0 +1,75 @@ + + + + + + boot-upgrade-27_30 + com.example + 0.0.1-SNAPSHOT + + 4.0.0 + + spring-app + + + 17 + 17 + + + + org.springframework.boot + spring-boot-starter-web + + + org.ehcache + ehcache + + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.h2database + h2 + runtime + + + io.projectreactor + reactor-core + + + org.apache.johnzon + johnzon-core + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/com/hello/GreetingConfig.java b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/com/hello/GreetingConfig.java new file mode 100644 index 000000000..67e5aeb24 --- /dev/null +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/com/hello/GreetingConfig.java @@ -0,0 +1,13 @@ +package com.hello; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class GreetingConfig { + + @Bean + public String hello() { + return "こんにちは"; + } +} diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/ehcache/EventLogger.java b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/ehcache/EventLogger.java new file mode 100644 index 000000000..883e58b7f --- /dev/null +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/ehcache/EventLogger.java @@ -0,0 +1,11 @@ +package org.springboot.example.ehcache; + +import org.ehcache.event.CacheEvent; +import org.ehcache.event.CacheEventListener; + +public class EventLogger implements CacheEventListener { + @Override + public void onEvent(CacheEvent cacheEvent) { + System.out.println("My ehcache event listener is called"); + } +} diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/BootUpgrade2730Application.java b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/BootUpgrade2730Application.java new file mode 100644 index 000000000..da6950db3 --- /dev/null +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/BootUpgrade2730Application.java @@ -0,0 +1,12 @@ +package org.springboot.example.upgrade; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class BootUpgrade2730Application { + + public static void main(String[] args) { + SpringApplication.run(BootUpgrade2730Application.class, args); + } +} diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/ConstructorBindingConfig.java b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/ConstructorBindingConfig.java new file mode 100644 index 000000000..d4a485b9a --- /dev/null +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/ConstructorBindingConfig.java @@ -0,0 +1,14 @@ +package org.springboot.example.upgrade; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.ConstructorBinding; + +@ConfigurationProperties(prefix = "mail") +@ConstructorBinding +public class ConstructorBindingConfig { + private String hostName; + + public ConstructorBindingConfig(String hostName) { + this.hostName = hostName; + } +} diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/RepositoryController.java b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/RepositoryController.java new file mode 100644 index 000000000..453de6e3a --- /dev/null +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/RepositoryController.java @@ -0,0 +1,19 @@ +package org.springboot.example.upgrade; + +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class RepositoryController { + private final StudentRepoPagingAndSorting studentRepoPagingAndSorting; + + public RepositoryController( + StudentRepoPagingAndSorting studentRepoPagingAndSorting) { + this.studentRepoPagingAndSorting = studentRepoPagingAndSorting; + } + + public void actWithRepositories() { + studentRepoPagingAndSorting.save(new Student()); + } +} diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/Student.java b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/Student.java new file mode 100644 index 000000000..ff60b3718 --- /dev/null +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/Student.java @@ -0,0 +1,11 @@ +package org.springboot.example.upgrade; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class Student { + @Id + private long id; + private String name; +} diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/StudentRepoPagingAndSorting.java b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/StudentRepoPagingAndSorting.java new file mode 100644 index 000000000..9db835330 --- /dev/null +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/java/org/springboot/example/upgrade/StudentRepoPagingAndSorting.java @@ -0,0 +1,6 @@ +package org.springboot.example.upgrade; + +import org.springframework.data.repository.PagingAndSortingRepository; + +public interface StudentRepoPagingAndSorting extends PagingAndSortingRepository { +} diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/resources/META-INF/spring.factories b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..f8533d053 --- /dev/null +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.hello.GreetingConfig diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/resources/application.properties b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/resources/application.properties new file mode 100644 index 000000000..ca4a5204b --- /dev/null +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/resources/application.properties @@ -0,0 +1,121 @@ +management.endpoint.jolokia.config="abc" +management.endpoint.jolokia.enabled=true +management.metrics.graphql.autotime.percentiles=100 +management.metrics.graphql.autotime.percentiles-histogram=20 + +spring.activemq.broker-url=http://google.com +spring.activemq.close-timeout=13 +spring.activemq.in-memory=true +spring.activemq.non-blocking-redelivery=true +spring.activemq.password=password +spring.activemq.send-timeout=11 +spring.activemq.user=user +spring.activemq.packages.trust-all=true +spring.activemq.packages.trusted=true +spring.activemq.pool.block-if-full=true +spring.activemq.pool.block-if-full-timeout=true +spring.activemq.pool.enabled=true +spring.activemq.pool.idle-timeout=12 +spring.activemq.pool.max-connections=200 +spring.activemq.pool.max-sessions-per-connection=300 +spring.activemq.pool.time-between-expiration-check=22 +spring.activemq.pool.use-anonymous-producers=true + +spring.artemis.pool.block-if-full=true +spring.artemis.pool.block-if-full-timeout=true +spring.artemis.pool.enabled=true +spring.artemis.pool.idle-timeout=1 +spring.artemis.pool.max-connections=100 +spring.artemis.pool.max-sessions-per-connection=10 +spring.artemis.pool.time-between-expiration-check=10 +spring.artemis.pool.use-anonymous-producers=true + +spring.cache.infinispan.config="config2" +spring.cache.ehcache.config="config1" + +spring.config.use-legacy-processing=false + +spring.data.elasticsearch.client.reactive.connection-timeout=1000 +spring.data.elasticsearch.client.reactive.max-in-memory-size=122 +spring.data.elasticsearch.client.reactive.password=abc +spring.data.elasticsearch.client.reactive.socket-timeout=100 +spring.data.elasticsearch.client.reactive.username=testUser +spring.data.elasticsearch.client.reactive.use-ssl=false + +spring.datasource.data=testdata +spring.datasource.data-password=password +spring.datasource.data-username=username +spring.datasource.initialization-mode=mode1 +spring.datasource.platform=pls +spring.datasource.schema=table1 +spring.datasource.schema-password=password2 +spring.datasource.schema-username=username2 +spring.datasource.separator=k +spring.datasource.sql-script-encoding=UTF-8 + +spring.elasticsearch.rest.connection-timeout=1 +spring.elasticsearch.rest.password=testpassword +spring.elasticsearch.rest.read-timeout=2 +spring.elasticsearch.rest.sniffer.delay-after-failure=3 +spring.elasticsearch.rest.sniffer.interval=4 +spring.elasticsearch.rest.username=username + +spring.graphql.websocket.path=/path +spring.graphql.websocket.connection-init-timeout=2 +spring.graphql.schema.printer.enabled=false +spring.graphql.schema.locations=abc +spring.graphql.schema.introspection.enabled=true +spring.graphql.schema.file-extensions=.txt +spring.graphql.path=null +spring.graphql.graphiql.path=/path2 +spring.graphql.graphiql.enabled=false +spring.graphql.cors.max-age=22 +spring.graphql.cors.exposed-headers=fd +spring.graphql.cors.allowed-origins=* +spring.graphql.cors.allowed-origin-patterns=* +spring.graphql.cors.allowed-methods=POST +spring.graphql.cors.allowed-headers=hello +spring.graphql.cors.allow-credentials=true + +spring.h2.console.enabled=true +spring.h2.console.path=/tmp +spring.h2.console.settings.trace=true +spring.h2.console.settings.web-admin-password=password +spring.h2.console.settings.web-allow-others=true + +spring.jersey.type=type1 +spring.jersey.init=true +spring.jersey.servlet.load-on-startup=true +spring.jersey.application-path="/path" +spring.jersey.filter.order="desc" + +spring.jta.transaction-manager-id=1 +spring.jta.log-dir=/tmp +spring.jta.atomikos.properties.transaction-manager-unique-name=name1 +spring.jta.atomikos.properties.serial-jta-transactions=transaction +spring.jta.atomikos.properties.recovery.retry-interval=2 +spring.jta.atomikos.properties.recovery.max-retries=3 +spring.jta.atomikos.properties.recovery.forget-orphaned-log-entries-delay=4 +spring.jta.atomikos.properties.recovery.delay=5 +spring.jta.atomikos.properties.max-timeout=6 +spring.jta.atomikos.properties.max-actives=7 +spring.jta.atomikos.properties.log-base-name=/tmp1 +spring.jta.atomikos.properties.log-base-dir=/tmp2 +spring.jta.atomikos.properties.force-shutdown-on-vm-exit=true +spring.jta.atomikos.properties.enable-logging=false +spring.jta.atomikos.properties.default-max-wait-time-on-shutdown=8 +spring.jta.atomikos.properties.default-jta-timeout=9 +spring.jta.atomikos.properties.checkpoint-interval=10 +spring.jta.atomikos.properties.allow-sub-transactions=true + +spring.security.saml2.relyingparty.registration.idpone.identityprovider.entity-id=https://idpone.com +spring.security.saml2.relyingparty.registration.idpone.identityprovider.sso-url=https://idpone.com +spring.security.saml2.relyingparty.registration.idpone.identityprovider.verification.credentials.certificate-location=classpath:saml/idpone.crt + +spring.webflux.session.cookie.same-site=true + +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password=password +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect diff --git a/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/resources/application.yaml b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/resources/application.yaml new file mode 100644 index 000000000..b3bda7b38 --- /dev/null +++ b/applications/spring-shell/src/test/resources/testcode/boot-migration-27-30-multi-module/spring-app/src/main/resources/application.yaml @@ -0,0 +1,158 @@ +spring: + datasource: + data: testdata + url: jdbc:h2:mem:testdb + data-username: sa + schema-username: sa + schema-password: password + driverClassName: org.h2.Driver + schema: table1 + initialization-mode: mode1 + data-password: password + sql-script-encoding: UTF-8 + platform: pls + separator: k + jpa: + database-platform: org.hibernate.dialect.H2Dialect + activemq: + pool: + max-sessions-per-connection: '300' + use-anonymous-producers: 'true' + block-if-full: 'true' + block-if-full-timeout: 'true' + time-between-expiration-check: '22' + idle-timeout: '12' + enabled: 'true' + max-connections: '200' + user: user + packages: + trust-all: 'true' + trusted: 'true' + send-timeout: '11' + password: password + broker-url: http://google.com + close-timeout: '13' + non-blocking-redelivery: 'true' + in-memory: 'true' + artemis: + pool: + idle-timeout: '1' + use-anonymous-producers: 'true' + block-if-full-timeout: 'true' + time-between-expiration-check: '10' + max-sessions-per-connection: '10' + max-connections: '100' + enabled: 'true' + block-if-full: 'true' + jta: + atomikos: + properties: + checkpoint-interval: '10' + recovery: + retry-interval: '2' + delay: '5' + max-retries: '3' + forget-orphaned-log-entries-delay: '4' + serial-jta-transactions: transaction + default-max-wait-time-on-shutdown: '8' + max-timeout: '6' + default-jta-timeout: '9' + max-actives: '7' + allow-sub-transactions: 'true' + log-base-name: /tmp1 + transaction-manager-unique-name: name1 + force-shutdown-on-vm-exit: 'true' + enable-logging: 'false' + log-base-dir: /tmp2 + transaction-manager-id: '1' + log-dir: /tmp + elasticsearch: + rest: + username: username + read-timeout: '2' + connection-timeout: '1' + sniffer: + interval: '4' + delay-after-failure: '3' + password: testpassword + data: + elasticsearch: + client: + reactive: + connection-timeout: '1000' + password: abc + use-ssl: 'false' + socket-timeout: '100' + max-in-memory-size: '122' + username: testUser + h2: + console: + path: "/tmp" + settings: + web-admin-password: "password" + web-allow-others: 'true' + trace: 'true' + enabled: 'true' + graphql: + schema: + file-extensions: .txt + introspection: + enabled: 'true' + locations: abc + printer: + enabled: 'false' + cors: + allowed-origins: '*' + allowed-headers: hello + allow-credentials: 'true' + allowed-origin-patterns: '*' + allowed-methods: POST + exposed-headers: fd + max-age: '22' + path: 'null' + graphiql: + enabled: 'false' + path: /path2 + websocket: + path: /path + connection-init-timeout: '2' + jersey: + servlet: + load-on-startup: 'true' + application-path: '"/path"' + filter: + order: '"desc"' + init: 'true' + type: type1 + config: + use-legacy-processing: 'false' + security: + saml2: + relyingparty: + registration: + idpone: + identityprovider: + verification: + credentials: + certificate-location: classpath:saml/idpone.crt + entity-id: https://idpone.com + sso-url: https://idpone.com + webflux: + session: + cookie: + same-site: 'true' + cache: + infinispan: + config: '"config2"' + ehcache: + config: '"config1"' +management: + metrics: + graphql: + autotime: + percentiles: '100' + percentiles-histogram: '20' + endpoint: + jolokia: + enabled: 'true' + config: '"abc"' From 0c6484380b1ed229429c15cdd69e1443b45642cb Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Mon, 22 Aug 2022 16:36:37 +0100 Subject: [PATCH 04/23] Itegration test scaffolding --- .../BootUpgrade_27_30_IntegrationTest.java | 1 + ...ade_27_30_MultiModule_IntegrationTest.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java diff --git a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_IntegrationTest.java b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_IntegrationTest.java index 2e8daaecc..a04d070b4 100644 --- a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_IntegrationTest.java +++ b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_IntegrationTest.java @@ -57,6 +57,7 @@ void migrateSimpleApplication() { verifyEhCacheVersionIsUpgraded(); verifyJohnzonCoreDependencyIsUpgraded(); } + private void buildProject() { executeMavenGoals(getTestDir(), "clean", "verify"); } diff --git a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java new file mode 100644 index 000000000..0c8321de3 --- /dev/null +++ b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java @@ -0,0 +1,37 @@ +/* + * 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.springframework.sbm; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +public class BootUpgrade_27_30_MultiModule_IntegrationTest extends IntegrationTestBaseClass { + @Override + protected String getTestSubDir() { + return "boot-migration-27-30"; + } + + @Test + @Tag("integration") + void migrateSimpleApplication() { + intializeTestProject(); + + scanProject(); + + applyRecipe("boot-2.7-3.0-dependency-version-update"); + } +} From 030bfd7c4a07e3a3bf289001711e74a75f7fe09c Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Mon, 22 Aug 2022 16:44:56 +0100 Subject: [PATCH 05/23] Itegration test scaffolding --- .../sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java index 0c8321de3..b16c2c137 100644 --- a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java +++ b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java @@ -22,7 +22,7 @@ public class BootUpgrade_27_30_MultiModule_IntegrationTest extends IntegrationTestBaseClass { @Override protected String getTestSubDir() { - return "boot-migration-27-30"; + return "boot-migration-27-30-multi-module"; } @Test From 427534e4b6d2f2561ecf693a2b2914d8e204bd8e Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Tue, 23 Aug 2022 15:51:53 +0100 Subject: [PATCH 06/23] wip --- .../CreateAutoconfigurationActionTest.java | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java index 91deb4e6d..cc728ed8c 100644 --- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java @@ -102,6 +102,91 @@ public void shouldMoveMultipleProperties() { ); } + @Test + public void multiMavenModule() { + + TestProjectContext. + buildProjectContext() + .addProjectResource("pom.xml", + """ + + + 4.0.0 + pom + + spring-app + + + + org.springframework.boot + spring-boot-starter-parent + 2.7.1 + + com.example + boot-upgrade-27_30 + 0.0.1-SNAPSHOT + boot-upgrade-27_30 + boot-upgrade-27_30 + + 17 + + + + + + spring-snapshot + https://repo.spring.io/snapshot + + false + + + + spring-milestone + https://repo.spring.io/milestone + + false + + + + spring-release + https://repo.spring.io/release + + false + + + + + """) + .addProjectResource( + "spring-app/src/main/java/com/hello", """ + package com.hello; + + import org.springframework.context.annotation.Bean; + import org.springframework.context.annotation.Configuration; + + @Configuration + public class GreetingConfig { + + @Bean + public String hello() { + return "こんにちは"; + } + } + + """); + ; + context = TestProjectContext.buildProjectContext() + .addProjectResource( + "src/main/resources/META-INF/spring.factories", + """ + hello.world=something + org.springframework.boot.autoconfigure.EnableAutoConfiguration=XYZ + """ + ) + .build(); + } + private String getNewAutoConfigFile() { return getFileAsProjectResource( "/**/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports" From 3e90e615232b843a626d785956b89452209eb02d Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Wed, 24 Aug 2022 13:55:30 +0100 Subject: [PATCH 07/23] CreateAutoconfigurationAction is multimodule aware --- .../migration/actions/AddMinimalPomXml.java | 6 - .../sbm/engine/recipe/RecipeUtil.java | 64 +++++++++ .../project/resource/ProjectResourceSet.java | 2 +- .../sbm/engine/recipe/RecipeUtilTest.java | 126 ++++++++++++++++++ .../CreateAutoconfigurationAction.java | 35 +++-- .../CreateAutoconfigurationActionTest.java | 83 +++++++++--- 6 files changed, 281 insertions(+), 35 deletions(-) create mode 100644 components/sbm-core/src/main/java/org/springframework/sbm/engine/recipe/RecipeUtil.java create mode 100644 components/sbm-core/src/test/java/org/springframework/sbm/engine/recipe/RecipeUtilTest.java diff --git a/components/sbm-core/src/main/java/org/springframework/sbm/build/migration/actions/AddMinimalPomXml.java b/components/sbm-core/src/main/java/org/springframework/sbm/build/migration/actions/AddMinimalPomXml.java index 089dbfece..5589ef33e 100644 --- a/components/sbm-core/src/main/java/org/springframework/sbm/build/migration/actions/AddMinimalPomXml.java +++ b/components/sbm-core/src/main/java/org/springframework/sbm/build/migration/actions/AddMinimalPomXml.java @@ -44,11 +44,6 @@ public class AddMinimalPomXml extends AbstractAction { @Setter private Configuration configuration; - @Autowired - @JsonIgnore - @Setter - private JavaParser javaParser; - @Override public void apply(ProjectContext context) { String projectDir = context.getProjectRootDirectory().toString(); @@ -70,7 +65,6 @@ public void apply(ProjectContext context) { RewriteMavenParser rewriteMavenParser = new RewriteMavenParser(); Parser.Input input = new Parser.Input(Path.of("pom.xml"), () -> new ByteArrayInputStream(src.getBytes(StandardCharsets.UTF_8))); Xml.Document maven = rewriteMavenParser.parseInputs(List.of(input), null, new RewriteExecutionContext(getEventPublisher())).get(0); -// Maven document = (Maven) maven.withSourcePath(Path.of("pom.xml")); OpenRewriteMavenBuildFile rewriteMavenBuildFile = new OpenRewriteMavenBuildFile(context.getProjectRootDirectory(), maven, getEventPublisher(), new RewriteExecutionContext(getEventPublisher())); context.getProjectResources().add(rewriteMavenBuildFile); } diff --git a/components/sbm-core/src/main/java/org/springframework/sbm/engine/recipe/RecipeUtil.java b/components/sbm-core/src/main/java/org/springframework/sbm/engine/recipe/RecipeUtil.java new file mode 100644 index 000000000..038f017f7 --- /dev/null +++ b/components/sbm-core/src/main/java/org/springframework/sbm/engine/recipe/RecipeUtil.java @@ -0,0 +1,64 @@ +/* + * 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.springframework.sbm.engine.recipe; + +import org.springframework.sbm.project.resource.ProjectResourceSet; +import org.springframework.sbm.project.resource.RewriteSourceFileHolder; + +import java.nio.file.Path; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +public class RecipeUtil { + + public Path getEnclosingMavenProjectForResource(ProjectResourceSet projectResources, Path absolutePath) { + + List listOfPom = projectResources + .stream() + .map(RewriteSourceFileHolder::getAbsolutePath) + .map(Path::toString) + .filter(k -> k.contains("pom.xml")) + .toList(); + + + Set binarySearchTree = new HashSet<>(); + + listOfPom.forEach(k -> { + String path = k.substring(0, k.length() - "pom.xml".length()); + binarySearchTree.add(path); + }); + + String interestedFile = absolutePath.toAbsolutePath().toString(); + + for (int i = interestedFile.length() - 1; i >= 0; i--) { + + if (interestedFile.charAt(i) != '/') continue; + + String subPath = interestedFile.substring(0, i + 1); + + if (binarySearchTree.contains(subPath)) { + return Path.of(subPath); + } + } + + throw new IllegalStateException("Cannot find enclosing maven project for file: " + + absolutePath + " could be caused by erroneously calling this function or running a recipe on an " + + "empty project"); + } +} diff --git a/components/sbm-core/src/main/java/org/springframework/sbm/project/resource/ProjectResourceSet.java b/components/sbm-core/src/main/java/org/springframework/sbm/project/resource/ProjectResourceSet.java index eee851d85..9ea09ea73 100644 --- a/components/sbm-core/src/main/java/org/springframework/sbm/project/resource/ProjectResourceSet.java +++ b/components/sbm-core/src/main/java/org/springframework/sbm/project/resource/ProjectResourceSet.java @@ -37,7 +37,7 @@ public ProjectResourceSet() { } public List> list() { - return stream().collect(Collectors.toUnmodifiableList()); + return stream().toList(); } public Stream> stream() { diff --git a/components/sbm-core/src/test/java/org/springframework/sbm/engine/recipe/RecipeUtilTest.java b/components/sbm-core/src/test/java/org/springframework/sbm/engine/recipe/RecipeUtilTest.java new file mode 100644 index 000000000..6473d6494 --- /dev/null +++ b/components/sbm-core/src/test/java/org/springframework/sbm/engine/recipe/RecipeUtilTest.java @@ -0,0 +1,126 @@ +/* + * 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.springframework.sbm.engine.recipe; + +import org.junit.jupiter.api.Test; +import org.openrewrite.SourceFile; +import org.springframework.sbm.project.resource.ProjectResourceSet; +import org.springframework.sbm.project.resource.RewriteSourceFileHolder; + +import java.nio.file.Path; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class RecipeUtilTest { + + private final RecipeUtil target = new RecipeUtil(); + + @Test + public void getsEnclosingMavenProject() { + ProjectResourceSet projectResourceSet = new ProjectResourceSet( + List.of( + file("pom.xml"), + file("spring-app/pom.xml"), + file("spring-app/src/main/Hello.java") + ) + ); + + Path result = target.getEnclosingMavenProjectForResource(projectResourceSet, + file("spring-app/src/main/Hello.java").getAbsolutePath()); + + assertThat(result.toAbsolutePath().toString()).isEqualTo("/tmp/spring-app"); + } + + @Test + public void whenItsNotAMultiModuleMavenFile() { + + ProjectResourceSet projectResourceSet = new ProjectResourceSet( + List.of( + file("pom.xml"), + file("src/main/Hello.java") + ) + ); + + + Path result = target.getEnclosingMavenProjectForResource(projectResourceSet, + file("src/main/Hello.java").getAbsolutePath()); + assertThat(result.toAbsolutePath().toString()).isEqualTo("/tmp"); + + } + + @Test + public void nestedMultiModuleFiles() { + + ProjectResourceSet projectResourceSet = new ProjectResourceSet( + List.of( + file("pom.xml"), + file("spring-app-multi/pom.xml"), + file("spring-app-multi/spring-1/src/main/Hello.java"), + file("spring-app-multi/spring-1/pom.xml"), + file("spring-app-multi/spring-2/src/main/Hello.java"), + file("spring-app-multi/spring-2/pom.xml") + ) + ); + + + Path result = target.getEnclosingMavenProjectForResource(projectResourceSet, + file("spring-app-multi/spring-2/src/main/Hello.java").getAbsolutePath()); + assertThat(result.toAbsolutePath().toString()).isEqualTo("/tmp/spring-app-multi/spring-2"); + + } + + @Test + public void multiModuleOnRootLevel() { + ProjectResourceSet projectResourceSet = new ProjectResourceSet( + List.of( + file("pom.xml"), + file("spring-app/pom.xml"), + file("spring-app/src/main/Hello.java"), + file("spring-app-2/pom.xml"), + file("spring-app-2/src/main/Hello.java") + ) + ); + + Path result = target.getEnclosingMavenProjectForResource(projectResourceSet, + file("spring-app-2/src/main/Hello.java").getAbsolutePath()); + + assertThat(result.toAbsolutePath().toString()).isEqualTo("/tmp/spring-app-2"); + } + + @Test + public void throwsErrorWhenNoResourceIsFound() { + + ProjectResourceSet projectResourceSet = new ProjectResourceSet(List.of()); + + assertThrows(IllegalStateException.class, () -> target.getEnclosingMavenProjectForResource(projectResourceSet, + file("hello/world/A.java").getAbsolutePath() + )); + } + + private RewriteSourceFileHolder file(String path) { + + + RewriteSourceFileHolder mockedRewriteSourceFileHolder = mock(RewriteSourceFileHolder.class); + when(mockedRewriteSourceFileHolder.getAbsolutePath()).thenReturn(Path.of("/tmp/" + path)); + + return mockedRewriteSourceFileHolder; + } +} diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java index e429b6b8a..78cf53e12 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java @@ -15,15 +15,19 @@ */ package org.springframework.sbm.boot.upgrade.common.actions; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; import org.springframework.sbm.common.filter.PathPatternMatchingProjectResourceFinder; import org.springframework.sbm.engine.context.ProjectContext; import org.springframework.sbm.engine.recipe.AbstractAction; +import org.springframework.sbm.engine.recipe.RecipeUtil; import org.springframework.sbm.project.resource.ProjectResource; import org.springframework.sbm.project.resource.StringProjectResource; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.StringWriter; +import java.nio.file.Path; import java.util.List; import java.util.Optional; import java.util.Properties; @@ -32,19 +36,21 @@ public class CreateAutoconfigurationAction extends AbstractAction { private static final String SPRING_FACTORIES_PATH = "/**/src/main/resources/META-INF/spring.factories"; - private static final String SPRING_FACTORIES_FILE = "src/main/resources/META-INF/spring.factories"; private static final String AUTO_CONFIGURATION_IMPORTS = "src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports"; public static final String ENABLE_AUTO_CONFIGURATION_KEY = "org.springframework.boot.autoconfigure.EnableAutoConfiguration"; public static final Pattern COMMENT_REGEX = Pattern.compile("^#.*(\r|\n)+"); + private final RecipeUtil recipeUtil = new RecipeUtil(); + @Override public void apply(ProjectContext context) { - Optional props = getSpringFactoriesProperties(context); + Optional> props = getSpringFactoriesProperties(context); + if (props.isEmpty()) { return; } - Optional springAutoConfigProperties = getEnableAutoConfigFromSpringFactories(props.get()); + Optional springAutoConfigProperties = getEnableAutoConfigFromSpringFactories(props.get().getLeft()); if (springAutoConfigProperties.isPresent()) { @@ -52,19 +58,24 @@ public void apply(ProjectContext context) { .get() .replaceAll(",", "\\\n"); + + Path enclosingMavenProjectForResource = recipeUtil.getEnclosingMavenProjectForResource(context.getProjectResources(), props.get().getRight().getAbsolutePath()); StringProjectResource springAutoconfigurationFile = new StringProjectResource( - context.getProjectRootDirectory(), - context.getProjectRootDirectory().resolve(AUTO_CONFIGURATION_IMPORTS), + enclosingMavenProjectForResource, + enclosingMavenProjectForResource.resolve(AUTO_CONFIGURATION_IMPORTS), autoConfigString ); context.getProjectResources().add(springAutoconfigurationFile); - removeAutoConfigKeyFromSpringFactories(props.get(), context); + removeAutoConfigKeyFromSpringFactories(props.get().getLeft(), context,enclosingMavenProjectForResource, props.get().getRight()); } } - private void removeAutoConfigKeyFromSpringFactories(Properties props, ProjectContext context) { + private void removeAutoConfigKeyFromSpringFactories(Properties props, + ProjectContext context, + Path projectRootDirectory, + ProjectResource originalResource) { try { props.remove(ENABLE_AUTO_CONFIGURATION_KEY); StringWriter stringWriter = new StringWriter(); @@ -73,12 +84,12 @@ private void removeAutoConfigKeyFromSpringFactories(Properties props, ProjectCon StringProjectResource springUpdatedSpringFactories = new StringProjectResource( - context.getProjectRootDirectory(), - context.getProjectRootDirectory().resolve(SPRING_FACTORIES_FILE), + projectRootDirectory, + originalResource.getAbsolutePath(), propertiesWithoutComment ); context.getProjectResources().replace( - context.getProjectRootDirectory().resolve(SPRING_FACTORIES_FILE), + originalResource.getAbsolutePath(), springUpdatedSpringFactories); } catch (IOException e) { throw new RuntimeException("Error whilst reading property file", e); @@ -90,7 +101,7 @@ private Optional getEnableAutoConfigFromSpringFactories(Properties props return Optional.ofNullable(content); } - private Optional getSpringFactoriesProperties(ProjectContext context) { + private Optional> getSpringFactoriesProperties(ProjectContext context) { List search = context.search( new PathPatternMatchingProjectResourceFinder( SPRING_FACTORIES_PATH @@ -102,7 +113,7 @@ private Optional getSpringFactoriesProperties(ProjectContext context try { prop.load(new ByteArrayInputStream(oldConfigFile.getBytes())); - return Optional.of(prop); + return Optional.of(new ImmutablePair<>(prop, search.get(0))); } catch (IOException e) { throw new RuntimeException("Error whilst reading property file " + SPRING_FACTORIES_PATH, e); } diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java index cc728ed8c..fb3115964 100644 --- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.sbm.common.filter.PathPatternMatchingProjectResourceFinder; import org.springframework.sbm.engine.context.ProjectContext; @@ -60,7 +61,7 @@ public void autoConfigurationImportsIsGenerated() { public void autoConfigurationImportsContent() { action.apply(context); - String content = getNewAutoConfigFile(); + String content = getNewAutoConfigFileContents(); assertThat(content).isEqualTo("XYZ"); } @@ -93,7 +94,7 @@ public void shouldMoveMultipleProperties() { action.apply(context); - String content = getNewAutoConfigFile(); + String content = getNewAutoConfigFileContents(); assertThat(content).isEqualTo(""" XYZ @@ -105,7 +106,17 @@ public void shouldMoveMultipleProperties() { @Test public void multiMavenModule() { - TestProjectContext. + context = setupMultiMavenSpringModule(); + + action.apply(context); + + List projectResources = getAutoConfigFileAsProjectResource(); + + assertThat(projectResources).hasSize(1); + } + + private ProjectContext setupMultiMavenSpringModule() { + return TestProjectContext. buildProjectContext() .addProjectResource("pom.xml", """ @@ -158,6 +169,52 @@ public void multiMavenModule() { """) + .addProjectResource("spring-app/pom.xml", + """ + + + + + boot-upgrade-27_30 + com.example + 0.0.1-SNAPSHOT + + 4.0.0 + + spring-app + + + 17 + 17 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + """) + .addProjectResource("spring-app/src/main/resources/META-INF//spring.factories", + """ + org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.hello.GreetingConfig + """) .addProjectResource( "spring-app/src/main/java/com/hello", """ package com.hello; @@ -174,23 +231,17 @@ public String hello() { } } - """); - ; - context = TestProjectContext.buildProjectContext() - .addProjectResource( - "src/main/resources/META-INF/spring.factories", - """ - hello.world=something - org.springframework.boot.autoconfigure.EnableAutoConfiguration=XYZ - """ - ) - .build(); + """).build(); + } + + private String getNewAutoConfigFileContents() { + return getAutoConfigFileAsProjectResource().get(0).print(); } - private String getNewAutoConfigFile() { + private List getAutoConfigFileAsProjectResource() { return getFileAsProjectResource( "/**/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports" - ).get(0).print(); + ); } private List getFileAsProjectResource(String path) { From 1ab8ba8bd58c58da6d58841185386160a650f70c Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Wed, 24 Aug 2022 14:00:43 +0100 Subject: [PATCH 08/23] Multi maven module builds after migration --- ...ade_27_30_MultiModule_IntegrationTest.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java index b16c2c137..91f3c45a9 100644 --- a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java +++ b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java @@ -16,8 +16,15 @@ package org.springframework.sbm; +import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; +import org.openrewrite.maven.MavenParser; +import org.openrewrite.xml.tree.Xml; + +import java.nio.file.Path; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; public class BootUpgrade_27_30_MultiModule_IntegrationTest extends IntegrationTestBaseClass { @Override @@ -33,5 +40,44 @@ void migrateSimpleApplication() { scanProject(); applyRecipe("boot-2.7-3.0-dependency-version-update"); + + buildProject(); + +// verifyParentPomVersion(); + } + + private void buildProject() { + executeMavenGoals(getTestDir(), "clean", "verify"); + } + + private void verifyParentPomVersion() { + Xml.Document mavenAsXMLDocument = getRootBuildFile(); + + Xml.Tag parentTag =mavenAsXMLDocument + .getRoot() + .getChildren("parent").get(0); + + String version = parentTag.getChildValue("version").get(); + + String groupId = parentTag.getChildValue("groupId").get(); + String artifactId = parentTag.getChildValue("artifactId").get(); + + assertThat(version).isEqualTo("3.0.0-M3"); + assertThat(groupId).isEqualTo("org.springframework.boot"); + assertThat(artifactId).isEqualTo("spring-boot-starter-parent"); + } + + + @NotNull + private Xml.Document getRootBuildFile() { + + return parsePom(loadFile(Path.of("spring-app/pom.xml"))); + } + + + @NotNull + private Xml.Document parsePom(String pomContent) { + MavenParser mavenParser = new MavenParser.Builder().build(); + return mavenParser.parse(pomContent).get(0); } } From aa9000b1cc0b25dbbd6e0a82272e836eb4fd44ef Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Wed, 24 Aug 2022 14:01:18 +0100 Subject: [PATCH 09/23] Failing test, ehcache does not work with multi maven module spring app --- .../sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java index 91f3c45a9..581fd00d2 100644 --- a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java +++ b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java @@ -43,7 +43,7 @@ void migrateSimpleApplication() { buildProject(); -// verifyParentPomVersion(); + verifyParentPomVersion(); } private void buildProject() { From d01be95ea4e2e5fe5328c423040430eb3b3beb34 Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Wed, 24 Aug 2022 15:00:36 +0100 Subject: [PATCH 10/23] Making it finder --- ...ade_27_30_MultiModule_IntegrationTest.java | 2 +- ...avenModuleFinderByFileByResourcePath.java} | 19 ++++++++----- ...ModuleFinderByFileByResourcePathTest.java} | 28 +++++++++---------- .../CreateAutoconfigurationAction.java | 10 +++---- .../CreateAutoconfigurationActionTest.java | 19 +------------ 5 files changed, 33 insertions(+), 45 deletions(-) rename components/sbm-core/src/main/java/org/springframework/sbm/{engine/recipe/RecipeUtil.java => common/filter/MavenModuleFinderByFileByResourcePath.java} (76%) rename components/sbm-core/src/test/java/org/springframework/sbm/engine/recipe/{RecipeUtilTest.java => MavenModuleFinderByFileByResourcePathTest.java} (75%) diff --git a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java index 581fd00d2..91f3c45a9 100644 --- a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java +++ b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java @@ -43,7 +43,7 @@ void migrateSimpleApplication() { buildProject(); - verifyParentPomVersion(); +// verifyParentPomVersion(); } private void buildProject() { diff --git a/components/sbm-core/src/main/java/org/springframework/sbm/engine/recipe/RecipeUtil.java b/components/sbm-core/src/main/java/org/springframework/sbm/common/filter/MavenModuleFinderByFileByResourcePath.java similarity index 76% rename from components/sbm-core/src/main/java/org/springframework/sbm/engine/recipe/RecipeUtil.java rename to components/sbm-core/src/main/java/org/springframework/sbm/common/filter/MavenModuleFinderByFileByResourcePath.java index 038f017f7..18bf4707a 100644 --- a/components/sbm-core/src/main/java/org/springframework/sbm/engine/recipe/RecipeUtil.java +++ b/components/sbm-core/src/main/java/org/springframework/sbm/common/filter/MavenModuleFinderByFileByResourcePath.java @@ -14,22 +14,27 @@ * limitations under the License. */ -package org.springframework.sbm.engine.recipe; +package org.springframework.sbm.common.filter; +import lombok.AllArgsConstructor; import org.springframework.sbm.project.resource.ProjectResourceSet; import org.springframework.sbm.project.resource.RewriteSourceFileHolder; +import org.springframework.sbm.project.resource.filter.ProjectResourceFinder; import java.nio.file.Path; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.TreeSet; -public class RecipeUtil { - public Path getEnclosingMavenProjectForResource(ProjectResourceSet projectResources, Path absolutePath) { +@AllArgsConstructor +public class MavenModuleFinderByFileByResourcePath implements ProjectResourceFinder { - List listOfPom = projectResources + private final Path resourcePath; + + @Override + public Path apply(ProjectResourceSet projectResourceSet) { + List listOfPom = projectResourceSet .stream() .map(RewriteSourceFileHolder::getAbsolutePath) .map(Path::toString) @@ -44,7 +49,7 @@ public Path getEnclosingMavenProjectForResource(ProjectResourceSet projectResour binarySearchTree.add(path); }); - String interestedFile = absolutePath.toAbsolutePath().toString(); + String interestedFile = resourcePath.toAbsolutePath().toString(); for (int i = interestedFile.length() - 1; i >= 0; i--) { @@ -58,7 +63,7 @@ public Path getEnclosingMavenProjectForResource(ProjectResourceSet projectResour } throw new IllegalStateException("Cannot find enclosing maven project for file: " - + absolutePath + " could be caused by erroneously calling this function or running a recipe on an " + + + resourcePath + " could be caused by erroneously calling this function or running a recipe on an " + "empty project"); } } diff --git a/components/sbm-core/src/test/java/org/springframework/sbm/engine/recipe/RecipeUtilTest.java b/components/sbm-core/src/test/java/org/springframework/sbm/engine/recipe/MavenModuleFinderByFileByResourcePathTest.java similarity index 75% rename from components/sbm-core/src/test/java/org/springframework/sbm/engine/recipe/RecipeUtilTest.java rename to components/sbm-core/src/test/java/org/springframework/sbm/engine/recipe/MavenModuleFinderByFileByResourcePathTest.java index 6473d6494..80ae50347 100644 --- a/components/sbm-core/src/test/java/org/springframework/sbm/engine/recipe/RecipeUtilTest.java +++ b/components/sbm-core/src/test/java/org/springframework/sbm/engine/recipe/MavenModuleFinderByFileByResourcePathTest.java @@ -18,6 +18,7 @@ import org.junit.jupiter.api.Test; import org.openrewrite.SourceFile; +import org.springframework.sbm.common.filter.MavenModuleFinderByFileByResourcePath; import org.springframework.sbm.project.resource.ProjectResourceSet; import org.springframework.sbm.project.resource.RewriteSourceFileHolder; @@ -29,9 +30,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -class RecipeUtilTest { - - private final RecipeUtil target = new RecipeUtil(); +class MavenModuleFinderByFileByResourcePathTest { @Test public void getsEnclosingMavenProject() { @@ -43,8 +42,9 @@ public void getsEnclosingMavenProject() { ) ); - Path result = target.getEnclosingMavenProjectForResource(projectResourceSet, - file("spring-app/src/main/Hello.java").getAbsolutePath()); + MavenModuleFinderByFileByResourcePath target = new MavenModuleFinderByFileByResourcePath(file("spring-app/src/main/Hello.java").getAbsolutePath()); + + Path result = target.apply(projectResourceSet); assertThat(result.toAbsolutePath().toString()).isEqualTo("/tmp/spring-app"); } @@ -60,8 +60,8 @@ public void whenItsNotAMultiModuleMavenFile() { ); - Path result = target.getEnclosingMavenProjectForResource(projectResourceSet, - file("src/main/Hello.java").getAbsolutePath()); + MavenModuleFinderByFileByResourcePath target = new MavenModuleFinderByFileByResourcePath(file("src/main/Hello.java").getAbsolutePath()); + Path result = target.apply(projectResourceSet); assertThat(result.toAbsolutePath().toString()).isEqualTo("/tmp"); } @@ -80,9 +80,9 @@ public void nestedMultiModuleFiles() { ) ); + MavenModuleFinderByFileByResourcePath target = new MavenModuleFinderByFileByResourcePath(file("spring-app-multi/spring-2/src/main/Hello.java").getAbsolutePath()); - Path result = target.getEnclosingMavenProjectForResource(projectResourceSet, - file("spring-app-multi/spring-2/src/main/Hello.java").getAbsolutePath()); + Path result = target.apply(projectResourceSet); assertThat(result.toAbsolutePath().toString()).isEqualTo("/tmp/spring-app-multi/spring-2"); } @@ -99,8 +99,8 @@ public void multiModuleOnRootLevel() { ) ); - Path result = target.getEnclosingMavenProjectForResource(projectResourceSet, - file("spring-app-2/src/main/Hello.java").getAbsolutePath()); + MavenModuleFinderByFileByResourcePath target = new MavenModuleFinderByFileByResourcePath(file("spring-app-2/src/main/Hello.java").getAbsolutePath()); + Path result = target.apply(projectResourceSet); assertThat(result.toAbsolutePath().toString()).isEqualTo("/tmp/spring-app-2"); } @@ -110,9 +110,9 @@ public void throwsErrorWhenNoResourceIsFound() { ProjectResourceSet projectResourceSet = new ProjectResourceSet(List.of()); - assertThrows(IllegalStateException.class, () -> target.getEnclosingMavenProjectForResource(projectResourceSet, - file("hello/world/A.java").getAbsolutePath() - )); + MavenModuleFinderByFileByResourcePath target = new MavenModuleFinderByFileByResourcePath(file("hello/world/A.java").getAbsolutePath()); + + assertThrows(IllegalStateException.class, () -> target.apply(projectResourceSet)); } private RewriteSourceFileHolder file(String path) { diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java index 78cf53e12..383a9eae6 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java @@ -20,7 +20,7 @@ import org.springframework.sbm.common.filter.PathPatternMatchingProjectResourceFinder; import org.springframework.sbm.engine.context.ProjectContext; import org.springframework.sbm.engine.recipe.AbstractAction; -import org.springframework.sbm.engine.recipe.RecipeUtil; +import org.springframework.sbm.common.filter.MavenModuleFinderByFileByResourcePath; import org.springframework.sbm.project.resource.ProjectResource; import org.springframework.sbm.project.resource.StringProjectResource; @@ -40,8 +40,6 @@ public class CreateAutoconfigurationAction extends AbstractAction { public static final String ENABLE_AUTO_CONFIGURATION_KEY = "org.springframework.boot.autoconfigure.EnableAutoConfiguration"; public static final Pattern COMMENT_REGEX = Pattern.compile("^#.*(\r|\n)+"); - private final RecipeUtil recipeUtil = new RecipeUtil(); - @Override public void apply(ProjectContext context) { Optional> props = getSpringFactoriesProperties(context); @@ -59,7 +57,9 @@ public void apply(ProjectContext context) { .replaceAll(",", "\\\n"); - Path enclosingMavenProjectForResource = recipeUtil.getEnclosingMavenProjectForResource(context.getProjectResources(), props.get().getRight().getAbsolutePath()); + Path enclosingMavenProjectForResource = context.search( + new MavenModuleFinderByFileByResourcePath(props.get().getRight().getAbsolutePath()) + ); StringProjectResource springAutoconfigurationFile = new StringProjectResource( enclosingMavenProjectForResource, @@ -68,7 +68,7 @@ public void apply(ProjectContext context) { ); context.getProjectResources().add(springAutoconfigurationFile); - removeAutoConfigKeyFromSpringFactories(props.get().getLeft(), context,enclosingMavenProjectForResource, props.get().getRight()); + removeAutoConfigKeyFromSpringFactories(props.get().getLeft(), context, enclosingMavenProjectForResource, props.get().getRight()); } } diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java index fb3115964..ec6ac528d 100644 --- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java @@ -17,7 +17,6 @@ import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.sbm.common.filter.PathPatternMatchingProjectResourceFinder; import org.springframework.sbm.engine.context.ProjectContext; @@ -215,23 +214,7 @@ private ProjectContext setupMultiMavenSpringModule() { """ org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.hello.GreetingConfig """) - .addProjectResource( - "spring-app/src/main/java/com/hello", """ - package com.hello; - - import org.springframework.context.annotation.Bean; - import org.springframework.context.annotation.Configuration; - - @Configuration - public class GreetingConfig { - - @Bean - public String hello() { - return "こんにちは"; - } - } - - """).build(); + .build(); } private String getNewAutoConfigFileContents() { From 297d20c7b705d66d9aca8dacd00eee6437bc6bab Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Fri, 26 Aug 2022 10:06:48 +0100 Subject: [PATCH 11/23] New approach using context.getModules --- .../CreateAutoconfigurationAction.java | 41 +++-- .../CreateAutoconfigurationActionTest.java | 156 +++++++++++------- 2 files changed, 124 insertions(+), 73 deletions(-) diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java index 383a9eae6..df5e7511b 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java @@ -17,6 +17,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; +import org.springframework.sbm.build.api.ApplicationModule; import org.springframework.sbm.common.filter.PathPatternMatchingProjectResourceFinder; import org.springframework.sbm.engine.context.ProjectContext; import org.springframework.sbm.engine.recipe.AbstractAction; @@ -48,7 +49,8 @@ public void apply(ProjectContext context) { return; } - Optional springAutoConfigProperties = getEnableAutoConfigFromSpringFactories(props.get().getLeft()); + Properties springProps = props.get().getLeft(); + Optional springAutoConfigProperties = getEnableAutoConfigFromSpringFactories(springProps); if (springAutoConfigProperties.isPresent()) { @@ -57,18 +59,37 @@ public void apply(ProjectContext context) { .replaceAll(",", "\\\n"); + ProjectResource springFactoriesResource = props.get().getRight(); + + Path springFactoriesPath = springFactoriesResource.getAbsolutePath(); Path enclosingMavenProjectForResource = context.search( - new MavenModuleFinderByFileByResourcePath(props.get().getRight().getAbsolutePath()) + new MavenModuleFinderByFileByResourcePath(springFactoriesPath) ); - StringProjectResource springAutoconfigurationFile = - new StringProjectResource( - enclosingMavenProjectForResource, - enclosingMavenProjectForResource.resolve(AUTO_CONFIGURATION_IMPORTS), - autoConfigString - ); - context.getProjectResources().add(springAutoconfigurationFile); - removeAutoConfigKeyFromSpringFactories(props.get().getLeft(), context, enclosingMavenProjectForResource, props.get().getRight()); + Optional springFactoriesApplicationModule = context + .getApplicationModules() + .stream() + .filter(k -> k.getBuildFile() + .getResourceFolders() + .stream() + .anyMatch(l -> springFactoriesPath.toString().startsWith(l.toString())) + ) + .findFirst(); + + if (springFactoriesApplicationModule.isPresent()) { + StringProjectResource springAutoconfigurationFile = + new StringProjectResource( + enclosingMavenProjectForResource, + enclosingMavenProjectForResource.resolve(AUTO_CONFIGURATION_IMPORTS), + autoConfigString + ); + context.getProjectResources().add(springAutoconfigurationFile); + + removeAutoConfigKeyFromSpringFactories(springProps, context, enclosingMavenProjectForResource, springFactoriesResource); + } + else { + throw new IllegalStateException("could not find module for resource: " + springFactoriesPath); + } } } diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java index ec6ac528d..4615ba7d8 100644 --- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java @@ -112,9 +112,36 @@ public void multiMavenModule() { List projectResources = getAutoConfigFileAsProjectResource(); assertThat(projectResources).hasSize(1); + assertSpringConfigFileContentsInProject("spring-app"); } - private ProjectContext setupMultiMavenSpringModule() { + @Test + public void moduleInsideModuleMavenSetup() { + context = moduleInModuleProjectContext(); + action.apply(context); + List projectResources = getAutoConfigFileAsProjectResource(); + assertThat(projectResources).hasSize(1); + + assertSpringConfigFileContentsInProject("app/spring-app"); + } + + private void assertSpringConfigFileContentsInProject(String project) { + List content = getAutoConfigFileAsProjectResource(); + assertThat(content).hasSize(1); + assertThat(content.get(0).getAbsolutePath().toString()) + .isEqualTo(TestProjectContext.getDefaultProjectRoot() + + "/" + project + "/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports"); + + List oldFile = getFileAsProjectResource(EXISTING_SPRING_FACTORIES_FILE); + assertThat(oldFile).hasSize(1); + assertThat(oldFile.get(0).getAbsolutePath().toString()) + .isEqualTo(TestProjectContext.getDefaultProjectRoot() + + "/" + project + "/src/main/resources/META-INF/spring.factories"); + + assertThat(oldFile.get(0).print()).isEqualTo(""); + } + + private ProjectContext moduleInModuleProjectContext() { return TestProjectContext. buildProjectContext() .addProjectResource("pom.xml", @@ -123,49 +150,76 @@ private ProjectContext setupMultiMavenSpringModule() { 4.0.0 - pom - spring-app + app + com.example + root + v1 + root + + """) + .addProjectResource("app/pom.xml", + """ + + - org.springframework.boot - spring-boot-starter-parent - 2.7.1 + root + com.example + v1 - com.example - boot-upgrade-27_30 - 0.0.1-SNAPSHOT - boot-upgrade-27_30 - boot-upgrade-27_30 - - 17 - + 4.0.0 + + app + + spring-app + + + """) + .addProjectResource("app/spring-app/pom.xml", + """ + + + + app + com.example + v1 + + 4.0.0 - - - spring-snapshot - https://repo.spring.io/snapshot - - false - - - - spring-milestone - https://repo.spring.io/milestone - - false - - - - spring-release - https://repo.spring.io/release - - false - - - + spring-app + + """) + .addProjectResource("app/spring-app/src/main/resources/META-INF/spring.factories", + """ + org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.hello.GreetingConfig + """) + .build(); + } + + private ProjectContext setupMultiMavenSpringModule() { + return TestProjectContext. + buildProjectContext() + .addProjectResource("pom.xml", + """ + + + 4.0.0 + pom + + spring-app + + com.example + root + v1 + root """) .addProjectResource("spring-app/pom.xml", @@ -176,37 +230,13 @@ private ProjectContext setupMultiMavenSpringModule() { xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - boot-upgrade-27_30 + root com.example - 0.0.1-SNAPSHOT + v1 4.0.0 spring-app - - - 17 - 17 - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - """) From d7758167c94f894647ed4500486f3c85746a487e Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Fri, 26 Aug 2022 10:10:03 +0100 Subject: [PATCH 12/23] Passing test after merge --- .../upgrade/common/actions/CreateAutoconfigurationAction.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java index df5e7511b..3094ff88b 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java @@ -17,7 +17,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; -import org.springframework.sbm.build.api.ApplicationModule; +import org.springframework.sbm.build.api.Module; import org.springframework.sbm.common.filter.PathPatternMatchingProjectResourceFinder; import org.springframework.sbm.engine.context.ProjectContext; import org.springframework.sbm.engine.recipe.AbstractAction; @@ -66,7 +66,7 @@ public void apply(ProjectContext context) { new MavenModuleFinderByFileByResourcePath(springFactoriesPath) ); - Optional springFactoriesApplicationModule = context + Optional springFactoriesApplicationModule = context .getApplicationModules() .stream() .filter(k -> k.getBuildFile() From dcdee3220fdd34478af621e844723bcf3c3dd0fa Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Fri, 26 Aug 2022 10:11:14 +0100 Subject: [PATCH 13/23] using applicationmodule.contains call --- .../common/actions/CreateAutoconfigurationAction.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java index 3094ff88b..b0cd6dba0 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java @@ -69,11 +69,7 @@ public void apply(ProjectContext context) { Optional springFactoriesApplicationModule = context .getApplicationModules() .stream() - .filter(k -> k.getBuildFile() - .getResourceFolders() - .stream() - .anyMatch(l -> springFactoriesPath.toString().startsWith(l.toString())) - ) + .filter(k -> k.contains(springFactoriesPath)) .findFirst(); if (springFactoriesApplicationModule.isPresent()) { From 6a9390397a09a273404078a31bb473aff537ca4c Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Fri, 26 Aug 2022 10:13:16 +0100 Subject: [PATCH 14/23] Clean up integration test --- ...ade_27_30_MultiModule_IntegrationTest.java | 42 +------------------ 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java index 91f3c45a9..a52b4689f 100644 --- a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java +++ b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java @@ -16,15 +16,8 @@ package org.springframework.sbm; -import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import org.openrewrite.maven.MavenParser; -import org.openrewrite.xml.tree.Xml; - -import java.nio.file.Path; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; public class BootUpgrade_27_30_MultiModule_IntegrationTest extends IntegrationTestBaseClass { @Override @@ -34,7 +27,7 @@ protected String getTestSubDir() { @Test @Tag("integration") - void migrateSimpleApplication() { + void migrateMultiModuleApplication() { intializeTestProject(); scanProject(); @@ -42,42 +35,9 @@ void migrateSimpleApplication() { applyRecipe("boot-2.7-3.0-dependency-version-update"); buildProject(); - -// verifyParentPomVersion(); } private void buildProject() { executeMavenGoals(getTestDir(), "clean", "verify"); } - - private void verifyParentPomVersion() { - Xml.Document mavenAsXMLDocument = getRootBuildFile(); - - Xml.Tag parentTag =mavenAsXMLDocument - .getRoot() - .getChildren("parent").get(0); - - String version = parentTag.getChildValue("version").get(); - - String groupId = parentTag.getChildValue("groupId").get(); - String artifactId = parentTag.getChildValue("artifactId").get(); - - assertThat(version).isEqualTo("3.0.0-M3"); - assertThat(groupId).isEqualTo("org.springframework.boot"); - assertThat(artifactId).isEqualTo("spring-boot-starter-parent"); - } - - - @NotNull - private Xml.Document getRootBuildFile() { - - return parsePom(loadFile(Path.of("spring-app/pom.xml"))); - } - - - @NotNull - private Xml.Document parsePom(String pomContent) { - MavenParser mavenParser = new MavenParser.Builder().build(); - return mavenParser.parse(pomContent).get(0); - } } From 35437e802bddfd67f02cec1cbfc2e8bce174be31 Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Fri, 26 Aug 2022 10:16:53 +0100 Subject: [PATCH 15/23] Removing unnecessary --- ...MavenModuleFinderByFileByResourcePath.java | 69 ---------- ...nModuleFinderByFileByResourcePathTest.java | 126 ------------------ 2 files changed, 195 deletions(-) delete mode 100644 components/sbm-core/src/main/java/org/springframework/sbm/common/filter/MavenModuleFinderByFileByResourcePath.java delete mode 100644 components/sbm-core/src/test/java/org/springframework/sbm/engine/recipe/MavenModuleFinderByFileByResourcePathTest.java diff --git a/components/sbm-core/src/main/java/org/springframework/sbm/common/filter/MavenModuleFinderByFileByResourcePath.java b/components/sbm-core/src/main/java/org/springframework/sbm/common/filter/MavenModuleFinderByFileByResourcePath.java deleted file mode 100644 index 18bf4707a..000000000 --- a/components/sbm-core/src/main/java/org/springframework/sbm/common/filter/MavenModuleFinderByFileByResourcePath.java +++ /dev/null @@ -1,69 +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.springframework.sbm.common.filter; - -import lombok.AllArgsConstructor; -import org.springframework.sbm.project.resource.ProjectResourceSet; -import org.springframework.sbm.project.resource.RewriteSourceFileHolder; -import org.springframework.sbm.project.resource.filter.ProjectResourceFinder; - -import java.nio.file.Path; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - - -@AllArgsConstructor -public class MavenModuleFinderByFileByResourcePath implements ProjectResourceFinder { - - private final Path resourcePath; - - @Override - public Path apply(ProjectResourceSet projectResourceSet) { - List listOfPom = projectResourceSet - .stream() - .map(RewriteSourceFileHolder::getAbsolutePath) - .map(Path::toString) - .filter(k -> k.contains("pom.xml")) - .toList(); - - - Set binarySearchTree = new HashSet<>(); - - listOfPom.forEach(k -> { - String path = k.substring(0, k.length() - "pom.xml".length()); - binarySearchTree.add(path); - }); - - String interestedFile = resourcePath.toAbsolutePath().toString(); - - for (int i = interestedFile.length() - 1; i >= 0; i--) { - - if (interestedFile.charAt(i) != '/') continue; - - String subPath = interestedFile.substring(0, i + 1); - - if (binarySearchTree.contains(subPath)) { - return Path.of(subPath); - } - } - - throw new IllegalStateException("Cannot find enclosing maven project for file: " - + resourcePath + " could be caused by erroneously calling this function or running a recipe on an " + - "empty project"); - } -} diff --git a/components/sbm-core/src/test/java/org/springframework/sbm/engine/recipe/MavenModuleFinderByFileByResourcePathTest.java b/components/sbm-core/src/test/java/org/springframework/sbm/engine/recipe/MavenModuleFinderByFileByResourcePathTest.java deleted file mode 100644 index 80ae50347..000000000 --- a/components/sbm-core/src/test/java/org/springframework/sbm/engine/recipe/MavenModuleFinderByFileByResourcePathTest.java +++ /dev/null @@ -1,126 +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.springframework.sbm.engine.recipe; - -import org.junit.jupiter.api.Test; -import org.openrewrite.SourceFile; -import org.springframework.sbm.common.filter.MavenModuleFinderByFileByResourcePath; -import org.springframework.sbm.project.resource.ProjectResourceSet; -import org.springframework.sbm.project.resource.RewriteSourceFileHolder; - -import java.nio.file.Path; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class MavenModuleFinderByFileByResourcePathTest { - - @Test - public void getsEnclosingMavenProject() { - ProjectResourceSet projectResourceSet = new ProjectResourceSet( - List.of( - file("pom.xml"), - file("spring-app/pom.xml"), - file("spring-app/src/main/Hello.java") - ) - ); - - MavenModuleFinderByFileByResourcePath target = new MavenModuleFinderByFileByResourcePath(file("spring-app/src/main/Hello.java").getAbsolutePath()); - - Path result = target.apply(projectResourceSet); - - assertThat(result.toAbsolutePath().toString()).isEqualTo("/tmp/spring-app"); - } - - @Test - public void whenItsNotAMultiModuleMavenFile() { - - ProjectResourceSet projectResourceSet = new ProjectResourceSet( - List.of( - file("pom.xml"), - file("src/main/Hello.java") - ) - ); - - - MavenModuleFinderByFileByResourcePath target = new MavenModuleFinderByFileByResourcePath(file("src/main/Hello.java").getAbsolutePath()); - Path result = target.apply(projectResourceSet); - assertThat(result.toAbsolutePath().toString()).isEqualTo("/tmp"); - - } - - @Test - public void nestedMultiModuleFiles() { - - ProjectResourceSet projectResourceSet = new ProjectResourceSet( - List.of( - file("pom.xml"), - file("spring-app-multi/pom.xml"), - file("spring-app-multi/spring-1/src/main/Hello.java"), - file("spring-app-multi/spring-1/pom.xml"), - file("spring-app-multi/spring-2/src/main/Hello.java"), - file("spring-app-multi/spring-2/pom.xml") - ) - ); - - MavenModuleFinderByFileByResourcePath target = new MavenModuleFinderByFileByResourcePath(file("spring-app-multi/spring-2/src/main/Hello.java").getAbsolutePath()); - - Path result = target.apply(projectResourceSet); - assertThat(result.toAbsolutePath().toString()).isEqualTo("/tmp/spring-app-multi/spring-2"); - - } - - @Test - public void multiModuleOnRootLevel() { - ProjectResourceSet projectResourceSet = new ProjectResourceSet( - List.of( - file("pom.xml"), - file("spring-app/pom.xml"), - file("spring-app/src/main/Hello.java"), - file("spring-app-2/pom.xml"), - file("spring-app-2/src/main/Hello.java") - ) - ); - - MavenModuleFinderByFileByResourcePath target = new MavenModuleFinderByFileByResourcePath(file("spring-app-2/src/main/Hello.java").getAbsolutePath()); - Path result = target.apply(projectResourceSet); - - assertThat(result.toAbsolutePath().toString()).isEqualTo("/tmp/spring-app-2"); - } - - @Test - public void throwsErrorWhenNoResourceIsFound() { - - ProjectResourceSet projectResourceSet = new ProjectResourceSet(List.of()); - - MavenModuleFinderByFileByResourcePath target = new MavenModuleFinderByFileByResourcePath(file("hello/world/A.java").getAbsolutePath()); - - assertThrows(IllegalStateException.class, () -> target.apply(projectResourceSet)); - } - - private RewriteSourceFileHolder file(String path) { - - - RewriteSourceFileHolder mockedRewriteSourceFileHolder = mock(RewriteSourceFileHolder.class); - when(mockedRewriteSourceFileHolder.getAbsolutePath()).thenReturn(Path.of("/tmp/" + path)); - - return mockedRewriteSourceFileHolder; - } -} From 6245cb024d5b7b2d3811f6b7e095b64454cf18a5 Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Fri, 26 Aug 2022 15:50:14 +0100 Subject: [PATCH 16/23] clean up --- .../common/actions/CreateAutoconfigurationActionTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java index 4615ba7d8..29cf839d3 100644 --- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationActionTest.java @@ -240,7 +240,7 @@ private ProjectContext setupMultiMavenSpringModule() { """) - .addProjectResource("spring-app/src/main/resources/META-INF//spring.factories", + .addProjectResource("spring-app/src/main/resources/META-INF/spring.factories", """ org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.hello.GreetingConfig """) From a71124b3af3d3a9d4ce7746c7e73484462d562fb Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Fri, 26 Aug 2022 15:54:02 +0100 Subject: [PATCH 17/23] Passing test --- .../common/actions/CreateAutoconfigurationAction.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java index b0cd6dba0..2cf1f96cb 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java @@ -21,7 +21,6 @@ import org.springframework.sbm.common.filter.PathPatternMatchingProjectResourceFinder; import org.springframework.sbm.engine.context.ProjectContext; import org.springframework.sbm.engine.recipe.AbstractAction; -import org.springframework.sbm.common.filter.MavenModuleFinderByFileByResourcePath; import org.springframework.sbm.project.resource.ProjectResource; import org.springframework.sbm.project.resource.StringProjectResource; @@ -62,9 +61,6 @@ public void apply(ProjectContext context) { ProjectResource springFactoriesResource = props.get().getRight(); Path springFactoriesPath = springFactoriesResource.getAbsolutePath(); - Path enclosingMavenProjectForResource = context.search( - new MavenModuleFinderByFileByResourcePath(springFactoriesPath) - ); Optional springFactoriesApplicationModule = context .getApplicationModules() @@ -73,6 +69,8 @@ public void apply(ProjectContext context) { .findFirst(); if (springFactoriesApplicationModule.isPresent()) { + Path enclosingMavenProjectForResource = springFactoriesApplicationModule.get().getBuildFile() + .getAbsolutePath().getParent(); StringProjectResource springAutoconfigurationFile = new StringProjectResource( enclosingMavenProjectForResource, From 7a077056dac931f2fc4a9288e91580899acbb203 Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Fri, 26 Aug 2022 15:56:51 +0100 Subject: [PATCH 18/23] Simplifying --- .../upgrade/common/actions/CreateAutoconfigurationAction.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java index 2cf1f96cb..df3df279c 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java @@ -64,9 +64,7 @@ public void apply(ProjectContext context) { Optional springFactoriesApplicationModule = context .getApplicationModules() - .stream() - .filter(k -> k.contains(springFactoriesPath)) - .findFirst(); + .findModuleContaining(springFactoriesPath); if (springFactoriesApplicationModule.isPresent()) { Path enclosingMavenProjectForResource = springFactoriesApplicationModule.get().getBuildFile() From 405612b50982110f8ffa89764aae60ffa4995e58 Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Fri, 26 Aug 2022 15:57:37 +0100 Subject: [PATCH 19/23] Completed --- .../upgrade/common/actions/CreateAutoconfigurationAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java index df3df279c..8e61dc0d9 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java @@ -71,7 +71,7 @@ public void apply(ProjectContext context) { .getAbsolutePath().getParent(); StringProjectResource springAutoconfigurationFile = new StringProjectResource( - enclosingMavenProjectForResource, + context.getProjectRootDirectory(), enclosingMavenProjectForResource.resolve(AUTO_CONFIGURATION_IMPORTS), autoConfigString ); From 61918b7e9bc20bcc0e42e3d4937e95167c44522e Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Mon, 5 Sep 2022 17:03:28 +0530 Subject: [PATCH 20/23] Removing exception throwing --- .../upgrade/common/actions/CreateAutoconfigurationAction.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java index 8e61dc0d9..99744e1bd 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/actions/CreateAutoconfigurationAction.java @@ -79,9 +79,6 @@ public void apply(ProjectContext context) { removeAutoConfigKeyFromSpringFactories(springProps, context, enclosingMavenProjectForResource, springFactoriesResource); } - else { - throw new IllegalStateException("could not find module for resource: " + springFactoriesPath); - } } } From d353b40dda661ca69d754ac12cfaa59f0126ed8f Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Mon, 5 Sep 2022 17:30:52 +0530 Subject: [PATCH 21/23] parent pom is bumped in multi module projects --- ...ade_27_30_MultiModule_IntegrationTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java index a52b4689f..dfaf42cf6 100644 --- a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java +++ b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java @@ -16,8 +16,15 @@ package org.springframework.sbm; +import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; +import org.openrewrite.maven.MavenParser; +import org.openrewrite.xml.tree.Xml; + +import java.nio.file.Path; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; public class BootUpgrade_27_30_MultiModule_IntegrationTest extends IntegrationTestBaseClass { @Override @@ -35,6 +42,37 @@ void migrateMultiModuleApplication() { applyRecipe("boot-2.7-3.0-dependency-version-update"); buildProject(); + + verifyParentPomVersion(); + } + + private void verifyParentPomVersion() { + Xml.Document mavenAsXMLDocument = getRootBuildFile(); + + Xml.Tag parentTag = mavenAsXMLDocument + .getRoot() + .getChildren("parent").get(0); + + String version = parentTag.getChildValue("version").get(); + + String groupId = parentTag.getChildValue("groupId").get(); + String artifactId = parentTag.getChildValue("artifactId").get(); + + assertThat(version).isEqualTo("3.0.0-M3"); + assertThat(groupId).isEqualTo("org.springframework.boot"); + assertThat(artifactId).isEqualTo("spring-boot-starter-parent"); + } + + @NotNull + private Xml.Document getRootBuildFile() { + + return parsePom(loadFile(Path.of("pom.xml"))); + } + + @NotNull + private Xml.Document parsePom(String pomContent) { + MavenParser mavenParser = new MavenParser.Builder().build(); + return mavenParser.parse(pomContent).get(0); } private void buildProject() { From 32ada222bcd0e5413fc3dbe775d5f27c245922b2 Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Mon, 5 Sep 2022 17:48:51 +0530 Subject: [PATCH 22/23] Failing test --- ...ade_27_30_MultiModule_IntegrationTest.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java index dfaf42cf6..782b3afde 100644 --- a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java +++ b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java @@ -20,9 +20,13 @@ import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.openrewrite.maven.MavenParser; +import org.openrewrite.maven.tree.Dependency; +import org.openrewrite.maven.tree.MavenResolutionResult; import org.openrewrite.xml.tree.Xml; import java.nio.file.Path; +import java.util.List; +import java.util.Optional; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -44,6 +48,38 @@ void migrateMultiModuleApplication() { buildProject(); verifyParentPomVersion(); + verifyEhCacheVersionIsUpgraded(); + } + + private void verifyEhCacheVersionIsUpgraded() { + Optional ehcacheResult = getDependencyByArtifactId("ehcache", "spring-app/"); + + assertThat(ehcacheResult).isPresent(); + + Dependency ehcacheDependency = ehcacheResult.get(); + + assertThat(ehcacheDependency.getArtifactId()).isEqualTo("ehcache"); + assertThat(ehcacheDependency.getGav().getGroupId()).isEqualTo("org.ehcache"); + assertThat(ehcacheDependency.getGav().getVersion()).isNull(); + assertThat(ehcacheDependency.getClassifier()).isEqualTo("jakarta"); + } + + private Optional getDependencyByArtifactId(String artifactId, String module) { + Xml.Document mavenAsXMLDocument = getBuildFileByModule(module); + List dependencies = getDependencies(mavenAsXMLDocument); + return dependencies + .stream() + .filter(dependency -> dependency.getArtifactId().equals(artifactId)) + .findFirst(); + } + + private List getDependencies(Xml.Document mavenAsXMLDocument) { + return mavenAsXMLDocument + .getMarkers() + .findFirst(MavenResolutionResult.class) + .get() + .getPom() + .getRequestedDependencies(); } private void verifyParentPomVersion() { @@ -63,10 +99,18 @@ private void verifyParentPomVersion() { assertThat(artifactId).isEqualTo("spring-boot-starter-parent"); } + + @NotNull + private Xml.Document getBuildFileByModule(String app) { + + return parsePom(loadFile(Path.of(app + "pom.xml"))); + } + + @NotNull private Xml.Document getRootBuildFile() { - return parsePom(loadFile(Path.of("pom.xml"))); + return getBuildFileByModule(""); } @NotNull From 41a84adf5ac30bdf30be2a8872f135141cc8c419 Mon Sep 17 00:00:00 2001 From: Andrei Shakirin Date: Mon, 5 Sep 2022 14:53:52 +0200 Subject: [PATCH 23/23] Updated and fixed integration test for verifying ehcache dependency upgrade --- ...pgrade_27_30_MultiModule_IntegrationTest.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java index 782b3afde..c97672567 100644 --- a/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java +++ b/applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_MultiModule_IntegrationTest.java @@ -99,24 +99,28 @@ private void verifyParentPomVersion() { assertThat(artifactId).isEqualTo("spring-boot-starter-parent"); } + @NotNull + private Xml.Document getRootBuildFile() { + return parsePom(loadFile(Path.of("pom.xml"))); + } @NotNull private Xml.Document getBuildFileByModule(String app) { - return parsePom(loadFile(Path.of(app + "pom.xml"))); + return parseSubmodulePom(loadFile(Path.of("pom.xml")), loadFile(Path.of(app + "pom.xml"))); } @NotNull - private Xml.Document getRootBuildFile() { - - return getBuildFileByModule(""); + private Xml.Document parsePom(String pomContent) { + MavenParser mavenParser = new MavenParser.Builder().build(); + return mavenParser.parse(pomContent).get(0); } @NotNull - private Xml.Document parsePom(String pomContent) { + private Xml.Document parseSubmodulePom(String parentPom, String pomContent) { MavenParser mavenParser = new MavenParser.Builder().build(); - return mavenParser.parse(pomContent).get(0); + return mavenParser.parse(parentPom, pomContent).get(1); } private void buildProject() {