diff --git a/README.adoc b/README.adoc index 650fade8a..a7d6148cf 100644 --- a/README.adoc +++ b/README.adoc @@ -3,11 +3,11 @@ image:https://img.shields.io/github/license/spring-projects-experimental/spring-boot-migrator[GitHub] image:https://img.shields.io/github/v/release/spring-projects-experimental/spring-boot-migrator[GitHub release (latest by date)] -image:https://img.shields.io/github/downloads/spring-projects-experimental/spring-boot-migrator/0.12.0/total[GitHub release (latest by date)] +image:https://img.shields.io/github/downloads/spring-projects-experimental/spring-boot-migrator/0.13.0/total[GitHub release (latest by date)] image:https://img.shields.io/badge/Join-Slack-green?logo=slack&color=007EC6&style=for-the-badge[link="https://join.slack.com/t/springbootmigrator/shared_invite/zt-1k6yxfi3b-MEQ_MM67qXufWtc~Tw6y9w"] image:https://img.shields.io/github/discussions/spring-projects-experimental/spring-boot-migrator?label=GitHub%20discussions&logo=GitHUb&style=for-the-badge[GitHub Discussions] -image:https://img.shields.io/gitter/room/spring-boot-migrator/community?color=007EC6&logo=gitter&style=for-the-badge[Gitter] +image:https://img.shields.io/gitter/room/spring-boot-migrator/community?color=007EC6&logo=gitter&style=for-the-badge[link="https://gitter.im/spring-boot-migrator/community"] [quote] ____ diff --git a/components/sbm-core/src/main/java/org/springframework/sbm/java/api/ProjectJavaSources.java b/components/sbm-core/src/main/java/org/springframework/sbm/java/api/ProjectJavaSources.java index 43e543eb4..7cc1e4554 100644 --- a/components/sbm-core/src/main/java/org/springframework/sbm/java/api/ProjectJavaSources.java +++ b/components/sbm-core/src/main/java/org/springframework/sbm/java/api/ProjectJavaSources.java @@ -52,7 +52,7 @@ public interface ProjectJavaSources { List findMethodCalls(String pattern); - List findTypesImplementing(String jpaRepositoryInterface); + List findTypesImplementing(String interfaceType); List findClassesUsingType(String databaseDriverGAE); } diff --git a/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/ProjectJavaSourcesImplTest.java b/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/ProjectJavaSourcesImplTest.java new file mode 100644 index 000000000..5d3b01079 --- /dev/null +++ b/components/sbm-core/src/test/java/org/springframework/sbm/java/impl/ProjectJavaSourcesImplTest.java @@ -0,0 +1,98 @@ +/* + * 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.java.impl; + +import org.junit.jupiter.api.Test; +import org.springframework.sbm.engine.context.ProjectContext; +import org.springframework.sbm.java.api.JavaSourceAndType; +import org.springframework.sbm.project.resource.TestProjectContext; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Fabian Krüger + */ +class ProjectJavaSourcesImplTest { + + @Test + void findTypesImplementing() { + ProjectContext context = TestProjectContext.buildProjectContext().addJavaSource("src/main/java", """ + package com.example; + + public interface TheInterface {} + """).addJavaSource("src/main/java", """ + package com.example; + + public class TheClass implements TheInterface {} + """).build(); + + List typesImplementingInterface = context + .getProjectJavaSources() + .findTypesImplementing("com.example.TheInterface"); + + assertThat(typesImplementingInterface).isNotEmpty(); + assertThat(typesImplementingInterface.get(0).getType().getFullyQualifiedName()).isEqualTo("com.example.TheClass"); + } + + @Test + void findTypesImplementingInterfaceFromJdk() { + ProjectContext context = TestProjectContext.buildProjectContext() + .addJavaSource("src/main/java", """ + package com.example; + + import java.io.Serializable; + + public class TheClass implements Serializable {} + """).build(); + + List typesImplementingInterface = context + .getProjectJavaSources() + .findTypesImplementing("java.io.Serializable"); + + assertThat(typesImplementingInterface).isNotEmpty(); + assertThat(typesImplementingInterface.get(0).getType().getFullyQualifiedName()).isEqualTo("com.example.TheClass"); + } + + @Test + void findTypesImplementingWithInterfaceFromJar() { + ProjectContext context = TestProjectContext.buildProjectContext() + .withBuildFileHavingDependencies("org.springframework:spring-context:5.3.23") + .addJavaSource("src/main/java", """ + package com.example; + + import org.springframework.beans.BeansException; + import org.springframework.context.ApplicationContext; + import org.springframework.context.ApplicationContextAware; + + public class TheClass implements ApplicationContextAware { + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + } + } + """).build(); + + List typesImplementingInterface = context + .getProjectJavaSources() + .findTypesImplementing("org.springframework.context.ApplicationContextAware"); + + assertThat(typesImplementingInterface).isNotEmpty(); + assertThat(typesImplementingInterface.get(0).getType().getFullyQualifiedName()).isEqualTo("com.example.TheClass"); + } + + +} \ No newline at end of file diff --git a/docs/boot-3.0.0-M3-upgrade.adoc b/docs/boot-3.0.0-M3-upgrade.adoc index 8cafac6f0..500200e68 100644 --- a/docs/boot-3.0.0-M3-upgrade.adoc +++ b/docs/boot-3.0.0-M3-upgrade.adoc @@ -29,12 +29,12 @@ Every section is declared in YAML ==== The Helper The `Helper` is condition and data provider for the template. -It must implement `ìsApplicable` and `getData` from `SpringBootUpgradeReportSection.Helper`. +It must implement `ìsApplicable` and `getData` from `SpringBootUpgradeReportSectionHelper`. All variables used in the template must be provided by `getData`. [source,java] .... - public interface Helper extends Condition { + public abstract class SpringBootUpgradeReportSectionHelper extends Condition { Map getData(ProjectContext context); } ....