From 277767c03fea3e76226d3eec8a822a6ce51d1df5 Mon Sep 17 00:00:00 2001 From: Lipeng <44571204+gaosaroma@users.noreply.github.com> Date: Mon, 2 Sep 2024 12:01:28 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=20=E6=A8=A1=E5=9D=97=E7=98=A6?= =?UTF-8?q?=E8=BA=AB=E6=8E=92=E9=99=A4=E9=97=B4=E6=8E=A5=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=20(#1000)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 优化显示 * fix as bizStateRecords * 更新显示 * 模块瘦身排除间接依赖 * refactor --- .../sofa/ark/boot/mojo/ModuleSlimConfig.java | 25 ++- .../ark/boot/mojo/ModuleSlimStrategy.java | 111 +++++++++++-- .../sofa/ark/boot/mojo/RepackageMojo.java | 16 +- .../sofa/ark/boot/mojo/utils/ParseUtils.java | 19 +++ .../ark/boot/mojo/ModuleSlimStrategyTest.java | 151 ++++++++++++++++-- .../ark/boot/mojo/utils/ParseUtilsTest.java | 9 ++ .../baseDir/conf/ark/bootstrap.properties | 5 +- .../resources/baseDir/conf/ark/bootstrap.yml | 4 +- 8 files changed, 304 insertions(+), 36 deletions(-) diff --git a/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/ModuleSlimConfig.java b/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/ModuleSlimConfig.java index 12667a6bb..a8ad89990 100644 --- a/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/ModuleSlimConfig.java +++ b/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/ModuleSlimConfig.java @@ -33,40 +33,45 @@ public class ModuleSlimConfig { * group-a:tracer-core:3.0.10 * group-b:tracer-core:3.0.10:jdk17 */ - private LinkedHashSet excludes = new LinkedHashSet<>(); + private LinkedHashSet excludes = new LinkedHashSet<>(); /** * list of groupId names to exclude (exact match). */ - private LinkedHashSet excludeGroupIds = new LinkedHashSet<>(); + private LinkedHashSet excludeGroupIds = new LinkedHashSet<>(); /** * list of artifact names to exclude (exact match). */ - private LinkedHashSet excludeArtifactIds = new LinkedHashSet<>(); + private LinkedHashSet excludeArtifactIds = new LinkedHashSet<>(); /** * Colon separated groupId, artifactId [and classifier] to exclude (exact match). e.g: * group-a:tracer-core:3.0.10 * group-b:tracer-core:3.0.10:jdk17 */ - private LinkedHashSet includes = new LinkedHashSet<>(); + private LinkedHashSet includes = new LinkedHashSet<>(); /** * list of groupId names to exclude (exact match). */ - private LinkedHashSet includeGroupIds = new LinkedHashSet<>(); + private LinkedHashSet includeGroupIds = new LinkedHashSet<>(); /** * list of artifact names to exclude (exact match). */ - private LinkedHashSet includeArtifactIds = new LinkedHashSet<>(); + private LinkedHashSet includeArtifactIds = new LinkedHashSet<>(); /** * 基座依赖标识,以 ${groupId}:${artifactId}:${version} 标识 */ private String baseDependencyParentIdentity; + /** + * 是否排除依赖时,同时排除依赖及间接依赖。如:A依赖B,B依赖C,当 excludes 只配置了 A 时,B 和 C 都会被排除 + */ + private boolean excludeWithIndirectDependencies = true; + public LinkedHashSet getExcludeArtifactIds() { return excludeArtifactIds; } @@ -144,4 +149,12 @@ public LinkedHashSet getIncludeArtifactIds() { public void setIncludeArtifactIds(LinkedHashSet includeArtifactIds) { this.includeArtifactIds = includeArtifactIds; } + + public boolean isExcludeWithIndirectDependencies() { + return excludeWithIndirectDependencies; + } + + public void setExcludeWithIndirectDependencies(boolean excludeWithIndirectDependencies) { + this.excludeWithIndirectDependencies = excludeWithIndirectDependencies; + } } \ No newline at end of file diff --git a/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/ModuleSlimStrategy.java b/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/ModuleSlimStrategy.java index 59657be83..06367ec38 100644 --- a/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/ModuleSlimStrategy.java +++ b/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/ModuleSlimStrategy.java @@ -34,6 +34,7 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.dependency.graph.DependencyNode; import java.io.BufferedReader; import java.io.File; @@ -50,9 +51,16 @@ import java.util.stream.Collectors; import static com.alipay.sofa.ark.boot.mojo.MavenUtils.inUnLogScopes; +import static com.alipay.sofa.ark.boot.mojo.utils.ParseUtils.getBooleanWithDefault; import static com.alipay.sofa.ark.boot.mojo.utils.ParseUtils.getStringSet; -import static com.alipay.sofa.ark.spi.constant.Constants.*; +import static com.alipay.sofa.ark.spi.constant.Constants.ARK_CONF_BASE_DIR; +import static com.alipay.sofa.ark.spi.constant.Constants.EXTENSION_EXCLUDES; +import static com.alipay.sofa.ark.spi.constant.Constants.EXTENSION_EXCLUDES_ARTIFACTIDS; +import static com.alipay.sofa.ark.spi.constant.Constants.EXTENSION_EXCLUDES_GROUPIDS; +import static com.alipay.sofa.ark.spi.constant.Constants.EXTENSION_INCLUDES; import static com.alipay.sofa.ark.spi.constant.Constants.EXTENSION_INCLUDES_ARTIFACTIDS; +import static com.alipay.sofa.ark.spi.constant.Constants.EXTENSION_INCLUDES_GROUPIDS; +import static com.alipay.sofa.ark.spi.constant.Constants.STRING_COLON; /** * @author lianglipeng.llp@alibaba-inc.com @@ -61,24 +69,31 @@ public class ModuleSlimStrategy { private MavenProject project; + + private DependencyNode projDependencyGraph; private ModuleSlimConfig config; private Log log; private File baseDir; - private static final String DEFAULT_EXCLUDE_RULES = "rules.txt"; + private static final String EXTENSION_EXCLUDE_WITH_INDIRECT_DEPENDENCIES = "excludeWithIndirectDependencies"; + + private static final String DEFAULT_EXCLUDE_RULES = "rules.txt"; - ModuleSlimStrategy(MavenProject project, ModuleSlimConfig config, File baseDir, Log log) { + ModuleSlimStrategy(MavenProject project, DependencyNode projDependencyGraph, + ModuleSlimConfig config, File baseDir, Log log) { this.project = project; + this.projDependencyGraph = projDependencyGraph; this.config = config; this.baseDir = baseDir; this.log = log; } public Set getSlimmedArtifacts() throws MojoExecutionException, IOException { + initSlimStrategyConfig(); Set toFilterByBase = getArtifactsToFilterByParentIdentity(project.getArtifacts()); - initExcludeAndIncludeConfig(toFilterByBase); + Set toFilterByExclude = getArtifactsToFilterByExcludeConfig(project .getArtifacts()); Set toAddByInclude = getArtifactsToAddByIncludeConfig(project.getArtifacts()); @@ -119,8 +134,7 @@ private Set getSameVersionArtifactsWithBase(Set artifacts) t private Model getBaseDependencyParentOriginalModel() { MavenProject proj = project; while (null != proj) { - if (getArtifactIdentity(proj.getArtifact()).equals( - config.getBaseDependencyParentIdentity())) { + if (getGAVIdentity(proj.getArtifact()).equals(config.getBaseDependencyParentIdentity())) { return proj.getOriginalModel(); } proj = proj.getParent(); @@ -128,13 +142,19 @@ private Model getBaseDependencyParentOriginalModel() { return null; } - private String getArtifactIdentity(Artifact artifact) { + private String getGAVIdentity(Artifact artifact) { + return artifact.getGroupId() + STRING_COLON + artifact.getArtifactId() + STRING_COLON + + artifact.getBaseVersion(); + } + + protected String getArtifactIdentity(Artifact artifact) { if (artifact.hasClassifier()) { return artifact.getGroupId() + STRING_COLON + artifact.getArtifactId() + STRING_COLON - + artifact.getBaseVersion() + STRING_COLON + artifact.getClassifier(); + + artifact.getBaseVersion() + STRING_COLON + artifact.getClassifier() + + STRING_COLON + artifact.getType(); } else { return artifact.getGroupId() + STRING_COLON + artifact.getArtifactId() + STRING_COLON - + artifact.getBaseVersion(); + + artifact.getBaseVersion() + STRING_COLON + artifact.getType(); } } @@ -143,14 +163,25 @@ private String getDependencyIdentity(Dependency dependency) { if (StringUtils.isNotEmpty(dependency.getClassifier())) { return dependency.getGroupId() + STRING_COLON + dependency.getArtifactId() + STRING_COLON + dependency.getVersion() + STRING_COLON - + dependency.getClassifier(); + + dependency.getClassifier() + STRING_COLON + dependency.getType(); } else { return dependency.getGroupId() + STRING_COLON + dependency.getArtifactId() - + STRING_COLON + dependency.getVersion(); + + STRING_COLON + dependency.getVersion() + STRING_COLON + dependency.getType(); } } - protected void initExcludeAndIncludeConfig(Set artifacts) throws IOException { + protected void initSlimStrategyConfig() throws IOException { + Map arkYaml = ArkConfigHolder.getArkYaml(baseDir.getAbsolutePath()); + Properties prop = ArkConfigHolder.getArkProperties(baseDir.getAbsolutePath()); + config.setExcludeWithIndirectDependencies(getBooleanWithDefault(prop, + EXTENSION_EXCLUDE_WITH_INDIRECT_DEPENDENCIES, true)); + config.setExcludeWithIndirectDependencies(getBooleanWithDefault(arkYaml, + EXTENSION_EXCLUDE_WITH_INDIRECT_DEPENDENCIES, true)); + + initExcludeAndIncludeConfig(); + } + + protected void initExcludeAndIncludeConfig() throws IOException { // extension from other resource if (!StringUtils.isEmpty(config.getPackExcludesConfig())) { extensionExcludeAndIncludeArtifacts(baseDir + File.separator + ARK_CONF_BASE_DIR @@ -164,11 +195,65 @@ protected void initExcludeAndIncludeConfig(Set artifacts) throws IOExc // extension from url if (StringUtils.isNotBlank(config.getPackExcludesUrl())) { - extensionExcludeArtifactsFromUrl(config.getPackExcludesUrl(), artifacts); + extensionExcludeArtifactsFromUrl(config.getPackExcludesUrl(), project.getArtifacts()); } } protected Set getArtifactsToFilterByExcludeConfig(Set artifacts) { + Set literalArtifactsToExclude = getLiteralArtifactsToFilterByExcludeConfig(artifacts); + if (config.isExcludeWithIndirectDependencies()) { + return excludeWithIndirectDependencies(literalArtifactsToExclude, artifacts); + } + return literalArtifactsToExclude; + } + + private Set excludeWithIndirectDependencies(Set literalArtifactsToExclude, Set artifacts) { + Set excludeArtifactIdentities = literalArtifactsToExclude.stream().map(this::getArtifactIdentity).collect(Collectors.toSet()); + Map artifactMap = artifacts.stream().collect(Collectors.toMap(this::getArtifactIdentity,it->it)); + return getExcludeWithIndirectDependencies(projDependencyGraph,excludeArtifactIdentities,artifactMap); + } + + private Set getExcludeWithIndirectDependencies(DependencyNode node, + Set literalArtifactsToExclude, + Map artifacts) { + if (null == node) { + return Collections.emptySet(); + } + + Set result = new LinkedHashSet<>(); + + String artifactIdentity = getArtifactIdentity(node.getArtifact()); + if (literalArtifactsToExclude.contains(artifactIdentity)) { + // 排除当前依赖 + result.add(artifacts.get(artifactIdentity)); + + // 排除当前依赖的所有依赖 + result.addAll(getAllDependencies(node, artifacts)); + return result; + } + + for (DependencyNode child : node.getChildren()) { + result.addAll(getExcludeWithIndirectDependencies(child, literalArtifactsToExclude, + artifacts)); + } + + return result; + } + + private Set getAllDependencies(DependencyNode node, Map artifacts) { + if (null == node) { + return Collections.emptySet(); + } + + Set result = new HashSet<>(); + for (DependencyNode child : node.getChildren()) { + result.add(artifacts.get(getArtifactIdentity(child.getArtifact()))); + result.addAll(getAllDependencies(child, artifacts)); + } + return result; + } + + protected Set getLiteralArtifactsToFilterByExcludeConfig(Set artifacts) { List excludeList = new ArrayList<>(); if (config != null && (config.getExcludes().contains("*") || config.getExcludes().contains(".*"))) { diff --git a/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/RepackageMojo.java b/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/RepackageMojo.java index 6fc52c4bc..0d7db306a 100644 --- a/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/RepackageMojo.java +++ b/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/RepackageMojo.java @@ -422,9 +422,16 @@ private void parseArtifactItems(DependencyNode rootNode, Set resul } } + private DependencyNode parseDependencyGraph() throws MojoExecutionException, + MojoFailureException { + if (null == super.getDependencyGraph()) { + super.execute(); + } + return super.getDependencyGraph(); + } + private Set getAllArtifact() throws MojoExecutionException, MojoFailureException { - super.execute(); - DependencyNode dependencyNode = super.getDependencyGraph(); + DependencyNode dependencyNode = parseDependencyGraph(); Set results = new HashSet<>(); parseArtifactItems(dependencyNode, results); return results; @@ -534,14 +541,15 @@ private Set getAdditionalArtifact() throws MojoExecutionException { } } - private Set getSlimmedArtifacts() throws MojoExecutionException, IOException { + private Set getSlimmedArtifacts() throws MojoExecutionException, IOException, + MojoFailureException { ModuleSlimConfig moduleSlimConfig = (new ModuleSlimConfig()) .setPackExcludesConfig(packExcludesConfig).setPackExcludesUrl(packExcludesUrl) .setExcludes(excludes).setExcludeGroupIds(excludeGroupIds) .setExcludeArtifactIds(excludeArtifactIds) .setBaseDependencyParentIdentity(baseDependencyParentIdentity); ModuleSlimStrategy slimStrategy = new ModuleSlimStrategy(this.mavenProject, - moduleSlimConfig, this.baseDir, this.getLog()); + parseDependencyGraph(), moduleSlimConfig, this.baseDir, this.getLog()); return slimStrategy.getSlimmedArtifacts(); } diff --git a/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/utils/ParseUtils.java b/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/utils/ParseUtils.java index 3003551e6..eb905e354 100644 --- a/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/utils/ParseUtils.java +++ b/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/utils/ParseUtils.java @@ -49,6 +49,25 @@ public static Set getStringSet(Map yaml, String confKey) return newHashSet((List) value); } + public static boolean getBooleanWithDefault(Map yaml, String confKey, + boolean defaultValue) { + Object value = getValue(yaml, confKey); + + if (null == value) { + return defaultValue; + } + return Boolean.parseBoolean(value.toString()); + } + + public static boolean getBooleanWithDefault(Properties prop, String confKey, + boolean defaultValue) { + Object value = prop.getProperty(confKey); + if (null == value) { + return defaultValue; + } + return Boolean.parseBoolean(value.toString()); + } + private static Object getValue(Map yaml, String confKey) { if (MapUtils.isEmpty(yaml) || StringUtils.isEmpty(confKey)) { return null; diff --git a/sofa-ark-parent/support/ark-maven-plugin/src/test/java/com/alipay/sofa/ark/boot/mojo/ModuleSlimStrategyTest.java b/sofa-ark-parent/support/ark-maven-plugin/src/test/java/com/alipay/sofa/ark/boot/mojo/ModuleSlimStrategyTest.java index 824be644b..29a7ac616 100644 --- a/sofa-ark-parent/support/ark-maven-plugin/src/test/java/com/alipay/sofa/ark/boot/mojo/ModuleSlimStrategyTest.java +++ b/sofa-ark-parent/support/ark-maven-plugin/src/test/java/com/alipay/sofa/ark/boot/mojo/ModuleSlimStrategyTest.java @@ -27,6 +27,7 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.dependency.graph.DependencyNode; import org.junit.Test; import java.io.File; @@ -35,9 +36,11 @@ import java.net.URL; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import static com.alipay.sofa.ark.boot.mojo.ReflectionUtils.setField; import static java.util.Arrays.asList; @@ -69,8 +72,8 @@ public void testGetSlimmedArtifacts() throws MojoExecutionException, IOException Set artifacts = Sets.newHashSet(a1, a2, a3); when(proj.getArtifacts()).thenReturn(artifacts); - ModuleSlimStrategy strategy = spy(new ModuleSlimStrategy(proj, new ModuleSlimConfig(), - mockBaseDir(), null)); + ModuleSlimStrategy strategy = spy(new ModuleSlimStrategy(proj, null, + new ModuleSlimConfig(), mockBaseDir(), null)); doReturn(Sets.newHashSet(a1)).when(strategy).getArtifactsToFilterByParentIdentity(anySet()); doReturn(Sets.newHashSet(a2)).when(strategy).getArtifactsToFilterByExcludeConfig(anySet()); @@ -92,8 +95,16 @@ public void testSlimmedAllArtifacts() throws MojoExecutionException, IOException ModuleSlimConfig moduleSlimConfig = new ModuleSlimConfig(); moduleSlimConfig.setExcludes(Sets.newLinkedHashSet(Arrays.asList(".*"))); moduleSlimConfig.setIncludes(Sets.newLinkedHashSet(Arrays.asList("*"))); - ModuleSlimStrategy strategy = spy(new ModuleSlimStrategy(proj, moduleSlimConfig, + ModuleSlimStrategy strategy = spy(new ModuleSlimStrategy(proj, null, moduleSlimConfig, mockBaseDir(), null)); + + doReturn("a1").when(strategy).getArtifactIdentity(a1); + doReturn("a2").when(strategy).getArtifactIdentity(a2); + doReturn("a3").when(strategy).getArtifactIdentity(a3); + doReturn("a4").when(strategy).getArtifactIdentity(a4); + doReturn("a5").when(strategy).getArtifactIdentity(a5); + doReturn("a6").when(strategy).getArtifactIdentity(a6); + assertEquals(6, strategy.getSlimmedArtifacts().size()); } @@ -102,20 +113,22 @@ public void testGetArtifactsToFilterByParentIdentity() throws URISyntaxException MojoExecutionException { ModuleSlimConfig config = (new ModuleSlimConfig()) .setBaseDependencyParentIdentity("com.mock:base-dependencies-starter:1.0"); - ModuleSlimStrategy strategy = new ModuleSlimStrategy(getMockBootstrapProject(), config, - mockBaseDir(), null); + ModuleSlimStrategy strategy = new ModuleSlimStrategy(getMockBootstrapProject(), null, + config, mockBaseDir(), null); Artifact sameArtifact = mock(Artifact.class); when(sameArtifact.getGroupId()).thenReturn("com.mock"); when(sameArtifact.getArtifactId()).thenReturn("same-dependency-artifact"); when(sameArtifact.getVersion()).thenReturn("1.0"); when(sameArtifact.getBaseVersion()).thenReturn("1.0-SNAPSHOT"); + when(sameArtifact.getType()).thenReturn("jar"); Artifact differenceArtifact = mock(Artifact.class); when(differenceArtifact.getGroupId()).thenReturn("com.mock"); when(differenceArtifact.getArtifactId()).thenReturn("difference-dependency-artifact"); when(differenceArtifact.getVersion()).thenReturn("2.0"); when(differenceArtifact.getBaseVersion()).thenReturn("2.0-SNAPSHOT"); + when(sameArtifact.getType()).thenReturn("jar"); Set res = strategy.getArtifactsToFilterByParentIdentity(Sets.newHashSet( sameArtifact, differenceArtifact)); @@ -127,8 +140,8 @@ public void testGetArtifactsToFilterByParentIdentity() throws URISyntaxException public void testExtensionExcludeAndIncludeArtifactsByDefault() throws URISyntaxException, IOException { ModuleSlimConfig config = new ModuleSlimConfig(); - ModuleSlimStrategy strategy = new ModuleSlimStrategy(getMockBootstrapProject(), config, - mockBaseDir(), mockLog()); + ModuleSlimStrategy strategy = new ModuleSlimStrategy(getMockBootstrapProject(), null, + config, mockBaseDir(), mockLog()); strategy.configExcludeArtifactsByDefault(); @@ -146,7 +159,8 @@ public void testExtensionExcludeAndIncludeArtifactsByDefault() throws URISyntaxE @Test public void testExtensionExcludeAndIncludeArtifacts() throws URISyntaxException { ModuleSlimConfig config = new ModuleSlimConfig(); - ModuleSlimStrategy strategy = new ModuleSlimStrategy(null, config, mockBaseDir(), mockLog()); + ModuleSlimStrategy strategy = new ModuleSlimStrategy(null, null, config, mockBaseDir(), + mockLog()); URL resource = this.getClass().getClassLoader().getResource("excludes.txt"); strategy.extensionExcludeAndIncludeArtifacts(resource.getPath()); @@ -171,7 +185,8 @@ public void testLogExcludeMessage() throws URISyntaxException { artifacts.add(defaultArtifact1); artifacts.add(defaultArtifact2); - ModuleSlimStrategy strategy = new ModuleSlimStrategy(null, null, mockBaseDir(), mockLog()); + ModuleSlimStrategy strategy = new ModuleSlimStrategy(null, null, null, mockBaseDir(), + mockLog()); strategy.logExcludeMessage(jarGroupIds, jarArtifactIds, jarList, artifacts, true); strategy.logExcludeMessage(jarGroupIds, jarArtifactIds, jarList, artifacts, false); } @@ -190,7 +205,7 @@ public void testExtensionExcludeAndIncludeArtifactsFromUrl() throws URISyntaxExc // NOTE: Access httpbin to run unit test, need vpn maybe. String packExcludesUrl = "http://httpbin.org/get"; - ModuleSlimStrategy strategy = new ModuleSlimStrategy(null, new ModuleSlimConfig(), + ModuleSlimStrategy strategy = new ModuleSlimStrategy(null, null, new ModuleSlimConfig(), mockBaseDir(), mockLog()); strategy.extensionExcludeArtifactsFromUrl(packExcludesUrl, artifacts); } @@ -224,11 +239,125 @@ public void testLogExcludeMessageWithMoreCases() throws URISyntaxException { artifact.setFile(new File("./")); artifacts.add(artifact); - ModuleSlimStrategy strategy = new ModuleSlimStrategy(null, null, mockBaseDir(), mockLog()); + ModuleSlimStrategy strategy = new ModuleSlimStrategy(null, null, null, mockBaseDir(), + mockLog()); strategy.logExcludeMessage(jarGroupIds, jarArtifactIds, jarList, artifacts, true); strategy.logExcludeMessage(jarGroupIds, jarArtifactIds, jarList, artifacts, false); } + @Test + public void testExcludeWithoutItsDependencies() throws URISyntaxException { + MavenProject proj = mock(MavenProject.class); + Artifact a1 = mockArtifact("com.exclude", "a1", "1.0.0", "jar", null, "compile"); + Artifact a2 = mockArtifact("com.exclude.group.id", "a2", "1.0.0", "jar", null, "compile"); + Artifact a3 = mockArtifact("com.exclude.artifact.id", "a3", "1.0.0", "jar", null, "compile"); + Artifact a4 = mockArtifact("com.include", "a4", "1.0.0", "jar", null, "compile"); + Set artifacts = Sets.newHashSet(a1, a2, a3, a4); + + ModuleSlimConfig moduleSlimConfig = new ModuleSlimConfig(); + moduleSlimConfig.setExcludes(Sets.newLinkedHashSet(Collections + .singletonList("com.exclude:a1"))); + moduleSlimConfig.setExcludeGroupIds(Sets.newLinkedHashSet(Collections + .singletonList("com.exclude.group.id"))); + moduleSlimConfig.setExcludeArtifactIds(Sets.newLinkedHashSet(Collections + .singletonList("a3"))); + moduleSlimConfig.setExcludeWithIndirectDependencies(false); + + ModuleSlimStrategy strategy = spy(new ModuleSlimStrategy(proj, null, moduleSlimConfig, + mockBaseDir(), null)); + Set res = strategy.getArtifactsToFilterByExcludeConfig(artifacts); + assertEquals(3, res.size()); + } + + @Test + public void testExcludeWithIndirectDependencies() throws URISyntaxException { + MavenProject proj = mock(MavenProject.class); + Artifact a1 = mockArtifact("com.exclude", "a1", "1.0.0", "jar", null, "compile"); + Artifact a2 = mockArtifact("com.exclude.group.id", "a2", "1.0.0", "jar", null, "compile"); + Artifact a3 = mockArtifact("com.exclude.artifact.id", "a3", "1.0.0", "jar", null, "compile"); + Artifact a4 = mockArtifact("com.include", "a4", "1.0.0", "jar", null, "compile"); + Artifact d1 = mockArtifact("com.exclude.dependency", "d1", "1.0.0", "jar", null, "compile"); + Artifact d2 = mockArtifact("com.exclude.dependency", "d2", "1.0.0", "jar", null, "compile"); + Artifact d3 = mockArtifact("com.exclude.dependency", "d3", "1.0.0", "jar", null, "compile"); + Artifact d4 = mockArtifact("com.exclude.dependency", "d4", "1.0.0", "jar", null, "compile"); + Artifact d5 = mockArtifact("com.include.dependency", "d5", "1.0.0", "jar", null, "compile"); + + + Set artifacts = Sets.newHashSet(a1, a2, a3, a4, d1,d2,d3,d4,d5); + + ModuleSlimConfig moduleSlimConfig = new ModuleSlimConfig(); + moduleSlimConfig.setExcludes(Sets.newLinkedHashSet(Collections.singletonList("com.exclude:a1"))); + moduleSlimConfig.setExcludeGroupIds(Sets.newLinkedHashSet(Collections.singletonList("com.exclude.group.id"))); + moduleSlimConfig.setExcludeArtifactIds(Sets.newLinkedHashSet(Collections.singletonList("a3"))); + moduleSlimConfig.setExcludeWithIndirectDependencies(true); + + /* + * 依赖关系如下: + * -> a1 -> d1 -> d2 + * / + * root -> a2 -> a3 -> d3 + * \ \ + * \ -> d4 + * -> a4 -> d5 + * 在此依赖关系下,a1, a2, a3 会因为 exclude 被排除 + * d1, d2, d3, d4 会因为 excludeWithDependencies 被排除 + * a4, d5 不会被排除 + */ + DependencyNode root = mockNode(mockArtifact("com.mock", "root", "1.0", "jar", null, "compile")); + DependencyNode a1Node = mockNode(a1); + DependencyNode a2Node = mockNode(a2); + DependencyNode a3Node = mockNode(a3); + DependencyNode a4Node = mockNode(a4); + DependencyNode d1Node = mockNode(d1); + DependencyNode d2Node = mockNode(d2); + DependencyNode d3Node = mockNode(d3); + DependencyNode d4Node = mockNode(d4); + DependencyNode d5Node = mockNode(d5); + + when(root.getChildren()).thenReturn(Lists.newArrayList(a1Node, a2Node,a4Node)); + when(a1Node.getChildren()).thenReturn(Lists.newArrayList(d1Node)); + when(d1Node.getChildren()).thenReturn(Lists.newArrayList(d2Node)); + when(a2Node.getChildren()).thenReturn(Lists.newArrayList(a3Node)); + when(a3Node.getChildren()).thenReturn(Lists.newArrayList(d3Node,d4Node)); + when(a4Node.getChildren()).thenReturn(Lists.newArrayList(d5Node)); + when(d2Node.getChildren()).thenReturn(Lists.newArrayList()); + when(d3Node.getChildren()).thenReturn(Lists.newArrayList(d4Node)); + when(d4Node.getChildren()).thenReturn(Lists.newArrayList()); + + + ModuleSlimStrategy strategy = spy(new ModuleSlimStrategy(proj, root, moduleSlimConfig, + null, null)); + Set res = strategy.getArtifactsToFilterByExcludeConfig(artifacts); + assertEquals(7, res.size()); + + Set resIdentities = res.stream().map(Artifact::getArtifactId).collect(Collectors.toSet()); + assertTrue(resIdentities.contains("a1")); + assertTrue(resIdentities.contains("a2")); + assertTrue(resIdentities.contains("a3")); + assertTrue(resIdentities.contains("d1")); + assertTrue(resIdentities.contains("d2")); + assertTrue(resIdentities.contains("d3")); + assertTrue(resIdentities.contains("d4")); + } + + private DependencyNode mockNode(Artifact artifact) { + DependencyNode node = mock(DependencyNode.class); + when(node.getArtifact()).thenReturn(artifact); + return node; + } + + private Artifact mockArtifact(String groupId, String artifactId, String version, String type, + String classifier, String scope) { + Artifact artifact = mock(Artifact.class); + when(artifact.getArtifactId()).thenReturn(artifactId); + when(artifact.getGroupId()).thenReturn(groupId); + when(artifact.getVersion()).thenReturn(version); + when(artifact.getType()).thenReturn(type); + when(artifact.getClassifier()).thenReturn(classifier); + when(artifact.getScope()).thenReturn(scope); + return artifact; + } + private MavenProject getMockBootstrapProject() throws URISyntaxException { MavenProject project = new MavenProject(); project.setArtifactId("base-bootstrap"); diff --git a/sofa-ark-parent/support/ark-maven-plugin/src/test/java/com/alipay/sofa/ark/boot/mojo/utils/ParseUtilsTest.java b/sofa-ark-parent/support/ark-maven-plugin/src/test/java/com/alipay/sofa/ark/boot/mojo/utils/ParseUtilsTest.java index 4c7bb0a82..fc1824bcd 100644 --- a/sofa-ark-parent/support/ark-maven-plugin/src/test/java/com/alipay/sofa/ark/boot/mojo/utils/ParseUtilsTest.java +++ b/sofa-ark-parent/support/ark-maven-plugin/src/test/java/com/alipay/sofa/ark/boot/mojo/utils/ParseUtilsTest.java @@ -28,7 +28,9 @@ import java.util.Map; import java.util.Set; +import static com.alipay.sofa.ark.boot.mojo.utils.ParseUtils.getBooleanWithDefault; import static com.alipay.sofa.ark.spi.constant.Constants.DECLARED_LIBRARIES_WHITELIST; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** @@ -49,6 +51,13 @@ public void testGetStringSetForYaml() throws URISyntaxException { assertTrue(whitelist.contains("com.ark.yml:ark-common-yml")); } + @Test + public void testGetBooleanWithDefault() throws URISyntaxException { + Map yml = (Map) loadYaml(); + assertFalse(getBooleanWithDefault(yml, "excludeWithIndirectDependencies", true)); + assertTrue(getBooleanWithDefault(yml, "aaa", true)); + } + private Object loadYaml() throws URISyntaxException { File yml = CommonUtils.getResourceFile("baseDir/conf/ark/bootstrap.yml"); try (FileInputStream fis = new FileInputStream(yml)) { diff --git a/sofa-ark-parent/support/ark-maven-plugin/src/test/resources/baseDir/conf/ark/bootstrap.properties b/sofa-ark-parent/support/ark-maven-plugin/src/test/resources/baseDir/conf/ark/bootstrap.properties index f4fb0a37a..624258420 100644 --- a/sofa-ark-parent/support/ark-maven-plugin/src/test/resources/baseDir/conf/ark/bootstrap.properties +++ b/sofa-ark-parent/support/ark-maven-plugin/src/test/resources/baseDir/conf/ark/bootstrap.properties @@ -6,4 +6,7 @@ excludeGroupIds=org.springframework excludeArtifactIds=sofa-ark-spi # declared libraries whitelist config {groupId:artifactId}, split by ',' -declared.libraries.whitelist=com.ark:ark-common,com.biz:biz-common \ No newline at end of file +declared.libraries.whitelist=com.ark:ark-common,com.biz:biz-common + + +excludeWithIndirectDependencies=false \ No newline at end of file diff --git a/sofa-ark-parent/support/ark-maven-plugin/src/test/resources/baseDir/conf/ark/bootstrap.yml b/sofa-ark-parent/support/ark-maven-plugin/src/test/resources/baseDir/conf/ark/bootstrap.yml index f5efdb671..7e41c3cf3 100644 --- a/sofa-ark-parent/support/ark-maven-plugin/src/test/resources/baseDir/conf/ark/bootstrap.yml +++ b/sofa-ark-parent/support/ark-maven-plugin/src/test/resources/baseDir/conf/ark/bootstrap.yml @@ -15,4 +15,6 @@ declared: libraries: whitelist: - com.ark.yml:ark-common-yml - - com.biz.yml:biz-common-yml \ No newline at end of file + - com.biz.yml:biz-common-yml + +excludeWithIndirectDependencies: false \ No newline at end of file From 79657169f5cb120af95975ac3de624c57eb2a478 Mon Sep 17 00:00:00 2001 From: leo james Date: Mon, 2 Sep 2024 17:26:20 +0800 Subject: [PATCH 02/11] update to 2.2.14-SNAPSHOT (#1002) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3860137f9..ebe5c183a 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ - 2.2.13 + 2.2.14-SNAPSHOT 2.2.12 UTF-8 1.8 From 9958c81201ff8c7365577d164e2bb969e3834cab Mon Sep 17 00:00:00 2001 From: leo james Date: Thu, 5 Sep 2024 16:39:12 +0800 Subject: [PATCH 03/11] update to 2.2.14 (#1003) --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index ebe5c183a..9774f3efe 100644 --- a/pom.xml +++ b/pom.xml @@ -14,8 +14,8 @@ - 2.2.14-SNAPSHOT - 2.2.12 + 2.2.14 + 2.2.13 UTF-8 1.8 3.0 From aafbe4c7ef70fde4fbaf0018ab52c26ab834128e Mon Sep 17 00:00:00 2001 From: leo james Date: Wed, 11 Sep 2024 18:43:20 +0800 Subject: [PATCH 04/11] fix log rolling update into wrong date (#1004) * Revert "fix no ark log in ark container (#891)" This reverts commit 75fa690c * update to 2.2.14-SNAPSHOT --------- Co-authored-by: 2041951416 <134405781+2041951416@users.noreply.github.com> --- pom.xml | 2 +- sofa-ark-bom/pom.xml | 2 +- .../ark/loader/DirectoryContainerArchive.java | 2 +- .../sofa/ark/container/ArkContainer.java | 56 +++++++++---------- 4 files changed, 28 insertions(+), 34 deletions(-) diff --git a/pom.xml b/pom.xml index 9774f3efe..2f15290df 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ - 2.2.14 + 2.2.14-SNAPSHOT 2.2.13 UTF-8 1.8 diff --git a/sofa-ark-bom/pom.xml b/sofa-ark-bom/pom.xml index bf5a468cf..aa25b6f68 100644 --- a/sofa-ark-bom/pom.xml +++ b/sofa-ark-bom/pom.xml @@ -14,7 +14,7 @@ 1.7.32 - 3.16.3 + 3.2.0 1.2.13 6.0.0 diff --git a/sofa-ark-parent/core-impl/archive/src/main/java/com/alipay/sofa/ark/loader/DirectoryContainerArchive.java b/sofa-ark-parent/core-impl/archive/src/main/java/com/alipay/sofa/ark/loader/DirectoryContainerArchive.java index d71b3faff..c0ac037ec 100644 --- a/sofa-ark-parent/core-impl/archive/src/main/java/com/alipay/sofa/ark/loader/DirectoryContainerArchive.java +++ b/sofa-ark-parent/core-impl/archive/src/main/java/com/alipay/sofa/ark/loader/DirectoryContainerArchive.java @@ -42,7 +42,7 @@ public class DirectoryContainerArchive implements ContainerArchive { private final static String[] AKR_CONTAINER_JAR = { "aopalliance-1.0", "commons-io-2.7", "guava-33.0.0-jre", "guice-6.0.0", "failureaccess-1.0.1", "javax.inject-1", - "logback-core-1.2.13", "logback-classic-1.2.13", "slf4j-api-1.7.32", + "logback-core-1.2.9", "logback-classic-1.2.9", "slf4j-api-1.7.32", "log-sofa-boot-starter", "log-sofa-boot", "sofa-common-tools", "netty-all-4.1.109.Final", "netty-transport-4.1.109.Final", "netty-common-4.1.109.Final", "netty-handler-4.1.109.Final", diff --git a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/ArkContainer.java b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/ArkContainer.java index f86360626..8949dfa8b 100644 --- a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/ArkContainer.java +++ b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/ArkContainer.java @@ -42,6 +42,10 @@ import com.alipay.sofa.ark.spi.service.biz.AddBizToStaticDeployHook; import com.alipay.sofa.ark.spi.service.extension.ArkServiceLoader; import com.alipay.sofa.common.log.MultiAppLoggerSpaceManager; +import com.alipay.sofa.common.log.SpaceId; +import com.alipay.sofa.common.log.SpaceInfo; +import com.alipay.sofa.common.log.env.LogEnvUtils; +import com.alipay.sofa.common.log.factory.LogbackLoggerSpaceFactory; import com.alipay.sofa.common.utils.ReportUtil; import java.io.File; @@ -56,13 +60,8 @@ import static com.alipay.sofa.ark.spi.constant.Constants.ARK_CONF_FILE; import static com.alipay.sofa.ark.spi.constant.Constants.ARK_CONF_FILE_FORMAT; import static com.alipay.sofa.common.log.Constants.LOGGING_PATH_DEFAULT; -import static com.alipay.sofa.common.log.Constants.LOG_CONFIG_PREFIX; import static com.alipay.sofa.common.log.Constants.LOG_ENCODING_PROP_KEY; -import static com.alipay.sofa.common.log.Constants.LOG_LEVEL_PREFIX; import static com.alipay.sofa.common.log.Constants.LOG_PATH; -import static com.alipay.sofa.common.log.Constants.LOG_PATH_PREFIX; -import static com.alipay.sofa.common.log.Constants.OLD_LOG_PATH; -import static com.alipay.sofa.common.log.Constants.SOFA_MIDDLEWARE_CONFIG_PREFIX; import static com.alipay.sofa.common.log.Constants.UTF8_STR; /** @@ -249,34 +248,29 @@ public List getProfileConfFiles(String... profiles) { * @throws ArkRuntimeException */ public void reInitializeArkLogger() throws ArkRuntimeException { - // log config from ark container or user app config files, the order of which to be used is: - // 1. using user app config files - // 2. using ark container config - // 3. using the default value - Map arkLogConfig = new HashMap<>(); - - // 1. set config from app config and ark container config first - for (String key : ArkConfigs.keySet()) { - if (filterAllLogConfig(key)) { - arkLogConfig.put(key, ArkConfigs.getStringValue(key)); + for (Map.Entry entry : MultiAppLoggerSpaceManager.getSpacesMap() + .entrySet()) { + SpaceId spaceId = entry.getKey(); + SpaceInfo spaceInfo = entry.getValue(); + if (!ArkLoggerFactory.SOFA_ARK_LOGGER_SPACE.equals(spaceId.getSpaceName())) { + continue; } + LogbackLoggerSpaceFactory arkLoggerSpaceFactory = (LogbackLoggerSpaceFactory) spaceInfo + .getAbstractLoggerSpaceFactory(); + Map arkLogConfig = new HashMap<>(); + // set base logging.path + arkLogConfig.put(LOG_PATH, ArkConfigs.getStringValue(LOG_PATH, LOGGING_PATH_DEFAULT)); + // set log file encoding + arkLogConfig.put(LOG_ENCODING_PROP_KEY, + ArkConfigs.getStringValue(LOG_ENCODING_PROP_KEY, UTF8_STR)); + // set other log config + for (String key : ArkConfigs.keySet()) { + if (LogEnvUtils.filterAllLogConfig(key)) { + arkLogConfig.put(key, ArkConfigs.getStringValue(key)); + } + } + arkLoggerSpaceFactory.reInitialize(arkLogConfig); } - - // 2. using the default value if not set - arkLogConfig.put(LOG_PATH, ArkConfigs.getStringValue(LOG_PATH, LOGGING_PATH_DEFAULT)); - arkLogConfig.put("logging.file.path", - ArkConfigs.getStringValue("logging.file.path", LOGGING_PATH_DEFAULT)); - arkLogConfig.put(LOG_ENCODING_PROP_KEY, - ArkConfigs.getStringValue(LOG_ENCODING_PROP_KEY, UTF8_STR)); - - MultiAppLoggerSpaceManager.init(ArkLoggerFactory.SOFA_ARK_LOGGER_SPACE, arkLogConfig); - } - - private boolean filterAllLogConfig(String key) { - return key.startsWith(SOFA_MIDDLEWARE_CONFIG_PREFIX) || key.startsWith(LOG_LEVEL_PREFIX) - || key.startsWith(LOG_PATH_PREFIX) || key.startsWith(LOG_CONFIG_PREFIX) - || key.equals(LOG_PATH) || key.equals(OLD_LOG_PATH) - || key.equals("logging.file.path") || key.equals(LOG_ENCODING_PROP_KEY); } /** From 9b6634291874f44233bc7a75e85c46fad47ad2eb Mon Sep 17 00:00:00 2001 From: leo james Date: Fri, 13 Sep 2024 14:27:55 +0800 Subject: [PATCH 05/11] update to 2.2.14 (#1006) * update to 2.2.14 * fix test --- pom.xml | 2 +- .../web/ArkTomcatServletWebServerFactory.java | 2 +- .../ArkTomcatServletWebServerFactoryTest.java | 40 ++++--------------- 3 files changed, 9 insertions(+), 35 deletions(-) diff --git a/pom.xml b/pom.xml index 2f15290df..9774f3efe 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ - 2.2.14-SNAPSHOT + 2.2.14 2.2.13 UTF-8 1.8 diff --git a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/web/ArkTomcatServletWebServerFactory.java b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/web/ArkTomcatServletWebServerFactory.java index f9ff4bd1d..e1903faa3 100644 --- a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/web/ArkTomcatServletWebServerFactory.java +++ b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/web/ArkTomcatServletWebServerFactory.java @@ -348,4 +348,4 @@ private boolean isInsideNestedJar(String dir) { protected WebServer getWebServer(Tomcat tomcat) { return new ArkTomcatWebServer(tomcat, getPort() >= 0, tomcat); } -} \ No newline at end of file +} diff --git a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/test/java/com/alipay/sofa/ark/springboot/web/ArkTomcatServletWebServerFactoryTest.java b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/test/java/com/alipay/sofa/ark/springboot/web/ArkTomcatServletWebServerFactoryTest.java index 93d915bc4..8d8be2fa0 100644 --- a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/test/java/com/alipay/sofa/ark/springboot/web/ArkTomcatServletWebServerFactoryTest.java +++ b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/test/java/com/alipay/sofa/ark/springboot/web/ArkTomcatServletWebServerFactoryTest.java @@ -19,10 +19,7 @@ import com.alipay.sofa.ark.api.ArkClient; import com.alipay.sofa.ark.container.model.BizModel; import com.alipay.sofa.ark.container.service.biz.BizManagerServiceImpl; -import com.alipay.sofa.ark.spi.registry.ServiceReference; -import com.alipay.sofa.ark.spi.service.ArkInject; -import com.alipay.sofa.ark.spi.service.registry.RegistryService; -import com.alipay.sofa.ark.spi.web.EmbeddedServerService; +import com.alipay.sofa.ark.spi.service.injection.InjectionService; import com.alipay.sofa.ark.springboot.web.ArkTomcatServletWebServerFactory.StaticResourceConfigurer; import org.apache.catalina.Context; import org.apache.catalina.LifecycleException; @@ -52,48 +49,25 @@ public class ArkTomcatServletWebServerFactoryTest { private ArkTomcatServletWebServerFactory arkTomcatServletWebServerFactory = new ArkTomcatServletWebServerFactory(); private ClassLoader currentThreadContextClassLoader; + private InjectionService injectionService; @Before public void setUp() { + injectionService = ArkClient.getInjectionService(); + ArkClient.setInjectionService(null); currentThreadContextClassLoader = currentThread().getContextClassLoader(); } @After public void tearDown() { + ArkClient.setInjectionService(injectionService); currentThread().setContextClassLoader(currentThreadContextClassLoader); } - private static class RegistryServiceHolder { - @ArkInject - private RegistryService registryService; - - public RegistryService getRegistryService() { - return registryService; - } - - } - @Test public void testGetWebServerWithEmbeddedServerServiceNull() { - ServiceReference reference = null; - RegistryServiceHolder holder = null; - if (ArkClient.getInjectionService() != null) { - holder = new RegistryServiceHolder(); - ArkClient.getInjectionService().inject(holder); - if (holder.getRegistryService() != null) { - ServiceReference ref = holder.getRegistryService().referenceService(EmbeddedServerService.class); - holder.getRegistryService().unPublishServices(svc -> svc == ref); - reference = ref; - } - } - try { - assertEquals(TomcatWebServer.class, arkTomcatServletWebServerFactory.getWebServer() - .getClass()); - } finally { - if (reference != null) { - holder.getRegistryService().publishService(EmbeddedServerService.class, reference.getService(), reference.getServiceMetadata().getUniqueId(), reference.getServiceMetadata().getServiceProvider()); - } - } + assertEquals(TomcatWebServer.class, arkTomcatServletWebServerFactory.getWebServer() + .getClass()); } @Test From 74f7edefcb35a2f507894982d4fb0d2936e85fd8 Mon Sep 17 00:00:00 2001 From: leo james Date: Wed, 18 Sep 2024 15:09:28 +0800 Subject: [PATCH 06/11] add check for auto slim config in sofa-ark-maven-plugin (#1009) --- .../alipay/sofa/ark/boot/mojo/ModuleSlimStrategy.java | 10 +++++++++- .../com/alipay/sofa/ark/boot/mojo/RepackageMojo.java | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/ModuleSlimStrategy.java b/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/ModuleSlimStrategy.java index 06367ec38..973f049fd 100644 --- a/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/ModuleSlimStrategy.java +++ b/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/ModuleSlimStrategy.java @@ -181,6 +181,13 @@ protected void initSlimStrategyConfig() throws IOException { initExcludeAndIncludeConfig(); } + /** + * exclude and include config comes from 3 parts: + * 1. extension from config file that configured by user in sofa-ark-maven-plugin + * 2. extension from default bootstrap.properties or bootstrap.yml + * 3. extension from url + * @throws IOException + */ protected void initExcludeAndIncludeConfig() throws IOException { // extension from other resource if (!StringUtils.isEmpty(config.getPackExcludesConfig())) { @@ -191,6 +198,7 @@ protected void initExcludeAndIncludeConfig() throws IOException { + File.separator + DEFAULT_EXCLUDE_RULES); } + // extension from default bootstrap.properties or bootstrap.yml configExcludeArtifactsByDefault(); // extension from url @@ -766,4 +774,4 @@ public void setJarWarnList(List jarWarnList) { } } -} \ No newline at end of file +} diff --git a/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/RepackageMojo.java b/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/RepackageMojo.java index 0d7db306a..94437e867 100644 --- a/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/RepackageMojo.java +++ b/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/RepackageMojo.java @@ -17,7 +17,6 @@ package com.alipay.sofa.ark.boot.mojo; import com.alipay.sofa.ark.boot.mojo.model.ArkConfigHolder; -import com.alipay.sofa.ark.common.util.AssertUtils; import com.alipay.sofa.ark.tools.ArtifactItem; import com.alipay.sofa.ark.tools.Libraries; import com.alipay.sofa.ark.tools.Repackager; @@ -107,6 +106,10 @@ public class RepackageMojo extends TreeMojo { @Parameter(defaultValue = "${project.basedir}", required = true) private File baseDir; + /** + * Deprecated by the default conf/ark/bootstrap.properties or conf/ark/bootstrap.yml + */ + @Deprecated @Parameter(defaultValue = "", required = false) private String packExcludesConfig; @@ -543,6 +546,10 @@ private Set getAdditionalArtifact() throws MojoExecutionException { private Set getSlimmedArtifacts() throws MojoExecutionException, IOException, MojoFailureException { + if (StringUtils.endsWithAny(packExcludesConfig, ".yml", ".properties")) { + throw new MojoExecutionException( + "not support packExcludesConfig of .yml or .properties in sofa-ark-maven-plugin, please using default conf/ark/bootstrap.yml or conf/ark/bootstrap.properties"); + } ModuleSlimConfig moduleSlimConfig = (new ModuleSlimConfig()) .setPackExcludesConfig(packExcludesConfig).setPackExcludesUrl(packExcludesUrl) .setExcludes(excludes).setExcludeGroupIds(excludeGroupIds) From 88fb8e2f89b171fac610977e62292014361757c5 Mon Sep 17 00:00:00 2001 From: leo james Date: Wed, 18 Sep 2024 15:45:58 +0800 Subject: [PATCH 07/11] support blank in properties for slim config @lvjing2 (#1010) * add check for auto slim config in sofa-ark-maven-plugin * support blank in properties for slim config --- .../com/alipay/sofa/ark/boot/mojo/utils/ParseUtils.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/utils/ParseUtils.java b/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/utils/ParseUtils.java index eb905e354..1042c2df6 100644 --- a/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/utils/ParseUtils.java +++ b/sofa-ark-parent/support/ark-maven-plugin/src/main/java/com/alipay/sofa/ark/boot/mojo/utils/ParseUtils.java @@ -38,7 +38,11 @@ public static Set getStringSet(Properties prop, String confKey) { return newHashSet(); } String[] values = StringUtils.split(prop.getProperty(confKey), COMMA_SPLIT); - return values == null ? newHashSet() : newHashSet(values); + if (values == null) { + return newHashSet(); + } + values = Arrays.stream(values).map(String::trim).filter(s -> !s.isEmpty()).toArray(String[]::new); + return newHashSet(values); } public static Set getStringSet(Map yaml, String confKey) { @@ -86,4 +90,4 @@ private static Object getValue(Map yaml, String confKey) { } return null; } -} \ No newline at end of file +} From f9573142b1cb890f579fd722a5b336c962ddcc5a Mon Sep 17 00:00:00 2001 From: leojames Date: Thu, 19 Sep 2024 20:04:46 +0800 Subject: [PATCH 08/11] enable handle AfterBizStopEvent --- pom.xml | 4 ++-- .../java/com/alipay/sofa/ark/container/model/BizModel.java | 2 +- .../ark/container/service/event/EventAdminServiceImpl.java | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 9774f3efe..b96d7e64a 100644 --- a/pom.xml +++ b/pom.xml @@ -14,8 +14,8 @@ - 2.2.14 - 2.2.13 + 2.2.15-SNAPSHOT + 2.2.14 UTF-8 1.8 3.0 diff --git a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java index 1c05e4e79..68ce51042 100644 --- a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java +++ b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java @@ -415,8 +415,8 @@ public void stop() { classLoader = null; recycleBizTempWorkDir(bizTempWorkDir); bizTempWorkDir = null; - ClassLoaderUtils.popContextClassLoader(oldClassLoader); eventAdminService.sendEvent(new AfterBizStopEvent(this)); + ClassLoaderUtils.popContextClassLoader(oldClassLoader); } } diff --git a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/event/EventAdminServiceImpl.java b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/event/EventAdminServiceImpl.java index f4234cd13..8ee9b38ef 100644 --- a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/event/EventAdminServiceImpl.java +++ b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/event/EventAdminServiceImpl.java @@ -19,7 +19,7 @@ import com.alipay.sofa.ark.common.log.ArkLoggerFactory; import com.alipay.sofa.ark.common.util.OrderComparator; import com.alipay.sofa.ark.spi.event.ArkEvent; -import com.alipay.sofa.ark.spi.event.biz.BeforeBizRecycleEvent; +import com.alipay.sofa.ark.spi.event.biz.AfterBizStopEvent; import com.alipay.sofa.ark.spi.event.plugin.AfterPluginStopEvent; import com.alipay.sofa.ark.spi.registry.ServiceReference; import com.alipay.sofa.ark.spi.service.PriorityOrdered; @@ -112,8 +112,8 @@ public void unRegister(ClassLoader classLoader) { public void handleEvent(ArkEvent event) { ClassLoader classLoader = null; - if (event instanceof BeforeBizRecycleEvent) { - classLoader = ((BeforeBizRecycleEvent) event).getSource().getBizClassLoader(); + if (event instanceof AfterBizStopEvent) { + classLoader = ((AfterBizStopEvent) event).getSource().getBizClassLoader(); } else if (event instanceof AfterPluginStopEvent) { classLoader = ((AfterPluginStopEvent) event).getSource().getPluginClassLoader(); } From 3b8c05ee42c58fd27f166b4b7a8867caf96e0d0f Mon Sep 17 00:00:00 2001 From: leojames Date: Tue, 24 Sep 2024 11:57:25 +0800 Subject: [PATCH 09/11] add clean up event handlers --- .../sofa/ark/container/model/BizModel.java | 2 + .../sofa/ark/container/model/PluginModel.java | 4 +- .../service/event/EventAdminServiceImpl.java | 12 +- .../sofa/ark/spi/constant/Constants.java | 289 +++++++++--------- .../spi/event/biz/CleanAfterBizStopEvent.java | 31 ++ .../plugin/CleanAfterPluginStopEvent.java | 33 ++ 6 files changed, 221 insertions(+), 150 deletions(-) create mode 100644 sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/biz/CleanAfterBizStopEvent.java create mode 100644 sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/plugin/CleanAfterPluginStopEvent.java diff --git a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java index 68ce51042..1e523aba0 100644 --- a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java +++ b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java @@ -36,6 +36,7 @@ import com.alipay.sofa.ark.spi.event.biz.BeforeBizRecycleEvent; import com.alipay.sofa.ark.spi.event.biz.BeforeBizStartupEvent; import com.alipay.sofa.ark.spi.event.biz.BeforeBizStopEvent; +import com.alipay.sofa.ark.spi.event.biz.CleanAfterBizStopEvent; import com.alipay.sofa.ark.spi.model.Biz; import com.alipay.sofa.ark.spi.model.BizState; import com.alipay.sofa.ark.spi.service.biz.BizManagerService; @@ -416,6 +417,7 @@ public void stop() { recycleBizTempWorkDir(bizTempWorkDir); bizTempWorkDir = null; eventAdminService.sendEvent(new AfterBizStopEvent(this)); + eventAdminService.sendEvent(new CleanAfterBizStopEvent(this)); ClassLoaderUtils.popContextClassLoader(oldClassLoader); } } diff --git a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/PluginModel.java b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/PluginModel.java index 2761e2d71..b3ae2d2b8 100644 --- a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/PluginModel.java +++ b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/PluginModel.java @@ -26,6 +26,7 @@ import com.alipay.sofa.ark.spi.event.plugin.AfterPluginStopEvent; import com.alipay.sofa.ark.spi.event.plugin.BeforePluginStartupEvent; import com.alipay.sofa.ark.spi.event.plugin.BeforePluginStopEvent; +import com.alipay.sofa.ark.spi.event.plugin.CleanAfterPluginStopEvent; import com.alipay.sofa.ark.spi.model.Plugin; import com.alipay.sofa.ark.spi.model.PluginContext; import com.alipay.sofa.ark.spi.service.PluginActivator; @@ -367,6 +368,7 @@ public void stop() throws ArkRuntimeException { throw new ArkRuntimeException(ex.getMessage(), ex); } finally { eventAdminService.sendEvent(new AfterPluginStopEvent(this)); + eventAdminService.sendEvent(new CleanAfterPluginStopEvent(this)); } } @@ -375,4 +377,4 @@ public String toString() { return "Ark Plugin: " + pluginName; } -} \ No newline at end of file +} diff --git a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/event/EventAdminServiceImpl.java b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/event/EventAdminServiceImpl.java index 8ee9b38ef..43fd69dc0 100644 --- a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/event/EventAdminServiceImpl.java +++ b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/event/EventAdminServiceImpl.java @@ -19,8 +19,8 @@ import com.alipay.sofa.ark.common.log.ArkLoggerFactory; import com.alipay.sofa.ark.common.util.OrderComparator; import com.alipay.sofa.ark.spi.event.ArkEvent; -import com.alipay.sofa.ark.spi.event.biz.AfterBizStopEvent; -import com.alipay.sofa.ark.spi.event.plugin.AfterPluginStopEvent; +import com.alipay.sofa.ark.spi.event.biz.CleanAfterBizStopEvent; +import com.alipay.sofa.ark.spi.event.plugin.CleanAfterPluginStopEvent; import com.alipay.sofa.ark.spi.registry.ServiceReference; import com.alipay.sofa.ark.spi.service.PriorityOrdered; import com.alipay.sofa.ark.spi.service.event.EventAdminService; @@ -112,10 +112,10 @@ public void unRegister(ClassLoader classLoader) { public void handleEvent(ArkEvent event) { ClassLoader classLoader = null; - if (event instanceof AfterBizStopEvent) { - classLoader = ((AfterBizStopEvent) event).getSource().getBizClassLoader(); - } else if (event instanceof AfterPluginStopEvent) { - classLoader = ((AfterPluginStopEvent) event).getSource().getPluginClassLoader(); + if (event instanceof CleanAfterBizStopEvent) { + classLoader = ((CleanAfterBizStopEvent) event).getSource().getBizClassLoader(); + } else if (event instanceof CleanAfterPluginStopEvent) { + classLoader = ((CleanAfterPluginStopEvent) event).getSource().getPluginClassLoader(); } if (classLoader != null) { diff --git a/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/constant/Constants.java b/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/constant/Constants.java index 143770f66..8e4a68009 100644 --- a/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/constant/Constants.java +++ b/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/constant/Constants.java @@ -27,236 +27,239 @@ public class Constants { /** * String Constants */ - public final static String SPACE_SPLIT = "\\s+"; - public final static String STRING_COLON = ":"; - public final static String STRING_SEMICOLON = ";"; - public final static String TELNET_STRING_END = new String( - new byte[] { - (byte) 13, (byte) 10 }); - public final static String COMMA_SPLIT = ","; - public final static String EMPTY_STR = ""; - public final static String AMPERSAND_SPLIT = "&"; - public final static String EQUAL_SPLIT = "="; - public final static String QUESTION_MARK_SPLIT = "?"; - public final static String ROOT_WEB_CONTEXT_PATH = "/"; + public final static String SPACE_SPLIT = "\\s+"; + public final static String STRING_COLON = ":"; + public final static String STRING_SEMICOLON = ";"; + public final static String TELNET_STRING_END = new String( + new byte[] { + (byte) 13, (byte) 10 }); + public final static String COMMA_SPLIT = ","; + public final static String EMPTY_STR = ""; + public final static String AMPERSAND_SPLIT = "&"; + public final static String EQUAL_SPLIT = "="; + public final static String QUESTION_MARK_SPLIT = "?"; + public final static String ROOT_WEB_CONTEXT_PATH = "/"; /** * ark conf */ - public final static String CONF_BASE_DIR = "conf/"; - public final static String ARK_CONF_BASE_DIR = "conf/ark"; - public final static String ARK_CONF_FILE = "bootstrap.properties"; - public final static String ARK_CONF_FILE_FORMAT = "bootstrap-%s.properties"; + public final static String CONF_BASE_DIR = "conf/"; + public final static String ARK_CONF_BASE_DIR = "conf/ark"; + public final static String ARK_CONF_FILE = "bootstrap.properties"; + public final static String ARK_CONF_FILE_FORMAT = "bootstrap-%s.properties"; - public final static String ARK_CONF_YAML_FILE = "bootstrap.yml"; + public final static String ARK_CONF_YAML_FILE = "bootstrap.yml"; - public final static String PLUGIN_EXTENSION_FORMAT = "PLUGIN-EXPORT[%s]"; + public final static String PLUGIN_EXTENSION_FORMAT = "PLUGIN-EXPORT[%s]"; - public final static String DEFAULT_PROFILE = EMPTY_STR; + public final static String DEFAULT_PROFILE = EMPTY_STR; - public final static String LOCAL_HOST = "localhost"; + public final static String LOCAL_HOST = "localhost"; /** * ark classloader cache conf */ - public final static String ARK_CLASSLOADER_CACHE_CLASS_SIZE_INITIAL = "ark.classloader.cache.class.size.initial"; - public final static String ARK_CLASSLOADER_CACHE_CLASS_SIZE_MAX = "ark.classloader.cache.class.size.max"; - public final static String ARK_CLASSLOADER_CACHE_CONCURRENCY_LEVEL = "ark.classloader.cache.concurrencylevel"; + public final static String ARK_CLASSLOADER_CACHE_CLASS_SIZE_INITIAL = "ark.classloader.cache.class.size.initial"; + public final static String ARK_CLASSLOADER_CACHE_CLASS_SIZE_MAX = "ark.classloader.cache.class.size.max"; + public final static String ARK_CLASSLOADER_CACHE_CONCURRENCY_LEVEL = "ark.classloader.cache.concurrencylevel"; /** * plugin conf, multi value is split by comma. */ - public final static String PLUGIN_ACTIVE_INCLUDE = "ark.plugin.active.include"; - public final static String PLUGIN_ACTIVE_EXCLUDE = "ark.plugin.active.exclude"; + public final static String PLUGIN_ACTIVE_INCLUDE = "ark.plugin.active.include"; + public final static String PLUGIN_ACTIVE_EXCLUDE = "ark.plugin.active.exclude"; /** * biz conf, multi value is split by comma. */ - public final static String BIZ_ACTIVE_INCLUDE = "ark.biz.active.include"; - public final static String BIZ_ACTIVE_EXCLUDE = "ark.biz.active.exclude"; + public final static String BIZ_ACTIVE_INCLUDE = "ark.biz.active.include"; + public final static String BIZ_ACTIVE_EXCLUDE = "ark.biz.active.exclude"; /** * Archiver Marker */ - public final static String ARK_CONTAINER_MARK_ENTRY = "com/alipay/sofa/ark/container/mark"; + public final static String ARK_CONTAINER_MARK_ENTRY = "com/alipay/sofa/ark/container/mark"; - public final static String ARK_PLUGIN_MARK_ENTRY = "com/alipay/sofa/ark/plugin/mark"; + public final static String ARK_PLUGIN_MARK_ENTRY = "com/alipay/sofa/ark/plugin/mark"; - public final static String ARK_BIZ_MARK_ENTRY = "com/alipay/sofa/ark/biz/mark"; + public final static String ARK_BIZ_MARK_ENTRY = "com/alipay/sofa/ark/biz/mark"; /** * Ark Plugin Attribute */ - public final static String PRIORITY_ATTRIBUTE = "priority"; - public final static String GROUP_ID_ATTRIBUTE = "groupId"; - public final static String ARTIFACT_ID_ATTRIBUTE = "artifactId"; - public final static String PLUGIN_NAME_ATTRIBUTE = "pluginName"; - public final static String PLUGIN_VERSION_ATTRIBUTE = "version"; - public final static String ACTIVATOR_ATTRIBUTE = "activator"; - public final static String WEB_CONTEXT_PATH = "web-context-path"; - public final static String IMPORT_CLASSES_ATTRIBUTE = "import-classes"; - public final static String IMPORT_PACKAGES_ATTRIBUTE = "import-packages"; - - public final static String EXPORT_MODE = "export-mode"; - public final static String EXPORT_CLASSES_ATTRIBUTE = "export-classes"; - public final static String EXPORT_PACKAGES_ATTRIBUTE = "export-packages"; + public final static String PRIORITY_ATTRIBUTE = "priority"; + public final static String GROUP_ID_ATTRIBUTE = "groupId"; + public final static String ARTIFACT_ID_ATTRIBUTE = "artifactId"; + public final static String PLUGIN_NAME_ATTRIBUTE = "pluginName"; + public final static String PLUGIN_VERSION_ATTRIBUTE = "version"; + public final static String ACTIVATOR_ATTRIBUTE = "activator"; + public final static String WEB_CONTEXT_PATH = "web-context-path"; + public final static String IMPORT_CLASSES_ATTRIBUTE = "import-classes"; + public final static String IMPORT_PACKAGES_ATTRIBUTE = "import-packages"; + + public final static String EXPORT_MODE = "export-mode"; + public final static String EXPORT_CLASSES_ATTRIBUTE = "export-classes"; + public final static String EXPORT_PACKAGES_ATTRIBUTE = "export-packages"; /** * Ark Biz Attribute */ - public final static String MAIN_CLASS_ATTRIBUTE = "Main-Class"; - public final static String START_CLASS_ATTRIBUTE = "Start-Class"; - public final static String ARK_BIZ_NAME = "Ark-Biz-Name"; - public final static String ARK_BIZ_VERSION = "Ark-Biz-Version"; - public final static String DENY_IMPORT_CLASSES = "deny-import-classes"; - public final static String DENY_IMPORT_PACKAGES = "deny-import-packages"; - public final static String DENY_IMPORT_RESOURCES = "deny-import-resources"; - public final static String INJECT_PLUGIN_DEPENDENCIES = "inject-plugin-dependencies"; - public final static String INJECT_EXPORT_PACKAGES = "inject-export-packages"; - public final static String DECLARED_LIBRARIES = "declared-libraries"; - - public static final String BRANCH = "commit-branch"; - public static final String COMMIT_ID = "commit-id"; - public static final String BUILD_USER = "build-user"; - public static final String BUILD_EMAIL = "build-email"; - public static final String BUILD_TIME = "build-time"; - public static final String COMMIT_AUTHOR_NAME = "commit-user-name"; - public static final String COMMIT_AUTHOR_EMAIL = "commit-user-email"; - public static final String COMMIT_TIMESTAMP = "commit-timestamp"; - public static final String COMMIT_TIME = "commit-time"; - public static final String REMOTE_ORIGIN_URL = "remote-origin-url"; - - public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ"; - - public final static String PACKAGE_PREFIX_MARK = "*"; - - public final static String PACKAGE_PREFIX_MARK_2 = ".*"; - public final static String DEFAULT_PACKAGE = "."; - public final static String MANIFEST_VALUE_SPLIT = COMMA_SPLIT; - public final static String RESOURCE_STEM_MARK = "*"; - - public final static String IMPORT_RESOURCES_ATTRIBUTE = "import-resources"; - public final static String EXPORT_RESOURCES_ATTRIBUTE = "export-resources"; - - public final static String SUREFIRE_BOOT_CLASSPATH = "Class-Path"; - public final static String SUREFIRE_BOOT_CLASSPATH_SPLIT = " "; - public final static String SUREFIRE_BOOT_JAR = "surefirebooter"; + public final static String MAIN_CLASS_ATTRIBUTE = "Main-Class"; + public final static String START_CLASS_ATTRIBUTE = "Start-Class"; + public final static String ARK_BIZ_NAME = "Ark-Biz-Name"; + public final static String ARK_BIZ_VERSION = "Ark-Biz-Version"; + public final static String DENY_IMPORT_CLASSES = "deny-import-classes"; + public final static String DENY_IMPORT_PACKAGES = "deny-import-packages"; + public final static String DENY_IMPORT_RESOURCES = "deny-import-resources"; + public final static String INJECT_PLUGIN_DEPENDENCIES = "inject-plugin-dependencies"; + public final static String INJECT_EXPORT_PACKAGES = "inject-export-packages"; + public final static String DECLARED_LIBRARIES = "declared-libraries"; + + public static final String BRANCH = "commit-branch"; + public static final String COMMIT_ID = "commit-id"; + public static final String BUILD_USER = "build-user"; + public static final String BUILD_EMAIL = "build-email"; + public static final String BUILD_TIME = "build-time"; + public static final String COMMIT_AUTHOR_NAME = "commit-user-name"; + public static final String COMMIT_AUTHOR_EMAIL = "commit-user-email"; + public static final String COMMIT_TIMESTAMP = "commit-timestamp"; + public static final String COMMIT_TIME = "commit-time"; + public static final String REMOTE_ORIGIN_URL = "remote-origin-url"; + + public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ"; + + public final static String PACKAGE_PREFIX_MARK = "*"; + + public final static String PACKAGE_PREFIX_MARK_2 = ".*"; + public final static String DEFAULT_PACKAGE = "."; + public final static String MANIFEST_VALUE_SPLIT = COMMA_SPLIT; + public final static String RESOURCE_STEM_MARK = "*"; + + public final static String IMPORT_RESOURCES_ATTRIBUTE = "import-resources"; + public final static String EXPORT_RESOURCES_ATTRIBUTE = "export-resources"; + + public final static String SUREFIRE_BOOT_CLASSPATH = "Class-Path"; + public final static String SUREFIRE_BOOT_CLASSPATH_SPLIT = " "; + public final static String SUREFIRE_BOOT_JAR = "surefirebooter"; /** * Telnet Server */ - public final static String TELNET_SERVER_ENABLE = "sofa.ark.telnet.server.enable"; - public final static String TELNET_SERVER_SECURITY_ENABLE = "sofa.ark.telnet.security.enable"; - public final static String CONFIG_SERVER_ENABLE = "sofa.ark.config.server.enable"; + public final static String TELNET_SERVER_ENABLE = "sofa.ark.telnet.server.enable"; + public final static String TELNET_SERVER_SECURITY_ENABLE = "sofa.ark.telnet.security.enable"; + public final static String CONFIG_SERVER_ENABLE = "sofa.ark.config.server.enable"; /** * 配置中心支持, 默认使用zookeeper * value值为com.alipay.sofa.ark.config.ConfigTypeEnum枚举的name() */ - public final static String CONFIG_SERVER_TYPE = "sofa.ark.config.server.type"; + public final static String CONFIG_SERVER_TYPE = "sofa.ark.config.server.type"; /** * 使用apollo的namespace */ - public final static String CONFIG_APOLLO_NAMESPACE = "sofa-ark"; + public final static String CONFIG_APOLLO_NAMESPACE = "sofa-ark"; /** * apollo的namespace下动态命名对应的key */ - public final static String APOLLO_MASTER_BIZ_KEY = "masterBiz"; - public final static String TELNET_PORT_ATTRIBUTE = "sofa.ark.telnet.port"; - public final static int DEFAULT_TELNET_PORT = 1234; - public final static int DEFAULT_SELECT_PORT_SIZE = 100; - public final static String TELNET_SERVER_WORKER_THREAD_POOL_NAME = "telnet-server-worker"; - public final static String TELNET_SESSION_PROMPT = "sofa-ark>"; - public final static String TELNET_COMMAND_THREAD_POOL_NAME = "telnet-command"; + public final static String APOLLO_MASTER_BIZ_KEY = "masterBiz"; + public final static String TELNET_PORT_ATTRIBUTE = "sofa.ark.telnet.port"; + public final static int DEFAULT_TELNET_PORT = 1234; + public final static int DEFAULT_SELECT_PORT_SIZE = 100; + public final static String TELNET_SERVER_WORKER_THREAD_POOL_NAME = "telnet-server-worker"; + public final static String TELNET_SESSION_PROMPT = "sofa-ark>"; + public final static String TELNET_COMMAND_THREAD_POOL_NAME = "telnet-command"; /** * Event */ - public final static String BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_START = "AFTER-INVOKE-BIZ-START"; - public final static String BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_STOP = "AFTER-INVOKE-BIZ-STOP"; - public final static String BIZ_EVENT_TOPIC_AFTER_BIZ_FAILED = "BIZ_EVENT_TOPIC_AFTER_BIZ_FAILED"; - public final static String BIZ_EVENT_TOPIC_BEFORE_RECYCLE_BIZ = "BEFORE-RECYCLE-BIZ"; - public final static String BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_START = "BEFORE-INVOKE-BIZ-START"; - public final static String BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_STOP = "BEFORE-INVOKE-BIZ-STOP"; + public final static String BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_START = "AFTER-INVOKE-BIZ-START"; + public final static String BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_STOP = "AFTER-INVOKE-BIZ-STOP"; + public final static String BIZ_EVENT_TOPIC_AFTER_BIZ_FAILED = "BIZ_EVENT_TOPIC_AFTER_BIZ_FAILED"; + public final static String BIZ_EVENT_TOPIC_CLEAN_AFTER_INVOKE_BIZ_STOP = "CLEAN-AFTER-INVOKE-BIZ-STOP"; - public final static String PLUGIN_EVENT_TOPIC_AFTER_INVOKE_PLUGIN_START = "AFTER-INVOKE-PLUGIN-START"; - public final static String PLUGIN_EVENT_TOPIC_AFTER_INVOKE_PLUGIN_STOP = "AFTER-INVOKE-PLUGIN-STOP"; - public final static String PLUGIN_EVENT_TOPIC_BEFORE_INVOKE_PLUGIN_START = "BEFORE-INVOKE-PLUGIN-START"; - public final static String PLUGIN_EVENT_TOPIC_BEFORE_INVOKE_PLUGIN_STOP = "BEFORE-INVOKE-PLUGIN-STOP"; + public final static String BIZ_EVENT_TOPIC_BEFORE_RECYCLE_BIZ = "BEFORE-RECYCLE-BIZ"; + public final static String BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_START = "BEFORE-INVOKE-BIZ-START"; + public final static String BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_STOP = "BEFORE-INVOKE-BIZ-STOP"; - public final static String BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_SWITCH = "BEFORE-INVOKE-BIZ-SWITCH"; - public final static String BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_SWITCH = "AFTER-INVOKE-BIZ-SWITCH"; + public final static String PLUGIN_EVENT_TOPIC_AFTER_INVOKE_PLUGIN_START = "AFTER-INVOKE-PLUGIN-START"; + public final static String PLUGIN_EVENT_TOPIC_AFTER_INVOKE_PLUGIN_STOP = "AFTER-INVOKE-PLUGIN-STOP"; + public final static String PLUGIN_EVENT_TOPIC_CLEAN_AFTER_INVOKE_PLUGIN_STOP = "CLEAN-AFTER-INVOKE-PLUGIN-STOP"; + public final static String PLUGIN_EVENT_TOPIC_BEFORE_INVOKE_PLUGIN_START = "BEFORE-INVOKE-PLUGIN-START"; + public final static String PLUGIN_EVENT_TOPIC_BEFORE_INVOKE_PLUGIN_STOP = "BEFORE-INVOKE-PLUGIN-STOP"; - public final static String ARK_EVENT_TOPIC_AFTER_FINISH_STARTUP_STAGE = "AFTER-FINISH-STARTUP-STAGE"; - public final static String ARK_EVENT_TOPIC_AFTER_FINISH_DEPLOY_STAGE = "AFTER-FINISH-DEPLOY-STAGE"; + public final static String BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_SWITCH = "BEFORE-INVOKE-BIZ-SWITCH"; + public final static String BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_SWITCH = "AFTER-INVOKE-BIZ-SWITCH"; + + public final static String ARK_EVENT_TOPIC_AFTER_FINISH_STARTUP_STAGE = "AFTER-FINISH-STARTUP-STAGE"; + public final static String ARK_EVENT_TOPIC_AFTER_FINISH_DEPLOY_STAGE = "AFTER-FINISH-DEPLOY-STAGE"; /** * Environment Properties */ - public final static String SPRING_BOOT_ENDPOINTS_JMX_ENABLED = "endpoints.jmx.enabled"; - public final static String LOG4J_IGNORE_TCL = "log4j.ignoreTCL"; - public final static String RESOLVE_PARENT_CONTEXT_SERIALIZER_FACTORY = "hessian.parent.context.create"; - public final static String EMBED_ENABLE = "sofa.ark.embed.enable"; - public final static String PLUGIN_EXPORT_CLASS_ENABLE = "sofa.ark.plugin.export.class.enable"; - public final static String EMBED_STATIC_BIZ_ENABLE = "sofa.ark.embed.static.biz.enable"; + public final static String SPRING_BOOT_ENDPOINTS_JMX_ENABLED = "endpoints.jmx.enabled"; + public final static String LOG4J_IGNORE_TCL = "log4j.ignoreTCL"; + public final static String RESOLVE_PARENT_CONTEXT_SERIALIZER_FACTORY = "hessian.parent.context.create"; + public final static String EMBED_ENABLE = "sofa.ark.embed.enable"; + public final static String PLUGIN_EXPORT_CLASS_ENABLE = "sofa.ark.plugin.export.class.enable"; + public final static String EMBED_STATIC_BIZ_ENABLE = "sofa.ark.embed.static.biz.enable"; - public final static String EMBED_STATIC_BIZ_IN_RESOURCE_ENABLE = "sofa.ark.embed.static.biz.in.resource.enable"; - public final static String ACTIVATE_NEW_MODULE = "activate.new.module"; + public final static String EMBED_STATIC_BIZ_IN_RESOURCE_ENABLE = "sofa.ark.embed.static.biz.in.resource.enable"; + public final static String ACTIVATE_NEW_MODULE = "activate.new.module"; - public final static String AUTO_UNINSTALL_WHEN_FAILED_ENABLE = "sofa.ark.auto.uninstall.when.failed.enable"; + public final static String AUTO_UNINSTALL_WHEN_FAILED_ENABLE = "sofa.ark.auto.uninstall.when.failed.enable"; /** * Command Provider */ - public final static String PLUGIN_COMMAND_UNIQUE_ID = "plugin-command-provider"; - public final static String BIZ_COMMAND_UNIQUE_ID = "biz-command-provider"; + public final static String PLUGIN_COMMAND_UNIQUE_ID = "plugin-command-provider"; + public final static String BIZ_COMMAND_UNIQUE_ID = "biz-command-provider"; /** * Ark SPI extension */ - public final static String EXTENSION_FILE_DIR = "META-INF/services/sofa-ark/"; - public final static String PLUGIN_CLASS_LOADER_HOOK = "plugin-classloader-hook"; - public final static String BIZ_CLASS_LOADER_HOOK = "biz-classloader-hook"; - public final static String BIZ_CLASS_LOADER_HOOK_DIR = "com.alipay.sofa.ark.biz.classloader.hook.dir"; - public final static String BIZ_TEMP_WORK_DIR_RECYCLE_FILE_SUFFIX = "deleted"; + public final static String EXTENSION_FILE_DIR = "META-INF/services/sofa-ark/"; + public final static String PLUGIN_CLASS_LOADER_HOOK = "plugin-classloader-hook"; + public final static String BIZ_CLASS_LOADER_HOOK = "biz-classloader-hook"; + public final static String BIZ_CLASS_LOADER_HOOK_DIR = "com.alipay.sofa.ark.biz.classloader.hook.dir"; + public final static String BIZ_TEMP_WORK_DIR_RECYCLE_FILE_SUFFIX = "deleted"; /** * Multiply biz name */ - public final static String MASTER_BIZ = "com.alipay.sofa.ark.master.biz"; + public final static String MASTER_BIZ = "com.alipay.sofa.ark.master.biz"; - public final static String SOFA_ARK_MODULE = "SOFA-ARK/biz/"; + public final static String SOFA_ARK_MODULE = "SOFA-ARK/biz/"; /** * Config Server */ - public final static String CONFIG_SERVER_ADDRESS = "com.alipay.sofa.ark.config.address"; - public final static String CONFIG_SERVER_ENVIRONMENT = "com.alipay.sofa.ark.config.env"; - public final static String CONFIG_PROTOCOL_ZOOKEEPER = "zookeeper"; - public final static String CONFIG_PROTOCOL_ZOOKEEPER_HEADER = "zookeeper://"; - public final static String ZOOKEEPER_CONTEXT_SPLIT = "/"; - public final static String CONFIG_INSTALL_BIZ_DIR = "com.alipay.sofa.ark.biz.dir"; - public final static String CONFIG_BIZ_URL = "bizUrl"; + public final static String CONFIG_SERVER_ADDRESS = "com.alipay.sofa.ark.config.address"; + public final static String CONFIG_SERVER_ENVIRONMENT = "com.alipay.sofa.ark.config.env"; + public final static String CONFIG_PROTOCOL_ZOOKEEPER = "zookeeper"; + public final static String CONFIG_PROTOCOL_ZOOKEEPER_HEADER = "zookeeper://"; + public final static String ZOOKEEPER_CONTEXT_SPLIT = "/"; + public final static String CONFIG_INSTALL_BIZ_DIR = "com.alipay.sofa.ark.biz.dir"; + public final static String CONFIG_BIZ_URL = "bizUrl"; - public final static String CONFIG_CONNECT_TIMEOUT = "com.alipay.sofa.ark.config.connect.timeout"; - public final static int DEFAULT_CONFIG_CONNECT_TIMEOUT = 20000; + public final static String CONFIG_CONNECT_TIMEOUT = "com.alipay.sofa.ark.config.connect.timeout"; + public final static int DEFAULT_CONFIG_CONNECT_TIMEOUT = 20000; /** * Test ClassLoader */ - public final static String FORCE_DELEGATE_TO_TEST_CLASSLOADER = "com.alipay.sofa.ark.delegate.to.testClassLoader"; - public final static String FORCE_DELEGATE_TO_APP_CLASSLOADER = "com.alipay.sofa.ark.delegate.to.appClassLoader"; + public final static String FORCE_DELEGATE_TO_TEST_CLASSLOADER = "com.alipay.sofa.ark.delegate.to.testClassLoader"; + public final static String FORCE_DELEGATE_TO_APP_CLASSLOADER = "com.alipay.sofa.ark.delegate.to.appClassLoader"; - public final static String EXTENSION_EXCLUDES = "excludes"; - public final static String EXTENSION_EXCLUDES_GROUPIDS = "excludeGroupIds"; - public final static String EXTENSION_EXCLUDES_ARTIFACTIDS = "excludeArtifactIds"; + public final static String EXTENSION_EXCLUDES = "excludes"; + public final static String EXTENSION_EXCLUDES_GROUPIDS = "excludeGroupIds"; + public final static String EXTENSION_EXCLUDES_ARTIFACTIDS = "excludeArtifactIds"; - public final static String EXTENSION_INCLUDES = "includes"; - public final static String EXTENSION_INCLUDES_GROUPIDS = "includeGroupIds"; - public final static String EXTENSION_INCLUDES_ARTIFACTIDS = "includeArtifactIds"; + public final static String EXTENSION_INCLUDES = "includes"; + public final static String EXTENSION_INCLUDES_GROUPIDS = "includeGroupIds"; + public final static String EXTENSION_INCLUDES_ARTIFACTIDS = "includeArtifactIds"; - public final static String DECLARED_LIBRARIES_WHITELIST = "declared.libraries.whitelist"; + public final static String DECLARED_LIBRARIES_WHITELIST = "declared.libraries.whitelist"; - public static final List CHANNEL_QUIT = new ArrayList<>(); + public static final List CHANNEL_QUIT = new ArrayList<>(); static { CHANNEL_QUIT.add("quit"); diff --git a/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/biz/CleanAfterBizStopEvent.java b/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/biz/CleanAfterBizStopEvent.java new file mode 100644 index 000000000..ff215ca48 --- /dev/null +++ b/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/biz/CleanAfterBizStopEvent.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.sofa.ark.spi.event.biz; + +import com.alipay.sofa.ark.spi.constant.Constants; +import com.alipay.sofa.ark.spi.event.AbstractArkEvent; +import com.alipay.sofa.ark.spi.model.Biz; + +/** + * only used to clean up biz module and event handlers in sofa-ark after biz stop + */ +public class CleanAfterBizStopEvent extends AbstractArkEvent { + public CleanAfterBizStopEvent(Biz source) { + super(source); + this.topic = Constants.BIZ_EVENT_TOPIC_CLEAN_AFTER_INVOKE_BIZ_STOP; + } +} diff --git a/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/plugin/CleanAfterPluginStopEvent.java b/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/plugin/CleanAfterPluginStopEvent.java new file mode 100644 index 000000000..9662b2564 --- /dev/null +++ b/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/plugin/CleanAfterPluginStopEvent.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alipay.sofa.ark.spi.event.plugin; + +import com.alipay.sofa.ark.spi.constant.Constants; +import com.alipay.sofa.ark.spi.event.AbstractArkEvent; +import com.alipay.sofa.ark.spi.model.Plugin; + +/** + * @author guolei.sgl (guolei.sgl@antfin.com) 2019/11/1 6:21 PM + * @since + **/ +public class CleanAfterPluginStopEvent extends AbstractArkEvent { + + public CleanAfterPluginStopEvent(Plugin source) { + super(source); + this.topic = Constants.PLUGIN_EVENT_TOPIC_CLEAN_AFTER_INVOKE_PLUGIN_STOP; + } +} From 5d66962b8416d6d5c628ce55c1d0f7c836c9b777 Mon Sep 17 00:00:00 2001 From: leojames Date: Tue, 24 Sep 2024 12:04:10 +0800 Subject: [PATCH 10/11] fix test --- .../alipay/sofa/ark/container/service/api/ArkClientTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/service/api/ArkClientTest.java b/sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/service/api/ArkClientTest.java index 055086b0b..b79f0335d 100644 --- a/sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/service/api/ArkClientTest.java +++ b/sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/service/api/ArkClientTest.java @@ -186,7 +186,8 @@ public int getPriority() { assertEquals("AFTER-INVOKE-BIZ-START", topicList.get(2)); // new event assertEquals("BEFORE-RECYCLE-BIZ", topicList.get(4)); - assertEquals("demo", topicList.get(7)); + assertEquals("CLEAN-AFTER-INVOKE-BIZ-STOP", topicList.get(6)); + assertEquals("demo", topicList.get(8)); } @Test From 6eef78553ff6167db2218c3a466f083bef48242f Mon Sep 17 00:00:00 2001 From: leo james Date: Tue, 24 Sep 2024 16:39:55 +0800 Subject: [PATCH 11/11] simply unregister event handlers (#1014) --- .../sofa/ark/container/model/BizModel.java | 6 +- .../sofa/ark/container/model/PluginModel.java | 5 +- .../service/event/EventAdminServiceImpl.java | 13 - .../container/service/api/ArkClientTest.java | 3 +- .../sofa/ark/spi/constant/Constants.java | 288 +++++++++--------- .../spi/event/biz/CleanAfterBizStopEvent.java | 31 -- .../plugin/CleanAfterPluginStopEvent.java | 33 -- 7 files changed, 150 insertions(+), 229 deletions(-) delete mode 100644 sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/biz/CleanAfterBizStopEvent.java delete mode 100644 sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/plugin/CleanAfterPluginStopEvent.java diff --git a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java index 1e523aba0..da65e6bd5 100644 --- a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java +++ b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java @@ -36,7 +36,6 @@ import com.alipay.sofa.ark.spi.event.biz.BeforeBizRecycleEvent; import com.alipay.sofa.ark.spi.event.biz.BeforeBizStartupEvent; import com.alipay.sofa.ark.spi.event.biz.BeforeBizStopEvent; -import com.alipay.sofa.ark.spi.event.biz.CleanAfterBizStopEvent; import com.alipay.sofa.ark.spi.model.Biz; import com.alipay.sofa.ark.spi.model.BizState; import com.alipay.sofa.ark.spi.service.biz.BizManagerService; @@ -413,11 +412,12 @@ public void stop() { "Ark biz {} close biz classloader fail", getIdentity()); } } + + eventAdminService.sendEvent(new AfterBizStopEvent(this)); + eventAdminService.unRegister(classLoader); classLoader = null; recycleBizTempWorkDir(bizTempWorkDir); bizTempWorkDir = null; - eventAdminService.sendEvent(new AfterBizStopEvent(this)); - eventAdminService.sendEvent(new CleanAfterBizStopEvent(this)); ClassLoaderUtils.popContextClassLoader(oldClassLoader); } } diff --git a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/PluginModel.java b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/PluginModel.java index b3ae2d2b8..bdcd395fa 100644 --- a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/PluginModel.java +++ b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/PluginModel.java @@ -26,7 +26,6 @@ import com.alipay.sofa.ark.spi.event.plugin.AfterPluginStopEvent; import com.alipay.sofa.ark.spi.event.plugin.BeforePluginStartupEvent; import com.alipay.sofa.ark.spi.event.plugin.BeforePluginStopEvent; -import com.alipay.sofa.ark.spi.event.plugin.CleanAfterPluginStopEvent; import com.alipay.sofa.ark.spi.model.Plugin; import com.alipay.sofa.ark.spi.model.PluginContext; import com.alipay.sofa.ark.spi.service.PluginActivator; @@ -368,7 +367,9 @@ public void stop() throws ArkRuntimeException { throw new ArkRuntimeException(ex.getMessage(), ex); } finally { eventAdminService.sendEvent(new AfterPluginStopEvent(this)); - eventAdminService.sendEvent(new CleanAfterPluginStopEvent(this)); + if (this.getPluginClassLoader() != null) { + eventAdminService.unRegister(this.getPluginClassLoader()); + } } } diff --git a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/event/EventAdminServiceImpl.java b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/event/EventAdminServiceImpl.java index 43fd69dc0..a1b82d9ff 100644 --- a/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/event/EventAdminServiceImpl.java +++ b/sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/event/EventAdminServiceImpl.java @@ -19,8 +19,6 @@ import com.alipay.sofa.ark.common.log.ArkLoggerFactory; import com.alipay.sofa.ark.common.util.OrderComparator; import com.alipay.sofa.ark.spi.event.ArkEvent; -import com.alipay.sofa.ark.spi.event.biz.CleanAfterBizStopEvent; -import com.alipay.sofa.ark.spi.event.plugin.CleanAfterPluginStopEvent; import com.alipay.sofa.ark.spi.registry.ServiceReference; import com.alipay.sofa.ark.spi.service.PriorityOrdered; import com.alipay.sofa.ark.spi.service.event.EventAdminService; @@ -110,17 +108,6 @@ public void unRegister(ClassLoader classLoader) { @Override public void handleEvent(ArkEvent event) { - ClassLoader classLoader = null; - - if (event instanceof CleanAfterBizStopEvent) { - classLoader = ((CleanAfterBizStopEvent) event).getSource().getBizClassLoader(); - } else if (event instanceof CleanAfterPluginStopEvent) { - classLoader = ((CleanAfterPluginStopEvent) event).getSource().getPluginClassLoader(); - } - - if (classLoader != null) { - unRegister(classLoader); - } } @Override diff --git a/sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/service/api/ArkClientTest.java b/sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/service/api/ArkClientTest.java index b79f0335d..055086b0b 100644 --- a/sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/service/api/ArkClientTest.java +++ b/sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/service/api/ArkClientTest.java @@ -186,8 +186,7 @@ public int getPriority() { assertEquals("AFTER-INVOKE-BIZ-START", topicList.get(2)); // new event assertEquals("BEFORE-RECYCLE-BIZ", topicList.get(4)); - assertEquals("CLEAN-AFTER-INVOKE-BIZ-STOP", topicList.get(6)); - assertEquals("demo", topicList.get(8)); + assertEquals("demo", topicList.get(7)); } @Test diff --git a/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/constant/Constants.java b/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/constant/Constants.java index 8e4a68009..eb9445c46 100644 --- a/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/constant/Constants.java +++ b/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/constant/Constants.java @@ -27,239 +27,237 @@ public class Constants { /** * String Constants */ - public final static String SPACE_SPLIT = "\\s+"; - public final static String STRING_COLON = ":"; - public final static String STRING_SEMICOLON = ";"; - public final static String TELNET_STRING_END = new String( - new byte[] { - (byte) 13, (byte) 10 }); - public final static String COMMA_SPLIT = ","; - public final static String EMPTY_STR = ""; - public final static String AMPERSAND_SPLIT = "&"; - public final static String EQUAL_SPLIT = "="; - public final static String QUESTION_MARK_SPLIT = "?"; - public final static String ROOT_WEB_CONTEXT_PATH = "/"; + public final static String SPACE_SPLIT = "\\s+"; + public final static String STRING_COLON = ":"; + public final static String STRING_SEMICOLON = ";"; + public final static String TELNET_STRING_END = new String( + new byte[] { + (byte) 13, (byte) 10 }); + public final static String COMMA_SPLIT = ","; + public final static String EMPTY_STR = ""; + public final static String AMPERSAND_SPLIT = "&"; + public final static String EQUAL_SPLIT = "="; + public final static String QUESTION_MARK_SPLIT = "?"; + public final static String ROOT_WEB_CONTEXT_PATH = "/"; /** * ark conf */ - public final static String CONF_BASE_DIR = "conf/"; - public final static String ARK_CONF_BASE_DIR = "conf/ark"; - public final static String ARK_CONF_FILE = "bootstrap.properties"; - public final static String ARK_CONF_FILE_FORMAT = "bootstrap-%s.properties"; + public final static String CONF_BASE_DIR = "conf/"; + public final static String ARK_CONF_BASE_DIR = "conf/ark"; + public final static String ARK_CONF_FILE = "bootstrap.properties"; + public final static String ARK_CONF_FILE_FORMAT = "bootstrap-%s.properties"; - public final static String ARK_CONF_YAML_FILE = "bootstrap.yml"; + public final static String ARK_CONF_YAML_FILE = "bootstrap.yml"; - public final static String PLUGIN_EXTENSION_FORMAT = "PLUGIN-EXPORT[%s]"; + public final static String PLUGIN_EXTENSION_FORMAT = "PLUGIN-EXPORT[%s]"; - public final static String DEFAULT_PROFILE = EMPTY_STR; + public final static String DEFAULT_PROFILE = EMPTY_STR; - public final static String LOCAL_HOST = "localhost"; + public final static String LOCAL_HOST = "localhost"; /** * ark classloader cache conf */ - public final static String ARK_CLASSLOADER_CACHE_CLASS_SIZE_INITIAL = "ark.classloader.cache.class.size.initial"; - public final static String ARK_CLASSLOADER_CACHE_CLASS_SIZE_MAX = "ark.classloader.cache.class.size.max"; - public final static String ARK_CLASSLOADER_CACHE_CONCURRENCY_LEVEL = "ark.classloader.cache.concurrencylevel"; + public final static String ARK_CLASSLOADER_CACHE_CLASS_SIZE_INITIAL = "ark.classloader.cache.class.size.initial"; + public final static String ARK_CLASSLOADER_CACHE_CLASS_SIZE_MAX = "ark.classloader.cache.class.size.max"; + public final static String ARK_CLASSLOADER_CACHE_CONCURRENCY_LEVEL = "ark.classloader.cache.concurrencylevel"; /** * plugin conf, multi value is split by comma. */ - public final static String PLUGIN_ACTIVE_INCLUDE = "ark.plugin.active.include"; - public final static String PLUGIN_ACTIVE_EXCLUDE = "ark.plugin.active.exclude"; + public final static String PLUGIN_ACTIVE_INCLUDE = "ark.plugin.active.include"; + public final static String PLUGIN_ACTIVE_EXCLUDE = "ark.plugin.active.exclude"; /** * biz conf, multi value is split by comma. */ - public final static String BIZ_ACTIVE_INCLUDE = "ark.biz.active.include"; - public final static String BIZ_ACTIVE_EXCLUDE = "ark.biz.active.exclude"; + public final static String BIZ_ACTIVE_INCLUDE = "ark.biz.active.include"; + public final static String BIZ_ACTIVE_EXCLUDE = "ark.biz.active.exclude"; /** * Archiver Marker */ - public final static String ARK_CONTAINER_MARK_ENTRY = "com/alipay/sofa/ark/container/mark"; + public final static String ARK_CONTAINER_MARK_ENTRY = "com/alipay/sofa/ark/container/mark"; - public final static String ARK_PLUGIN_MARK_ENTRY = "com/alipay/sofa/ark/plugin/mark"; + public final static String ARK_PLUGIN_MARK_ENTRY = "com/alipay/sofa/ark/plugin/mark"; - public final static String ARK_BIZ_MARK_ENTRY = "com/alipay/sofa/ark/biz/mark"; + public final static String ARK_BIZ_MARK_ENTRY = "com/alipay/sofa/ark/biz/mark"; /** * Ark Plugin Attribute */ - public final static String PRIORITY_ATTRIBUTE = "priority"; - public final static String GROUP_ID_ATTRIBUTE = "groupId"; - public final static String ARTIFACT_ID_ATTRIBUTE = "artifactId"; - public final static String PLUGIN_NAME_ATTRIBUTE = "pluginName"; - public final static String PLUGIN_VERSION_ATTRIBUTE = "version"; - public final static String ACTIVATOR_ATTRIBUTE = "activator"; - public final static String WEB_CONTEXT_PATH = "web-context-path"; - public final static String IMPORT_CLASSES_ATTRIBUTE = "import-classes"; - public final static String IMPORT_PACKAGES_ATTRIBUTE = "import-packages"; - - public final static String EXPORT_MODE = "export-mode"; - public final static String EXPORT_CLASSES_ATTRIBUTE = "export-classes"; - public final static String EXPORT_PACKAGES_ATTRIBUTE = "export-packages"; + public final static String PRIORITY_ATTRIBUTE = "priority"; + public final static String GROUP_ID_ATTRIBUTE = "groupId"; + public final static String ARTIFACT_ID_ATTRIBUTE = "artifactId"; + public final static String PLUGIN_NAME_ATTRIBUTE = "pluginName"; + public final static String PLUGIN_VERSION_ATTRIBUTE = "version"; + public final static String ACTIVATOR_ATTRIBUTE = "activator"; + public final static String WEB_CONTEXT_PATH = "web-context-path"; + public final static String IMPORT_CLASSES_ATTRIBUTE = "import-classes"; + public final static String IMPORT_PACKAGES_ATTRIBUTE = "import-packages"; + + public final static String EXPORT_MODE = "export-mode"; + public final static String EXPORT_CLASSES_ATTRIBUTE = "export-classes"; + public final static String EXPORT_PACKAGES_ATTRIBUTE = "export-packages"; /** * Ark Biz Attribute */ - public final static String MAIN_CLASS_ATTRIBUTE = "Main-Class"; - public final static String START_CLASS_ATTRIBUTE = "Start-Class"; - public final static String ARK_BIZ_NAME = "Ark-Biz-Name"; - public final static String ARK_BIZ_VERSION = "Ark-Biz-Version"; - public final static String DENY_IMPORT_CLASSES = "deny-import-classes"; - public final static String DENY_IMPORT_PACKAGES = "deny-import-packages"; - public final static String DENY_IMPORT_RESOURCES = "deny-import-resources"; - public final static String INJECT_PLUGIN_DEPENDENCIES = "inject-plugin-dependencies"; - public final static String INJECT_EXPORT_PACKAGES = "inject-export-packages"; - public final static String DECLARED_LIBRARIES = "declared-libraries"; - - public static final String BRANCH = "commit-branch"; - public static final String COMMIT_ID = "commit-id"; - public static final String BUILD_USER = "build-user"; - public static final String BUILD_EMAIL = "build-email"; - public static final String BUILD_TIME = "build-time"; - public static final String COMMIT_AUTHOR_NAME = "commit-user-name"; - public static final String COMMIT_AUTHOR_EMAIL = "commit-user-email"; - public static final String COMMIT_TIMESTAMP = "commit-timestamp"; - public static final String COMMIT_TIME = "commit-time"; - public static final String REMOTE_ORIGIN_URL = "remote-origin-url"; - - public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ"; - - public final static String PACKAGE_PREFIX_MARK = "*"; - - public final static String PACKAGE_PREFIX_MARK_2 = ".*"; - public final static String DEFAULT_PACKAGE = "."; - public final static String MANIFEST_VALUE_SPLIT = COMMA_SPLIT; - public final static String RESOURCE_STEM_MARK = "*"; - - public final static String IMPORT_RESOURCES_ATTRIBUTE = "import-resources"; - public final static String EXPORT_RESOURCES_ATTRIBUTE = "export-resources"; - - public final static String SUREFIRE_BOOT_CLASSPATH = "Class-Path"; - public final static String SUREFIRE_BOOT_CLASSPATH_SPLIT = " "; - public final static String SUREFIRE_BOOT_JAR = "surefirebooter"; + public final static String MAIN_CLASS_ATTRIBUTE = "Main-Class"; + public final static String START_CLASS_ATTRIBUTE = "Start-Class"; + public final static String ARK_BIZ_NAME = "Ark-Biz-Name"; + public final static String ARK_BIZ_VERSION = "Ark-Biz-Version"; + public final static String DENY_IMPORT_CLASSES = "deny-import-classes"; + public final static String DENY_IMPORT_PACKAGES = "deny-import-packages"; + public final static String DENY_IMPORT_RESOURCES = "deny-import-resources"; + public final static String INJECT_PLUGIN_DEPENDENCIES = "inject-plugin-dependencies"; + public final static String INJECT_EXPORT_PACKAGES = "inject-export-packages"; + public final static String DECLARED_LIBRARIES = "declared-libraries"; + + public static final String BRANCH = "commit-branch"; + public static final String COMMIT_ID = "commit-id"; + public static final String BUILD_USER = "build-user"; + public static final String BUILD_EMAIL = "build-email"; + public static final String BUILD_TIME = "build-time"; + public static final String COMMIT_AUTHOR_NAME = "commit-user-name"; + public static final String COMMIT_AUTHOR_EMAIL = "commit-user-email"; + public static final String COMMIT_TIMESTAMP = "commit-timestamp"; + public static final String COMMIT_TIME = "commit-time"; + public static final String REMOTE_ORIGIN_URL = "remote-origin-url"; + + public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ"; + + public final static String PACKAGE_PREFIX_MARK = "*"; + + public final static String PACKAGE_PREFIX_MARK_2 = ".*"; + public final static String DEFAULT_PACKAGE = "."; + public final static String MANIFEST_VALUE_SPLIT = COMMA_SPLIT; + public final static String RESOURCE_STEM_MARK = "*"; + + public final static String IMPORT_RESOURCES_ATTRIBUTE = "import-resources"; + public final static String EXPORT_RESOURCES_ATTRIBUTE = "export-resources"; + + public final static String SUREFIRE_BOOT_CLASSPATH = "Class-Path"; + public final static String SUREFIRE_BOOT_CLASSPATH_SPLIT = " "; + public final static String SUREFIRE_BOOT_JAR = "surefirebooter"; /** * Telnet Server */ - public final static String TELNET_SERVER_ENABLE = "sofa.ark.telnet.server.enable"; - public final static String TELNET_SERVER_SECURITY_ENABLE = "sofa.ark.telnet.security.enable"; - public final static String CONFIG_SERVER_ENABLE = "sofa.ark.config.server.enable"; + public final static String TELNET_SERVER_ENABLE = "sofa.ark.telnet.server.enable"; + public final static String TELNET_SERVER_SECURITY_ENABLE = "sofa.ark.telnet.security.enable"; + public final static String CONFIG_SERVER_ENABLE = "sofa.ark.config.server.enable"; /** * 配置中心支持, 默认使用zookeeper * value值为com.alipay.sofa.ark.config.ConfigTypeEnum枚举的name() */ - public final static String CONFIG_SERVER_TYPE = "sofa.ark.config.server.type"; + public final static String CONFIG_SERVER_TYPE = "sofa.ark.config.server.type"; /** * 使用apollo的namespace */ - public final static String CONFIG_APOLLO_NAMESPACE = "sofa-ark"; + public final static String CONFIG_APOLLO_NAMESPACE = "sofa-ark"; /** * apollo的namespace下动态命名对应的key */ - public final static String APOLLO_MASTER_BIZ_KEY = "masterBiz"; - public final static String TELNET_PORT_ATTRIBUTE = "sofa.ark.telnet.port"; - public final static int DEFAULT_TELNET_PORT = 1234; - public final static int DEFAULT_SELECT_PORT_SIZE = 100; - public final static String TELNET_SERVER_WORKER_THREAD_POOL_NAME = "telnet-server-worker"; - public final static String TELNET_SESSION_PROMPT = "sofa-ark>"; - public final static String TELNET_COMMAND_THREAD_POOL_NAME = "telnet-command"; + public final static String APOLLO_MASTER_BIZ_KEY = "masterBiz"; + public final static String TELNET_PORT_ATTRIBUTE = "sofa.ark.telnet.port"; + public final static int DEFAULT_TELNET_PORT = 1234; + public final static int DEFAULT_SELECT_PORT_SIZE = 100; + public final static String TELNET_SERVER_WORKER_THREAD_POOL_NAME = "telnet-server-worker"; + public final static String TELNET_SESSION_PROMPT = "sofa-ark>"; + public final static String TELNET_COMMAND_THREAD_POOL_NAME = "telnet-command"; /** * Event */ - public final static String BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_START = "AFTER-INVOKE-BIZ-START"; - public final static String BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_STOP = "AFTER-INVOKE-BIZ-STOP"; - public final static String BIZ_EVENT_TOPIC_AFTER_BIZ_FAILED = "BIZ_EVENT_TOPIC_AFTER_BIZ_FAILED"; - public final static String BIZ_EVENT_TOPIC_CLEAN_AFTER_INVOKE_BIZ_STOP = "CLEAN-AFTER-INVOKE-BIZ-STOP"; + public final static String BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_START = "AFTER-INVOKE-BIZ-START"; + public final static String BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_STOP = "AFTER-INVOKE-BIZ-STOP"; + public final static String BIZ_EVENT_TOPIC_AFTER_BIZ_FAILED = "BIZ_EVENT_TOPIC_AFTER_BIZ_FAILED"; - public final static String BIZ_EVENT_TOPIC_BEFORE_RECYCLE_BIZ = "BEFORE-RECYCLE-BIZ"; - public final static String BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_START = "BEFORE-INVOKE-BIZ-START"; - public final static String BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_STOP = "BEFORE-INVOKE-BIZ-STOP"; + public final static String BIZ_EVENT_TOPIC_BEFORE_RECYCLE_BIZ = "BEFORE-RECYCLE-BIZ"; + public final static String BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_START = "BEFORE-INVOKE-BIZ-START"; + public final static String BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_STOP = "BEFORE-INVOKE-BIZ-STOP"; - public final static String PLUGIN_EVENT_TOPIC_AFTER_INVOKE_PLUGIN_START = "AFTER-INVOKE-PLUGIN-START"; - public final static String PLUGIN_EVENT_TOPIC_AFTER_INVOKE_PLUGIN_STOP = "AFTER-INVOKE-PLUGIN-STOP"; - public final static String PLUGIN_EVENT_TOPIC_CLEAN_AFTER_INVOKE_PLUGIN_STOP = "CLEAN-AFTER-INVOKE-PLUGIN-STOP"; - public final static String PLUGIN_EVENT_TOPIC_BEFORE_INVOKE_PLUGIN_START = "BEFORE-INVOKE-PLUGIN-START"; - public final static String PLUGIN_EVENT_TOPIC_BEFORE_INVOKE_PLUGIN_STOP = "BEFORE-INVOKE-PLUGIN-STOP"; + public final static String PLUGIN_EVENT_TOPIC_AFTER_INVOKE_PLUGIN_START = "AFTER-INVOKE-PLUGIN-START"; + public final static String PLUGIN_EVENT_TOPIC_AFTER_INVOKE_PLUGIN_STOP = "AFTER-INVOKE-PLUGIN-STOP"; + public final static String PLUGIN_EVENT_TOPIC_BEFORE_INVOKE_PLUGIN_START = "BEFORE-INVOKE-PLUGIN-START"; + public final static String PLUGIN_EVENT_TOPIC_BEFORE_INVOKE_PLUGIN_STOP = "BEFORE-INVOKE-PLUGIN-STOP"; - public final static String BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_SWITCH = "BEFORE-INVOKE-BIZ-SWITCH"; - public final static String BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_SWITCH = "AFTER-INVOKE-BIZ-SWITCH"; + public final static String BIZ_EVENT_TOPIC_BEFORE_INVOKE_BIZ_SWITCH = "BEFORE-INVOKE-BIZ-SWITCH"; + public final static String BIZ_EVENT_TOPIC_AFTER_INVOKE_BIZ_SWITCH = "AFTER-INVOKE-BIZ-SWITCH"; - public final static String ARK_EVENT_TOPIC_AFTER_FINISH_STARTUP_STAGE = "AFTER-FINISH-STARTUP-STAGE"; - public final static String ARK_EVENT_TOPIC_AFTER_FINISH_DEPLOY_STAGE = "AFTER-FINISH-DEPLOY-STAGE"; + public final static String ARK_EVENT_TOPIC_AFTER_FINISH_STARTUP_STAGE = "AFTER-FINISH-STARTUP-STAGE"; + public final static String ARK_EVENT_TOPIC_AFTER_FINISH_DEPLOY_STAGE = "AFTER-FINISH-DEPLOY-STAGE"; /** * Environment Properties */ - public final static String SPRING_BOOT_ENDPOINTS_JMX_ENABLED = "endpoints.jmx.enabled"; - public final static String LOG4J_IGNORE_TCL = "log4j.ignoreTCL"; - public final static String RESOLVE_PARENT_CONTEXT_SERIALIZER_FACTORY = "hessian.parent.context.create"; - public final static String EMBED_ENABLE = "sofa.ark.embed.enable"; - public final static String PLUGIN_EXPORT_CLASS_ENABLE = "sofa.ark.plugin.export.class.enable"; - public final static String EMBED_STATIC_BIZ_ENABLE = "sofa.ark.embed.static.biz.enable"; + public final static String SPRING_BOOT_ENDPOINTS_JMX_ENABLED = "endpoints.jmx.enabled"; + public final static String LOG4J_IGNORE_TCL = "log4j.ignoreTCL"; + public final static String RESOLVE_PARENT_CONTEXT_SERIALIZER_FACTORY = "hessian.parent.context.create"; + public final static String EMBED_ENABLE = "sofa.ark.embed.enable"; + public final static String PLUGIN_EXPORT_CLASS_ENABLE = "sofa.ark.plugin.export.class.enable"; + public final static String EMBED_STATIC_BIZ_ENABLE = "sofa.ark.embed.static.biz.enable"; - public final static String EMBED_STATIC_BIZ_IN_RESOURCE_ENABLE = "sofa.ark.embed.static.biz.in.resource.enable"; - public final static String ACTIVATE_NEW_MODULE = "activate.new.module"; + public final static String EMBED_STATIC_BIZ_IN_RESOURCE_ENABLE = "sofa.ark.embed.static.biz.in.resource.enable"; + public final static String ACTIVATE_NEW_MODULE = "activate.new.module"; - public final static String AUTO_UNINSTALL_WHEN_FAILED_ENABLE = "sofa.ark.auto.uninstall.when.failed.enable"; + public final static String AUTO_UNINSTALL_WHEN_FAILED_ENABLE = "sofa.ark.auto.uninstall.when.failed.enable"; /** * Command Provider */ - public final static String PLUGIN_COMMAND_UNIQUE_ID = "plugin-command-provider"; - public final static String BIZ_COMMAND_UNIQUE_ID = "biz-command-provider"; + public final static String PLUGIN_COMMAND_UNIQUE_ID = "plugin-command-provider"; + public final static String BIZ_COMMAND_UNIQUE_ID = "biz-command-provider"; /** * Ark SPI extension */ - public final static String EXTENSION_FILE_DIR = "META-INF/services/sofa-ark/"; - public final static String PLUGIN_CLASS_LOADER_HOOK = "plugin-classloader-hook"; - public final static String BIZ_CLASS_LOADER_HOOK = "biz-classloader-hook"; - public final static String BIZ_CLASS_LOADER_HOOK_DIR = "com.alipay.sofa.ark.biz.classloader.hook.dir"; - public final static String BIZ_TEMP_WORK_DIR_RECYCLE_FILE_SUFFIX = "deleted"; + public final static String EXTENSION_FILE_DIR = "META-INF/services/sofa-ark/"; + public final static String PLUGIN_CLASS_LOADER_HOOK = "plugin-classloader-hook"; + public final static String BIZ_CLASS_LOADER_HOOK = "biz-classloader-hook"; + public final static String BIZ_CLASS_LOADER_HOOK_DIR = "com.alipay.sofa.ark.biz.classloader.hook.dir"; + public final static String BIZ_TEMP_WORK_DIR_RECYCLE_FILE_SUFFIX = "deleted"; /** * Multiply biz name */ - public final static String MASTER_BIZ = "com.alipay.sofa.ark.master.biz"; + public final static String MASTER_BIZ = "com.alipay.sofa.ark.master.biz"; - public final static String SOFA_ARK_MODULE = "SOFA-ARK/biz/"; + public final static String SOFA_ARK_MODULE = "SOFA-ARK/biz/"; /** * Config Server */ - public final static String CONFIG_SERVER_ADDRESS = "com.alipay.sofa.ark.config.address"; - public final static String CONFIG_SERVER_ENVIRONMENT = "com.alipay.sofa.ark.config.env"; - public final static String CONFIG_PROTOCOL_ZOOKEEPER = "zookeeper"; - public final static String CONFIG_PROTOCOL_ZOOKEEPER_HEADER = "zookeeper://"; - public final static String ZOOKEEPER_CONTEXT_SPLIT = "/"; - public final static String CONFIG_INSTALL_BIZ_DIR = "com.alipay.sofa.ark.biz.dir"; - public final static String CONFIG_BIZ_URL = "bizUrl"; + public final static String CONFIG_SERVER_ADDRESS = "com.alipay.sofa.ark.config.address"; + public final static String CONFIG_SERVER_ENVIRONMENT = "com.alipay.sofa.ark.config.env"; + public final static String CONFIG_PROTOCOL_ZOOKEEPER = "zookeeper"; + public final static String CONFIG_PROTOCOL_ZOOKEEPER_HEADER = "zookeeper://"; + public final static String ZOOKEEPER_CONTEXT_SPLIT = "/"; + public final static String CONFIG_INSTALL_BIZ_DIR = "com.alipay.sofa.ark.biz.dir"; + public final static String CONFIG_BIZ_URL = "bizUrl"; - public final static String CONFIG_CONNECT_TIMEOUT = "com.alipay.sofa.ark.config.connect.timeout"; - public final static int DEFAULT_CONFIG_CONNECT_TIMEOUT = 20000; + public final static String CONFIG_CONNECT_TIMEOUT = "com.alipay.sofa.ark.config.connect.timeout"; + public final static int DEFAULT_CONFIG_CONNECT_TIMEOUT = 20000; /** * Test ClassLoader */ - public final static String FORCE_DELEGATE_TO_TEST_CLASSLOADER = "com.alipay.sofa.ark.delegate.to.testClassLoader"; - public final static String FORCE_DELEGATE_TO_APP_CLASSLOADER = "com.alipay.sofa.ark.delegate.to.appClassLoader"; + public final static String FORCE_DELEGATE_TO_TEST_CLASSLOADER = "com.alipay.sofa.ark.delegate.to.testClassLoader"; + public final static String FORCE_DELEGATE_TO_APP_CLASSLOADER = "com.alipay.sofa.ark.delegate.to.appClassLoader"; - public final static String EXTENSION_EXCLUDES = "excludes"; - public final static String EXTENSION_EXCLUDES_GROUPIDS = "excludeGroupIds"; - public final static String EXTENSION_EXCLUDES_ARTIFACTIDS = "excludeArtifactIds"; + public final static String EXTENSION_EXCLUDES = "excludes"; + public final static String EXTENSION_EXCLUDES_GROUPIDS = "excludeGroupIds"; + public final static String EXTENSION_EXCLUDES_ARTIFACTIDS = "excludeArtifactIds"; - public final static String EXTENSION_INCLUDES = "includes"; - public final static String EXTENSION_INCLUDES_GROUPIDS = "includeGroupIds"; - public final static String EXTENSION_INCLUDES_ARTIFACTIDS = "includeArtifactIds"; + public final static String EXTENSION_INCLUDES = "includes"; + public final static String EXTENSION_INCLUDES_GROUPIDS = "includeGroupIds"; + public final static String EXTENSION_INCLUDES_ARTIFACTIDS = "includeArtifactIds"; - public final static String DECLARED_LIBRARIES_WHITELIST = "declared.libraries.whitelist"; + public final static String DECLARED_LIBRARIES_WHITELIST = "declared.libraries.whitelist"; - public static final List CHANNEL_QUIT = new ArrayList<>(); + public static final List CHANNEL_QUIT = new ArrayList<>(); static { CHANNEL_QUIT.add("quit"); diff --git a/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/biz/CleanAfterBizStopEvent.java b/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/biz/CleanAfterBizStopEvent.java deleted file mode 100644 index ff215ca48..000000000 --- a/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/biz/CleanAfterBizStopEvent.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alipay.sofa.ark.spi.event.biz; - -import com.alipay.sofa.ark.spi.constant.Constants; -import com.alipay.sofa.ark.spi.event.AbstractArkEvent; -import com.alipay.sofa.ark.spi.model.Biz; - -/** - * only used to clean up biz module and event handlers in sofa-ark after biz stop - */ -public class CleanAfterBizStopEvent extends AbstractArkEvent { - public CleanAfterBizStopEvent(Biz source) { - super(source); - this.topic = Constants.BIZ_EVENT_TOPIC_CLEAN_AFTER_INVOKE_BIZ_STOP; - } -} diff --git a/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/plugin/CleanAfterPluginStopEvent.java b/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/plugin/CleanAfterPluginStopEvent.java deleted file mode 100644 index 9662b2564..000000000 --- a/sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/plugin/CleanAfterPluginStopEvent.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alipay.sofa.ark.spi.event.plugin; - -import com.alipay.sofa.ark.spi.constant.Constants; -import com.alipay.sofa.ark.spi.event.AbstractArkEvent; -import com.alipay.sofa.ark.spi.model.Plugin; - -/** - * @author guolei.sgl (guolei.sgl@antfin.com) 2019/11/1 6:21 PM - * @since - **/ -public class CleanAfterPluginStopEvent extends AbstractArkEvent { - - public CleanAfterPluginStopEvent(Plugin source) { - super(source); - this.topic = Constants.PLUGIN_EVENT_TOPIC_CLEAN_AFTER_INVOKE_PLUGIN_STOP; - } -}