From 866cd2e12c6a5bd44e02313db5597d5dd4fc340b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=87=B4=E8=8A=82?= Date: Fri, 9 Jun 2023 13:46:20 +0800 Subject: [PATCH 1/5] 1. distinct requrie modules 2. split loadPropertiesFormUrlResource method 3. remove require modules if module is none spring powered --- .../boot/isle/ApplicationRuntimeModel.java | 17 +++++++++++++++ .../AbstractDeploymentDescriptor.java | 3 ++- .../DefaultModuleDeploymentValidator.java | 3 +-- .../boot/isle/stage/ModelCreatingStage.java | 21 +++++++++++++------ .../nospring-module/sofa-module.properties | 1 + .../META-INF/spring/service.xml | 6 ++++++ .../sofa-module.properties | 2 ++ ...aModuleProfileCheckerIntegrationTests.java | 9 +++++--- 8 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-isle/src/main/resources/nospring-module/sofa-module.properties create mode 100644 sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-isle/src/main/resources/nospringchild-module/META-INF/spring/service.xml create mode 100644 sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-isle/src/main/resources/nospringchild-module/sofa-module.properties diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/ApplicationRuntimeModel.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/ApplicationRuntimeModel.java index 901047d39..97e9367f1 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/ApplicationRuntimeModel.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/ApplicationRuntimeModel.java @@ -26,9 +26,11 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; /** @@ -51,6 +53,8 @@ public class ApplicationRuntimeModel implements IsleDeploymentModel { private final Map deploymentMap = new LinkedHashMap<>(); /** deploy registry */ private final DeployRegistry deployRegistry = new DeployRegistry(); + /** no spring powered deploys name*/ + private final Set noSpringPoweredDeploys = new HashSet<>(); /** module deployment validator */ private ModuleDeploymentValidator moduleDeploymentValidator; /** module profiles checker */ @@ -91,10 +95,23 @@ public List getResolvedDeployments() { return resolvedDeployments; } + //remove all required when no spring powered module exist + deploymentMap.values().forEach(dd -> { + List requiredModules = dd.getRequiredModules(); + if (requiredModules != null) { + // if required module is no spring powered, remove it + requiredModules.removeIf(module -> !deploymentMap.containsKey(module) && noSpringPoweredDeploys.contains(module)); + } + }); + resolvedDeployments = deployRegistry.getResolvedObjects(); return resolvedDeployments; } + public void addNoSpringPoweredDeployment(DeploymentDescriptor dd) { + noSpringPoweredDeploys.add(dd.getModuleName()); + } + public DeployRegistry getDeployRegistry() { return deployRegistry; } diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/deployment/AbstractDeploymentDescriptor.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/deployment/AbstractDeploymentDescriptor.java index b713f0761..781e1b971 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/deployment/AbstractDeploymentDescriptor.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/deployment/AbstractDeploymentDescriptor.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.Objects; import java.util.Properties; +import java.util.stream.Collectors; /** * Base implementation of {@link DeploymentDescriptor} to create module for url. @@ -225,7 +226,7 @@ protected List getRequiredModulesFromProperties() { if (StringUtils.hasText(springParent)) { requires.add(springParent); } - return requires; + return requires.stream().distinct().collect(Collectors.toList()); } protected String getSpringParentFromProperties() { diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/deployment/DefaultModuleDeploymentValidator.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/deployment/DefaultModuleDeploymentValidator.java index 29d221e75..7989c55f6 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/deployment/DefaultModuleDeploymentValidator.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/deployment/DefaultModuleDeploymentValidator.java @@ -27,7 +27,6 @@ public class DefaultModuleDeploymentValidator implements ModuleDeploymentValidat @Override public boolean isModuleDeployment(DeploymentDescriptor deploymentDescriptor) { - return StringUtils.hasText(deploymentDescriptor.getModuleName()) - && deploymentDescriptor.isSpringPowered(); + return StringUtils.hasText(deploymentDescriptor.getModuleName()); } } diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/stage/ModelCreatingStage.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/stage/ModelCreatingStage.java index 33411c3b7..28a72e2ef 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/stage/ModelCreatingStage.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/boot/isle/stage/ModelCreatingStage.java @@ -91,8 +91,7 @@ protected List getDeploymentDescriptors(String modulePrope while (urls.hasMoreElements()) { URL url = urls.nextElement(); UrlResource urlResource = new UrlResource(url); - Properties props = new Properties(); - props.load(urlResource.getInputStream()); + Properties props = loadPropertiesFormUrlResource(urlResource); DeploymentDescriptor deploymentDescriptor = createDeploymentDescriptor(url, props, deploymentDescriptorConfiguration, appClassLoader, modulePropertyFileName); if (ignoreCalculateRequireModules.contains(deploymentDescriptor.getModuleName())) { @@ -103,6 +102,12 @@ protected List getDeploymentDescriptors(String modulePrope return deploymentDescriptors; } + protected Properties loadPropertiesFormUrlResource(UrlResource urlResource) throws IOException { + Properties props = new Properties(); + props.load(urlResource.getInputStream()); + return props; + } + protected DeploymentDescriptor createDeploymentDescriptor(URL url, Properties props, DeploymentDescriptorConfiguration deploymentDescriptorConfiguration, @@ -115,10 +120,14 @@ protected DeploymentDescriptor createDeploymentDescriptor(URL url, protected void addDeploymentDescriptors(List deploymentDescriptors) throws DeploymentException { for (DeploymentDescriptor dd : deploymentDescriptors) { - if (application.isModuleDeployment(dd) && !ignoreModules.contains(dd.getModuleName())) { - if (application.acceptModule(dd)) { - if (validateDuplicateModule(dd)) { - application.addDeployment(dd); + if (application.isModuleDeployment(dd)) { + if (application.acceptModule(dd) && !ignoreModules.contains(dd.getModuleName())) { + if (dd.isSpringPowered()) { + if (validateDuplicateModule(dd)) { + application.addDeployment(dd); + } + } else { + application.addNoSpringPoweredDeployment(dd); } } else { application.addInactiveDeployment(dd); diff --git a/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-isle/src/main/resources/nospring-module/sofa-module.properties b/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-isle/src/main/resources/nospring-module/sofa-module.properties new file mode 100644 index 000000000..5f9315e82 --- /dev/null +++ b/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-isle/src/main/resources/nospring-module/sofa-module.properties @@ -0,0 +1 @@ +Module-Name=com.alipay.sofa.no-spring diff --git a/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-isle/src/main/resources/nospringchild-module/META-INF/spring/service.xml b/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-isle/src/main/resources/nospringchild-module/META-INF/spring/service.xml new file mode 100644 index 000000000..b30bee5b7 --- /dev/null +++ b/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-isle/src/main/resources/nospringchild-module/META-INF/spring/service.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-isle/src/main/resources/nospringchild-module/sofa-module.properties b/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-isle/src/main/resources/nospringchild-module/sofa-module.properties new file mode 100644 index 000000000..dd6d48cf5 --- /dev/null +++ b/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-isle/src/main/resources/nospringchild-module/sofa-module.properties @@ -0,0 +1,2 @@ +Module-Name=com.alipay.sofa.no-spring-child +Spring-Parent=com.alipay.sofa.no-spring diff --git a/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-isle/src/test/java/com/alipay/sofa/smoke/tests/isle/DefaultSofaModuleProfileCheckerIntegrationTests.java b/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-isle/src/test/java/com/alipay/sofa/smoke/tests/isle/DefaultSofaModuleProfileCheckerIntegrationTests.java index 9b23c5b79..3b4a7c3b8 100644 --- a/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-isle/src/test/java/com/alipay/sofa/smoke/tests/isle/DefaultSofaModuleProfileCheckerIntegrationTests.java +++ b/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-isle/src/test/java/com/alipay/sofa/smoke/tests/isle/DefaultSofaModuleProfileCheckerIntegrationTests.java @@ -33,7 +33,8 @@ * @version DefaultSofaModuleProfileCheckerIntegrationTests.java, v 0.1 2023年02月21日 8:25 PM huzijie Exp $ */ @SpringBootTest(classes = IsleSofaBootApplication.class) -@AddCustomJar({ "dev-module", "test-module", "sample-module" }) +@AddCustomJar({ "dev-module", "test-module", "sample-module", "nospring-module", + "nospringchild-module" }) @TestPropertySource(properties = "sofa.boot.isle.activeProfiles=dev") public class DefaultSofaModuleProfileCheckerIntegrationTests { @@ -43,12 +44,14 @@ public class DefaultSofaModuleProfileCheckerIntegrationTests { @Test public void verifyRuntimeModel() { // contains 2 Deployments - assertThat(applicationRuntimeModel.getAllDeployments().size()).isEqualTo(2); - assertThat(applicationRuntimeModel.getInstalled().size()).isEqualTo(2); + assertThat(applicationRuntimeModel.getAllDeployments().size()).isEqualTo(3); + assertThat(applicationRuntimeModel.getInstalled().size()).isEqualTo(3); assertThat(applicationRuntimeModel.getFailed().size()).isEqualTo(0); // check module init success assertThat(applicationRuntimeModel.getInstalled().stream()).noneMatch(deploymentDescriptor -> deploymentDescriptor.getModuleName().equals("com.alipay.sofa.test")); + assertThat(applicationRuntimeModel.getInstalled().stream()).noneMatch(deploymentDescriptor -> + deploymentDescriptor.getModuleName().equals("com.alipay.sofa.no-spring")); } } From 53273a714c4fb30ad4a455ca619cc9532705361f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=87=B4=E8=8A=82?= Date: Fri, 9 Jun 2023 15:49:58 +0800 Subject: [PATCH 2/5] revert extension package --- .../alipay/sofa/runtime/ext/client/ExtensionClientImpl.java | 2 +- .../sofa/runtime/ext/component/ExtensionComponent.java | 6 +++--- .../sofa/runtime/ext/component/ExtensionInternal.java | 2 +- .../sofa/runtime/ext/component/ExtensionPointComponent.java | 2 +- .../sofa/runtime/ext/component/ExtensionPointInternal.java | 2 +- .../alipay/sofa/runtime/ext/spring/ExtensionBuilder.java | 2 +- .../sofa/runtime/ext/spring/ExtensionPointBuilder.java | 2 +- .../{runtime/ext => service/api/component}/Extensible.java | 2 +- .../{runtime/ext => service/api/component}/Extension.java | 2 +- .../ext => service/api/component}/ExtensionPoint.java | 2 +- .../sofa/runtime/ext/component/ExtensionComponentTests.java | 6 +++--- .../runtime/ext/component/ExtensionPointComponentTests.java | 2 +- .../smoke/tests/actuator/sample/beans/ExtensionBean.java | 2 +- .../smoke/tests/runtime/extension/bean/IExtensionImpl.java | 2 +- 14 files changed, 18 insertions(+), 18 deletions(-) rename sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/{runtime/ext => service/api/component}/Extensible.java (96%) rename sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/{runtime/ext => service/api/component}/Extension.java (97%) rename sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/{runtime/ext => service/api/component}/ExtensionPoint.java (96%) diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/client/ExtensionClientImpl.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/client/ExtensionClientImpl.java index c4f7c40aa..37df5c2a5 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/client/ExtensionClientImpl.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/client/ExtensionClientImpl.java @@ -30,7 +30,7 @@ import com.alipay.sofa.runtime.spi.component.Implementation; import com.alipay.sofa.runtime.spi.component.SofaRuntimeContext; import com.alipay.sofa.runtime.spi.component.ComponentNameFactory; -import com.alipay.sofa.runtime.ext.ExtensionPoint; +import com.alipay.sofa.service.api.component.ExtensionPoint; /** * Programming API Implementation of Extension/Extension-Point. diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionComponent.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionComponent.java index 741f96c12..8d34aec1c 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionComponent.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionComponent.java @@ -20,9 +20,9 @@ import com.alipay.sofa.boot.log.SofaBootLoggerFactory; import com.alipay.sofa.runtime.api.ServiceRuntimeException; import com.alipay.sofa.runtime.api.component.ComponentName; -import com.alipay.sofa.runtime.ext.Extensible; -import com.alipay.sofa.runtime.ext.Extension; -import com.alipay.sofa.runtime.ext.ExtensionPoint; +import com.alipay.sofa.service.api.component.Extensible; +import com.alipay.sofa.service.api.component.Extension; +import com.alipay.sofa.service.api.component.ExtensionPoint; import com.alipay.sofa.runtime.model.ComponentStatus; import com.alipay.sofa.runtime.model.ComponentType; import com.alipay.sofa.runtime.spi.component.AbstractComponent; diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionInternal.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionInternal.java index 38402951c..e44e4a7d9 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionInternal.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionInternal.java @@ -19,7 +19,7 @@ import org.w3c.dom.Element; import com.alipay.sofa.runtime.api.component.ComponentName; -import com.alipay.sofa.runtime.ext.Extension; +import com.alipay.sofa.service.api.component.Extension; /** * SOFA Extension Internal Object. diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionPointComponent.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionPointComponent.java index 3b23c87e6..60057b92b 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionPointComponent.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionPointComponent.java @@ -27,7 +27,7 @@ import com.alipay.sofa.runtime.spi.component.SofaRuntimeContext; import com.alipay.sofa.runtime.ext.spring.SpringImplementationImpl; import com.alipay.sofa.runtime.spi.component.ComponentNameFactory; -import com.alipay.sofa.runtime.ext.ExtensionPoint; +import com.alipay.sofa.service.api.component.ExtensionPoint; /** * SOFA ExtensionPoint Component. diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionPointInternal.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionPointInternal.java index f0f02d76f..850dd5fb0 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionPointInternal.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionPointInternal.java @@ -16,7 +16,7 @@ */ package com.alipay.sofa.runtime.ext.component; -import com.alipay.sofa.runtime.ext.ExtensionPoint; +import com.alipay.sofa.service.api.component.ExtensionPoint; /** * SOFA Extension Point Internal Object. diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/spring/ExtensionBuilder.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/spring/ExtensionBuilder.java index 0bdb1414d..d3c6dab1b 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/spring/ExtensionBuilder.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/spring/ExtensionBuilder.java @@ -21,7 +21,7 @@ import com.alipay.sofa.runtime.api.component.ComponentName; import com.alipay.sofa.runtime.ext.component.ExtensionInternal; -import com.alipay.sofa.runtime.ext.Extension; +import com.alipay.sofa.service.api.component.Extension; /** * Extension Builder. diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/spring/ExtensionPointBuilder.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/spring/ExtensionPointBuilder.java index 6910f448d..3bf46f698 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/spring/ExtensionPointBuilder.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/spring/ExtensionPointBuilder.java @@ -17,7 +17,7 @@ package com.alipay.sofa.runtime.ext.spring; import com.alipay.sofa.runtime.ext.component.ExtensionPointInternal; -import com.alipay.sofa.runtime.ext.ExtensionPoint; +import com.alipay.sofa.service.api.component.ExtensionPoint; /** * Extension point builder. diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/Extensible.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/service/api/component/Extensible.java similarity index 96% rename from sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/Extensible.java rename to sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/service/api/component/Extensible.java index a73d50413..a3ba8bc2c 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/Extensible.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/service/api/component/Extensible.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alipay.sofa.runtime.ext; +package com.alipay.sofa.service.api.component; /** * Interface to register or unregister extension. diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/Extension.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/service/api/component/Extension.java similarity index 97% rename from sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/Extension.java rename to sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/service/api/component/Extension.java index 1bc4a6cf5..3e8c2d765 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/Extension.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/service/api/component/Extension.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alipay.sofa.runtime.ext; +package com.alipay.sofa.service.api.component; import org.w3c.dom.Element; diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/ExtensionPoint.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/service/api/component/ExtensionPoint.java similarity index 96% rename from sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/ExtensionPoint.java rename to sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/service/api/component/ExtensionPoint.java index 3e3b54232..b928057ec 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/ExtensionPoint.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/service/api/component/ExtensionPoint.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alipay.sofa.runtime.ext; +package com.alipay.sofa.service.api.component; import java.util.List; diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/ext/component/ExtensionComponentTests.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/ext/component/ExtensionComponentTests.java index 8b84a71ea..db7fd32b0 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/ext/component/ExtensionComponentTests.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/ext/component/ExtensionComponentTests.java @@ -17,9 +17,9 @@ package com.alipay.sofa.runtime.ext.component; import com.alipay.sofa.runtime.api.component.ComponentName; -import com.alipay.sofa.runtime.ext.Extensible; -import com.alipay.sofa.runtime.ext.Extension; -import com.alipay.sofa.runtime.ext.ExtensionPoint; +import com.alipay.sofa.service.api.component.Extensible; +import com.alipay.sofa.service.api.component.Extension; +import com.alipay.sofa.service.api.component.ExtensionPoint; import com.alipay.sofa.runtime.model.ComponentStatus; import com.alipay.sofa.runtime.model.ComponentType; import com.alipay.sofa.runtime.spi.component.ComponentInfo; diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/ext/component/ExtensionPointComponentTests.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/ext/component/ExtensionPointComponentTests.java index d51d49b82..b8d8d25c8 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/ext/component/ExtensionPointComponentTests.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/ext/component/ExtensionPointComponentTests.java @@ -17,7 +17,7 @@ package com.alipay.sofa.runtime.ext.component; import com.alipay.sofa.runtime.api.ServiceRuntimeException; -import com.alipay.sofa.runtime.ext.ExtensionPoint; +import com.alipay.sofa.service.api.component.ExtensionPoint; import com.alipay.sofa.runtime.model.ComponentStatus; import com.alipay.sofa.runtime.spi.component.ComponentInfo; import com.alipay.sofa.runtime.spi.component.ComponentManager; diff --git a/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-actuator/src/main/java/com/alipay/sofa/smoke/tests/actuator/sample/beans/ExtensionBean.java b/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-actuator/src/main/java/com/alipay/sofa/smoke/tests/actuator/sample/beans/ExtensionBean.java index ad26732c0..783526bd4 100644 --- a/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-actuator/src/main/java/com/alipay/sofa/smoke/tests/actuator/sample/beans/ExtensionBean.java +++ b/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-actuator/src/main/java/com/alipay/sofa/smoke/tests/actuator/sample/beans/ExtensionBean.java @@ -16,7 +16,7 @@ */ package com.alipay.sofa.smoke.tests.actuator.sample.beans; -import com.alipay.sofa.runtime.ext.Extension; +import com.alipay.sofa.service.api.component.Extension; /** * @author huzijie diff --git a/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-runtime/src/main/java/com/alipay/sofa/smoke/tests/runtime/extension/bean/IExtensionImpl.java b/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-runtime/src/main/java/com/alipay/sofa/smoke/tests/runtime/extension/bean/IExtensionImpl.java index e9b53a3a8..e4408f1ff 100755 --- a/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-runtime/src/main/java/com/alipay/sofa/smoke/tests/runtime/extension/bean/IExtensionImpl.java +++ b/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-runtime/src/main/java/com/alipay/sofa/smoke/tests/runtime/extension/bean/IExtensionImpl.java @@ -30,7 +30,7 @@ import com.alipay.sofa.smoke.tests.runtime.extension.descriptor.SpringListExtensionDescriptor; import com.alipay.sofa.smoke.tests.runtime.extension.descriptor.SpringMapExtensionDescriptor; import com.alipay.sofa.smoke.tests.runtime.extension.descriptor.SpringSimpleExtensionDescriptor; -import com.alipay.sofa.runtime.ext.Extension; +import com.alipay.sofa.service.api.component.Extension; /** * @author khotyn From 4926513161410f96f56b19dc354543e38babc21b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=87=B4=E8=8A=82?= Date: Thu, 15 Jun 2023 21:04:55 +0800 Subject: [PATCH 3/5] support legacy proeprty for sofarpc --- .../autoconfigure/rpc/SofaBootRpcProperties.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/rpc/SofaBootRpcProperties.java b/sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/rpc/SofaBootRpcProperties.java index 79c365c42..9b6b06fa8 100644 --- a/sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/rpc/SofaBootRpcProperties.java +++ b/sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/rpc/SofaBootRpcProperties.java @@ -34,6 +34,10 @@ @ConfigurationProperties("sofa.boot.rpc") public class SofaBootRpcProperties implements EnvironmentAware { + public static final String PREFIX = "sofa.boot.rpc"; + + public static final String OLD_PREFIX = "com.alipay.sofa.rpc"; + private Environment environment; /** @@ -858,8 +862,13 @@ private String getDotString(String enclosingMethodName) { if (environment == null) { return null; } - return environment.getProperty("sofa.boot.rpc." - + camelToDot(enclosingMethodName.substring(3))); + String key = camelToDot(enclosingMethodName.substring(3)); + String result = environment.getProperty(PREFIX + "." + key); + if (result != null) { + return result; + } else { + return environment.getProperty(OLD_PREFIX + "." + key); + } } public String camelToDot(String camelCaseString) { From b5abab5bd56bcee58ac80ef5f8cd7c1f5e4619de Mon Sep 17 00:00:00 2001 From: HzjNeverStop <441627022@qq.com> Date: Wed, 21 Jun 2023 14:13:56 +0800 Subject: [PATCH 4/5] 1. update version 3.18.1 (#1192) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 1. update version 3.18.1 2. fix @SofaService Annotation parse * format * format --------- Co-authored-by: 致节 --- .../ServiceBeanFactoryPostProcessor.java | 19 +- .../sofa/boot/util/SmartAnnotationUtils.java | 82 +++++++ .../boot/util/SmartAnnotationUtilsTests.java | 226 ++++++++++++++++++ .../spring/RepeatableSofaServiceTests.java | 13 + 4 files changed, 329 insertions(+), 11 deletions(-) create mode 100644 sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/SmartAnnotationUtils.java create mode 100644 sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/SmartAnnotationUtilsTests.java diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spring/ServiceBeanFactoryPostProcessor.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spring/ServiceBeanFactoryPostProcessor.java index c5bf24bab..202efeaf7 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spring/ServiceBeanFactoryPostProcessor.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spring/ServiceBeanFactoryPostProcessor.java @@ -22,6 +22,7 @@ import com.alipay.sofa.boot.log.ErrorCode; import com.alipay.sofa.boot.log.SofaBootLoggerFactory; import com.alipay.sofa.boot.util.BeanDefinitionUtil; +import com.alipay.sofa.boot.util.SmartAnnotationUtils; import com.alipay.sofa.runtime.api.ServiceRuntimeException; import com.alipay.sofa.runtime.api.annotation.SofaReference; import com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding; @@ -60,8 +61,6 @@ import org.springframework.context.annotation.ScannedGenericBeanDefinition; import org.springframework.core.Ordered; import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.core.annotation.MergedAnnotation; -import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.type.MethodMetadata; import org.springframework.core.type.StandardMethodMetadata; import org.springframework.util.Assert; @@ -72,6 +71,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -187,17 +187,15 @@ private void generateSofaServiceDefinitionOnMethod(String beanId, if (candidateMethods.size() == 1) { Method method = candidateMethods.get(0); - MergedAnnotations annotations = MergedAnnotations.from(method, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY); + Collection sofaServiceList = SmartAnnotationUtils.getAnnotations(method, SofaService.class); // use method @SofaService annotations - if (annotations.isPresent(SofaService.class)) { - annotations.stream(SofaService.class).map(MergedAnnotation::synthesize) - .forEach((annotation) -> generateSofaServiceDefinition(beanId, annotation, returnType, beanDefinition, + if (!sofaServiceList.isEmpty()) { + sofaServiceList.forEach((annotation) -> generateSofaServiceDefinition(beanId, annotation, returnType, beanDefinition, registry)); } else { // use returnType class @SofaService annotations - annotations = MergedAnnotations.from(returnType, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY); - annotations.stream(SofaService.class).map(MergedAnnotation::synthesize) - .forEach((annotation) -> generateSofaServiceDefinition(beanId, annotation, returnType, beanDefinition, + sofaServiceList = SmartAnnotationUtils.getAnnotations(returnType, SofaService.class); + sofaServiceList.forEach((annotation) -> generateSofaServiceDefinition(beanId, annotation, returnType, beanDefinition, registry)); } generateSofaReferenceDefinition(beanId, candidateMethods.get(0), registry); @@ -286,8 +284,7 @@ private void generateSofaServiceDefinitionOnClass(String beanId, Class beanCl BeanDefinition beanDefinition, BeanDefinitionRegistry registry) { // See issue: https://github.com/sofastack/sofa-boot/issues/835 - MergedAnnotations annotations = MergedAnnotations.from(beanClass, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY); - annotations.stream(SofaService.class).map(MergedAnnotation::synthesize) + SmartAnnotationUtils.getAnnotations(beanClass, SofaService.class) .forEach((annotation) -> generateSofaServiceDefinition(beanId, annotation, beanClass, beanDefinition, registry)); } diff --git a/sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/SmartAnnotationUtils.java b/sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/SmartAnnotationUtils.java new file mode 100644 index 000000000..09c4036f5 --- /dev/null +++ b/sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/SmartAnnotationUtils.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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 com.alipay.sofa.boot.util; + +import org.springframework.core.annotation.MergedAnnotation; +import org.springframework.core.annotation.MergedAnnotations; + +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * Utils to find suitable annotations. + * + * @author huzijie + * @version SmartAnnotationUtils.java, v 0.1 2023年06月20日 5:44 PM huzijie Exp $ + */ +public class SmartAnnotationUtils { + + /** + * 使用 {@link MergedAnnotations.SearchStrategy#TYPE_HIERARCHY} 搜索策略获取最近的注解集合 + *

