From e76badfd0be0eb61ec23d2c30592bbb2f1c60a83 Mon Sep 17 00:00:00 2001 From: sky <915601659@qq.com> Date: Fri, 15 Jul 2022 17:49:56 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=B8=BB=E7=A8=8B=E5=BA=8F=E5=8A=A0?= =?UTF-8?q?=E5=85=A5spring-boot-starter-data-jpa=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=EF=BC=8CLinux=E4=B8=8AResource=E8=A7=A3=E6=9E=90=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=EF=BC=88javax.persistence.PersistenceException:=20Una?= =?UTF-8?q?ble=20to=20resolve=20persistence=20unit=20root=20URL=EF=BC=89?= =?UTF-8?q?=EF=BC=8C=E5=B0=86=E2=80=9C;=E2=80=9D=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=88=90=E6=96=87=E4=BB=B6=E8=B7=AF=E8=B7=AF=E5=BE=84=E5=88=86?= =?UTF-8?q?=E9=9A=94=E7=AC=A6=EF=BC=8C=E5=81=9AWindows=E3=80=81Linux?= =?UTF-8?q?=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gitee/starblues/loader/launcher/MainProgramLauncher.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/MainProgramLauncher.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/MainProgramLauncher.java index 00ce88a..9ece160 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/MainProgramLauncher.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/MainProgramLauncher.java @@ -22,6 +22,7 @@ import com.gitee.starblues.loader.launcher.runner.MethodRunner; import com.gitee.starblues.loader.utils.ObjectUtils; +import java.io.File; import java.lang.management.ManagementFactory; import java.net.URL; import java.net.URLClassLoader; @@ -66,7 +67,7 @@ public class MainProgramLauncher extends AbstractMainLauncher{ protected void addResource(GenericClassLoader classLoader) throws Exception{ String classPath = ManagementFactory.getRuntimeMXBean().getClassPath(); if(!ObjectUtils.isEmpty(classPath)){ - String[] classPathStr = classPath.split(";"); + String[] classPathStr = classPath.split(File.pathSeparator); for (String path : classPathStr) { classLoader.addResource(path); } -- Gitee From 4ccbe5180a673c1d95dfe53701c73250245b14c8 Mon Sep 17 00:00:00 2001 From: StarBlues <5053202+starblues@user.noreply.gitee.com> Date: Tue, 19 Jul 2022 10:46:11 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!107?= =?UTF-8?q?=20:=20=E4=B8=BB=E7=A8=8B=E5=BA=8F=E5=8A=A0=E5=85=A5spring-boot?= =?UTF-8?q?-starter-data-jpa=E6=A8=A1=E5=9D=97=EF=BC=8CLinux=E4=B8=8AResou?= =?UTF-8?q?rce=E8=A7=A3=E6=9E=90=E5=BC=82=E5=B8=B8=EF=BC=88javax.persisten?= =?UTF-8?q?ce.PersistenceException:=20Unable=20to=20resolve=20persistence?= =?UTF-8?q?=20unit=20root=20URL=EF=BC=89'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gitee/starblues/loader/launcher/MainProgramLauncher.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/MainProgramLauncher.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/MainProgramLauncher.java index 9ece160..00ce88a 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/MainProgramLauncher.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/MainProgramLauncher.java @@ -22,7 +22,6 @@ import com.gitee.starblues.loader.launcher.runner.MethodRunner; import com.gitee.starblues.loader.utils.ObjectUtils; -import java.io.File; import java.lang.management.ManagementFactory; import java.net.URL; import java.net.URLClassLoader; @@ -67,7 +66,7 @@ public class MainProgramLauncher extends AbstractMainLauncher{ protected void addResource(GenericClassLoader classLoader) throws Exception{ String classPath = ManagementFactory.getRuntimeMXBean().getClassPath(); if(!ObjectUtils.isEmpty(classPath)){ - String[] classPathStr = classPath.split(File.pathSeparator); + String[] classPathStr = classPath.split(";"); for (String path : classPathStr) { classLoader.addResource(path); } -- Gitee From b003eb9bc9d2d56b60a698a8ec473be460724a7c Mon Sep 17 00:00:00 2001 From: StarBlues Date: Sat, 30 Jul 2022 20:30:36 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PluginOneselfSpringApplication.java | 90 +++++++++++++++++++ .../bootstrap/PluginSpringApplication.java | 23 ++--- .../launcher/CoexistBootstrapLauncher.java | 3 +- .../DefaultBootstrapLauncherFactory.java | 7 +- .../launcher/IsolationBootstrapLauncher.java | 3 +- .../launcher/OneselfBootstrapLauncher.java | 47 ++++++++++ .../bootstrap/processor/ProcessorContext.java | 1 - .../gitee/starblues/common/ManifestKey.java | 6 ++ .../starblues/loader/DevelopmentMode.java | 50 +++-------- .../starblues/loader/LoaderConstant.java | 1 + .../storage/DefaultResourceStorage.java | 13 ++- .../loader/launcher/AbstractMainLauncher.java | 4 +- .../launcher/DevelopmentModeSetting.java | 31 +++++-- .../loader/launcher/ProdLauncher.java | 7 ++ .../loader/launcher/SpringBootstrap.java | 2 +- .../launcher/coexist/CoexistBaseLauncher.java | 8 +- .../isolation/IsolationBaseLauncher.java | 2 +- .../ResourceLoaderFactoryGetter.java | 9 +- .../gitee/starblues/plugin/pack/Constant.java | 6 ++ .../plugin/pack/main/JarNestPackager.java | 2 + .../plugin/pack/main/JarOuterPackager.java | 2 +- .../plugin/pack/main/MainConfig.java | 11 ++- .../plugin/pack/main/MainRepackager.java | 51 +++++++++++ .../AbstractPluginDescriptorLoader.java | 10 ++- .../plugin/PluginIsolationLauncher.java | 3 - .../operator/DefaultPluginOperator.java | 6 +- .../operator/EmptyPluginOperator.java | 88 ++++++++++++++++++ update.md | 4 +- 28 files changed, 395 insertions(+), 95 deletions(-) create mode 100644 spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginOneselfSpringApplication.java create mode 100644 spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/OneselfBootstrapLauncher.java create mode 100644 spring-brick/src/main/java/com/gitee/starblues/integration/operator/EmptyPluginOperator.java diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginOneselfSpringApplication.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginOneselfSpringApplication.java new file mode 100644 index 0000000..677b081 --- /dev/null +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginOneselfSpringApplication.java @@ -0,0 +1,90 @@ +package com.gitee.starblues.bootstrap; + +import com.gitee.starblues.bootstrap.processor.ProcessorContext; +import com.gitee.starblues.bootstrap.processor.SpringPluginProcessor; +import com.gitee.starblues.integration.operator.EmptyPluginOperator; +import com.gitee.starblues.integration.user.DefaultPluginUser; +import com.gitee.starblues.spring.extract.DefaultOpExtractFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.GenericApplicationContext; +import org.springframework.core.env.ConfigurableEnvironment; + +/** + * 插件自主启动的 SpringApplication + * + * @author starBlues + * @version 3.0.4 + * @since 3.0.4 + */ +public class PluginOneselfSpringApplication extends SpringApplication { + + private final Logger logger = LoggerFactory.getLogger(PluginSpringApplication.class); + + protected final SpringPluginProcessor pluginProcessor; + protected final ProcessorContext processorContext; + + private final ConfigurePluginEnvironment configurePluginEnvironment; + private final GenericApplicationContext applicationContext; + + + public PluginOneselfSpringApplication(SpringPluginProcessor pluginProcessor, + ProcessorContext processorContext, + Class... primarySources) { + super(primarySources); + this.pluginProcessor = pluginProcessor; + this.processorContext = processorContext; + this.configurePluginEnvironment = new ConfigurePluginEnvironment(processorContext); + this.applicationContext = getApplicationContext(); + } + + protected GenericApplicationContext getApplicationContext() { + return (GenericApplicationContext) super.createApplicationContext(); + } + + @Override + protected void configureEnvironment(ConfigurableEnvironment environment, String[] args) { + super.configureEnvironment(environment, args); + configurePluginEnvironment.configureEnvironment(environment, args); + } + + @Override + protected ConfigurableApplicationContext createApplicationContext() { + return this.applicationContext; + } + + @Override + public ConfigurableApplicationContext run(String... args) { + try { + processorContext.setApplicationContext(this.applicationContext); + PluginContextHolder.initialize(processorContext); + pluginProcessor.initialize(processorContext); + registerMainBean(); + return super.run(args); + } catch (Exception e) { + pluginProcessor.failure(processorContext); + logger.debug("启动插件[{}]失败. {}", + processorContext.getPluginDescriptor().getPluginId(), + e.getMessage(), e); + throw new RuntimeException(e); + } + } + + @Override + protected void refresh(ConfigurableApplicationContext applicationContext) { + pluginProcessor.refreshBefore(processorContext); + super.refresh(applicationContext); + pluginProcessor.refreshAfter(processorContext); + } + + private void registerMainBean(){ + DefaultListableBeanFactory beanFactory = applicationContext.getDefaultListableBeanFactory(); + beanFactory.registerSingleton("extractFactory", new DefaultOpExtractFactory()); + beanFactory.registerSingleton("pluginUser", new DefaultPluginUser(applicationContext)); + beanFactory.registerSingleton("pluginOperator", new EmptyPluginOperator()); + } + +} diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginSpringApplication.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginSpringApplication.java index 3eabf8f..fdbff10 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginSpringApplication.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginSpringApplication.java @@ -18,17 +18,13 @@ package com.gitee.starblues.bootstrap; import com.gitee.starblues.bootstrap.processor.ProcessorContext; import com.gitee.starblues.bootstrap.processor.SpringPluginProcessor; -import com.gitee.starblues.spring.ApplicationContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.boot.Banner; import org.springframework.boot.SpringApplication; import org.springframework.boot.WebApplicationType; -import org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.StandardEnvironment; @@ -47,7 +43,6 @@ public class PluginSpringApplication extends SpringApplication { protected final SpringPluginProcessor pluginProcessor; protected final ProcessorContext processorContext; - private final ProcessorContext.RunMode runMode; private final ConfigurePluginEnvironment configurePluginEnvironment; private final GenericApplicationContext applicationContext; private final ResourceLoader resourceLoader; @@ -57,7 +52,6 @@ public class PluginSpringApplication extends SpringApplication { ProcessorContext processorContext, Class... primarySources) { super(primarySources); - this.runMode = processorContext.runMode(); this.pluginProcessor = pluginProcessor; this.processorContext = processorContext; this.resourceLoader = processorContext.getResourceLoader(); @@ -67,9 +61,6 @@ public class PluginSpringApplication extends SpringApplication { } protected GenericApplicationContext getApplicationContext(){ - if(runMode == ProcessorContext.RunMode.ONESELF){ - return (GenericApplicationContext) super.createApplicationContext(); - } DefaultListableBeanFactory beanFactory = getBeanFactory(processorContext); if(processorContext.getMainApplicationContext().isWebEnvironment()){ return new PluginWebApplicationContext(beanFactory, processorContext); @@ -83,14 +74,12 @@ public class PluginSpringApplication extends SpringApplication { } public void setDefaultPluginConfig(){ - if(runMode == ProcessorContext.RunMode.PLUGIN){ - setResourceLoader(resourceLoader); - setBannerMode(Banner.Mode.OFF); - setEnvironment(new StandardEnvironment()); - setWebApplicationType(WebApplicationType.NONE); - setRegisterShutdownHook(false); - setLogStartupInfo(false); - } + setResourceLoader(resourceLoader); + setBannerMode(Banner.Mode.OFF); + setEnvironment(new StandardEnvironment()); + setWebApplicationType(WebApplicationType.NONE); + setRegisterShutdownHook(false); + setLogStartupInfo(false); } @Override diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/CoexistBootstrapLauncher.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/CoexistBootstrapLauncher.java index abd8a2e..be89db5 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/CoexistBootstrapLauncher.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/CoexistBootstrapLauncher.java @@ -27,6 +27,7 @@ import com.gitee.starblues.spring.SpringPluginHook; import lombok.AllArgsConstructor; import org.springframework.beans.factory.config.DependencyDescriptor; import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.boot.SpringApplication; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; @@ -50,7 +51,7 @@ public class CoexistBootstrapLauncher implements BootstrapLauncher{ ProcessorContext processorContext = new DefaultProcessorContext( bootstrap.getRunMode(), bootstrap, pluginInteractive, bootstrap.getClass() ); - CoexistSpringApplication springApplication = new CoexistSpringApplication( + SpringApplication springApplication = new CoexistSpringApplication( pluginProcessor, processorContext, primarySources); diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/DefaultBootstrapLauncherFactory.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/DefaultBootstrapLauncherFactory.java index 3632f20..f76074f 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/DefaultBootstrapLauncherFactory.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/DefaultBootstrapLauncherFactory.java @@ -23,6 +23,7 @@ import com.gitee.starblues.bootstrap.processor.ProcessorContext; import com.gitee.starblues.bootstrap.processor.SpringPluginProcessor; import com.gitee.starblues.core.launcher.plugin.PluginInteractive; import com.gitee.starblues.loader.launcher.DevelopmentModeSetting; +import com.gitee.starblues.loader.launcher.simple.SimpleBaseLauncher; import java.util.List; @@ -45,8 +46,12 @@ public class DefaultBootstrapLauncherFactory implements BootstrapLauncherFactory BootstrapLauncher bootstrapLauncher = null; if(DevelopmentModeSetting.isolation()){ bootstrapLauncher = new IsolationBootstrapLauncher(bootstrap, pluginProcessor, pluginInteractive); - } else { + } else if(DevelopmentModeSetting.coexist()){ bootstrapLauncher = new CoexistBootstrapLauncher(bootstrap, pluginProcessor, pluginInteractive); + } else if(DevelopmentModeSetting.simple()){ + throw new RuntimeException("暂未实现[" + DevelopmentModeSetting.getDevelopmentMode().toString() + "]模式"); + } else { + bootstrapLauncher = new OneselfBootstrapLauncher(bootstrap, pluginProcessor, pluginInteractive); } return bootstrapLauncher; } diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/IsolationBootstrapLauncher.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/IsolationBootstrapLauncher.java index 6d4fde7..f4b2f97 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/IsolationBootstrapLauncher.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/IsolationBootstrapLauncher.java @@ -25,6 +25,7 @@ import com.gitee.starblues.bootstrap.processor.SpringPluginProcessor; import com.gitee.starblues.core.launcher.plugin.PluginInteractive; import com.gitee.starblues.spring.SpringPluginHook; import lombok.AllArgsConstructor; +import org.springframework.boot.SpringApplication; /** * isolation 模式插件启动器 @@ -48,7 +49,7 @@ public class IsolationBootstrapLauncher implements BootstrapLauncher{ ProcessorContext processorContext = new DefaultProcessorContext( runMode, bootstrap, pluginInteractive, bootstrap.getClass() ); - PluginSpringApplication springApplication = new PluginSpringApplication( + SpringApplication springApplication = new PluginSpringApplication( pluginProcessor, processorContext, primarySources); diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/OneselfBootstrapLauncher.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/OneselfBootstrapLauncher.java new file mode 100644 index 0000000..4949b30 --- /dev/null +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/OneselfBootstrapLauncher.java @@ -0,0 +1,47 @@ +package com.gitee.starblues.bootstrap.launcher; + +import com.gitee.starblues.bootstrap.DefaultSpringPluginHook; +import com.gitee.starblues.bootstrap.PluginOneselfSpringApplication; +import com.gitee.starblues.bootstrap.PluginSpringApplication; +import com.gitee.starblues.bootstrap.SpringPluginBootstrap; +import com.gitee.starblues.bootstrap.processor.DefaultProcessorContext; +import com.gitee.starblues.bootstrap.processor.ProcessorContext; +import com.gitee.starblues.bootstrap.processor.SpringPluginProcessor; +import com.gitee.starblues.core.launcher.plugin.PluginInteractive; +import com.gitee.starblues.spring.SpringPluginHook; +import lombok.AllArgsConstructor; +import org.springframework.boot.SpringApplication; + +/** + * 插件自主启动配置 + * + * @author starBlues + * @version 3.0.4 + * @since 3.0.4 + */ +@AllArgsConstructor +public class OneselfBootstrapLauncher implements BootstrapLauncher{ + + private final SpringPluginBootstrap bootstrap; + private final SpringPluginProcessor pluginProcessor; + private final PluginInteractive pluginInteractive; + + + @Override + public SpringPluginHook launch(Class[] primarySources, String[] args) { + ProcessorContext.RunMode runMode = bootstrap.getRunMode(); + + ProcessorContext processorContext = new DefaultProcessorContext( + runMode, bootstrap, pluginInteractive, bootstrap.getClass() + ); + SpringApplication springApplication = new PluginOneselfSpringApplication( + pluginProcessor, + processorContext, + primarySources); + springApplication.run(args); + return new DefaultSpringPluginHook(pluginProcessor, processorContext); + } + + + +} diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/ProcessorContext.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/ProcessorContext.java index e9c23b4..42cec5b 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/ProcessorContext.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/ProcessorContext.java @@ -132,7 +132,6 @@ public interface ProcessorContext extends RegistryInfo { /** * 插件独立运行 */ - @Deprecated ONESELF } diff --git a/spring-brick-common/src/main/java/com/gitee/starblues/common/ManifestKey.java b/spring-brick-common/src/main/java/com/gitee/starblues/common/ManifestKey.java index fdfc471..c4b25f9 100644 --- a/spring-brick-common/src/main/java/com/gitee/starblues/common/ManifestKey.java +++ b/spring-brick-common/src/main/java/com/gitee/starblues/common/ManifestKey.java @@ -83,6 +83,11 @@ public class ManifestKey { */ public static final String MAIN_PACKAGE_TYPE = "Main-Package-Type"; + /** + * jar main development mode + */ + public static final String DEVELOPMENT_MODE = "Development-Mode"; + /** * jar package name */ @@ -93,6 +98,7 @@ public class ManifestKey { */ public static final String IMPLEMENTATION_VERSION = "Implementation-Version"; + /** * 获取值 * diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/DevelopmentMode.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/DevelopmentMode.java index 08d7a9a..ac3e555 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/DevelopmentMode.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/DevelopmentMode.java @@ -1,67 +1,43 @@ /** * Copyright [2019-2022] [starBlues] * - * 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 + * 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 * * 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. + * 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.gitee.starblues.loader; /** - * 插件开发模式 + * 开发模式key定义 * * @author starBlues * @since 3.0.4 * @version 3.0.4 */ -public enum DevelopmentMode { +public abstract class DevelopmentMode { /** * 隔离模式 */ - ISOLATION("isolation"), + public static final String ISOLATION = "isolation"; /** * 共存模式 */ - COEXIST("coexist"), + public static final String COEXIST = "coexist"; /** * 简单模式 */ - SIMPLE("simple"); + public static final String SIMPLE = "simple"; - private final String developmentMode; - - DevelopmentMode(String developmentMode) { - this.developmentMode = developmentMode; - } - - public String getDevelopmentMode() { - return developmentMode; - } - - @Override - public String toString() { - return developmentMode; - } - - public static DevelopmentMode byName(String model){ - if(COEXIST.getDevelopmentMode().equalsIgnoreCase(model)){ - return DevelopmentMode.ISOLATION; - } else if(SIMPLE.getDevelopmentMode().equalsIgnoreCase(model)){ - return DevelopmentMode.SIMPLE; - } else { - return DevelopmentMode.ISOLATION; - } - } } diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/LoaderConstant.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/LoaderConstant.java index 4631f55..94f65c4 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/LoaderConstant.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/LoaderConstant.java @@ -42,6 +42,7 @@ public class LoaderConstant { public static final String MAIN_LIB_INDEXES_SPLIT = " "; public static final String START_CLASS = "Start-Class"; + public static final String MAIN_DEVELOPMENT_MODE = "Development-Mode"; public static final String MAIN_PACKAGE_TYPE = "Main-Package-Type"; public static final String MAIN_PACKAGE_TYPE_JAR = "jar"; diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/storage/DefaultResourceStorage.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/storage/DefaultResourceStorage.java index 84a7733..a1f230d 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/storage/DefaultResourceStorage.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/storage/DefaultResourceStorage.java @@ -49,8 +49,9 @@ public class DefaultResourceStorage extends SameRootResourceStorage{ @Override public void add(String name, URL url, ResourceByteGetter byteGetter) throws Exception{ - Assert.isNotEmpty(name, "name 不能为空"); - Assert.isNotNull(url, "url 不能为空"); + if(ObjectUtils.isEmpty(name) || url == null){ + return; + } name = formatResourceName(name); if(resourceStorage.containsKey(name)){ return; @@ -61,6 +62,9 @@ public class DefaultResourceStorage extends SameRootResourceStorage{ @Override public void add(String name, URL url) throws Exception{ + if(ObjectUtils.isEmpty(name) || url == null){ + return; + } this.add(name, url, null); } @@ -74,8 +78,9 @@ public class DefaultResourceStorage extends SameRootResourceStorage{ } protected void addResource(String name, Resource resource){ - Assert.isNotEmpty(name, "name 不能为空"); - Assert.isNotNull(resource, "resource 不能为空"); + if(ObjectUtils.isEmpty(name) || resource == null){ + return; + } resourceStorage.put(name, resource); } diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/AbstractMainLauncher.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/AbstractMainLauncher.java index 509097a..06be41d 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/AbstractMainLauncher.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/AbstractMainLauncher.java @@ -76,12 +76,12 @@ public abstract class AbstractMainLauncher extends AbstractLauncher classLoader.loadClass(SPRING_PLUGIN_BOOTSTRAP_PACKAGE_NAME); if(DevelopmentModeSetting.isolation()){ // 主程序加载到了 - throw new RuntimeException("[" + DevelopmentMode.ISOLATION.getDevelopmentMode() + "]模式下" + + throw new RuntimeException("[" + DevelopmentMode.ISOLATION + "]模式下" + "不能将[" + SPRING_PLUGIN_BOOTSTRAP_COORDINATE + "]依赖定义到主程序中, 只能依赖到插件中!"); } } catch (ClassNotFoundException e) { if(!DevelopmentModeSetting.isolation()){ - String mode = DevelopmentMode.COEXIST.getDevelopmentMode() + "/" + DevelopmentMode.SIMPLE.getDevelopmentMode(); + String mode = DevelopmentMode.COEXIST + "/" + DevelopmentMode.SIMPLE; throw new RuntimeException("[" + mode + "]模式" + "需要将[" + SPRING_PLUGIN_BOOTSTRAP_COORDINATE + "]依赖定义到主程序中!"); } diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/DevelopmentModeSetting.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/DevelopmentModeSetting.java index 21635c1..4ee30c5 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/DevelopmentModeSetting.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/DevelopmentModeSetting.java @@ -18,8 +18,6 @@ package com.gitee.starblues.loader.launcher; import com.gitee.starblues.loader.DevelopmentMode; -import java.util.Objects; - /** * DevelopmentMode 设置者 * @@ -29,26 +27,41 @@ import java.util.Objects; */ public class DevelopmentModeSetting { - private static DevelopmentMode developmentMode; + private static String developmentMode = DevelopmentMode.ISOLATION; - static void setDevelopmentMode(DevelopmentMode developmentMode) { - DevelopmentModeSetting.developmentMode = developmentMode; + static void setDevelopmentMode(String developmentMode) { + DevelopmentModeSetting.developmentMode = checkModeKey(developmentMode); } public static boolean isolation(){ - return Objects.equals(developmentMode, DevelopmentMode.ISOLATION); + return DevelopmentMode.ISOLATION.equalsIgnoreCase(developmentMode); } public static boolean coexist(){ - return Objects.equals(developmentMode, DevelopmentMode.COEXIST); + return DevelopmentMode.COEXIST.equalsIgnoreCase(developmentMode); } public static boolean simple(){ - return Objects.equals(developmentMode, DevelopmentMode.SIMPLE); + return DevelopmentMode.SIMPLE.equalsIgnoreCase(developmentMode); } - public static DevelopmentMode getDevelopmentMode(){ + public static String getDevelopmentMode(){ return developmentMode; } + private static String checkModeKey(String developmentMode){ + if(developmentMode == null || "".equals(developmentMode)){ + throw new RuntimeException("developmentMode设置不能为空"); + } + if(DevelopmentMode.ISOLATION.equalsIgnoreCase(developmentMode)){ + return developmentMode; + } else if(DevelopmentMode.COEXIST.equalsIgnoreCase(developmentMode)){ + return developmentMode; + } else if(DevelopmentMode.SIMPLE.equalsIgnoreCase(developmentMode)){ + return developmentMode; + } else { + throw new RuntimeException("不支持开发模式: " + developmentMode); + } + } + } diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/ProdLauncher.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/ProdLauncher.java index bf6d92c..eb2893b 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/ProdLauncher.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/ProdLauncher.java @@ -55,6 +55,7 @@ public class ProdLauncher implements Launcher{ File rootJarFile = getRootJarFile(); String startClass = null; String mainPackageType; + String developmentMode; try (JarFile jarFile = new JarFile(rootJarFile)){ Manifest manifest = jarFile.getManifest(); IllegalStateException exception = new IllegalStateException("当前启动包非法包!"); @@ -67,8 +68,14 @@ public class ProdLauncher implements Launcher{ throw exception; } mainPackageType = mainAttributes.getValue(MAIN_PACKAGE_TYPE); + developmentMode = mainAttributes.getValue(MAIN_DEVELOPMENT_MODE); } + if(ObjectUtils.isEmpty(developmentMode)){ + throw new RuntimeException("未发现 developmentMode 配置"); + } + DevelopmentModeSetting.setDevelopmentMode(developmentMode); + MethodRunner methodRunner = new MethodRunner(startClass, SPRING_BOOTSTRAP_RUN_METHOD, args); AbstractMainLauncher launcher; diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/SpringBootstrap.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/SpringBootstrap.java index ee02018..8a86ddf 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/SpringBootstrap.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/SpringBootstrap.java @@ -38,7 +38,7 @@ public interface SpringBootstrap { * * @return DevelopmentMode */ - default DevelopmentMode developmentMode(){ + default String developmentMode(){ return DevelopmentMode.ISOLATION; } diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/coexist/CoexistBaseLauncher.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/coexist/CoexistBaseLauncher.java index 790bb6b..2ce521e 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/coexist/CoexistBaseLauncher.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/coexist/CoexistBaseLauncher.java @@ -38,8 +38,10 @@ public class CoexistBaseLauncher extends AbstractMainLauncher { @Override protected ClassLoader createClassLoader(String... args) throws Exception { - return new GeneralUrlClassLoader(MAIN_CLASS_LOADER_NAME, + GeneralUrlClassLoader urlClassLoader = new GeneralUrlClassLoader(MAIN_CLASS_LOADER_NAME, this.getClass().getClassLoader()); + addResource(urlClassLoader); + return urlClassLoader; } @Override @@ -48,4 +50,8 @@ public class CoexistBaseLauncher extends AbstractMainLauncher { return classLoader; } + protected void addResource(GeneralUrlClassLoader classLoader) throws Exception{ + + } + } diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/isolation/IsolationBaseLauncher.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/isolation/IsolationBaseLauncher.java index bea556f..9cb11d5 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/isolation/IsolationBaseLauncher.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/isolation/IsolationBaseLauncher.java @@ -48,7 +48,7 @@ public class IsolationBaseLauncher extends AbstractMainLauncher { @Override protected ClassLoader createClassLoader(String... args) throws Exception { GenericClassLoader classLoader = new GenericClassLoader(MAIN_CLASS_LOADER_NAME, getParentClassLoader(), - getResourceLoaderFactory()); + getResourceLoaderFactory(args)); addResource(classLoader); return classLoader; } diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/isolation/ResourceLoaderFactoryGetter.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/isolation/ResourceLoaderFactoryGetter.java index b04ba0a..6cbd1f1 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/isolation/ResourceLoaderFactoryGetter.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/isolation/ResourceLoaderFactoryGetter.java @@ -80,12 +80,15 @@ public class ResourceLoaderFactoryGetter { public static SameRootResourceStorage getResourceStorage(String key, URL baseUrl){ SameRootResourceStorage resourceStorage = null; - if(Objects.equals(resourceMode, RESOURCE_MODE_NO_CACHE)){ - resourceStorage = new DefaultResourceStorage(baseUrl); + if(Objects.equals(resourceMode, RESOURCE_MODE_CACHE_ISOLATION)){ + // 资源可缓存, 且隔离 + resourceStorage = new CacheResourceStorage(baseUrl); } else if(Objects.equals(resourceMode, RESOURCE_MODE_CACHE_SHARE)){ + // 资源可缓存, 共享式 resourceStorage = new ShareResourceStorage(key, baseUrl); } else { - resourceStorage = new CacheResourceStorage(baseUrl); + // 资源不缓存 + resourceStorage = new DefaultResourceStorage(baseUrl); } return resourceStorage; } diff --git a/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/Constant.java b/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/Constant.java index b66fe5d..ce11f06 100644 --- a/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/Constant.java +++ b/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/Constant.java @@ -41,6 +41,12 @@ public class Constant { public static final String PLUGIN_METE_COMMENTS = "plugin meta configuration"; + /** + * 开发模式方法名称 + */ + public static final String DEVELOPMENT_MODE_METHOD_NAME = "developmentMode"; + + public static boolean isPom(String packageType){ return PACKAGING_POM.equalsIgnoreCase(packageType); } diff --git a/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/main/JarNestPackager.java b/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/main/JarNestPackager.java index 9e1eeaa..3b9eeb9 100644 --- a/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/main/JarNestPackager.java +++ b/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/main/JarNestPackager.java @@ -83,6 +83,8 @@ public class JarNestPackager implements Repackager { attributes.putValue(START_CLASS, mainConfig.getMainClass()); attributes.putValue(MAIN_CLASS, MAIN_CLASS_VALUE); attributes.putValue(MAIN_PACKAGE_TYPE, PackageType.MAIN_PACKAGE_TYPE_JAR); + attributes.putValue(DEVELOPMENT_MODE, mainConfig.getDevelopmentMode()); + // 增加jar包title和version属性 MavenProject mavenProject = this.repackageMojo.getProject(); attributes.putValue(IMPLEMENTATION_TITLE, mavenProject.getArtifactId()); diff --git a/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/main/JarOuterPackager.java b/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/main/JarOuterPackager.java index ec75a2b..f4db7ca 100644 --- a/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/main/JarOuterPackager.java +++ b/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/main/JarOuterPackager.java @@ -86,7 +86,7 @@ public class JarOuterPackager extends JarNestPackager { attributes.putValue(MAIN_CLASS, MAIN_CLASS_VALUE); attributes.putValue(MAIN_PACKAGE_TYPE, PackageType.MAIN_PACKAGE_TYPE_JAR_OUTER); attributes.putValue(MAIN_LIB_DIR, getLibPath()); - attributes.putValue(MAIN_LIB_INDEXES, getLibIndexes()); + attributes.putValue(DEVELOPMENT_MODE, mainConfig.getDevelopmentMode()); // 增加jar包title和version属性 MavenProject mavenProject = this.repackageMojo.getProject(); diff --git a/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/main/MainConfig.java b/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/main/MainConfig.java index f8ee0ee..1640483 100644 --- a/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/main/MainConfig.java +++ b/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/main/MainConfig.java @@ -16,11 +16,8 @@ package com.gitee.starblues.plugin.pack.main; - -import com.gitee.starblues.common.PackageStructure; import lombok.Data; import org.apache.maven.plugins.annotations.Parameter; -import com.gitee.starblues.plugin.pack.Constant; /** * 主程序打包配置 @@ -59,6 +56,12 @@ public class MainConfig { */ private String outputDirectory; - + /** + * 开发模式: + * isolation: 隔离模式[默认] + * coexist: 共享模式 + * simple: 简单模式 + */ + private String developmentMode; } diff --git a/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/main/MainRepackager.java b/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/main/MainRepackager.java index a32d278..e0d73f2 100644 --- a/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/main/MainRepackager.java +++ b/spring-brick-maven-packager/src/main/java/com/gitee/starblues/plugin/pack/main/MainRepackager.java @@ -17,14 +17,24 @@ package com.gitee.starblues.plugin.pack.main; import com.gitee.starblues.common.PackageType; +import com.gitee.starblues.plugin.pack.Constant; import com.gitee.starblues.plugin.pack.RepackageMojo; import com.gitee.starblues.plugin.pack.Repackager; import com.gitee.starblues.utils.ObjectUtils; +import com.gitee.starblues.utils.ReflectionUtils; import lombok.Getter; +import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; +import java.io.File; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Set; + /** * 主程序打包 * @author starBlues @@ -44,6 +54,7 @@ public class MainRepackager implements Repackager { @Override public void repackage() throws MojoExecutionException, MojoFailureException { checkConfig(); + setDevelopmentMode(); String packageType = mainConfig.getPackageType(); if(PackageType.MAIN_PACKAGE_TYPE_JAR.equalsIgnoreCase(packageType)){ new JarNestPackager(this).repackage(); @@ -76,5 +87,45 @@ public class MainRepackager implements Repackager { } } + private void setDevelopmentMode() throws MojoFailureException{ + String developmentMode = mainConfig.getDevelopmentMode(); + if(!ObjectUtils.isEmpty(developmentMode)){ + return; + } + try { + File file = new File(repackageMojo.getProject().getBuild().getOutputDirectory()); + Set artifacts = repackageMojo.getProject().getArtifacts(); + + URL[] urls = new URL[artifacts.size() + 1]; + int i = 0; + for (Artifact artifact : artifacts) { + urls[i] = artifact.getFile().toURI().toURL(); + i++; + } + urls[i] = file.toURI().toURL(); + URLClassLoader urlClassLoader = new URLClassLoader(urls, null); + + String mainClass = repackageMojo.getMainConfig().getMainClass(); + if(ObjectUtils.isEmpty(mainClass)){ + throw new Exception("mainConfig.mainClass config can't be empty"); + } + Class aClass = urlClassLoader.loadClass(mainClass); + Method method = ReflectionUtils.findMethod(aClass, Constant.DEVELOPMENT_MODE_METHOD_NAME); + String methodKey = aClass.getName() + "#" + Constant.DEVELOPMENT_MODE_METHOD_NAME + "()"; + if(method == null){ + throw new Exception("Not found method : " + methodKey); + } + method.setAccessible(true); + Object o = aClass.getConstructor().newInstance(); + Object result = method.invoke(o); + if(ObjectUtils.isEmpty(result)){ + throw new Exception(methodKey + " return value can't be empty"); + } + getMainConfig().setDevelopmentMode(String.valueOf(result)); + } catch (Exception e) { + throw new MojoFailureException("Set developmentMode failure:" + e.getMessage()); + } + } + } diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/descriptor/AbstractPluginDescriptorLoader.java b/spring-brick/src/main/java/com/gitee/starblues/core/descriptor/AbstractPluginDescriptorLoader.java index 3f7bd73..d9d48f1 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/descriptor/AbstractPluginDescriptorLoader.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/descriptor/AbstractPluginDescriptorLoader.java @@ -158,8 +158,11 @@ public abstract class AbstractPluginDescriptorLoader implements PluginDescriptor String pluginLibDir = descriptor.getPluginLibDir(); boolean configPluginLibDir = false; if(!ObjectUtils.isEmpty(pluginLibDir)){ - descriptor.setPluginLibDir(getLibDir(descriptor, pluginLibDir)); - configPluginLibDir = true; + String libDir = getLibDir(descriptor, pluginLibDir); + if(!ObjectUtils.isEmpty(libDir)){ + descriptor.setPluginLibDir(libDir); + configPluginLibDir = true; + } } if(ObjectUtils.isEmpty(dependenciesIndex)){ return Collections.emptySet(); @@ -202,8 +205,7 @@ public abstract class AbstractPluginDescriptorLoader implements PluginDescriptor if(new File(resolveRelativePath).exists()){ return resolveRelativePath; } - throw new PluginException("插件["+ MsgUtils.getPluginUnique(descriptor) +"]" + - "依赖目录[" + descriptor.getPluginLibDir() + "]不存在!"); + return null; } protected String getLibPath(DefaultInsidePluginDescriptor descriptor, String index){ diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/PluginIsolationLauncher.java b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/PluginIsolationLauncher.java index 0edcdbe..af1baad 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/PluginIsolationLauncher.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/PluginIsolationLauncher.java @@ -16,12 +16,9 @@ package com.gitee.starblues.core.launcher.plugin; -import com.gitee.starblues.common.Constants; import com.gitee.starblues.core.classloader.*; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; -import com.gitee.starblues.core.exception.PluginException; import com.gitee.starblues.core.launcher.plugin.involved.PluginLaunchInvolved; -import com.gitee.starblues.loader.DevelopmentMode; import com.gitee.starblues.loader.classloader.GenericClassLoader; import com.gitee.starblues.loader.classloader.resource.loader.DefaultResourceLoaderFactory; import com.gitee.starblues.loader.classloader.resource.loader.ResourceLoaderFactory; diff --git a/spring-brick/src/main/java/com/gitee/starblues/integration/operator/DefaultPluginOperator.java b/spring-brick/src/main/java/com/gitee/starblues/integration/operator/DefaultPluginOperator.java index c91557e..11e1c82 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/integration/operator/DefaultPluginOperator.java +++ b/spring-brick/src/main/java/com/gitee/starblues/integration/operator/DefaultPluginOperator.java @@ -28,7 +28,6 @@ import com.gitee.starblues.integration.listener.PluginInitializerListenerFactory import com.gitee.starblues.integration.operator.upload.UploadByInputStreamParam; import com.gitee.starblues.integration.operator.upload.UploadByMultipartFileParam; import com.gitee.starblues.integration.operator.upload.UploadParam; -import com.gitee.starblues.loader.DevelopmentMode; import com.gitee.starblues.loader.launcher.DevelopmentModeSetting; import com.gitee.starblues.spring.web.PluginStaticResourceConfig; import com.gitee.starblues.utils.*; @@ -55,7 +54,8 @@ import java.util.concurrent.atomic.AtomicBoolean; /** * 默认的插件操作者 * @author starBlues - * @version 3.0.1 + * @version 3.0.0 + * @since 3.0.4 */ public class DefaultPluginOperator implements PluginOperator { protected final Logger log = LoggerFactory.getLogger(this.getClass()); @@ -86,7 +86,7 @@ public class DefaultPluginOperator implements PluginOperator { } try { log.info("插件加载环境: {}", configuration.environment().toString()); - log.info("插件加载模式: {}", DevelopmentModeSetting.getDevelopmentMode().getDevelopmentMode()); + log.info("插件加载模式: {}", DevelopmentModeSetting.getDevelopmentMode()); pluginInitializerListenerFactory.addListener(pluginInitializerListener); List pluginsRoots = pluginManager.getPluginsRoots(); if(pluginsRoots.isEmpty()){ diff --git a/spring-brick/src/main/java/com/gitee/starblues/integration/operator/EmptyPluginOperator.java b/spring-brick/src/main/java/com/gitee/starblues/integration/operator/EmptyPluginOperator.java new file mode 100644 index 0000000..c56b306 --- /dev/null +++ b/spring-brick/src/main/java/com/gitee/starblues/integration/operator/EmptyPluginOperator.java @@ -0,0 +1,88 @@ +package com.gitee.starblues.integration.operator; + +import com.gitee.starblues.core.PluginInfo; +import com.gitee.starblues.core.exception.PluginException; +import com.gitee.starblues.integration.listener.PluginInitializerListener; +import com.gitee.starblues.integration.operator.upload.UploadParam; + +import java.nio.file.Path; +import java.util.List; + +/** + * 空操作的 PluginOperator + * + * @author starBlues + * @version 3.0.4 + * @since 3.0.4 + */ +public class EmptyPluginOperator implements PluginOperator{ + @Override + public boolean initPlugins(PluginInitializerListener pluginInitializerListener) throws PluginException { + return false; + } + + @Override + public boolean verify(Path pluginPath) throws PluginException { + return false; + } + + @Override + public PluginInfo parse(Path pluginPath) throws PluginException { + return null; + } + + @Override + public PluginInfo install(Path pluginPath, boolean unpackPlugin) throws PluginException { + return null; + } + + @Override + public void uninstall(String pluginId, boolean isDelete, boolean isBackup) throws PluginException { + + } + + @Override + public PluginInfo load(Path pluginPath, boolean unpackPlugin) throws PluginException { + return null; + } + + @Override + public boolean unload(String pluginId) throws PluginException { + return false; + } + + @Override + public boolean start(String pluginId) throws PluginException { + return false; + } + + @Override + public boolean stop(String pluginId) throws PluginException { + return false; + } + + @Override + public PluginInfo uploadPlugin(UploadParam uploadParam) throws PluginException { + return null; + } + + @Override + public Path backupPlugin(Path backDirPath, String sign) throws PluginException { + return null; + } + + @Override + public Path backupPlugin(String pluginId, String sign) throws PluginException { + return null; + } + + @Override + public List getPluginInfo() { + return null; + } + + @Override + public PluginInfo getPluginInfo(String pluginId) { + return null; + } +} diff --git a/update.md b/update.md index 5abb417..467a849 100644 --- a/update.md +++ b/update.md @@ -3,4 +3,6 @@ 3. 【修复】修复插件中`LiveBeansView`注册异常问题 4. 【修复[#I5IFR4](https://gitee.com/starblues/springboot-plugin-framework-parent/issues/I5IFR3)】 `ExtractFactory#getExtractByCoordinate` 类型转换`Bug` 5. 【修复[#I5GJO9](https://gitee.com/starblues/springboot-plugin-framework-parent/issues/I5GJO9)】`DefaultPluginManager#install` 异常无法抛出 -6. 【修复】修复插件无法加载其他包依赖中的`mybatis-xml`问题 \ No newline at end of file +6. 【修复】修复插件无法加载其他包依赖中的`mybatis-xml`问题 +7. 【修复】修复插件子启动问题 +8. 【优化】优化依赖资源默认不缓存, 以减少内存 -- Gitee