Skip to content

Commit

Permalink
merge master to 3.1.4 (#933)
Browse files Browse the repository at this point in the history
* 优化排包配置 (#918)

* 优化显示

* fix as bizStateRecords

* 更新显示

* 优化自动排包配置

* 更新排包描述

---------

Co-authored-by: leo james <leojames.googol@gmail.com>
(cherry picked from commit 5a13e01)

* runtime中静态合并部署时多模块并行执行createTempDir时异常 (#911)

Co-authored-by: jiyunfei <jiyunfei@come-future.com>
Co-authored-by: leo james <leojames.googol@gmail.com>
(cherry picked from commit 67a0bdf)

* add string contains (#926)

(cherry picked from commit 07009d7)

* fix ReactiveWebServerFactoryAutoConfiguration not support sprintboot 1.x (#927)

(cherry picked from commit 41d3cda)

* add biz jar url in biz module (#928)

(cherry picked from commit e1f5872)

* update netty version (#931)

* update netty version

* fix version netty

---------

Co-authored-by: tangjiafu <tangjiafu@kuaishou.com>
Co-authored-by: leojames <leojames.googol@gmail.com>

(cherry picked from commit fb233cf)

* update version to 3.1.4-SNAPSHOT

* fix multi ark boot runner test

---------

Co-authored-by: Lipeng <44571204+gaosaroma@users.noreply.github.com>
Co-authored-by: FFF <31267018+1034323716@users.noreply.github.com>
Co-authored-by: Laglangyue <35491928+laglangyue@users.noreply.github.com>
  • Loading branch information
4 people authored May 28, 2024
1 parent e323686 commit 339579a
Show file tree
Hide file tree
Showing 16 changed files with 264 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</modules>

<properties>
<sofa.ark.version>3.1.3</sofa.ark.version>
<sofa.ark.version>3.1.4-SNAPSHOT</sofa.ark.version>
<sofa.ark.version.old>3.1.2</sofa.ark.version.old>
<project.encoding>UTF-8</project.encoding>
<java.version>17</java.version>
Expand Down
8 changes: 7 additions & 1 deletion sofa-ark-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<maven.assembly.plugin>2.4</maven.assembly.plugin>
<maven.plugin.plugin>3.6.1</maven.plugin.plugin>
<surefire.version>2.22.2</surefire.version>
<netty.version>4.1.94.Final</netty.version>
<netty.version>4.1.109.Final</netty.version>
<reactor-netty.version>0.9.19.RELEASE</reactor-netty.version>
<spring.boot.version>3.2.1</spring.boot.version>
</properties>
Expand Down Expand Up @@ -357,6 +357,12 @@
<version>2.14.3</version>
</dependency>

<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.1</version>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ 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",
"jakarta.inject-api-2.0.1", "logback-core-1.4.14", "logback-classic-1.4.14",
"slf4j-api-2.0.11", "sofa-common-tools", "netty-all-4.1.94.Final",
"netty-transport-4.1.94.Final", "netty-common-4.1.94.Final",
"jakarta.inject-api-2.0.1", "netty-handler-4.1.94.Final", "netty-codec-4.1.94.Final",
"netty-buffer-4.1.94.Final", "sofa-ark-parent/core-impl/container/target/classes",
"slf4j-api-2.0.11", "sofa-common-tools", "netty-all-4.1.109.Final",
"netty-transport-4.1.109.Final", "netty-common-4.1.109.Final",
"jakarta.inject-api-2.0.1", "netty-handler-4.1.109.Final", "netty-codec-4.1.109.Final",
"netty-buffer-4.1.109.Final", "sofa-ark-parent/core-impl/container/target/classes",
"sofa-ark-parent/core-impl/archive/target/classes",
"sofa-ark-parent/core/spi/target/classes",
"sofa-ark-parent/core/common/target/classes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public class BizModel implements Biz {

private URL[] urls;

private URL bizUrl;

private URL[] pluginUrls;

private ClassLoader classLoader;
Expand Down Expand Up @@ -138,6 +140,11 @@ public BizModel setClassPath(URL[] urls) {
return this;
}

public BizModel setBizUrl(URL url) {
this.bizUrl = url;
return this;
}

public BizModel setPluginClassPath(URL[] urls) {
this.pluginUrls = urls;
return this;
Expand Down Expand Up @@ -235,6 +242,11 @@ public URL[] getClassPath() {
return urls;
}

@Override
public URL getBizUrl() {
return bizUrl;
}

@Override
public int getPriority() {
return priority;
Expand Down Expand Up @@ -412,8 +424,9 @@ public List<BizStateRecord> getBizStateRecords() {

@Override
public String toString() {
return "Ark Biz: " + getIdentity() + ",\n classloader: " + classLoader
+ ",\n current state: " + bizState + ",\n history states: " + bizStateRecords;
return "Ark Biz: " + getIdentity() + ",\n biz url: " + bizUrl + ",\n classloader: "
+ classLoader + ",\n current state: " + bizState + ",\n history states: "
+ bizStateRecords;
}

private void resetProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public Biz createBiz(BizArchive bizArchive) throws IOException {
.setBizName(manifestMainAttributes.getValue(ARK_BIZ_NAME))
.setBizVersion(manifestMainAttributes.getValue(ARK_BIZ_VERSION))
.setMainClass(!StringUtils.isEmpty(startClass) ? startClass : mainClass)
.setBizUrl(bizArchive.getUrl())
.setPriority(manifestMainAttributes.getValue(PRIORITY_ATTRIBUTE))
.setWebContextPath(manifestMainAttributes.getValue(WEB_CONTEXT_PATH))
.setDenyImportPackages(manifestMainAttributes.getValue(DENY_IMPORT_PACKAGES))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static String bytesToHex(byte[] bytes) {
* Atomically creates a new directory somewhere beneath the system's
* temporary directory (as defined by the {@code java.io.tmpdir} system
*/
public static File createTempDir(String subPath) {
public static synchronized File createTempDir(String subPath) {
File baseDir = FileUtils.file(System.getProperty("java.io.tmpdir"));
File tempDir = new File(baseDir, subPath);
if (tempDir.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ public static String setToStr(Set<String> stringSet, String delimiter) {
return setToStr(stringSet, delimiter, EMPTY_STRING);
}

public static boolean contains(String sourceStr, String searchStr) {
if (sourceStr != null && searchStr != null) {
return sourceStr.contains(searchStr);
} else {
return false;
}
}

/**
* <p>Transform a string set to a long string separated by delimiter</p>
* @param stringSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ public void testListToStr() {
Assert.assertTrue("abbacb".equals(StringUtils.setToStr(linkedHashSet, "")));
}

@Test
public void testContains() {
String a = "This is my test source string";
Assert.assertTrue(StringUtils.contains(a, "my"));
Assert.assertTrue(StringUtils.contains(a, ""));
Assert.assertFalse(StringUtils.contains(a, null));
Assert.assertFalse(StringUtils.contains(null, null));
Assert.assertFalse(StringUtils.contains(null, "my"));
}

@Test
public void testStrToList() {
List<String> list = StringUtils.strToList("ab,ba,cb", ",");
Expand Down Expand Up @@ -114,4 +124,4 @@ public void testRemoveSpcChar() {
Assert.assertEquals("com.alipay.sofa:biz-child1-child1:1.0.0:jar:test", StringUtils.removeSpcChar("com.alipay.sofa:biz-child1-child1:1.0.0:jar:test\r\n", "\r\n"));
Assert.assertEquals("com.alipay.sofa:biz-child1-child1:1.0.0:jar:test\r", StringUtils.removeSpcChar("com.alipay.sofa:biz-child1-child1:1.0.0:jar:test\r\n", "\n"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public interface BizInfo {
*/
URL[] getClassPath();

/**
* get biz url
*/
URL getBizUrl();

/**
* get denied imported packages config
* @return
Expand Down
5 changes: 5 additions & 0 deletions sofa-ark-parent/support/ark-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@
import org.apache.maven.shared.invoker.InvocationResult;
import org.apache.maven.shared.invoker.Invoker;
import org.apache.maven.shared.invoker.MavenInvocationException;
import org.yaml.snakeyaml.Yaml;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.Charset;
Expand All @@ -75,6 +77,7 @@

import static com.alipay.sofa.ark.boot.mojo.MavenUtils.inUnLogScopes;
import static com.alipay.sofa.ark.spi.constant.Constants.ARK_CONF_BASE_DIR;
import static com.alipay.sofa.ark.spi.constant.Constants.COMMA_SPLIT;
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;
Expand All @@ -93,6 +96,13 @@ public class RepackageMojo extends TreeMojo {

private static final String DEFAULT_EXCLUDE_RULES = "rules.txt";

public final static String ARK_PROPERTIES_FILE = "ark.properties";

public final static String ARK_YML_FILE = "ark.yml";

public final static String RESOURCES_DIR = "src" + File.separator + "main"
+ File.separator + "resources";

@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject mavenProject;

Expand Down Expand Up @@ -604,6 +614,8 @@ protected Set<Artifact> filterExcludeArtifacts(Set<Artifact> artifacts) {
+ DEFAULT_EXCLUDE_RULES);
}

extensionExcludeArtifactsByDefault();

// extension from url
if (StringUtils.isNotBlank(packExcludesUrl)) {
extensionExcludeArtifactsFromUrl(packExcludesUrl, artifacts);
Expand All @@ -625,6 +637,84 @@ protected Set<Artifact> filterExcludeArtifacts(Set<Artifact> artifacts) {
return result;
}

protected void extensionExcludeArtifactsByDefault() {
// extension from default ark.properties and ark.yml
extensionExcludeArtifactsFromProp();
extensionExcludeArtifactsFromYaml();
}

protected void extensionExcludeArtifactsFromProp() {
String configPath = baseDir + File.separator + RESOURCES_DIR + File.separator
+ ARK_PROPERTIES_FILE;
File configFile = com.alipay.sofa.ark.common.util.FileUtils.file(configPath);
if (!configFile.exists()) {
getLog().info(
String.format(
"sofa-ark-maven-plugin: extension-config %s not found, will not config it",
configPath));
return;
}

getLog().info(
String.format("sofa-ark-maven-plugin: find extension-config %s and will config it",
configPath));

Properties prop = new Properties();
try (FileInputStream fis = new FileInputStream(configPath)) {
prop.load(fis);

parseExcludeProp(excludes, prop, EXTENSION_EXCLUDES);
parseExcludeProp(excludeGroupIds, prop, EXTENSION_EXCLUDES_GROUPIDS);
parseExcludeProp(excludeArtifactIds, prop, EXTENSION_EXCLUDES_ARTIFACTIDS);
} catch (IOException ex) {
getLog().error(
String.format("failed to parse excludes artifacts from %s.", configPath), ex);
}
}

protected void extensionExcludeArtifactsFromYaml() {
String configPath = baseDir + File.separator + RESOURCES_DIR + File.separator
+ ARK_YML_FILE;
File configFile = com.alipay.sofa.ark.common.util.FileUtils.file(configPath);
if (!configFile.exists()) {
getLog().info(
String.format(
"sofa-ark-maven-plugin: extension-config %s not found, will not config it",
configPath));
return;
}

getLog().info(
String.format("sofa-ark-maven-plugin: find extension-config %s and will config it",
configPath));

try (FileInputStream fis = new FileInputStream(configPath)) {
Yaml yaml = new Yaml();
Map<String, List<String>> parsedYaml = yaml.load(fis);
parseExcludeYaml(excludes, parsedYaml, EXTENSION_EXCLUDES);
parseExcludeYaml(excludeGroupIds, parsedYaml, EXTENSION_EXCLUDES_GROUPIDS);
parseExcludeYaml(excludeArtifactIds, parsedYaml, EXTENSION_EXCLUDES_ARTIFACTIDS);

} catch (IOException ex) {
getLog().error(
String.format("failed to parse excludes artifacts from %s.", configPath), ex);
}
}

private void parseExcludeProp(LinkedHashSet<String> targetSet, Properties prop, String confKey) {
String[] parsed = StringUtils.split(prop.getProperty(confKey), COMMA_SPLIT);
if (null != parsed) {
targetSet.addAll(Arrays.asList(parsed));
}
}

private void parseExcludeYaml(LinkedHashSet<String> targetSet, Map<String, List<String>> yaml,
String confKey) {
if (yaml.containsKey(confKey) && null != yaml.get(confKey)) {
targetSet.addAll(yaml.get(confKey));
}
}

/**
* This method is core method for excluding artifacts in sofa-ark-maven-plugin &lt;excludeGroupIds&gt;
* and &lt;excludeArtifactIds&gt; config.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,24 @@
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static com.alipay.sofa.ark.boot.mojo.RepackageMojo.ArkConstants.getClassifier;
import static java.lang.System.clearProperty;
import static java.lang.System.setProperty;
import static java.util.Arrays.asList;
import static org.apache.commons.beanutils.BeanUtils.copyProperties;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -231,6 +240,52 @@ public void testExtensionExcludeArtifactsFromUrl() throws NoSuchMethodException,
extensionExcludeArtifactsFromUrl.invoke(repackageMojo, packExcludesUrl, artifacts);
}

@Test
public void testExtensionExcludeArtifactsByDefault() throws NoSuchMethodException,
NoSuchFieldException, URISyntaxException,
IllegalAccessException,
InvocationTargetException {
RepackageMojo repackageMojo = new RepackageMojo();
Method extensionExcludeArtifactsByDefault = repackageMojo.getClass().getDeclaredMethod(
"extensionExcludeArtifactsByDefault");
extensionExcludeArtifactsByDefault.setAccessible(true);

Field baseDirField = RepackageMojo.class.getDeclaredField("baseDir");
baseDirField.setAccessible(true);
baseDirField.set(repackageMojo, getResourceFile("baseDir"));

Field excludesField = RepackageMojo.class.getDeclaredField("excludes");
excludesField.setAccessible(true);
LinkedHashSet<String> excludes = (LinkedHashSet<String>) excludesField.get(repackageMojo);

Field excludeGroupIdsField = RepackageMojo.class.getDeclaredField("excludeGroupIds");
excludeGroupIdsField.setAccessible(true);
LinkedHashSet<String> excludeGroupIds = (LinkedHashSet<String>) excludeGroupIdsField
.get(repackageMojo);

Field excludeArtifactIdsField = RepackageMojo.class.getDeclaredField("excludeArtifactIds");
excludeArtifactIdsField.setAccessible(true);
LinkedHashSet<String> excludeArtifactIds = (LinkedHashSet<String>) excludeArtifactIdsField
.get(repackageMojo);

extensionExcludeArtifactsByDefault.invoke(repackageMojo);

// 验证 ark.properties
assertTrue(excludes.contains("commons-beanutils:commons-beanutils"));
assertTrue(excludeGroupIds.contains("org.springframework"));
assertTrue(excludeArtifactIds.contains("sofa-ark-spi"));

// 验证 ark.yml
assertTrue(excludes.contains("commons-beanutils:commons-beanutils-yml"));
assertTrue(excludeGroupIds.contains("org.springframework-yml"));
assertTrue(excludeArtifactIds.contains("sofa-ark-spi-yml"));
}

private File getResourceFile(String resourceName) throws URISyntaxException {
URL url = this.getClass().getClassLoader().getResource(resourceName);
return new File(url.toURI());
}

@Test
public void testLogExcludeMessage() throws NoSuchMethodException, InvocationTargetException,
IllegalAccessException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# excludes config ${groupId}:{artifactId}:{version}, split by ','
excludes=org.apache.commons:commons-lang3,commons-beanutils:commons-beanutils
# excludeGroupIds config ${groupId}, split by ','
excludeGroupIds=org.springframework
# excludeArtifactIds config ${artifactId}, split by ','
excludeArtifactIds=sofa-ark-spi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# excludes 中配置 ${groupId}:{artifactId}:{version}, 不同依赖以 - 隔开
# excludeGroupIds 中配置 ${groupId}, 不同依赖以 - 隔开
# excludeArtifactIds 中配置 ${artifactId}, 不同依赖以 - 隔开
excludes:
- org.apache.commons:commons-lang3-yml
- commons-beanutils:commons-beanutils-yml
excludeGroupIds:
- org.springframework-yml
excludeArtifactIds:
- sofa-ark-spi-yml
Loading

0 comments on commit 339579a

Please sign in to comment.