如果元素上无注解,返回空的集合 + *

如果元素上仅有一个注解,返回包含该注解的集合 + *

如果元素上有多个注解,通过 {@link MergedAnnotations#get(Class)} 方法拿到最近的注解,返回的集合仅包含最近的注解所在元素上的注解 + * + * @param element 注解所在元素 + * @param annotationType 注解类 + * @param 注解类型 + * @return 注解集合,可能为空或者多个,如果存在多个注解,仅保留最高优先级元素上的注解 + */ + public static Collection getAnnotations(AnnotatedElement element, + Class annotationType) { + return getAnnotations(element, annotationType, + MergedAnnotations.SearchStrategy.TYPE_HIERARCHY); + } + + /** + * 使用指定搜索策略获取最近的注解集合 + *

如果元素上无注解,返回空的集合 + *

如果元素上仅有一个注解,返回包含该注解的集合 + *

如果元素上有多个注解,通过 {@link MergedAnnotations#get(Class)} 方法拿到最近的注解,返回的集合仅包含最近的注解所在元素上的注解 + * + * @param element 注解所在元素 + * @param annotationType 注解类 + * @param searchStrategy 搜索策略 + * @param 注解类型 + * @return 注解集合,可能为空或者多个,如果存在多个注解,仅保留最高优先级元素上的注解 + */ + public static Collection getAnnotations(AnnotatedElement element, Class annotationType, + MergedAnnotations.SearchStrategy searchStrategy) { + MergedAnnotations annotations = MergedAnnotations.from(element, searchStrategy); + List sofaServiceList = annotations.stream(annotationType).map(MergedAnnotation::synthesize).collect(Collectors.toList()); + if (sofaServiceList.size() > 1) { + // 如果存在多个注解,先通过 get 方法拿到最高优先级的注解所在的 element + Object source = annotations.get(annotationType).getSource(); + // 排除非最高优先级 element 以外的注解 + return annotations.stream(annotationType) + .filter(annotation -> Objects.equals(annotation.getSource(), source)) + .map(MergedAnnotation::synthesize).collect(Collectors.toList()); + } else { + // 如果不存在注解或者只有一个注解,直接返回 + return sofaServiceList; + } + } +} diff --git a/sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/SmartAnnotationUtilsTests.java b/sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/SmartAnnotationUtilsTests.java new file mode 100644 index 000000000..ed3258925 --- /dev/null +++ b/sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/SmartAnnotationUtilsTests.java @@ -0,0 +1,226 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License).isEqualTo(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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing).isEqualTo(software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND).isEqualTo(either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.sofa.boot.util; + +import org.junit.jupiter.api.Test; +import org.springframework.util.ReflectionUtils; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Method; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SmartAnnotationUtils} + * + * @author huzijie + * @version SmartAnnotationUtilsTests.java).isEqualTo(v 0.1 2023年06月20日 6:13 PM huzijie Exp $ + */ +public class SmartAnnotationUtilsTests { + + private List getAnnotations(AnnotatedElement element) { + return SmartAnnotationUtils.getAnnotations(element, SampleAnnotation.class) + .stream().map(SampleAnnotation::id).collect(Collectors.toList()); + } + + private Method getMethod(Class clazz, String methodName) { + return ReflectionUtils.findMethod(clazz, methodName); + } + + @Test + public void testAnnotationOnClass() { + assertThat(1).isEqualTo(getAnnotations(SampleService.class).size()); + assertThat("SampleClass").isEqualTo(getAnnotations(SampleService.class).get(0)); + + assertThat(1).isEqualTo(getAnnotations(NormalClass.class).size()); + assertThat("NormalClass").isEqualTo(getAnnotations(NormalClass.class).get(0)); + + assertThat(2).isEqualTo(getAnnotations(RepeatableClass.class).size()); + assertThat("RepeatableA").isEqualTo(getAnnotations(RepeatableClass.class).get(0)); + assertThat("RepeatableB").isEqualTo(getAnnotations(RepeatableClass.class).get(1)); + + assertThat(2).isEqualTo(getAnnotations(RepeatAnnotationClass.class).size()); + assertThat("RepeatableA").isEqualTo(getAnnotations(RepeatAnnotationClass.class).get(0)); + assertThat("RepeatableB").isEqualTo(getAnnotations(RepeatAnnotationClass.class).get(1)); + + assertThat(2).isEqualTo(getAnnotations(RepeatableChildClass.class).size()); + assertThat("RepeatableA").isEqualTo(getAnnotations(RepeatableChildClass.class).get(0)); + assertThat("RepeatableB").isEqualTo(getAnnotations(RepeatableChildClass.class).get(1)); + + assertThat(2).isEqualTo(getAnnotations(ChildRepeatableClass.class).size()); + assertThat("RepeatableC").isEqualTo(getAnnotations(ChildRepeatableClass.class).get(0)); + assertThat("RepeatableD").isEqualTo(getAnnotations(ChildRepeatableClass.class).get(1)); + + assertThat(0).isEqualTo(getAnnotations(NoneAnnotationClass.class).size()); + + assertThat(1).isEqualTo(getAnnotations(ChildClass.class).size()); + assertThat("ChildClass").isEqualTo(getAnnotations(ChildClass.class).get(0)); + + assertThat(1).isEqualTo(getAnnotations(NoAnnotationChildClass.class).size()); + assertThat("NormalClass").isEqualTo(getAnnotations(NoAnnotationChildClass.class).get(0)); + + assertThat(1).isEqualTo(getAnnotations(ImplClass.class).size()); + assertThat("ImplClass").isEqualTo(getAnnotations(ImplClass.class).get(0)); + + assertThat(1).isEqualTo(getAnnotations(NoAnnotationImplClass.class).size()); + assertThat("SampleClass").isEqualTo(getAnnotations(NoAnnotationImplClass.class).get(0)); + + assertThat(1).isEqualTo(getAnnotations(ChildAndImplClass.class).size()); + assertThat("ImplClass").isEqualTo(getAnnotations(ChildAndImplClass.class).get(0)); + } + + @Test + public void testAnnotationOnMethod() { + assertThat(0).isEqualTo(getAnnotations(getMethod(ChildMethodClass.class, "noMethod")).size()); + + assertThat(1).isEqualTo(getAnnotations(getMethod(ChildMethodClass.class, "parentMethod")) + .size()); + assertThat("overrideParentMethod").isEqualTo( + getAnnotations(getMethod(ChildMethodClass.class, "parentMethod")).get(0)); + + assertThat(2).isEqualTo(getAnnotations(getMethod(ChildMethodClass.class, "selfMethod")) + .size()); + assertThat("selfMethodA").isEqualTo( + getAnnotations(getMethod(ChildMethodClass.class, "selfMethod")).get(0)); + assertThat("selfMethodB").isEqualTo( + getAnnotations(getMethod(ChildMethodClass.class, "selfMethod")).get(1)); + + assertThat(1).isEqualTo( + getAnnotations(getMethod(ChildMethodClass.class, "parentSelfMethod")).size()); + assertThat("parentSelfMethod").isEqualTo( + getAnnotations(getMethod(ChildMethodClass.class, "parentSelfMethod")).get(0)); + + assertThat(1).isEqualTo(getAnnotations(getMethod(ParentMethodClass.class, "parentMethod")) + .size()); + assertThat("parentMethod").isEqualTo( + getAnnotations(getMethod(ParentMethodClass.class, "parentMethod")).get(0)); + } + + @SampleAnnotation(id = "SampleClass") + interface SampleService { + + } + + @SampleAnnotation(id = "NormalClass") + static class NormalClass { + + } + + @SampleAnnotation(id = "RepeatableA") + @SampleAnnotation(id = "RepeatableB") + static class RepeatableClass { + + } + + @SampleAnnotations(value = { @SampleAnnotation(id = "RepeatableA"), + @SampleAnnotation(id = "RepeatableB") }) + static class RepeatAnnotationClass { + + } + + @SampleAnnotation(id = "RepeatableA") + @SampleAnnotation(id = "RepeatableB") + static class RepeatableChildClass extends NormalClass { + + } + + @SampleAnnotation(id = "RepeatableC") + @SampleAnnotation(id = "RepeatableD") + static class ChildRepeatableClass extends RepeatableClass { + + } + + static class NoneAnnotationClass { + + } + + @SampleAnnotation(id = "ChildClass") + static class ChildClass extends NormalClass { + + } + + static class NoAnnotationChildClass extends NormalClass { + + } + + @SampleAnnotation(id = "ImplClass") + static class ImplClass implements SampleService { + + } + + static class NoAnnotationImplClass implements SampleService { + + } + + static class ChildAndImplClass extends ImplClass { + + } + + static class ParentMethodClass { + + @SampleAnnotation(id = "parentMethod") + public void parentMethod() { + + } + + @SampleAnnotation(id = "parentSelfMethod") + public void parentSelfMethod() { + + } + } + + static class ChildMethodClass extends ParentMethodClass { + + public void noMethod() { + + } + + @Override + @SampleAnnotation(id = "overrideParentMethod") + public void parentMethod() { + + } + + @SampleAnnotation(id = "selfMethodA") + @SampleAnnotation(id = "selfMethodB") + public void selfMethod() { + + } + } + + @Retention(RetentionPolicy.RUNTIME) + @Target({ ElementType.TYPE, ElementType.METHOD }) + @Repeatable(SampleAnnotations.class) + public @interface SampleAnnotation { + + String id() default ""; + } + + @Retention(RetentionPolicy.RUNTIME) + @Target({ ElementType.TYPE, ElementType.METHOD }) + public @interface SampleAnnotations { + + SampleAnnotation[] value(); + } +} diff --git a/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-runtime/src/test/java/com/alipay/sofa/smoke/tests/runtime/spring/RepeatableSofaServiceTests.java b/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-runtime/src/test/java/com/alipay/sofa/smoke/tests/runtime/spring/RepeatableSofaServiceTests.java index 78733d179..b1156386f 100644 --- a/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-runtime/src/test/java/com/alipay/sofa/smoke/tests/runtime/spring/RepeatableSofaServiceTests.java +++ b/sofa-boot-tests/sofa-boot-smoke-tests/sofa-boot-smoke-tests-runtime/src/test/java/com/alipay/sofa/smoke/tests/runtime/spring/RepeatableSofaServiceTests.java @@ -45,6 +45,7 @@ @Import({ RepeatableSofaServiceTests.RepeatableClassA.class, RepeatableSofaServiceTests.RepeatableClassB.class, RepeatableSofaServiceTests.RepeatableClassD.class, + RepeatableSofaServiceTests.RepeatableClassE.class, RepeatableSofaServiceTests.RepeatableConfiguration.class }) public class RepeatableSofaServiceTests { @@ -65,6 +66,8 @@ public void checkSofaService() { assertThat((findServiceByUniqueId(components, "H"))).isTrue(); assertThat((findServiceByUniqueId(components, "I"))).isTrue(); assertThat((findServiceByUniqueId(components, "J"))).isTrue(); + assertThat((findServiceByUniqueId(components, "K"))).isTrue(); + assertThat((findServiceByUniqueId(components, "L"))).isTrue(); } private boolean findServiceByUniqueId(Collection componentInfos, String value) { @@ -115,6 +118,16 @@ public String service() { } } + @SofaServices({ @SofaService(interfaceType = SampleService.class, uniqueId = "L"), + @SofaService(interfaceType = SampleService.class, uniqueId = "K") }) + static class RepeatableClassE extends RepeatableClassC { + + @Override + public String service() { + return null; + } + } + @Configuration static class RepeatableConfiguration { From 4ab0c0d03d500756d82e993b1ff5ce1e0d7f15a7 Mon Sep 17 00:00:00 2001 From: HzjNeverStop <441627022@qq.com> Date: Wed, 21 Jun 2023 14:13:56 +0800 Subject: [PATCH 5/5] format --- .../boot/util/SmartAnnotationUtilsTests.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/SmartAnnotationUtilsTests.java b/sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/SmartAnnotationUtilsTests.java index ed3258925..46e803a1f 100644 --- a/sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/SmartAnnotationUtilsTests.java +++ b/sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/SmartAnnotationUtilsTests.java @@ -2,15 +2,15 @@ * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License).isEqualTo(Version 2.0 + * The ASF licenses this file to You 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 * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing).isEqualTo(software + * 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).isEqualTo(either express or implied. + * 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. */ @@ -92,15 +92,16 @@ public void testAnnotationOnClass() { @Test public void testAnnotationOnMethod() { - assertThat(0).isEqualTo(getAnnotations(getMethod(ChildMethodClass.class, "noMethod")).size()); + assertThat(0).isEqualTo( + getAnnotations(getMethod(ChildMethodClass.class, "noMethod")).size()); - assertThat(1).isEqualTo(getAnnotations(getMethod(ChildMethodClass.class, "parentMethod")) - .size()); + assertThat(1).isEqualTo( + getAnnotations(getMethod(ChildMethodClass.class, "parentMethod")).size()); assertThat("overrideParentMethod").isEqualTo( getAnnotations(getMethod(ChildMethodClass.class, "parentMethod")).get(0)); - assertThat(2).isEqualTo(getAnnotations(getMethod(ChildMethodClass.class, "selfMethod")) - .size()); + assertThat(2).isEqualTo( + getAnnotations(getMethod(ChildMethodClass.class, "selfMethod")).size()); assertThat("selfMethodA").isEqualTo( getAnnotations(getMethod(ChildMethodClass.class, "selfMethod")).get(0)); assertThat("selfMethodB").isEqualTo( @@ -111,8 +112,8 @@ public void testAnnotationOnMethod() { assertThat("parentSelfMethod").isEqualTo( getAnnotations(getMethod(ChildMethodClass.class, "parentSelfMethod")).get(0)); - assertThat(1).isEqualTo(getAnnotations(getMethod(ParentMethodClass.class, "parentMethod")) - .size()); + assertThat(1).isEqualTo( + getAnnotations(getMethod(ParentMethodClass.class, "parentMethod")).size()); assertThat("parentMethod").isEqualTo( getAnnotations(getMethod(ParentMethodClass.class, "parentMethod")).get(0)); }