From b47a539996a3f90361422578cf9c90b6de494541 Mon Sep 17 00:00:00 2001 From: StarBlues Date: Sat, 27 Aug 2022 17:40:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=88=B03.1.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- spring-brick-bootstrap/pom.xml | 2 +- .../bootstrap/AutowiredTypeResolver.java | 2 +- .../DefaultAutowiredTypeResolver.java | 2 +- .../bootstrap/DefaultSpringPluginHook.java | 14 +++--- .../PluginDisableAutoConfiguration.java | 2 +- .../bootstrap/PluginOneselfInteractive.java | 20 +++++--- .../PluginOneselfSpringApplication.java | 2 +- .../bootstrap/PluginSpringApplication.java | 2 +- .../SpringPluginBootstrapBinder.java | 2 +- .../annotation/ResolveClassLoader.java | 2 +- .../CoexistAllowAutoConfiguration.java | 2 +- .../CoexistResolveClassLoaderAspect.java | 2 +- .../bootstrap/launcher/BootstrapLauncher.java | 2 +- .../launcher/BootstrapLauncherFactory.java | 2 +- .../launcher/CoexistBootstrapLauncher.java | 2 +- .../DefaultBootstrapLauncherFactory.java | 2 +- .../launcher/IsolationBootstrapLauncher.java | 2 +- .../launcher/OneselfBootstrapLauncher.java | 2 +- .../processor/DefaultProcessorContext.java | 6 +++ .../processor/FrameDefineBeanProcessor.java | 1 + .../bootstrap/processor/ProcessorContext.java | 7 +++ .../processor/oneself/OneselfProcessor.java | 2 +- .../realize/PluginCloseListener.java | 20 +++++++- spring-brick-common/pom.xml | 2 +- .../common/PluginDisableAutoConfig.java | 2 +- spring-brick-loader/pom.xml | 2 +- .../starblues/loader/DevelopmentMode.java | 2 +- .../loader/PluginResourceStorage.java | 6 +++ .../starblues/loader/archive/Archive.java | 14 ++++-- .../loader/archive/ExplodedArchive.java | 16 +++--- .../loader/archive/JarFileArchive.java | 15 +++--- .../classloader/ClassLoaderTranslator.java | 7 ++- .../classloader/GeneralUrlClassLoader.java | 7 ++- .../classloader/GenericClassLoader.java | 31 ++++++------ .../loader/DefaultResourceLoaderFactory.java | 28 +++++++---- .../resource/loader/ResourceLoader.java | 1 + .../loader/ResourceLoaderFactory.java | 7 +++ .../storage/CacheResourceStorage.java | 2 - .../storage/EmptyResourceStorage.java | 2 +- .../storage/ShareResourceStorage.java | 7 ++- .../starblues/loader/jar/AbstractJarFile.java | 13 ++--- .../starblues/loader/jar/AsciiBytes.java | 15 +++--- .../com/gitee/starblues/loader/jar/Bytes.java | 13 ++--- .../loader/jar/CentralDirectoryEndRecord.java | 16 +++--- .../jar/CentralDirectoryFileHeader.java | 16 +++--- .../loader/jar/CentralDirectoryParser.java | 15 +++--- .../loader/jar/CentralDirectoryVisitor.java | 13 ++--- .../starblues/loader/jar/FileHeader.java | 15 +++--- .../gitee/starblues/loader/jar/Handler.java | 16 +++--- .../gitee/starblues/loader/jar/JarEntry.java | 14 +++--- .../loader/jar/JarEntryCertification.java | 14 +++--- .../starblues/loader/jar/JarEntryFilter.java | 13 ++--- .../gitee/starblues/loader/jar/JarFile.java | 22 ++++++--- .../starblues/loader/jar/JarFileEntries.java | 22 ++++++--- .../starblues/loader/jar/JarFileWrapper.java | 18 ++++--- .../loader/jar/JarURLConnection.java | 15 +++--- .../loader/jar/RandomAccessData.java | 15 +++--- .../loader/jar/RandomAccessDataFile.java | 15 +++--- .../starblues/loader/jar/StringSequence.java | 15 +++--- .../loader/jar/ZipInflaterInputStream.java | 14 +++--- .../loader/launcher/DevLauncher.java | 2 +- .../launcher/DevelopmentModeSetting.java | 2 +- .../loader/launcher/ProdLauncher.java | 2 +- .../launcher/classpath/ClasspathResource.java | 2 +- .../classpath/FastJarClasspathResource.java | 2 +- .../classpath/JarOutClasspathResource.java | 2 +- .../launcher/coexist/CoexistBaseLauncher.java | 2 +- .../ResourceLoaderFactoryGetter.java | 10 +--- spring-brick-maven-packager/pom.xml | 2 +- .../plugin-help.xml | 2 +- .../main/resources/META-INF/maven/plugin.xml | 2 +- spring-brick/pom.xml | 2 +- .../core/DefaultPluginInsideInfo.java | 20 ++++++++ .../starblues/core/DefaultPluginManager.java | 9 ++-- .../starblues/core/PluginExtensionInfo.java | 21 ++++++++ .../com/gitee/starblues/core/PluginInfo.java | 8 ++- .../gitee/starblues/core/PluginInfoFace.java | 9 ++++ .../starblues/core/PluginInsideInfo.java | 19 ++++++- .../starblues/core/PluginLauncherManager.java | 15 +++--- .../ComposeMainResourceMatcher.java | 12 ++++- .../NestedPluginJarResourceLoader.java | 4 +- .../core/classloader/PluginClassLoader.java | 7 ++- .../PluginGeneralUrlClassLoader.java | 9 +++- .../PluginResourceLoaderFactory.java | 2 +- .../PluginResourceLoaderFactoryProxy.java | 7 ++- .../plugin/DefaultPluginInteractive.java | 15 ++++-- .../plugin/PluginCoexistLauncher.java | 12 +++-- .../launcher/plugin/PluginInteractive.java | 7 +++ .../plugin/PluginIsolationLauncher.java | 23 ++++----- .../plugin/SpringPluginHookWrapper.java | 24 ++++++--- .../involved/DefaultPluginLaunchInvolved.java | 49 +++++++++++++++++-- .../PluginApplicationContextGetter.java | 10 ++-- .../plugin/involved/PluginLaunchInvolved.java | 21 ++++---- .../involved/PluginLaunchInvolvedFactory.java | 20 ++++---- .../integration/ExtendPointConfiguration.java | 4 +- .../operator/EmptyPluginOperator.java | 2 +- .../starblues/spring/ApplicationContext.java | 2 +- .../starblues/spring/SpringPluginHook.java | 10 +++- .../extract/DefaultOpExtractFactory.java | 2 +- .../thymeleaf/PluginThymeleafInvolved.java | 11 +++-- update.md | 2 + 102 files changed, 640 insertions(+), 312 deletions(-) create mode 100644 spring-brick/src/main/java/com/gitee/starblues/core/PluginExtensionInfo.java diff --git a/pom.xml b/pom.xml index 3c86c78..c14f897 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ com.gitee.starblues spring-brick-parent pom - 3.0.4 + 3.1.0 spring-brick-common diff --git a/spring-brick-bootstrap/pom.xml b/spring-brick-bootstrap/pom.xml index 6c779cb..d6cf302 100644 --- a/spring-brick-bootstrap/pom.xml +++ b/spring-brick-bootstrap/pom.xml @@ -7,7 +7,7 @@ spring-brick-parent com.gitee.starblues - 3.0.4 + 3.1.0 spring-brick-bootstrap diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/AutowiredTypeResolver.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/AutowiredTypeResolver.java index 3dd0603..3941f87 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/AutowiredTypeResolver.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/AutowiredTypeResolver.java @@ -31,7 +31,7 @@ import java.util.Set; /** * @author starBlues * @since 3.0.3 - * @version 3.0.4 + * @version 3.1.0 */ public interface AutowiredTypeResolver { diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/DefaultAutowiredTypeResolver.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/DefaultAutowiredTypeResolver.java index 0c62ebf..ef58144 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/DefaultAutowiredTypeResolver.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/DefaultAutowiredTypeResolver.java @@ -32,7 +32,7 @@ import java.util.Set; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 */ public class DefaultAutowiredTypeResolver implements AutowiredTypeResolver{ diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/DefaultSpringPluginHook.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/DefaultSpringPluginHook.java index 5b24cff..f2680f8 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/DefaultSpringPluginHook.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/DefaultSpringPluginHook.java @@ -39,7 +39,7 @@ import java.util.Map; * 默认的插件钩子器 * @author starBlues * @since 3.0.0 - * @version 3.0.4 + * @version 3.1.0 */ public class DefaultSpringPluginHook implements SpringPluginHook { @@ -77,14 +77,12 @@ public class DefaultSpringPluginHook implements SpringPluginHook { @Override - public void close() throws Exception{ + public void close(boolean isUninstall) throws Exception{ try { GenericApplicationContext applicationContext = processorContext.getApplicationContext(); - callPluginCloseListener(applicationContext); + callPluginCloseListener(applicationContext, isUninstall); pluginProcessor.close(processorContext); - if(applicationContext != null){ - applicationContext.close(); - } + applicationContext.close(); processorContext.clearRegistryInfo(); DestroyUtils.destroyAll(null, SpringFactoriesLoader.class, "cache", Map.class); } catch (Exception e){ @@ -109,7 +107,7 @@ public class DefaultSpringPluginHook implements SpringPluginHook { return processorContext.getRegistryInfo(PluginThymeleafProcessor.CONFIG_KEY); } - private void callPluginCloseListener(GenericApplicationContext applicationContext){ + private void callPluginCloseListener(GenericApplicationContext applicationContext, boolean isUninstall){ List pluginCloseListeners = SpringBeanUtils.getBeans( applicationContext, PluginCloseListener.class); if(pluginCloseListeners.isEmpty()){ @@ -117,7 +115,7 @@ public class DefaultSpringPluginHook implements SpringPluginHook { } for (PluginCloseListener pluginCloseListener : pluginCloseListeners) { try { - pluginCloseListener.close(processorContext.getPluginDescriptor()); + pluginCloseListener.close(applicationContext, processorContext.getPluginInfo(), isUninstall); } catch (Exception e){ e.printStackTrace(); } diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginDisableAutoConfiguration.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginDisableAutoConfiguration.java index 7586a5c..b126533 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginDisableAutoConfiguration.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginDisableAutoConfiguration.java @@ -29,7 +29,7 @@ import java.util.*; * 插件禁用的 AutoConfiguration * * @author starBlues - * @version 3.0.4 + * @version 3.1.0 * @since 3.0.3 */ public class PluginDisableAutoConfiguration implements AutoConfigurationImportFilter { diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginOneselfInteractive.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginOneselfInteractive.java index 2723562..6d13aca 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginOneselfInteractive.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/PluginOneselfInteractive.java @@ -17,6 +17,8 @@ package com.gitee.starblues.bootstrap; import com.gitee.starblues.common.PackageStructure; +import com.gitee.starblues.core.DefaultPluginInsideInfo; +import com.gitee.starblues.core.PluginInsideInfo; import com.gitee.starblues.core.descriptor.DevPluginDescriptorLoader; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; import com.gitee.starblues.core.descriptor.PluginDescriptorLoader; @@ -37,27 +39,33 @@ import java.nio.file.Paths; /** * 插件自己的Interactive * @author starBlues - * @version 3.0.0 + * @version 3.1.0 */ public class PluginOneselfInteractive implements PluginInteractive { - private final InsidePluginDescriptor pluginDescriptor; + private final PluginInsideInfo pluginInsideInfo; private final MainApplicationContext mainApplicationContext; private final IntegrationConfiguration configuration; private final InvokeSupperCache invokeSupperCache; private final OpExtractFactory opExtractFactory; public PluginOneselfInteractive(){ - this.pluginDescriptor = createPluginDescriptor(); + this.pluginInsideInfo = createPluginInsideInfo(); this.mainApplicationContext = new EmptyMainApplicationContext(); this.configuration = new AutoIntegrationConfiguration(); this.invokeSupperCache = new DefaultInvokeSupperCache(); this.opExtractFactory = new DefaultOpExtractFactory(); } + @Override public InsidePluginDescriptor getPluginDescriptor() { - return pluginDescriptor; + return pluginInsideInfo.getPluginDescriptor(); + } + + @Override + public PluginInsideInfo getPluginInsideInfo() { + return pluginInsideInfo; } @Override @@ -80,7 +88,7 @@ public class PluginOneselfInteractive implements PluginInteractive { return opExtractFactory; } - private InsidePluginDescriptor createPluginDescriptor(){ + private PluginInsideInfo createPluginInsideInfo(){ EmptyPluginDescriptorDecrypt descriptorDecrypt = new EmptyPluginDescriptorDecrypt(); try (PluginDescriptorLoader pluginDescriptorLoader = new DevPluginDescriptorLoader(descriptorDecrypt)){ Path classesPath = Paths.get(this.getClass().getResource("/").toURI()).getParent(); @@ -89,7 +97,7 @@ public class PluginOneselfInteractive implements PluginInteractive { if(pluginDescriptor == null){ throw new RuntimeException("没有发现插件信息, 请使用框架提供的Maven插件器对插件进行编译!"); } - return pluginDescriptor; + return new DefaultPluginInsideInfo(pluginDescriptor); } catch (Exception e){ throw new RuntimeException(e); } 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 index d7db19c..b49e658 100644 --- 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 @@ -14,7 +14,7 @@ import org.springframework.core.env.ConfigurableEnvironment; * 插件自主启动的 SpringApplication * * @author starBlues - * @version 3.0.4 + * @version 3.1.0 * @since 3.0.4 */ public class PluginOneselfSpringApplication extends SpringApplication { 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 fdbff10..c21fc3f 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 @@ -34,7 +34,7 @@ import org.springframework.core.io.ResourceLoader; * 插件SpringApplication实现 * @author starBlues * @since 3.0.0 - * @version 3.0.4 + * @version 3.1.0 */ public class PluginSpringApplication extends SpringApplication { diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/SpringPluginBootstrapBinder.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/SpringPluginBootstrapBinder.java index 19f4ad5..da40ce7 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/SpringPluginBootstrapBinder.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/SpringPluginBootstrapBinder.java @@ -5,7 +5,7 @@ package com.gitee.starblues.bootstrap; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 */ public class SpringPluginBootstrapBinder { diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/annotation/ResolveClassLoader.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/annotation/ResolveClassLoader.java index b9f22e9..a93ffe0 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/annotation/ResolveClassLoader.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/annotation/ResolveClassLoader.java @@ -23,7 +23,7 @@ import java.lang.annotation.*; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/coexist/CoexistAllowAutoConfiguration.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/coexist/CoexistAllowAutoConfiguration.java index fc646f0..73355f6 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/coexist/CoexistAllowAutoConfiguration.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/coexist/CoexistAllowAutoConfiguration.java @@ -26,7 +26,7 @@ import java.util.Set; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 */ public class CoexistAllowAutoConfiguration { diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/coexist/CoexistResolveClassLoaderAspect.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/coexist/CoexistResolveClassLoaderAspect.java index 9b6c309..0d1b1df 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/coexist/CoexistResolveClassLoaderAspect.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/coexist/CoexistResolveClassLoaderAspect.java @@ -27,7 +27,7 @@ import org.aspectj.lang.annotation.Pointcut; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 */ @Aspect public class CoexistResolveClassLoaderAspect { diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/BootstrapLauncher.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/BootstrapLauncher.java index 6ed280a..994ecc0 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/BootstrapLauncher.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/BootstrapLauncher.java @@ -23,7 +23,7 @@ import com.gitee.starblues.spring.SpringPluginHook; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 */ public interface BootstrapLauncher { diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/BootstrapLauncherFactory.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/BootstrapLauncherFactory.java index 42292ad..bc14d22 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/BootstrapLauncherFactory.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/launcher/BootstrapLauncherFactory.java @@ -23,7 +23,7 @@ import com.gitee.starblues.bootstrap.SpringPluginBootstrap; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 */ public interface BootstrapLauncherFactory { 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 be89db5..59868a6 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 @@ -36,7 +36,7 @@ import org.springframework.core.env.ConfigurableEnvironment; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 * @see com.gitee.starblues.loader.DevelopmentMode#COEXIST */ @AllArgsConstructor 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 fcf5d72..5fb5cef 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 @@ -31,7 +31,7 @@ import java.util.List; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 */ public class DefaultBootstrapLauncherFactory implements BootstrapLauncherFactory{ @Override 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 f4b2f97..6618443 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 @@ -32,7 +32,7 @@ import org.springframework.boot.SpringApplication; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 * @see com.gitee.starblues.loader.DevelopmentMode#ISOLATION */ @AllArgsConstructor 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 index 4949b30..d0f4dcd 100644 --- 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 @@ -16,7 +16,7 @@ import org.springframework.boot.SpringApplication; * 插件自主启动配置 * * @author starBlues - * @version 3.0.4 + * @version 3.1.0 * @since 3.0.4 */ @AllArgsConstructor diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/DefaultProcessorContext.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/DefaultProcessorContext.java index d0801cc..8867f90 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/DefaultProcessorContext.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/DefaultProcessorContext.java @@ -17,6 +17,7 @@ package com.gitee.starblues.bootstrap.processor; import com.gitee.starblues.bootstrap.SpringPluginBootstrap; +import com.gitee.starblues.core.PluginInfo; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; import com.gitee.starblues.core.launcher.plugin.CacheRegistryInfo; import com.gitee.starblues.core.launcher.plugin.PluginInteractive; @@ -82,6 +83,11 @@ public class DefaultProcessorContext extends CacheRegistryInfo implements Proces return pluginInteractive.getPluginDescriptor(); } + @Override + public PluginInfo getPluginInfo() { + return pluginInteractive.getPluginInsideInfo(); + } + @Override public Class getRunnerClass() { return runnerClass; diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/FrameDefineBeanProcessor.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/FrameDefineBeanProcessor.java index ddbb7b8..5098ffc 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/FrameDefineBeanProcessor.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/FrameDefineBeanProcessor.java @@ -36,6 +36,7 @@ public class FrameDefineBeanProcessor implements SpringPluginProcessor { InsidePluginDescriptor pluginDescriptor = context.getPluginDescriptor(); ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory(); beanFactory.registerSingleton("pluginDescriptor", pluginDescriptor.toPluginDescriptor()); + beanFactory.registerSingleton("pluginInfo", context.getPluginInfo()); beanFactory.registerSingleton("mainApplicationContext", context.getMainApplicationContext()); } 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 42cec5b..d7aba02 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 @@ -18,6 +18,7 @@ package com.gitee.starblues.bootstrap.processor; import com.gitee.starblues.bootstrap.SpringPluginBootstrap; +import com.gitee.starblues.core.PluginInfo; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; import com.gitee.starblues.core.launcher.plugin.PluginInteractive; import com.gitee.starblues.core.launcher.plugin.RegistryInfo; @@ -54,6 +55,12 @@ public interface ProcessorContext extends RegistryInfo { */ InsidePluginDescriptor getPluginDescriptor(); + /** + * 得到插件信息 PluginInfo + * @return PluginInfo + */ + PluginInfo getPluginInfo(); + /** * 得到启动的class类 * @return Class diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/oneself/OneselfProcessor.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/oneself/OneselfProcessor.java index 8808ba2..f320f7c 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/oneself/OneselfProcessor.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/processor/oneself/OneselfProcessor.java @@ -29,7 +29,7 @@ import org.springframework.context.support.GenericApplicationContext; * 子启动处理器 * * @author starBlues - * @version 3.0.4 + * @version 3.1.0 * @since 3.0.4 */ public class OneselfProcessor implements SpringPluginProcessor { diff --git a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/realize/PluginCloseListener.java b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/realize/PluginCloseListener.java index 7942eae..5dd8ebf 100644 --- a/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/realize/PluginCloseListener.java +++ b/spring-brick-bootstrap/src/main/java/com/gitee/starblues/bootstrap/realize/PluginCloseListener.java @@ -16,20 +16,36 @@ package com.gitee.starblues.bootstrap.realize; +import com.gitee.starblues.core.PluginInfo; import com.gitee.starblues.core.descriptor.PluginDescriptor; +import org.springframework.context.support.GenericApplicationContext; /** * 插件被停止监听者。用于自定义关闭资源 * @author starBlues * @since 3.0.0 - * @version 3.0.0 + * @version 3.1.0 */ public interface PluginCloseListener { /** * 关闭时调用 * @param descriptor 当前插件描述者 + * @deprecated 在 3.1.1 版本会被删除 + * @since 3.0.0 */ - void close(PluginDescriptor descriptor); + default void close(PluginDescriptor descriptor){} + + /** + * 关闭时调用 + * @param applicationContext 当前插件的ApplicationContext + * @param pluginInfo 当前插件信息 + * @param isUninstall 是否为卸载关闭。true: 为卸载, false 不为卸载 + * @since 3.1.0 + */ + default void close(GenericApplicationContext applicationContext, + PluginInfo pluginInfo, boolean isUninstall){ + close(pluginInfo != null ? pluginInfo.getPluginDescriptor() : null); + } } diff --git a/spring-brick-common/pom.xml b/spring-brick-common/pom.xml index c284b46..3a57ab0 100644 --- a/spring-brick-common/pom.xml +++ b/spring-brick-common/pom.xml @@ -7,7 +7,7 @@ spring-brick-parent com.gitee.starblues - 3.0.4 + 3.1.0 spring-brick-common diff --git a/spring-brick-common/src/main/java/com/gitee/starblues/common/PluginDisableAutoConfig.java b/spring-brick-common/src/main/java/com/gitee/starblues/common/PluginDisableAutoConfig.java index bf7ecfd..24bdefe 100644 --- a/spring-brick-common/src/main/java/com/gitee/starblues/common/PluginDisableAutoConfig.java +++ b/spring-brick-common/src/main/java/com/gitee/starblues/common/PluginDisableAutoConfig.java @@ -7,7 +7,7 @@ import java.util.Set; * 插件禁用的 AutoConfiguration 配置 * * @author starBlues - * @version 3.0.4 + * @version 3.1.0 * @since 3.0.4 */ public class PluginDisableAutoConfig { diff --git a/spring-brick-loader/pom.xml b/spring-brick-loader/pom.xml index 90eaa40..d453dab 100644 --- a/spring-brick-loader/pom.xml +++ b/spring-brick-loader/pom.xml @@ -5,7 +5,7 @@ spring-brick-parent com.gitee.starblues - 3.0.4 + 3.1.0 4.0.0 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 eddd279..82d0029 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 @@ -21,7 +21,7 @@ package com.gitee.starblues.loader; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 */ public abstract class DevelopmentMode { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/PluginResourceStorage.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/PluginResourceStorage.java index 056596a..c32edec 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/PluginResourceStorage.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/PluginResourceStorage.java @@ -143,6 +143,12 @@ public class PluginResourceStorage { IOUtils.closeQuietly(jarFile); } } + for (JarFile jarFile : rootJarFileMap.values()) { + if(jarFile == null){ + continue; + } + IOUtils.closeQuietly(jarFile); + } jarFileMap.clear(); rootJarFileMap.clear(); } diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/archive/Archive.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/archive/Archive.java index 50bdc2c..8c351af 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/archive/Archive.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/archive/Archive.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,8 +26,11 @@ import java.util.jar.Manifest; /** * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * An archive that can be launched by the {@link Launcher}. + * + * @author Phillip Webb + * @since 1.0.0 + * @see JarFileArchive */ public interface Archive extends Iterable, AutoCloseable { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/archive/ExplodedArchive.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/archive/ExplodedArchive.java index 284a270..7ec7f03 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/archive/ExplodedArchive.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/archive/ExplodedArchive.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,9 +27,12 @@ import java.util.*; import java.util.jar.Manifest; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * {@link Archive} implementation backed by an exploded archive directory. + * + * @author Phillip Webb + * @author Andy Wilkinson + * @author Madhura Bhave + * @since 1.0.0 */ public class ExplodedArchive implements Archive { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/archive/JarFileArchive.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/archive/JarFileArchive.java index 8698a2e..1183476 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/archive/JarFileArchive.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/archive/JarFileArchive.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -35,9 +36,11 @@ import java.util.jar.JarEntry; import java.util.jar.Manifest; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * {@link Archive} implementation backed by a {@link JarFile}. + * + * @author Phillip Webb + * @author Andy Wilkinson + * @since 1.0.0 */ public class JarFileArchive implements Archive { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/ClassLoaderTranslator.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/ClassLoaderTranslator.java index 1465f26..3030b17 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/ClassLoaderTranslator.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/ClassLoaderTranslator.java @@ -36,7 +36,7 @@ import java.util.List; * classloader 转换器 * * @author starBlues - * @version 3.0.4 + * @version 3.1.0 * @since 3.0.4 */ public class ClassLoaderTranslator implements ResourceLoaderFactory { @@ -67,6 +67,11 @@ public class ClassLoaderTranslator implements ResourceLoaderFactory { throw new RuntimeException("Does not support!"); } + @Override + public void addResource(Resource resource) throws Exception { + throw new RuntimeException("Does not support!"); + } + @Override public void addResource(ResourceLoader resourceLoader) throws Exception { throw new RuntimeException("Does not support!"); diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/GeneralUrlClassLoader.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/GeneralUrlClassLoader.java index eb93c52..c7a07e6 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/GeneralUrlClassLoader.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/GeneralUrlClassLoader.java @@ -37,7 +37,7 @@ import java.util.List; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 */ public class GeneralUrlClassLoader extends URLClassLoader implements ResourceLoaderFactory { @@ -79,6 +79,11 @@ public class GeneralUrlClassLoader extends URLClassLoader implements ResourceLoa super.addURL(url); } + @Override + public void addResource(Resource resource) throws Exception { + addResource(resource.getUrl()); + } + @Override public void addResource(ResourceLoader resourceLoader) throws Exception { resourceLoader.load(resourceStorage); diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/GenericClassLoader.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/GenericClassLoader.java index 1542645..a186c84 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/GenericClassLoader.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/GenericClassLoader.java @@ -28,7 +28,6 @@ import java.net.URL; import java.net.URLClassLoader; import java.nio.file.Path; import java.util.*; -import java.util.concurrent.ConcurrentHashMap; /** * 基本的 ClassLoader @@ -43,7 +42,6 @@ public class GenericClassLoader extends URLClassLoader implements ResourceLoader protected final ResourceLoaderFactory resourceLoaderFactory; private final ResourceLoaderFactory classLoaderTranslator; - private final Map> pluginClassCache = new ConcurrentHashMap<>(); public GenericClassLoader(String name, ResourceLoaderFactory resourceLoaderFactory) { this(name, null, resourceLoaderFactory); @@ -81,6 +79,11 @@ public class GenericClassLoader extends URLClassLoader implements ResourceLoader resourceLoaderFactory.addResource(url); } + @Override + public void addResource(Resource resource) throws Exception { + resourceLoaderFactory.addResource(resource); + } + @Override public void addResource(ResourceLoader resourceLoader) throws Exception{ resourceLoaderFactory.addResource(resourceLoader); @@ -144,10 +147,6 @@ public class GenericClassLoader extends URLClassLoader implements ResourceLoader protected Class findClassFromLocal(String name) { Class aClass; String formatClassName = formatClassName(name); - aClass = pluginClassCache.get(formatClassName); - if (aClass != null) { - return aClass; - } Resource resource = resourceLoaderFactory.findFirstResource(formatClassName); byte[] bytes = null; if(resource != null){ @@ -159,17 +158,16 @@ public class GenericClassLoader extends URLClassLoader implements ResourceLoader if(bytes == null || bytes.length == 0){ return null; } - aClass = defineClass(name, bytes, 0, bytes.length ); + aClass = super.defineClass(name, bytes, 0, bytes.length ); if(aClass == null) { return null; } if (aClass.getPackage() == null) { int lastDotIndex = name.lastIndexOf( '.' ); String packageName = (lastDotIndex >= 0) ? name.substring( 0, lastDotIndex) : ""; - definePackage(packageName, null, null, null, + super.definePackage(packageName, null, null, null, null, null, null, null ); } - pluginClassCache.put(name, aClass); return aClass; } @@ -178,13 +176,20 @@ public class GenericClassLoader extends URLClassLoader implements ResourceLoader if(inputStream == null){ return null; } + ByteArrayOutputStream output = new ByteArrayOutputStream(); try { - return IOUtils.read(inputStream); + byte[] buffer = new byte[4096]; + int n = 0; + while (-1 != (n = inputStream.read(buffer))) { + output.write(buffer, 0, n); + } + return output.toByteArray(); } catch (Exception e){ e.printStackTrace(); return null; } finally { IOUtils.closeQuietly(inputStream); + IOUtils.closeQuietly(output); } } @@ -297,10 +302,8 @@ public class GenericClassLoader extends URLClassLoader implements ResourceLoader @Override public void close() throws IOException { - synchronized (pluginClassCache){ - pluginClassCache.clear(); - IOUtils.closeQuietly(resourceLoaderFactory); - } + super.close(); + IOUtils.closeQuietly(resourceLoaderFactory); } private String formatResourceName(String name) { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/loader/DefaultResourceLoaderFactory.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/loader/DefaultResourceLoaderFactory.java index 10790fa..5666521 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/loader/DefaultResourceLoaderFactory.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/loader/DefaultResourceLoaderFactory.java @@ -96,20 +96,30 @@ public class DefaultResourceLoaderFactory implements ResourceLoaderFactory{ } @Override - public void addResource(ResourceLoader resourceLoader) throws Exception { - if(resourceLoader == null){ - return; + public void addResource(Resource resource) throws Exception { + SameRootResourceStorage resourceStorage = resourceLoaderMap.get(resource.getBaseUrl()); + if (resourceStorage == null) { + resourceStorage = ResourceLoaderFactoryGetter.getResourceStorage( + classLoaderName, + resource.getBaseUrl()); + resourceLoaderMap.put(resource.getBaseUrl(), resourceStorage); } - if (resourceLoaderMap.containsKey(resourceLoader.getBaseUrl())) { + resourceStorage.add(resource.getName(), resource.getUrl(), resource::getBytes); + } + + @Override + public synchronized void addResource(ResourceLoader resourceLoader) throws Exception { + if(resourceLoader == null){ return; } - SameRootResourceStorage resourceStorage = ResourceLoaderFactoryGetter.getResourceStorage( - classLoaderName, - resourceLoader.getBaseUrl()); - resourceLoader.load(resourceStorage); - if(!resourceStorage.isEmpty()){ + SameRootResourceStorage resourceStorage = resourceLoaderMap.get(resourceLoader.getBaseUrl()); + if (resourceStorage == null) { + resourceStorage = ResourceLoaderFactoryGetter.getResourceStorage( + classLoaderName, + resourceLoader.getBaseUrl()); resourceLoaderMap.put(resourceLoader.getBaseUrl(), resourceStorage); } + resourceLoader.load(resourceStorage); } @Override diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/loader/ResourceLoader.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/loader/ResourceLoader.java index 17fb706..7b722d7 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/loader/ResourceLoader.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/loader/ResourceLoader.java @@ -34,6 +34,7 @@ public interface ResourceLoader extends AutoCloseable{ */ URL getBaseUrl(); + /** * 装载资源到ResourceStorage * @param resourceStorage 资源存储 diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/loader/ResourceLoaderFactory.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/loader/ResourceLoaderFactory.java index 195d9f9..60cedc8 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/loader/ResourceLoaderFactory.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/loader/ResourceLoaderFactory.java @@ -62,6 +62,13 @@ public interface ResourceLoaderFactory extends AutoCloseable { */ void addResource(URL url) throws Exception; + /** + * 根据 Resource 添加 + * @param resource 资源 + * @throws Exception 添加资源异常 + */ + void addResource(Resource resource) throws Exception; + /** * 根据资源加载器添加资源 * @param resourceLoader 资源加载者 diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/storage/CacheResourceStorage.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/storage/CacheResourceStorage.java index 9f3872f..a24a7c9 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/storage/CacheResourceStorage.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/storage/CacheResourceStorage.java @@ -32,8 +32,6 @@ import java.util.concurrent.ConcurrentHashMap; */ public class CacheResourceStorage extends DefaultResourceStorage{ - protected final Map resourceStorage = new ConcurrentHashMap<>(); - public CacheResourceStorage(URL baseUrl) { super(baseUrl); } diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/storage/EmptyResourceStorage.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/storage/EmptyResourceStorage.java index 5d248db..72b1984 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/storage/EmptyResourceStorage.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/storage/EmptyResourceStorage.java @@ -27,7 +27,7 @@ import java.util.List; * 空的资源存储 * * @author starBlues - * @version 3.0.4 + * @version 3.1.0 * @since 3.0.4 */ public class EmptyResourceStorage implements ResourceStorage{ diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/storage/ShareResourceStorage.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/storage/ShareResourceStorage.java index 6cd1cc9..ec61cf9 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/storage/ShareResourceStorage.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/classloader/resource/storage/ShareResourceStorage.java @@ -52,6 +52,11 @@ public class ShareResourceStorage extends DefaultResourceStorage{ super.addResource(name, shareResource); } + @Override + public void close() throws Exception { + super.close(); + } + private static class ShareResource extends DefaultResource { private final static Map BYTE_STORE_MAP = new ConcurrentHashMap<>(); @@ -73,7 +78,7 @@ public class ShareResourceStorage extends DefaultResourceStorage{ if(byteStore == null){ byteStore = new ByteStore(name); byteStore.addByte(key, bytes); - BYTE_STORE_MAP.put(getName(), byteStore); + BYTE_STORE_MAP.put(name, byteStore); } else { byteStore.addByte(key, bytes); } diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/AbstractJarFile.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/AbstractJarFile.java index ae88cdd..1e6f6f5 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/AbstractJarFile.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/AbstractJarFile.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,9 +25,9 @@ import java.net.URL; import java.security.Permission; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * Base class for extended variants of {@link java.util.jar.JarFile}. + * + * @author Phillip Webb */ public abstract class AbstractJarFile extends java.util.jar.JarFile{ diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/AsciiBytes.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/AsciiBytes.java index be75721..801719b 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/AsciiBytes.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/AsciiBytes.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,9 +20,11 @@ package com.gitee.starblues.loader.jar; import java.nio.charset.StandardCharsets; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * Simple wrapper around a byte array that represents an ASCII. Used for performance + * reasons to save constructing Strings for ZIP data. + * + * @author Phillip Webb + * @author Andy Wilkinson */ public class AsciiBytes { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/Bytes.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/Bytes.java index 6b19352..5f3dc3c 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/Bytes.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/Bytes.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,9 +18,9 @@ package com.gitee.starblues.loader.jar; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * Utilities for dealing with bytes from ZIP files. + * + * @author Phillip Webb */ public class Bytes { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/CentralDirectoryEndRecord.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/CentralDirectoryEndRecord.java index 3e941a3..49d86d3 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/CentralDirectoryEndRecord.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/CentralDirectoryEndRecord.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,9 +20,12 @@ package com.gitee.starblues.loader.jar; import java.io.IOException; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * A ZIP File "End of central directory record" (EOCD). + * + * @author Phillip Webb + * @author Andy Wilkinson + * @author Camille Vienot + * @see Zip File Format */ public class CentralDirectoryEndRecord { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/CentralDirectoryFileHeader.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/CentralDirectoryFileHeader.java index be3a473..a2a4d12 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/CentralDirectoryFileHeader.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/CentralDirectoryFileHeader.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,9 +25,12 @@ import java.time.temporal.ChronoUnit; import java.time.temporal.ValueRange; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * A ZIP File "Central directory file header record" (CDFH). + * + * @author Phillip Webb + * @author Andy Wilkinson + * @author Dmytro Nosan + * @see Zip File Format */ public class CentralDirectoryFileHeader implements FileHeader { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/CentralDirectoryParser.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/CentralDirectoryParser.java index e589c37..8548c4b 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/CentralDirectoryParser.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/CentralDirectoryParser.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,9 +22,11 @@ import java.util.ArrayList; import java.util.List; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * Parses the central directory from a JAR file. + * + * @author Phillip Webb + * @author Andy Wilkinson + * @see CentralDirectoryVisitor */ public class CentralDirectoryParser { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/CentralDirectoryVisitor.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/CentralDirectoryVisitor.java index 046120c..2f45f46 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/CentralDirectoryVisitor.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/CentralDirectoryVisitor.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,9 +18,9 @@ package com.gitee.starblues.loader.jar; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * Callback visitor triggered by {@link CentralDirectoryParser}. + * + * @author Phillip Webb */ public interface CentralDirectoryVisitor { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/FileHeader.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/FileHeader.java index 7c500e4..a360f64 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/FileHeader.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/FileHeader.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,9 +20,11 @@ package com.gitee.starblues.loader.jar; import java.util.zip.ZipEntry; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * A file header record that has been loaded from a Jar file. + * + * @author Phillip Webb + * @see JarEntry + * @see CentralDirectoryFileHeader */ public interface FileHeader { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/Handler.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/Handler.java index 558bb1b..e8f61ed 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/Handler.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/Handler.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -29,9 +30,12 @@ import java.util.logging.Logger; import java.util.regex.Pattern; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * {@link URLStreamHandler} for Spring Boot loader {@link JarFile}s. + * + * @author Phillip Webb + * @author Andy Wilkinson + * @since 1.0.0 + * @see JarFile#registerUrlProtocolHandler() */ public class Handler extends URLStreamHandler { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarEntry.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarEntry.java index b5c0a7c..165e79d 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarEntry.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarEntry.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,9 +26,10 @@ import java.util.jar.Attributes; import java.util.jar.Manifest; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * Extended variant of {@link java.util.jar.JarEntry} returned by {@link JarFile}s. + * + * @author Phillip Webb + * @author Andy Wilkinson */ public class JarEntry extends java.util.jar.JarEntry implements FileHeader { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarEntryCertification.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarEntryCertification.java index 2313ef8..2ba0a16 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarEntryCertification.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarEntryCertification.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,9 +21,10 @@ import java.security.CodeSigner; import java.security.cert.Certificate; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * {@link Certificate} and {@link CodeSigner} details for a {@link JarEntry} from a signed + * {@link JarFile}. + * + * @author Phillip Webb */ public class JarEntryCertification { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarEntryFilter.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarEntryFilter.java index defa225..e6990e7 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarEntryFilter.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarEntryFilter.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,9 +18,9 @@ package com.gitee.starblues.loader.jar; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * Interface that can be used to filter and optionally rename jar entries. + * + * @author Phillip Webb */ public interface JarEntryFilter { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarFile.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarFile.java index e22c64d..a02274b 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarFile.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarFile.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -37,9 +38,18 @@ import java.util.stream.StreamSupport; import java.util.zip.ZipEntry; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * Extended variant of {@link java.util.jar.JarFile} that behaves in the same way but + * offers the following additional functionality. + *
    + *
  • A nested {@link JarFile} can be {@link #getNestedJarFile(ZipEntry) obtained} based + * on any directory entry.
  • + *
  • A nested {@link JarFile} can be {@link #getNestedJarFile(ZipEntry) obtained} for + * embedded JAR files (as long as their entry is not compressed).
  • + *
+ * + * @author Phillip Webb + * @author Andy Wilkinson + * @since 1.0.0 */ public class JarFile extends AbstractJarFile implements Iterable { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarFileEntries.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarFileEntries.java index 9a45c20..bb43d83 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarFileEntries.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarFileEntries.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,9 +26,18 @@ import java.util.jar.Manifest; import java.util.zip.ZipEntry; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * Provides access to entries from a {@link JarFile}. In order to reduce memory + * consumption entry details are stored using arrays. The {@code hashCodes} array stores + * the hash code of the entry name, the {@code centralDirectoryOffsets} provides the + * offset to the central directory record and {@code positions} provides the original + * order position of the entry. The arrays are stored in hashCode order so that a binary + * search can be used to find a name. + *

+ * A typical Spring Boot application will have somewhere in the region of 10,500 entries + * which should consume about 122K. + * + * @author Phillip Webb + * @author Andy Wilkinson */ public class JarFileEntries implements CentralDirectoryVisitor, Iterable { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarFileWrapper.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarFileWrapper.java index 212f4c4..46d6d21 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarFileWrapper.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarFileWrapper.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -34,9 +35,10 @@ import java.util.zip.ZipEntry; import com.gitee.starblues.loader.utils.ObjectUtils; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * A wrapper used to create a copy of a {@link JarFile} so that it can be safely closed + * without closing the original. + * + * @author Phillip Webb */ public class JarFileWrapper extends AbstractJarFile { @@ -132,6 +134,7 @@ public class JarFileWrapper extends AbstractJarFile { @Override public void close() throws IOException { super.close(); + // Modified Added close logic if(canClosed.get()){ for (List inputStreams : inputStreamCache.values()) { if(ObjectUtils.isEmpty(inputStreams)){ @@ -144,7 +147,8 @@ public class JarFileWrapper extends AbstractJarFile { IOUtils.closeQuietly(inputStream); } } - parent.close(); + IOUtils.closeQuietly(parent); + inputStreamCache.clear(); } } diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarURLConnection.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarURLConnection.java index b2aec95..5dce1fd 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarURLConnection.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/JarURLConnection.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,9 +25,11 @@ import java.net.*; import java.security.Permission; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * {@link java.net.JarURLConnection} used to support {@link JarFile#getUrl()}. + * + * @author Phillip Webb + * @author Andy Wilkinson + * @author Rostyslav Dudka */ public class JarURLConnection extends java.net.JarURLConnection { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/RandomAccessData.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/RandomAccessData.java index 52bc260..1c25ec0 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/RandomAccessData.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/RandomAccessData.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,9 +22,11 @@ import java.io.IOException; import java.io.InputStream; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * Interface that provides read-only random access to some underlying data. + * Implementations must allow concurrent reads in a thread-safe manner. + * + * @author Phillip Webb + * @since 1.0.0 */ public interface RandomAccessData { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/RandomAccessDataFile.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/RandomAccessDataFile.java index 8c97592..7f671af 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/RandomAccessDataFile.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/RandomAccessDataFile.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,9 +20,11 @@ package com.gitee.starblues.loader.jar; import java.io.*; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * {@link RandomAccessData} implementation backed by a {@link RandomAccessFile}. + * + * @author Phillip Webb + * @author Andy Wilkinson + * @since 1.0.0 */ public class RandomAccessDataFile implements RandomAccessData{ diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/StringSequence.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/StringSequence.java index 0cc1e81..7b2c1f7 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/StringSequence.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/StringSequence.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,9 +20,11 @@ package com.gitee.starblues.loader.jar; import java.util.Objects; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * A {@link CharSequence} backed by a single shared {@link String}. Unlike a regular + * {@link String}, {@link #subSequence(int, int)} operations will not copy the underlying + * character array. + * + * @author Phillip Webb */ public class StringSequence implements CharSequence { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/ZipInflaterInputStream.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/ZipInflaterInputStream.java index 05c8bf4..e4192f1 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/ZipInflaterInputStream.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/jar/ZipInflaterInputStream.java @@ -1,11 +1,12 @@ -/** - * Copyright [2019-2022] [starBlues] +/* + * Copyright 2012-2021 the original author or authors. + * Copy from spring-boot-loader * * 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 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,9 +24,10 @@ import java.util.zip.Inflater; import java.util.zip.InflaterInputStream; /** - * copy from spring-boot-loader - * @author starBlues - * @version 3.0.0 + * {@link InflaterInputStream} that supports the writing of an extra "dummy" byte (which + * is required with JDK 6) and returns accurate available() results. + * + * @author Phillip Webb */ public class ZipInflaterInputStream extends InflaterInputStream { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/DevLauncher.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/DevLauncher.java index cc112ab..2cac0c7 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/DevLauncher.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/DevLauncher.java @@ -26,7 +26,7 @@ import lombok.AllArgsConstructor; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 */ @AllArgsConstructor public class DevLauncher implements Launcher{ 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 11f08c6..2d2ee5d 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 @@ -23,7 +23,7 @@ import com.gitee.starblues.loader.DevelopmentMode; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 */ public class DevelopmentModeSetting { 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 34117cc..33d34ea 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 @@ -40,7 +40,7 @@ import static com.gitee.starblues.loader.LoaderConstant.*; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 */ public class ProdLauncher implements Launcher{ diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/classpath/ClasspathResource.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/classpath/ClasspathResource.java index e390b5d..cd296e5 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/classpath/ClasspathResource.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/classpath/ClasspathResource.java @@ -24,7 +24,7 @@ import java.util.List; * 获取classpath资源路径 * * @author starBlues - * @version 3.0.4 + * @version 3.1.0 * @since 3.0.4 */ public interface ClasspathResource { diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/classpath/FastJarClasspathResource.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/classpath/FastJarClasspathResource.java index ab18378..a15ad9d 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/classpath/FastJarClasspathResource.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/classpath/FastJarClasspathResource.java @@ -35,7 +35,7 @@ import static com.gitee.starblues.loader.LoaderConstant.PROD_LIB_PATH; * fast jar 类型的 classpath 获取者 * * @author starBlues - * @version 3.0.4 + * @version 3.1.0 * @since 3.0.4 */ @AllArgsConstructor diff --git a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/classpath/JarOutClasspathResource.java b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/classpath/JarOutClasspathResource.java index 0b94363..69dab01 100644 --- a/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/classpath/JarOutClasspathResource.java +++ b/spring-brick-loader/src/main/java/com/gitee/starblues/loader/launcher/classpath/JarOutClasspathResource.java @@ -36,7 +36,7 @@ import static com.gitee.starblues.loader.LoaderConstant.*; * jar out 类型的 classpath 获取者 * * @author starBlues - * @version 3.0.4 + * @version 3.1.0 * @since 3.0.4 */ @AllArgsConstructor 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 2ce521e..c7fffbf 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 @@ -26,7 +26,7 @@ import com.gitee.starblues.loader.launcher.runner.MethodRunner; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 */ public class CoexistBaseLauncher extends AbstractMainLauncher { 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 6cbd1f1..719f2a5 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 @@ -46,11 +46,6 @@ public class ResourceLoaderFactoryGetter { private static final String RESOURCE_MODE_CACHE_SHARE = "cache-share"; - /** - * 资源模式--不缓存模式 - */ - private static final String RESOURCE_MODE_NO_CACHE = "no-cache"; - private static volatile String resourceMode; @@ -83,12 +78,9 @@ public class ResourceLoaderFactoryGetter { if(Objects.equals(resourceMode, RESOURCE_MODE_CACHE_ISOLATION)){ // 资源可缓存, 且隔离 resourceStorage = new CacheResourceStorage(baseUrl); - } else if(Objects.equals(resourceMode, RESOURCE_MODE_CACHE_SHARE)){ + } else { // 资源可缓存, 共享式 resourceStorage = new ShareResourceStorage(key, baseUrl); - } else { - // 资源不缓存 - resourceStorage = new DefaultResourceStorage(baseUrl); } return resourceStorage; } diff --git a/spring-brick-maven-packager/pom.xml b/spring-brick-maven-packager/pom.xml index dd87002..cacdf5d 100644 --- a/spring-brick-maven-packager/pom.xml +++ b/spring-brick-maven-packager/pom.xml @@ -7,7 +7,7 @@ spring-brick-parent com.gitee.starblues - 3.0.4 + 3.1.0 spring-brick-maven-packager diff --git a/spring-brick-maven-packager/src/main/resources/META-INF/maven/com.gitee.starblues.springboot-plugin-maven-packager/plugin-help.xml b/spring-brick-maven-packager/src/main/resources/META-INF/maven/com.gitee.starblues.springboot-plugin-maven-packager/plugin-help.xml index c2b84e8..0e203ae 100644 --- a/spring-brick-maven-packager/src/main/resources/META-INF/maven/com.gitee.starblues.springboot-plugin-maven-packager/plugin-help.xml +++ b/spring-brick-maven-packager/src/main/resources/META-INF/maven/com.gitee.starblues.springboot-plugin-maven-packager/plugin-help.xml @@ -4,7 +4,7 @@ Spring Boot Plugin Maven Packager com.gitee.starblues spring-brick-maven-packager - 3.0.4 + 3.1.0 spring-brick-packager false true diff --git a/spring-brick-maven-packager/src/main/resources/META-INF/maven/plugin.xml b/spring-brick-maven-packager/src/main/resources/META-INF/maven/plugin.xml index c2b84e8..0e203ae 100644 --- a/spring-brick-maven-packager/src/main/resources/META-INF/maven/plugin.xml +++ b/spring-brick-maven-packager/src/main/resources/META-INF/maven/plugin.xml @@ -4,7 +4,7 @@ Spring Boot Plugin Maven Packager com.gitee.starblues spring-brick-maven-packager - 3.0.4 + 3.1.0 spring-brick-packager false true diff --git a/spring-brick/pom.xml b/spring-brick/pom.xml index 0f86efc..9118a92 100644 --- a/spring-brick/pom.xml +++ b/spring-brick/pom.xml @@ -7,7 +7,7 @@ spring-brick-parent com.gitee.starblues - 3.0.4 + 3.1.0 spring-brick diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/DefaultPluginInsideInfo.java b/spring-brick/src/main/java/com/gitee/starblues/core/DefaultPluginInsideInfo.java index 1f56225..c1374eb 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/DefaultPluginInsideInfo.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/DefaultPluginInsideInfo.java @@ -18,8 +18,11 @@ package com.gitee.starblues.core; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; import com.gitee.starblues.utils.Assert; +import lombok.Setter; import java.util.Date; +import java.util.Map; +import java.util.function.Supplier; /** * 默认的内部PluginWrapperInside实现 @@ -36,6 +39,8 @@ public class DefaultPluginInsideInfo implements PluginInsideInfo { private Date startTime; private Date stopTime; + private Supplier> extensionInfoSupplier; + public DefaultPluginInsideInfo(InsidePluginDescriptor pluginDescriptor) { this.pluginId = pluginDescriptor.getPluginId(); this.pluginDescriptor = pluginDescriptor; @@ -52,6 +57,16 @@ public class DefaultPluginInsideInfo implements PluginInsideInfo { isFollowInitial = true; } + @Override + public void setExtensionInfoSupplier(Supplier> supplier) { + this.extensionInfoSupplier = supplier; + } + + @Override + public Supplier> getExtensionInfoSupplier() { + return extensionInfoSupplier; + } + @Override public String getPluginId() { return pluginId; @@ -92,6 +107,11 @@ public class DefaultPluginInsideInfo implements PluginInsideInfo { return isFollowInitial; } + @Override + public Map getExtensionInfo() { + return extensionInfoSupplier.get(); + } + private void resolveTime(PluginState pluginState){ if(pluginState == PluginState.STARTED || pluginState == PluginState.STARTED_FAILURE){ startTime = new Date(); diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/DefaultPluginManager.java b/spring-brick/src/main/java/com/gitee/starblues/core/DefaultPluginManager.java index 27237f4..047dc45 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/DefaultPluginManager.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/DefaultPluginManager.java @@ -49,7 +49,7 @@ import java.util.stream.Collectors; /** * 抽象的插件管理者 * @author starBlues - * @version 3.0.4 + * @version 3.1.0 * @since 3.0.0 */ public class DefaultPluginManager implements PluginManager{ @@ -270,7 +270,7 @@ public class DefaultPluginManager implements PluginManager{ PluginInfo pluginInfo = wrapperInside.toPluginInfo(); if(wrapperInside.getPluginState() == PluginState.STARTED){ try { - stop(wrapperInside); + stop(wrapperInside, true); pluginListenerFactory.stopSuccess(pluginInfo); } catch (Throwable e) { PluginException pluginException = PluginException.getPluginException(e, @@ -356,7 +356,7 @@ public class DefaultPluginManager implements PluginManager{ } PluginInfo pluginInfo = pluginInsideInfo.toPluginInfo(); try { - stop(pluginInsideInfo); + stop(pluginInsideInfo, false); log.info("停止插件[{}]成功", MsgUtils.getPluginUnique(pluginInsideInfo.getPluginDescriptor())); pluginListenerFactory.stopSuccess(pluginInfo); return pluginInfo; @@ -538,9 +538,10 @@ public class DefaultPluginManager implements PluginManager{ /** * 统一停止插件操作 * @param pluginInsideInfo PluginInsideInfo + * @param isUninstall 是否为卸载停止 * @throws Exception 启动异常 */ - protected void stop(PluginInsideInfo pluginInsideInfo) throws Exception{ + protected void stop(PluginInsideInfo pluginInsideInfo, boolean isUninstall) throws Exception{ launcherChecker.checkCanStop(pluginInsideInfo); pluginInsideInfo.setPluginState(PluginState.STOPPED); stopFinish(pluginInsideInfo); diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/PluginExtensionInfo.java b/spring-brick/src/main/java/com/gitee/starblues/core/PluginExtensionInfo.java new file mode 100644 index 0000000..a741d01 --- /dev/null +++ b/spring-brick/src/main/java/com/gitee/starblues/core/PluginExtensionInfo.java @@ -0,0 +1,21 @@ +package com.gitee.starblues.core; + +import java.util.Map; + +/** + * 自主实现插件的扩展信息 + * + * @author starBlues + * @version 3.1.0 + * @since 3.1.0 + */ +public interface PluginExtensionInfo { + + /** + * 实现返回扩展信息 + * @return 扩展信息Map + */ + Map extensionInfo(); + + +} diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/PluginInfo.java b/spring-brick/src/main/java/com/gitee/starblues/core/PluginInfo.java index 851d1f8..9cf4d18 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/PluginInfo.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/PluginInfo.java @@ -19,6 +19,7 @@ package com.gitee.starblues.core; import com.gitee.starblues.core.descriptor.PluginDescriptor; import java.util.Date; +import java.util.Map; /** * 插件信息 @@ -63,11 +64,16 @@ public interface PluginInfo { */ Date getStopTime(); - /** * 是否跟随系统启动而加载的插件 * @return true: 是, false: 否 */ boolean isFollowSystem(); + /** + * 获取插件自主扩展信息 + * @return 扩展信息Map + */ + Map getExtensionInfo(); + } diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/PluginInfoFace.java b/spring-brick/src/main/java/com/gitee/starblues/core/PluginInfoFace.java index 0822f84..d0d53d7 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/PluginInfoFace.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/PluginInfoFace.java @@ -20,6 +20,8 @@ import com.gitee.starblues.core.descriptor.PluginDescriptor; import com.gitee.starblues.utils.Assert; import java.util.Date; +import java.util.Map; +import java.util.function.Supplier; /** * 外部 PluginWrapperFace @@ -31,6 +33,7 @@ public class PluginInfoFace implements PluginInfo { private final PluginDescriptor pluginDescriptor; private final PluginState pluginState; private final boolean followSystem; + private final Supplier> extensionInfoSupplier; private final Date startTime; private final Date stopTime; @@ -40,6 +43,7 @@ public class PluginInfoFace implements PluginInfo { this.pluginDescriptor = pluginInsideInfo.getPluginDescriptor().toPluginDescriptor(); this.pluginState = pluginInsideInfo.getPluginState(); this.followSystem = pluginInsideInfo.isFollowSystem(); + this.extensionInfoSupplier = pluginInsideInfo.getExtensionInfoSupplier(); this.startTime = pluginInsideInfo.getStartTime(); this.stopTime = pluginInsideInfo.getStopTime(); } @@ -78,4 +82,9 @@ public class PluginInfoFace implements PluginInfo { public boolean isFollowSystem() { return followSystem; } + + @Override + public Map getExtensionInfo() { + return extensionInfoSupplier.get(); + } } diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/PluginInsideInfo.java b/spring-brick/src/main/java/com/gitee/starblues/core/PluginInsideInfo.java index 1c2a39c..0d7d7d6 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/PluginInsideInfo.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/PluginInsideInfo.java @@ -18,9 +18,14 @@ package com.gitee.starblues.core; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; +import java.util.Map; +import java.util.function.Supplier; + /** * 内部的 PluginInfo - * @version 3.0.0 + * + * @since 3.0.0 + * @version 3.1.0 * @author starBlues */ public interface PluginInsideInfo extends PluginInfo { @@ -36,6 +41,18 @@ public interface PluginInsideInfo extends PluginInfo { */ void setFollowSystem(); + /** + * 设置插件扩展信息 + * @param supplier 插件扩展信息自主提供者 + */ + void setExtensionInfoSupplier(Supplier> supplier); + + /** + * 获取插件信息提供者 + * @return 插件扩展信息自主提供者 + */ + Supplier> getExtensionInfoSupplier(); + /** * 得到插件描述 * @return PluginDescriptor diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/PluginLauncherManager.java b/spring-brick/src/main/java/com/gitee/starblues/core/PluginLauncherManager.java index ae87521..c64a2b1 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/PluginLauncherManager.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/PluginLauncherManager.java @@ -97,13 +97,15 @@ public class PluginLauncherManager extends DefaultPluginManager{ launcherChecker.checkCanStart(pluginInsideInfo); try { InsidePluginDescriptor pluginDescriptor = pluginInsideInfo.getPluginDescriptor(); - PluginInteractive pluginInteractive = new DefaultPluginInteractive(pluginDescriptor, + PluginInteractive pluginInteractive = new DefaultPluginInteractive(pluginInsideInfo, mainApplicationContext, configuration, invokeSupperCache); AbstractLauncher pluginLauncher; if(DevelopmentModeSetting.isolation()){ pluginLauncher = new PluginIsolationLauncher(pluginInteractive, pluginLaunchInvolved); - } else { + } else if(DevelopmentModeSetting.coexist()){ pluginLauncher = new PluginCoexistLauncher(pluginInteractive, pluginLaunchInvolved); + } else { + throw DevelopmentModeSetting.getUnknownModeException(); } SpringPluginHook springPluginHook = pluginLauncher.run(); RegistryPluginInfo registryPluginInfo = new RegistryPluginInfo(pluginDescriptor, springPluginHook); @@ -117,11 +119,8 @@ public class PluginLauncherManager extends DefaultPluginManager{ } } - - - @Override - protected void stop(PluginInsideInfo pluginInsideInfo) throws Exception { + protected void stop(PluginInsideInfo pluginInsideInfo, boolean isUninstall) throws Exception { String pluginId = pluginInsideInfo.getPluginId(); RegistryPluginInfo registryPluginInfo = registryInfo.get(pluginId); if(registryPluginInfo == null){ @@ -130,10 +129,10 @@ public class PluginLauncherManager extends DefaultPluginManager{ try { SpringPluginHook springPluginHook = registryPluginInfo.getSpringPluginHook(); springPluginHook.stopVerify(); - springPluginHook.close(); + springPluginHook.close(isUninstall); invokeSupperCache.remove(pluginId); registryInfo.remove(pluginId); - super.stop(pluginInsideInfo); + super.stop(pluginInsideInfo, isUninstall); } catch (Exception e){ if(e instanceof PluginProhibitStopException){ // 禁止停止时, 不设置插件状态 diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/classloader/ComposeMainResourceMatcher.java b/spring-brick/src/main/java/com/gitee/starblues/core/classloader/ComposeMainResourceMatcher.java index c993535..e8206bf 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/classloader/ComposeMainResourceMatcher.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/classloader/ComposeMainResourceMatcher.java @@ -16,6 +16,7 @@ package com.gitee.starblues.core.classloader; +import com.gitee.starblues.loader.utils.IOUtils; import com.gitee.starblues.utils.ObjectUtils; import java.util.ArrayList; @@ -27,7 +28,7 @@ import java.util.List; * @author starBlues * @version 3.0.3 */ -public class ComposeMainResourceMatcher implements MainResourceMatcher{ +public class ComposeMainResourceMatcher implements MainResourceMatcher, AutoCloseable{ private final List resourceMatchers; @@ -59,4 +60,13 @@ public class ComposeMainResourceMatcher implements MainResourceMatcher{ } return Boolean.FALSE; } + + @Override + public void close() throws Exception { + for (MainResourceMatcher resourceMatcher : resourceMatchers) { + if(resourceMatcher instanceof AutoCloseable){ + IOUtils.closeQuietly((AutoCloseable)resourceMatcher); + } + } + } } diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/classloader/NestedPluginJarResourceLoader.java b/spring-brick/src/main/java/com/gitee/starblues/core/classloader/NestedPluginJarResourceLoader.java index 628c96b..df179b0 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/classloader/NestedPluginJarResourceLoader.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/classloader/NestedPluginJarResourceLoader.java @@ -39,7 +39,7 @@ import java.util.zip.ZipEntry; * 嵌套插件jar加载者 * @author starBlues * @since 3.0.0 - * @version 3.0.4 + * @version 3.1.0 */ @Slf4j public class NestedPluginJarResourceLoader extends AbstractResourceLoader { @@ -80,7 +80,7 @@ public class NestedPluginJarResourceLoader extends AbstractResourceLoader { } String realName = jarEntry.getName().replace(classesPath, ""); URL url = new URL(baseUrl.toString() + jarEntry.getName()); - resourceLoaderFactory.addResource(url); + resourceLoaderFactory.addResource(new DefaultResource(realName, baseUrl, url)); resourceStorage.add(realName, url, ()->{ return getClassBytes(realName, jarFile.getInputStream(jarEntry), true); }); diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/classloader/PluginClassLoader.java b/spring-brick/src/main/java/com/gitee/starblues/core/classloader/PluginClassLoader.java index f26ece9..11ab94c 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/classloader/PluginClassLoader.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/classloader/PluginClassLoader.java @@ -21,7 +21,9 @@ import com.gitee.starblues.core.descriptor.PluginLibInfo; import com.gitee.starblues.core.descriptor.PluginType; import com.gitee.starblues.core.exception.PluginException; import com.gitee.starblues.loader.classloader.*; +import com.gitee.starblues.loader.classloader.resource.Resource; import com.gitee.starblues.loader.classloader.resource.loader.ResourceLoaderFactory; +import com.gitee.starblues.loader.utils.IOUtils; import com.gitee.starblues.utils.Assert; import com.gitee.starblues.utils.FilesUtils; import com.gitee.starblues.utils.MsgUtils; @@ -56,10 +58,6 @@ public class PluginClassLoader extends GenericClassLoader implements PluginResou this.proxy = new PluginResourceLoaderFactoryProxy(resourceLoaderFactory, parentClassLoader); } - public MainResourceMatcher getMainResourceMatcher() { - return mainResourceMatcher; - } - @Override public void addResource(InsidePluginDescriptor descriptor) throws Exception { proxy.addResource(descriptor); @@ -117,4 +115,5 @@ public class PluginClassLoader extends GenericClassLoader implements PluginResou } } + } diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/classloader/PluginGeneralUrlClassLoader.java b/spring-brick/src/main/java/com/gitee/starblues/core/classloader/PluginGeneralUrlClassLoader.java index e93e7fa..1326662 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/classloader/PluginGeneralUrlClassLoader.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/classloader/PluginGeneralUrlClassLoader.java @@ -18,13 +18,16 @@ package com.gitee.starblues.core.classloader; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; import com.gitee.starblues.loader.classloader.GeneralUrlClassLoader; +import com.gitee.starblues.loader.utils.IOUtils; import lombok.extern.slf4j.Slf4j; +import java.io.IOException; + /** * 插件基本 url classLoader * * @author starBlues - * @version 3.0.4 + * @version 3.1.0 * @since 3.0.4 */ @Slf4j @@ -42,4 +45,8 @@ public class PluginGeneralUrlClassLoader extends GeneralUrlClassLoader implement proxy.addResource(descriptor); } + @Override + public void close() throws IOException { + super.close(); + } } diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/classloader/PluginResourceLoaderFactory.java b/spring-brick/src/main/java/com/gitee/starblues/core/classloader/PluginResourceLoaderFactory.java index 64e7089..3be839a 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/classloader/PluginResourceLoaderFactory.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/classloader/PluginResourceLoaderFactory.java @@ -23,7 +23,7 @@ import com.gitee.starblues.loader.classloader.resource.loader.ResourceLoaderFact * 插件资源工程 * * @author starBlues - * @version 3.0.4 + * @version 3.1.0 * @since 3.0.4 */ public interface PluginResourceLoaderFactory extends ResourceLoaderFactory { diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/classloader/PluginResourceLoaderFactoryProxy.java b/spring-brick/src/main/java/com/gitee/starblues/core/classloader/PluginResourceLoaderFactoryProxy.java index a3839ef..10143b8 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/classloader/PluginResourceLoaderFactoryProxy.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/classloader/PluginResourceLoaderFactoryProxy.java @@ -40,7 +40,7 @@ import java.util.Set; * 插件资源加载工厂代理 * * @author starBlues - * @version 3.0.4 + * @version 3.1.0 * @since 13.0.4 */ @Slf4j @@ -145,6 +145,11 @@ public class PluginResourceLoaderFactoryProxy implements PluginResourceLoaderFac target.addResource(url); } + @Override + public void addResource(Resource resource) throws Exception { + target.addResource(resource); + } + @Override public void addResource(ResourceLoader resourceLoader) throws Exception { target.addResource(resourceLoader); diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/DefaultPluginInteractive.java b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/DefaultPluginInteractive.java index c26810d..a9249b8 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/DefaultPluginInteractive.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/DefaultPluginInteractive.java @@ -16,6 +16,7 @@ package com.gitee.starblues.core.launcher.plugin; +import com.gitee.starblues.core.PluginInsideInfo; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; import com.gitee.starblues.integration.IntegrationConfiguration; import com.gitee.starblues.spring.MainApplicationContext; @@ -31,17 +32,17 @@ import com.gitee.starblues.spring.invoke.InvokeSupperCache; */ public class DefaultPluginInteractive implements PluginInteractive{ - private final InsidePluginDescriptor pluginDescriptor; + private final PluginInsideInfo pluginInsideInfo; private final MainApplicationContext mainApplicationContext; private final IntegrationConfiguration configuration; private final InvokeSupperCache invokeSupperCache; private final OpExtractFactory opExtractFactory; - public DefaultPluginInteractive(InsidePluginDescriptor pluginDescriptor, + public DefaultPluginInteractive(PluginInsideInfo pluginInsideInfo, MainApplicationContext mainApplicationContext, IntegrationConfiguration configuration, InvokeSupperCache invokeSupperCache) { - this.pluginDescriptor = pluginDescriptor; + this.pluginInsideInfo = pluginInsideInfo; this.mainApplicationContext = mainApplicationContext; this.configuration = configuration; this.invokeSupperCache = invokeSupperCache; @@ -53,10 +54,14 @@ public class DefaultPluginInteractive implements PluginInteractive{ return (OpExtractFactory) defaultExtractFactory.getTarget(); } - @Override public InsidePluginDescriptor getPluginDescriptor() { - return pluginDescriptor; + return pluginInsideInfo.getPluginDescriptor(); + } + + @Override + public PluginInsideInfo getPluginInsideInfo() { + return pluginInsideInfo; } @Override diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/PluginCoexistLauncher.java b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/PluginCoexistLauncher.java index 5b8f502..3bb4d27 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/PluginCoexistLauncher.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/PluginCoexistLauncher.java @@ -1,5 +1,6 @@ package com.gitee.starblues.core.launcher.plugin; +import com.gitee.starblues.core.PluginInsideInfo; import com.gitee.starblues.core.classloader.NestedPluginJarResourceLoader; import com.gitee.starblues.core.classloader.PluginGeneralUrlClassLoader; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; @@ -24,7 +25,7 @@ import java.util.Set; * * @author starBlues * @since 3.0.4 - * @version 3.0.4 + * @version 3.1.0 */ @Slf4j public class PluginCoexistLauncher extends AbstractLauncher { @@ -50,17 +51,18 @@ public class PluginCoexistLauncher extends AbstractLauncher { @Override protected SpringPluginHook launch(ClassLoader classLoader, String... args) throws Exception { InsidePluginDescriptor pluginDescriptor = pluginInteractive.getPluginDescriptor(); - pluginLaunchInvolved.before(pluginDescriptor, classLoader); + PluginInsideInfo pluginInsideInfo = pluginInteractive.getPluginInsideInfo(); + pluginLaunchInvolved.before(pluginInsideInfo, classLoader); try { SpringPluginHook springPluginHook = (SpringPluginHook) new PluginMethodRunner(pluginInteractive) .run(classLoader); if(springPluginHook == null){ throw new PluginException("插件返回的 SpringPluginHook 不能为空"); } - pluginLaunchInvolved.after(pluginDescriptor, classLoader, springPluginHook); - return new SpringPluginHookWrapper(springPluginHook, pluginDescriptor, pluginLaunchInvolved, classLoader); + pluginLaunchInvolved.after(pluginInsideInfo, classLoader, springPluginHook); + return new SpringPluginHookWrapper(springPluginHook, pluginInsideInfo, pluginLaunchInvolved, classLoader); } catch (Throwable throwable){ - pluginLaunchInvolved.failure(pluginDescriptor,classLoader, throwable); + pluginLaunchInvolved.failure(pluginInsideInfo,classLoader, throwable); throw throwable; } } diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/PluginInteractive.java b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/PluginInteractive.java index e9e87e1..2278ca5 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/PluginInteractive.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/PluginInteractive.java @@ -16,6 +16,7 @@ package com.gitee.starblues.core.launcher.plugin; +import com.gitee.starblues.core.PluginInsideInfo; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; import com.gitee.starblues.integration.IntegrationConfiguration; import com.gitee.starblues.spring.MainApplicationContext; @@ -35,6 +36,12 @@ public interface PluginInteractive { */ InsidePluginDescriptor getPluginDescriptor(); + /** + * 获取插件内部信息 + * @return PluginInsideInfo + */ + PluginInsideInfo getPluginInsideInfo(); + /** * 获取主程序的 MainApplicationContext * @return MainApplicationContext 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 af1baad..9041233 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,6 +16,7 @@ package com.gitee.starblues.core.launcher.plugin; +import com.gitee.starblues.core.PluginInsideInfo; import com.gitee.starblues.core.classloader.*; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; import com.gitee.starblues.core.launcher.plugin.involved.PluginLaunchInvolved; @@ -39,14 +40,14 @@ import java.util.WeakHashMap; * * @author starBlues * @since 3.0.0 - * @version 3.0.4 + * @version 3.1.0 */ public class PluginIsolationLauncher extends AbstractLauncher { private static final Map CLASS_LOADER_CACHE = new WeakHashMap<>(); protected final PluginInteractive pluginInteractive; - protected final InsidePluginDescriptor pluginDescriptor; + protected final PluginInsideInfo pluginInsideInfo; protected final MainResourceMatcher mainResourceMatcher; protected final PluginLaunchInvolved pluginLaunchInvolved; @@ -54,7 +55,7 @@ public class PluginIsolationLauncher extends AbstractLauncher public PluginIsolationLauncher(PluginInteractive pluginInteractive, PluginLaunchInvolved pluginLaunchInvolved) { this.pluginInteractive = pluginInteractive; - this.pluginDescriptor = pluginInteractive.getPluginDescriptor(); + this.pluginInsideInfo = pluginInteractive.getPluginInsideInfo(); this.mainResourceMatcher = getMainResourceMatcher(pluginInteractive); this.pluginLaunchInvolved = pluginLaunchInvolved; } @@ -76,13 +77,13 @@ public class PluginIsolationLauncher extends AbstractLauncher @Override protected ClassLoader createClassLoader(String... args) throws Exception { PluginClassLoader pluginClassLoader = getPluginClassLoader(); - pluginClassLoader.addResource(pluginDescriptor); + pluginClassLoader.addResource(pluginInsideInfo.getPluginDescriptor()); return pluginClassLoader; } protected synchronized PluginClassLoader getPluginClassLoader() throws Exception { - String pluginId = pluginDescriptor.getPluginId(); - String key = MsgUtils.getPluginUnique(pluginDescriptor); + String pluginId = pluginInsideInfo.getPluginId(); + String key = MsgUtils.getPluginUnique(pluginInsideInfo.getPluginDescriptor()); PluginClassLoader classLoader = CLASS_LOADER_CACHE.get(key); if(classLoader != null){ return classLoader; @@ -95,7 +96,7 @@ public class PluginIsolationLauncher extends AbstractLauncher } protected ResourceLoaderFactory getResourceLoaderFactory(){ - return new DefaultResourceLoaderFactory(pluginDescriptor.getPluginId()); + return new DefaultResourceLoaderFactory(pluginInsideInfo.getPluginId()); } protected GenericClassLoader getParentClassLoader() throws Exception { @@ -109,14 +110,14 @@ public class PluginIsolationLauncher extends AbstractLauncher @Override protected SpringPluginHook launch(ClassLoader classLoader, String... args) throws Exception { - pluginLaunchInvolved.before(pluginDescriptor, classLoader); + pluginLaunchInvolved.before(pluginInsideInfo, classLoader); try { SpringPluginHook springPluginHook = (SpringPluginHook) new PluginMethodRunner(pluginInteractive) .run(classLoader); - pluginLaunchInvolved.after(pluginDescriptor, classLoader, springPluginHook); - return new SpringPluginHookWrapper(springPluginHook, pluginDescriptor, pluginLaunchInvolved, classLoader); + pluginLaunchInvolved.after(pluginInsideInfo, classLoader, springPluginHook); + return new SpringPluginHookWrapper(springPluginHook, pluginInsideInfo, pluginLaunchInvolved, classLoader); } catch (Throwable throwable){ - pluginLaunchInvolved.failure(pluginDescriptor,classLoader, throwable); + pluginLaunchInvolved.failure(pluginInsideInfo,classLoader, throwable); throw throwable; } } diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/SpringPluginHookWrapper.java b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/SpringPluginHookWrapper.java index e25ac5f..3ccdf43 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/SpringPluginHookWrapper.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/SpringPluginHookWrapper.java @@ -16,6 +16,7 @@ package com.gitee.starblues.core.launcher.plugin; +import com.gitee.starblues.core.PluginInsideInfo; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; import com.gitee.starblues.core.exception.PluginProhibitStopException; import com.gitee.starblues.core.launcher.plugin.involved.PluginLaunchInvolved; @@ -24,24 +25,26 @@ import com.gitee.starblues.spring.SpringPluginHook; import com.gitee.starblues.spring.WebConfig; import com.gitee.starblues.spring.web.thymeleaf.ThymeleafConfig; import com.gitee.starblues.utils.ResourceUtils; +import lombok.extern.slf4j.Slf4j; /** * SpringPluginHook-Wrapper * @author starBlues * @version 3.0.0 */ +@Slf4j public class SpringPluginHookWrapper implements SpringPluginHook { private final SpringPluginHook target; - private final InsidePluginDescriptor descriptor; + private final PluginInsideInfo pluginInsideInfo; private final PluginLaunchInvolved pluginLaunchInvolved; private final ClassLoader classLoader; - public SpringPluginHookWrapper(SpringPluginHook target, InsidePluginDescriptor descriptor, + public SpringPluginHookWrapper(SpringPluginHook target, PluginInsideInfo pluginInsideInfo, PluginLaunchInvolved pluginLaunchInvolved, ClassLoader classLoader) { this.target = target; - this.descriptor = descriptor; + this.pluginInsideInfo = pluginInsideInfo; this.pluginLaunchInvolved = pluginLaunchInvolved; this.classLoader = classLoader; } @@ -67,9 +70,16 @@ public class SpringPluginHookWrapper implements SpringPluginHook { } @Override - public void close() throws Exception { - pluginLaunchInvolved.close(descriptor, classLoader); - ResourceUtils.closeQuietly(target); - ResourceUtils.closeQuietly(classLoader); + public void close(boolean isUninstall) throws Exception { + try { + pluginLaunchInvolved.close(pluginInsideInfo, classLoader); + } catch (Exception e){ + log.error("关闭插件异常: {}", e.getMessage(), e); + } + try { + target.close(isUninstall); + } finally { + ResourceUtils.closeQuietly(classLoader); + } } } diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/involved/DefaultPluginLaunchInvolved.java b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/involved/DefaultPluginLaunchInvolved.java index 33fee5b..4e25965 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/involved/DefaultPluginLaunchInvolved.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/involved/DefaultPluginLaunchInvolved.java @@ -16,32 +16,73 @@ package com.gitee.starblues.core.launcher.plugin.involved; +import com.gitee.starblues.core.PluginInsideInfo; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; +import com.gitee.starblues.core.PluginExtensionInfo; import com.gitee.starblues.loader.PluginResourceStorage; +import com.gitee.starblues.spring.ApplicationContext; import com.gitee.starblues.spring.SpringPluginHook; import com.gitee.starblues.spring.web.PluginStaticResourceResolver; +import com.gitee.starblues.utils.ObjectUtils; +import com.gitee.starblues.utils.SpringBeanCustomUtils; +import lombok.extern.slf4j.Slf4j; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * 默认的插件启动介入者 * @author starBlues - * @version 3.0.0 + * @since 3.0.0 + * @version 3.1.0 */ +@Slf4j public class DefaultPluginLaunchInvolved implements PluginLaunchInvolved{ @Override - public void before(InsidePluginDescriptor descriptor, ClassLoader classLoader) throws Exception { + public void before(PluginInsideInfo pluginInsideInfo, ClassLoader classLoader) throws Exception { + InsidePluginDescriptor descriptor = pluginInsideInfo.getPluginDescriptor(); PluginResourceStorage.addPlugin(descriptor.getPluginId(), descriptor.getPluginFileName()); } @Override - public void after(InsidePluginDescriptor descriptor, ClassLoader classLoader, SpringPluginHook pluginHook) throws Exception { + public void after(PluginInsideInfo pluginInsideInfo, ClassLoader classLoader, SpringPluginHook pluginHook) throws Exception { + InsidePluginDescriptor descriptor = pluginInsideInfo.getPluginDescriptor(); PluginStaticResourceResolver.parse(descriptor, classLoader, pluginHook.getWebConfig()); + setExtensionInfoSupplier(pluginInsideInfo, pluginHook); } @Override - public void close(InsidePluginDescriptor descriptor, ClassLoader classLoader) throws Exception { + public void close(PluginInsideInfo pluginInsideInfo, ClassLoader classLoader) throws Exception { + InsidePluginDescriptor descriptor = pluginInsideInfo.getPluginDescriptor(); String pluginId = descriptor.getPluginId(); PluginResourceStorage.removePlugin(pluginId); PluginStaticResourceResolver.remove(pluginId); } + + private void setExtensionInfoSupplier(PluginInsideInfo pluginInsideInfo, SpringPluginHook pluginHook){ + pluginInsideInfo.setExtensionInfoSupplier(()->{ + // 设置插件自主扩展信息 + ApplicationContext applicationContext = pluginHook.getApplicationContext(); + List beans = SpringBeanCustomUtils.getBeans(applicationContext, + PluginExtensionInfo.class); + if(ObjectUtils.isEmpty(beans)){ + return new HashMap<>(0); + } + Map extensionInfos = new HashMap<>(); + for (PluginExtensionInfo extensionInfoBean : beans) { + try { + Map extensionInfo = extensionInfoBean.extensionInfo(); + if(!ObjectUtils.isEmpty(extensionInfo)){ + extensionInfos.putAll(extensionInfo); + } + } catch (Exception e){ + log.error(e.getMessage(), e); + } + } + return extensionInfos; + }); + } + } diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/involved/PluginApplicationContextGetter.java b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/involved/PluginApplicationContextGetter.java index 8a8754e..165db50 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/involved/PluginApplicationContextGetter.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/involved/PluginApplicationContextGetter.java @@ -16,6 +16,7 @@ package com.gitee.starblues.core.launcher.plugin.involved; +import com.gitee.starblues.core.PluginInsideInfo; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; import com.gitee.starblues.spring.ApplicationContext; import com.gitee.starblues.spring.SpringPluginHook; @@ -25,19 +26,22 @@ import java.util.concurrent.ConcurrentHashMap; /** * @author starBlues - * @version 3.0.0 + * @since 3.0.0 + * @version 3.1.0 */ public class PluginApplicationContextGetter implements PluginLaunchInvolved{ private static final Map PLUGIN_CONTEXTS = new ConcurrentHashMap<>(); @Override - public void after(InsidePluginDescriptor descriptor, ClassLoader classLoader, SpringPluginHook pluginHook) throws Exception { + public void after(PluginInsideInfo pluginInsideInfo, ClassLoader classLoader, SpringPluginHook pluginHook) throws Exception { + InsidePluginDescriptor descriptor = pluginInsideInfo.getPluginDescriptor(); PLUGIN_CONTEXTS.put(descriptor.getPluginId(), pluginHook.getApplicationContext()); } @Override - public void close(InsidePluginDescriptor descriptor, ClassLoader classLoader) throws Exception { + public void close(PluginInsideInfo pluginInsideInfo, ClassLoader classLoader) throws Exception { + InsidePluginDescriptor descriptor = pluginInsideInfo.getPluginDescriptor(); PLUGIN_CONTEXTS.remove(descriptor.getPluginId()); } diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/involved/PluginLaunchInvolved.java b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/involved/PluginLaunchInvolved.java index 93fc5a1..5e3bbe6 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/involved/PluginLaunchInvolved.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/involved/PluginLaunchInvolved.java @@ -16,7 +16,7 @@ package com.gitee.starblues.core.launcher.plugin.involved; -import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; +import com.gitee.starblues.core.PluginInsideInfo; import com.gitee.starblues.integration.IntegrationConfiguration; import com.gitee.starblues.spring.SpringPluginHook; import com.gitee.starblues.utils.OrderPriority; @@ -25,7 +25,8 @@ import org.springframework.context.support.GenericApplicationContext; /** * 插件启动前后介入 * @author starBlues - * @version 3.0.0 + * @since 3.0.0 + * @version 3.1.0 */ public interface PluginLaunchInvolved { @@ -38,38 +39,38 @@ public interface PluginLaunchInvolved { /** * 启动之前 - * @param descriptor 插件信息 + * @param pluginInsideInfo 插件信息 * @param classLoader 插件classloader * @throws Exception 执行异常 */ - default void before(InsidePluginDescriptor descriptor, ClassLoader classLoader) throws Exception{} + default void before(PluginInsideInfo pluginInsideInfo, ClassLoader classLoader) throws Exception{} /** * 启动之后 - * @param descriptor 插件信息 + * @param pluginInsideInfo 插件信息 * @param classLoader 插件classloader * @param pluginHook 启动成功后插件返回的钩子 * @throws Exception 执行异常 */ - default void after(InsidePluginDescriptor descriptor, ClassLoader classLoader, + default void after(PluginInsideInfo pluginInsideInfo, ClassLoader classLoader, SpringPluginHook pluginHook) throws Exception{} /** * 启动失败 - * @param descriptor 插件信息 + * @param pluginInsideInfo 插件信息 * @param classLoader 插件classloader * @param throwable 异常信息 * @throws Exception 执行异常 */ - default void failure(InsidePluginDescriptor descriptor, ClassLoader classLoader, Throwable throwable) throws Exception{} + default void failure(PluginInsideInfo pluginInsideInfo, ClassLoader classLoader, Throwable throwable) throws Exception{} /** * 关闭的时候 - * @param descriptor 插件信息 + * @param pluginInsideInfo 插件信息 * @param classLoader 插件classloader * @throws Exception 执行异常 */ - default void close(InsidePluginDescriptor descriptor, ClassLoader classLoader) throws Exception{} + default void close(PluginInsideInfo pluginInsideInfo, ClassLoader classLoader) throws Exception{} /** * 执行顺序 diff --git a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/involved/PluginLaunchInvolvedFactory.java b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/involved/PluginLaunchInvolvedFactory.java index 8330ce2..67bc9cc 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/involved/PluginLaunchInvolvedFactory.java +++ b/spring-brick/src/main/java/com/gitee/starblues/core/launcher/plugin/involved/PluginLaunchInvolvedFactory.java @@ -16,6 +16,7 @@ package com.gitee.starblues.core.launcher.plugin.involved; +import com.gitee.starblues.core.PluginInsideInfo; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; import com.gitee.starblues.integration.IntegrationConfiguration; import com.gitee.starblues.spring.SpringPluginHook; @@ -32,7 +33,8 @@ import java.util.Map; /** * 插件启动介入工厂 * @author starBlues - * @version 3.0.0 + * @since 3.0.0 + * @version 3.1.0 */ public class PluginLaunchInvolvedFactory implements PluginLaunchInvolved{ @@ -75,24 +77,24 @@ public class PluginLaunchInvolvedFactory implements PluginLaunchInvolved{ } @Override - public void before(InsidePluginDescriptor descriptor, ClassLoader classLoader) throws Exception { + public void before(PluginInsideInfo pluginInsideInfo, ClassLoader classLoader) throws Exception { for (PluginLaunchInvolved pluginLaunchInvolved : pluginLaunchInvolvedList) { - pluginLaunchInvolved.before(descriptor, classLoader); + pluginLaunchInvolved.before(pluginInsideInfo, classLoader); } } @Override - public void after(InsidePluginDescriptor descriptor, ClassLoader classLoader, SpringPluginHook pluginHook) throws Exception { + public void after(PluginInsideInfo pluginInsideInfo, ClassLoader classLoader, SpringPluginHook pluginHook) throws Exception { for (PluginLaunchInvolved pluginLaunchInvolved : pluginLaunchInvolvedList) { - pluginLaunchInvolved.after(descriptor, classLoader, pluginHook); + pluginLaunchInvolved.after(pluginInsideInfo, classLoader, pluginHook); } } @Override - public void failure(InsidePluginDescriptor descriptor, ClassLoader classLoader, Throwable throwable) throws Exception { + public void failure(PluginInsideInfo pluginInsideInfo, ClassLoader classLoader, Throwable throwable) throws Exception { for (PluginLaunchInvolved pluginLaunchInvolved : pluginLaunchInvolvedList) { try { - pluginLaunchInvolved.failure(descriptor, classLoader, throwable); + pluginLaunchInvolved.failure(pluginInsideInfo, classLoader, throwable); } catch (Exception e){ logger.error("[{}] execute failure exception : {}", pluginLaunchInvolved.getClass().getName(), e.getMessage(), e); @@ -101,10 +103,10 @@ public class PluginLaunchInvolvedFactory implements PluginLaunchInvolved{ } @Override - public void close(InsidePluginDescriptor descriptor, ClassLoader classLoader) throws Exception { + public void close(PluginInsideInfo pluginInsideInfo, ClassLoader classLoader) throws Exception { for (PluginLaunchInvolved pluginLaunchInvolved : pluginLaunchInvolvedList) { try { - pluginLaunchInvolved.close(descriptor, classLoader); + pluginLaunchInvolved.close(pluginInsideInfo, classLoader); } catch (Exception e){ logger.error("[{}] execute close exception : {}", pluginLaunchInvolved.getClass().getName(), e.getMessage(), e); diff --git a/spring-brick/src/main/java/com/gitee/starblues/integration/ExtendPointConfiguration.java b/spring-brick/src/main/java/com/gitee/starblues/integration/ExtendPointConfiguration.java index 79f43b5..1d0f5d7 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/integration/ExtendPointConfiguration.java +++ b/spring-brick/src/main/java/com/gitee/starblues/integration/ExtendPointConfiguration.java @@ -19,6 +19,7 @@ package com.gitee.starblues.integration; import com.gitee.starblues.core.DefaultRealizeProvider; import com.gitee.starblues.core.RealizeProvider;; import com.gitee.starblues.core.classloader.CacheMainResourceMatcher; +import com.gitee.starblues.core.classloader.DefaultMainResourceMatcher; import com.gitee.starblues.core.classloader.MainResourceMatcher; import com.gitee.starblues.core.descriptor.decrypt.DefaultPluginDescriptorDecrypt; import com.gitee.starblues.core.descriptor.decrypt.PluginDescriptorDecrypt; @@ -49,6 +50,7 @@ public class ExtendPointConfiguration { IntegrationConfiguration configuration) { this.applicationContext = applicationContext; this.configuration = configuration; + this.configuration.checkConfig(); } @Bean @@ -83,7 +85,7 @@ public class ExtendPointConfiguration { @Bean public MainResourceMatcher mainResourceMatcher(){ - return new CacheMainResourceMatcher(new DefaultMainResourcePatternDefiner( + return new DefaultMainResourceMatcher(new DefaultMainResourcePatternDefiner( configuration.mainPackage(), applicationContext )); 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 index c56b306..7990567 100644 --- 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 @@ -12,7 +12,7 @@ import java.util.List; * 空操作的 PluginOperator * * @author starBlues - * @version 3.0.4 + * @version 3.1.0 * @since 3.0.4 */ public class EmptyPluginOperator implements PluginOperator{ diff --git a/spring-brick/src/main/java/com/gitee/starblues/spring/ApplicationContext.java b/spring-brick/src/main/java/com/gitee/starblues/spring/ApplicationContext.java index 77c9079..af30214 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/spring/ApplicationContext.java +++ b/spring-brick/src/main/java/com/gitee/starblues/spring/ApplicationContext.java @@ -20,7 +20,7 @@ package com.gitee.starblues.spring; * 自定义ApplicationContext * @author starBlues * @since 3.0.0 - * @version 3.0.4 + * @version 3.1.0 */ public interface ApplicationContext extends AutoCloseable { diff --git a/spring-brick/src/main/java/com/gitee/starblues/spring/SpringPluginHook.java b/spring-brick/src/main/java/com/gitee/starblues/spring/SpringPluginHook.java index 55cdc24..6cf5c61 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/spring/SpringPluginHook.java +++ b/spring-brick/src/main/java/com/gitee/starblues/spring/SpringPluginHook.java @@ -25,7 +25,7 @@ import com.gitee.starblues.spring.web.thymeleaf.ThymeleafConfig; * @author starBlues * @version 3.0.0 */ -public interface SpringPluginHook extends AutoCloseable{ +public interface SpringPluginHook { /** * 停止前校验. 如果抛出 PluginProhibitStopException 异常, 表示当前插件不可停止 @@ -51,4 +51,12 @@ public interface SpringPluginHook extends AutoCloseable{ */ ThymeleafConfig getThymeleafConfig(); + /** + * 卸载调用 + * @param isUninstall 是否是卸载关闭 + * @since 3.1.0 + * @throws Exception 关闭异常 + */ + void close(boolean isUninstall) throws Exception; + } diff --git a/spring-brick/src/main/java/com/gitee/starblues/spring/extract/DefaultOpExtractFactory.java b/spring-brick/src/main/java/com/gitee/starblues/spring/extract/DefaultOpExtractFactory.java index 7f56688..73096b2 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/spring/extract/DefaultOpExtractFactory.java +++ b/spring-brick/src/main/java/com/gitee/starblues/spring/extract/DefaultOpExtractFactory.java @@ -28,7 +28,7 @@ import java.util.stream.Collectors; /** * 默认的可扩展的工厂 * @author starBlues - * @version 3.0.4 + * @version 3.1.0 * @since 3.0.0 */ public class DefaultOpExtractFactory implements OpExtractFactory { diff --git a/spring-brick/src/main/java/com/gitee/starblues/spring/web/thymeleaf/PluginThymeleafInvolved.java b/spring-brick/src/main/java/com/gitee/starblues/spring/web/thymeleaf/PluginThymeleafInvolved.java index 999816e..333f0af 100644 --- a/spring-brick/src/main/java/com/gitee/starblues/spring/web/thymeleaf/PluginThymeleafInvolved.java +++ b/spring-brick/src/main/java/com/gitee/starblues/spring/web/thymeleaf/PluginThymeleafInvolved.java @@ -16,6 +16,7 @@ package com.gitee.starblues.spring.web.thymeleaf; +import com.gitee.starblues.core.PluginInsideInfo; import com.gitee.starblues.core.descriptor.InsidePluginDescriptor; import com.gitee.starblues.core.launcher.plugin.involved.PluginLaunchInvolved; import com.gitee.starblues.integration.IntegrationConfiguration; @@ -36,7 +37,8 @@ import java.util.concurrent.ConcurrentHashMap; /** * 插件 Thymeleaf 注册 * @author starBlues - * @version 3.0.0 + * @since 3.0.0 + * @version 3.1.0 */ public class PluginThymeleafInvolved implements PluginLaunchInvolved { @@ -52,7 +54,7 @@ public class PluginThymeleafInvolved implements PluginLaunchInvolved { } @Override - public void after(InsidePluginDescriptor descriptor, ClassLoader classLoader, SpringPluginHook pluginHook) throws Exception { + public void after(PluginInsideInfo pluginInsideInfo, ClassLoader classLoader, SpringPluginHook pluginHook) throws Exception { if(templateResolvers == null){ return; } @@ -93,14 +95,15 @@ public class PluginThymeleafInvolved implements PluginLaunchInvolved { } resolver.setCheckExistence(true); templateResolvers.add(resolver); + InsidePluginDescriptor descriptor = pluginInsideInfo.getPluginDescriptor(); if(!pluginTemplateResolver.containsKey(descriptor.getPluginId())){ pluginTemplateResolver.put(descriptor.getPluginId(), resolver); } } @Override - public void close(InsidePluginDescriptor descriptor, ClassLoader classLoader) throws Exception { - pluginTemplateResolver.remove(descriptor.getPluginId()); + public void close(PluginInsideInfo pluginInsideInfo, ClassLoader classLoader) throws Exception { + pluginTemplateResolver.remove(pluginInsideInfo.getPluginId()); } private SpringTemplateEngine getSpringTemplateEngine(GenericApplicationContext context){ diff --git a/update.md b/update.md index 467a849..fc7b034 100644 --- a/update.md +++ b/update.md @@ -1,5 +1,7 @@ 1. 【新增】增加主包MAINIFEST中title和version定义, 标准jar包中包含`Implementation-Version`和`Implementation-Title`属性 2. 【新增】新增根据个人需求选择开发模式,支持隔离式开发模式(目前已有的)、共享式开发模式 +3. 【新增】新增可自主实现扩展插件信息 +4. 【新增】新增插件可判断卸载事件 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` 异常无法抛出 -- Gitee