diff --git a/pom.xml b/pom.xml index 4262dadba..9edf9b285 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ - 3.0.2-SNAPSHOT + 3.1.0-SNAPSHOT UTF-8 17 3.0 diff --git a/sofa-ark-bom/pom.xml b/sofa-ark-bom/pom.xml index a74c8e8dc..57d793484 100644 --- a/sofa-ark-bom/pom.xml +++ b/sofa-ark-bom/pom.xml @@ -48,7 +48,7 @@ 3.6.1 2.22.2 4.1.94.Final - 3.0.9 + 3.2.1 @@ -238,18 +238,6 @@ logback-core ${logback.version} - - - com.alipay.sofa - log-sofa-boot-starter - ${log.sofa.starter.version} - - - org.springframework.boot - spring-boot - - - com.alipay.sofa.common sofa-common-tools 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 1b7818c60..bdae6a73c 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 @@ -45,8 +45,8 @@ public class DirectoryContainerArchive implements ContainerArchive { "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", - "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", + "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", "sofa-ark-parent/core-impl/archive/target/classes", "sofa-ark-parent/core/spi/target/classes", "sofa-ark-parent/core/common/target/classes", diff --git a/sofa-ark-parent/core-impl/archive/src/test/java/com/alipay/sofa/ark/loader/EmbedClassPathArchiveTest.java b/sofa-ark-parent/core-impl/archive/src/test/java/com/alipay/sofa/ark/loader/EmbedClassPathArchiveTest.java index 9485764ca..4d510e055 100644 --- a/sofa-ark-parent/core-impl/archive/src/test/java/com/alipay/sofa/ark/loader/EmbedClassPathArchiveTest.java +++ b/sofa-ark-parent/core-impl/archive/src/test/java/com/alipay/sofa/ark/loader/EmbedClassPathArchiveTest.java @@ -17,17 +17,15 @@ package com.alipay.sofa.ark.loader; import com.alipay.sofa.ark.common.util.FileUtils; +import com.alipay.sofa.ark.loader.archive.JarFileArchive; import com.alipay.sofa.ark.spi.archive.BizArchive; +import com.alipay.sofa.ark.spi.archive.Archive; import org.junit.Assert; import org.junit.Test; -import org.springframework.boot.loader.archive.Archive; -import org.springframework.boot.loader.archive.JarFileArchive; -import java.io.File; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Objects; @@ -44,15 +42,16 @@ public void testGetContainerArchive() throws Exception { ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL springbootFatJar = cl.getResource("sample-springboot-fat-biz.jar"); JarFileArchive jarFileArchive = new JarFileArchive(FileUtils.file(springbootFatJar.getFile())); - Iterator archives = jarFileArchive.getNestedArchives(this::isNestedArchive,null); + + List archives = jarFileArchive.getNestedArchives(this::isNestedArchive); List urls = new ArrayList<>(); - while (archives.hasNext()){ - urls.add(archives.next().getUrl()); + for (Archive archive : archives) { + urls.add(archive.getUrl()); } EmbedClassPathArchive archive = new EmbedClassPathArchive( "com.alipay.sofa.ark.sample.springbootdemo.SpringbootDemoApplication", "main", - urls.toArray(new URL[] {})); + urls.toArray(new URL[]{})); assertTrue(archive.getContainerArchive().getUrls().length != 0); assertTrue(archive.getConfClasspath().size() != 0); assertTrue(archive.getBizArchives().size() == 0); @@ -77,15 +76,15 @@ public void testStaticCombineGetBizArchives() throws Exception { ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL springbootFatJar = cl.getResource("static-combine-demo.jar"); JarFileArchive jarFileArchive = new JarFileArchive(FileUtils.file(springbootFatJar.getFile())); - Iterator archives = jarFileArchive.getNestedArchives(this::isNestedArchive,null); + List archives = jarFileArchive.getNestedArchives(this::isNestedArchive); List urls = new ArrayList<>(); - while (archives.hasNext()){ - urls.add(archives.next().getUrl()); + for (Archive archive : archives) { + urls.add(archive.getUrl()); } EmbedClassPathArchive archive = new EmbedClassPathArchive("com.alipay.sofa.ark.sample.springbootdemo.SpringbootDemoApplication", "main", - urls.toArray(new URL[] {})); + urls.toArray(new URL[]{})); List bizArchives = archive.getBizArchives(); - Assert.assertFalse(bizArchives==null||bizArchives.isEmpty()); + Assert.assertFalse(bizArchives == null || bizArchives.isEmpty()); } } \ No newline at end of file diff --git a/sofa-ark-parent/core-impl/archive/src/test/java/com/alipay/sofa/ark/loader/jar/ZipInflaterInputStreamTest.java b/sofa-ark-parent/core-impl/archive/src/test/java/com/alipay/sofa/ark/loader/jar/ZipInflaterInputStreamTest.java index 6672a0f35..290c62168 100644 --- a/sofa-ark-parent/core-impl/archive/src/test/java/com/alipay/sofa/ark/loader/jar/ZipInflaterInputStreamTest.java +++ b/sofa-ark-parent/core-impl/archive/src/test/java/com/alipay/sofa/ark/loader/jar/ZipInflaterInputStreamTest.java @@ -33,7 +33,6 @@ public void testFill() throws Exception { new ByteArrayInputStream(new byte[0]), 0); assertEquals(0, zipInflaterInputStream.available()); zipInflaterInputStream.fill(); - Field field = ZipInflaterInputStream.class.getDeclaredField("extraBytesWritten"); field.setAccessible(true); assertEquals(true, field.get(zipInflaterInputStream)); diff --git a/sofa-ark-parent/core/common/pom.xml b/sofa-ark-parent/core/common/pom.xml index 4c0047a4f..4a43bcf6a 100644 --- a/sofa-ark-parent/core/common/pom.xml +++ b/sofa-ark-parent/core/common/pom.xml @@ -10,23 +10,15 @@ sofa-ark-common - - - com.alipay.sofa - sofa-ark-spi + com.alipay.sofa.common + sofa-common-tools + ${sofa.common.tools.version} - - + com.alipay.sofa - log-sofa-boot-starter - - - org.springframework.boot - spring-boot - - + sofa-ark-spi com.google.inject 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 2111ff664..18806699e 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 @@ -1065,5 +1065,4 @@ public static String getType() { } } - } diff --git a/sofa-ark-parent/support/ark-plugin-maven-plugin/src/main/resources/META-INF/maven/plugin.xml b/sofa-ark-parent/support/ark-plugin-maven-plugin/src/main/resources/META-INF/maven/plugin.xml index fb5501611..29bfd260a 100644 --- a/sofa-ark-parent/support/ark-plugin-maven-plugin/src/main/resources/META-INF/maven/plugin.xml +++ b/sofa-ark-parent/support/ark-plugin-maven-plugin/src/main/resources/META-INF/maven/plugin.xml @@ -7,7 +7,7 @@ A light-weight, java based classloader-isolated framework open-sourced by Ant Financial. com.alipay.sofa sofa-ark-plugin-maven-plugin - 2.0.1-SNAPSHOT + 3.0.1-SNAPSHOT sofa-ark false true @@ -209,12 +209,6 @@ jar 2.0.1-SNAPSHOT - - com.alipay.sofa - log-sofa-boot-starter - jar - 3.2.0 - com.alipay.sofa.common sofa-common-tools diff --git a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/pom.xml b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/pom.xml index 7ebd7b2eb..5fa365cec 100644 --- a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/pom.xml +++ b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/pom.xml @@ -11,7 +11,7 @@ 4.0.0 - 3.0.9 + 3.2.1 sofa-ark-springboot-starter @@ -140,7 +140,13 @@ org.apache.logging.log4j log4j-slf4j-impl - 2.17.1 + 2.19.0 + test + + + org.apache.logging.log4j + log4j-api + 2.19.0 test diff --git a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/loader/CachedLaunchedURLClassLoader.java b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/loader/CachedLaunchedURLClassLoader.java index f71455572..7ca117374 100644 --- a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/loader/CachedLaunchedURLClassLoader.java +++ b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/loader/CachedLaunchedURLClassLoader.java @@ -16,8 +16,8 @@ */ package com.alipay.sofa.ark.springboot.loader; -import org.springframework.boot.loader.LaunchedURLClassLoader; -import org.springframework.boot.loader.archive.Archive; +import org.springframework.boot.loader.launch.Archive; +import org.springframework.boot.loader.launch.LaunchedClassLoader; import java.io.IOException; import java.net.URL; @@ -36,7 +36,7 @@ * * @author bingjie.lbj */ -public class CachedLaunchedURLClassLoader extends LaunchedURLClassLoader { +public class CachedLaunchedURLClassLoader extends LaunchedClassLoader { private final Map classCache = new ConcurrentHashMap<>( 3000); private final Map> resourceUrlCache = new ConcurrentHashMap<>( diff --git a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/loader/JarLauncher.java b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/loader/JarLauncher.java index 0fba578d6..b9e8fa9ee 100644 --- a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/loader/JarLauncher.java +++ b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/loader/JarLauncher.java @@ -17,20 +17,24 @@ package com.alipay.sofa.ark.springboot.loader; import java.net.URL; +import java.util.Collection; /** * A JarLauncher to load classes with CachedLaunchedURLClassLoader * * @author bingjie.lbj */ -public class JarLauncher extends org.springframework.boot.loader.JarLauncher { +public class JarLauncher extends org.springframework.boot.loader.launch.JarLauncher { + public JarLauncher() throws Exception { + } + public static void main(String[] args) throws Exception { new JarLauncher().launch(args); } @Override - protected ClassLoader createClassLoader(URL[] urls) throws Exception { - return new CachedLaunchedURLClassLoader(isExploded(), getArchive(), urls, getClass() - .getClassLoader()); + protected ClassLoader createClassLoader(Collection urls) throws Exception { + return new CachedLaunchedURLClassLoader(isExploded(), getArchive(), + urls.toArray(new URL[0]), getClass().getClassLoader()); } } diff --git a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/web/ArkNettyReactiveWebServerFactory.java b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/web/ArkNettyReactiveWebServerFactory.java index 4c3c32993..b5d7873d9 100644 --- a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/web/ArkNettyReactiveWebServerFactory.java +++ b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/main/java/com/alipay/sofa/ark/springboot/web/ArkNettyReactiveWebServerFactory.java @@ -20,6 +20,7 @@ import com.alipay.sofa.ark.spi.service.ArkInject; import com.alipay.sofa.ark.spi.service.biz.BizManagerService; import com.alipay.sofa.ark.spi.web.EmbeddedServerService; +import org.springframework.boot.ssl.SslBundle; import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; import org.springframework.boot.web.embedded.netty.NettyRouteProvider; import org.springframework.boot.web.embedded.netty.NettyServerCustomizer; @@ -35,6 +36,8 @@ import reactor.netty.http.server.HttpServer; import reactor.netty.resources.LoopResources; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.InetSocketAddress; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -46,6 +49,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Consumer; import static com.alipay.sofa.ark.spi.constant.Constants.ROOT_WEB_CONTEXT_PATH; @@ -150,9 +154,30 @@ private HttpServer initEmbedNetty(){ } private HttpServer customizeSslConfiguration(HttpServer httpServer) { - SslServerCustomizer sslServerCustomizer = new SslServerCustomizer(this.getSsl(), - this.getHttp2(), this.getSslStoreProvider()); - return sslServerCustomizer.apply(httpServer); + + SslServerCustomizer customizer = new SslServerCustomizer(this.getHttp2(), this.getSsl().getClientAuth(), this.getSslBundle()); + String bundleName = this.getSsl().getBundle(); + if (StringUtils.hasText(bundleName)) { + try{ + // 找到类 SslServerCustomizer 的updateSslBundle方法 + Method updateSslBundleMethod = SslServerCustomizer.class.getDeclaredMethod("updateSslBundle", SslBundle.class); + updateSslBundleMethod.setAccessible(true); + + // 使用反射创建Consumer + Consumer consumer = sslBundle -> { + try { + // 通过反射调用updateSslBundle方法 + updateSslBundleMethod.invoke(customizer, sslBundle); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + }; + this.getSslBundles().addBundleUpdateHandler(bundleName, consumer); + }catch (Exception e){ + throw new RuntimeException(e); + } + } + return customizer.apply(httpServer); } private HttpProtocol[] listProtocols() { diff --git a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/test/java/com/alipay/sofa/ark/springboot/loader/CachedLaunchedURLClassLoaderTest.java b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/test/java/com/alipay/sofa/ark/springboot/loader/CachedLaunchedURLClassLoaderTest.java index 0e3ca7e8d..56faa5a79 100644 --- a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/test/java/com/alipay/sofa/ark/springboot/loader/CachedLaunchedURLClassLoaderTest.java +++ b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/test/java/com/alipay/sofa/ark/springboot/loader/CachedLaunchedURLClassLoaderTest.java @@ -15,21 +15,27 @@ * limitations under the License. */ package com.alipay.sofa.ark.springboot.loader; - import org.junit.Before; import org.junit.Test; -import org.springframework.boot.loader.archive.ExplodedArchive; +import org.springframework.boot.loader.launch.Archive; import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; import java.lang.reflect.Field; import java.net.URL; -import java.util.Map; +import java.util.*; +import java.util.function.Predicate; +import java.util.jar.Manifest; -import static com.alipay.sofa.ark.springboot.loader.JarLauncher.main; import static org.junit.Assert.*; - +import static com.alipay.sofa.ark.springboot.loader.JarLauncher.main; public class CachedLaunchedURLClassLoaderTest { + private static final Object NO_MANIFEST = new Object(); + private static final Set SKIPPED_NAMES = Set.of(".", ".."); + + private static final Comparator entryComparator = Comparator.comparing(File::getAbsolutePath); private CachedLaunchedURLClassLoader cachedLaunchedURLClassLoader; private File resourcesDir = new File("src/test/resources/"); @@ -37,8 +43,8 @@ public class CachedLaunchedURLClassLoaderTest { @Before public void setUp() throws Exception { cachedLaunchedURLClassLoader = new CachedLaunchedURLClassLoader(true, new ExplodedArchive( - resourcesDir), new URL[] { new URL("file:///" + resourcesDir.getAbsolutePath()) }, this - .getClass().getClassLoader()); + resourcesDir), new URL[] { new URL("file:///" + resourcesDir.getAbsolutePath()) }, this + .getClass().getClassLoader()); } @Test @@ -61,11 +67,11 @@ public void testLoadClass() throws Exception { } assertEquals(CachedLaunchedURLClassLoaderTest.class, - cachedLaunchedURLClassLoader.loadClass( - "com.alipay.sofa.ark.springboot.loader.CachedLaunchedURLClassLoaderTest", true)); + cachedLaunchedURLClassLoader.loadClass( + "com.alipay.sofa.ark.springboot.loader.CachedLaunchedURLClassLoaderTest", true)); assertEquals(CachedLaunchedURLClassLoaderTest.class, - cachedLaunchedURLClassLoader.loadClass( - "com.alipay.sofa.ark.springboot.loader.CachedLaunchedURLClassLoaderTest", true)); + cachedLaunchedURLClassLoader.loadClass( + "com.alipay.sofa.ark.springboot.loader.CachedLaunchedURLClassLoaderTest", true)); assertEquals(1, ((Map) field.get(cachedLaunchedURLClassLoader)).size()); } @@ -93,13 +99,89 @@ public void testFindResources() throws Exception { assertEquals(null, cachedLaunchedURLClassLoader.findResources("b")); assertEquals(1, ((Map) field.get(cachedLaunchedURLClassLoader)).size()); } - @Test public void testJarLauncher() throws Exception { try { main(new String[] {}); } catch (Exception e) { } - assertNotNull(new JarLauncher().createClassLoader(new URL[] {})); + List urls = new ArrayList<>(); + assertNotNull(new JarLauncher().createClassLoader(urls)); + } + + class ExplodedArchive implements Archive { + + private final File rootDirectory; + + private final String rootUriPath; + + private volatile Object manifest; + + /** + * Create a new {@link org.springframework.boot.loader.launch.ExplodedArchive} instance. + * @param rootDirectory the root directory + */ + ExplodedArchive(File rootDirectory) { + if (!rootDirectory.exists() || !rootDirectory.isDirectory()) { + throw new IllegalArgumentException("Invalid source directory " + rootDirectory); + } + this.rootDirectory = rootDirectory; + this.rootUriPath = this.rootDirectory.toURI().getPath(); + } + + @Override + public Manifest getManifest() throws IOException { + Object manifest = this.manifest; + if (manifest == null) { + manifest = loadManifest(); + this.manifest = manifest; + } + return (manifest != NO_MANIFEST) ? (Manifest) manifest : null; + } + + private Object loadManifest() throws IOException { + File file = new File(this.rootDirectory, "META-INF/MANIFEST.MF"); + if (!file.exists()) { + return NO_MANIFEST; + } + try (FileInputStream inputStream = new FileInputStream(file)) { + return new Manifest(inputStream); + } + } + @Override + public Set getClassPathUrls(Predicate includeFilter, Predicate directorySearchFilter) + throws IOException { + Set urls = new LinkedHashSet<>(); + LinkedList files = new LinkedList<>(listFiles(this.rootDirectory)); + while (!files.isEmpty()) { + File file = files.poll(); + if (SKIPPED_NAMES.contains(file.getName())) { + continue; + } + String entryName = file.toURI().getPath().substring(this.rootUriPath.length()); + files.addAll(0, listFiles(file)); + } + return urls; + } + + private List listFiles(File file) { + File[] files = file.listFiles(); + if (files == null) { + return Collections.emptyList(); + } + Arrays.sort(files, entryComparator); + return Arrays.asList(files); + } + + @Override + public File getRootDirectory() { + return this.rootDirectory; + } + + @Override + public String toString() { + return this.rootDirectory.toString(); + } + } } diff --git a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/test/java/com/alipay/sofa/ark/test/ArkBootRunnerTest.java b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/test/java/com/alipay/sofa/ark/test/ArkBootRunnerTest.java index 213e1218f..c023322ba 100644 --- a/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/test/java/com/alipay/sofa/ark/test/ArkBootRunnerTest.java +++ b/sofa-ark-parent/support/ark-springboot-integration/ark-springboot-starter/src/test/java/com/alipay/sofa/ark/test/ArkBootRunnerTest.java @@ -120,13 +120,13 @@ public int compare(Description o1, Description o2) { */ @Test public void testLogClassCastBug() { - Throwable throwable = null; + Class clazz = null; try { - this.getClass().getClassLoader() - .loadClass("org.apache.logging.slf4j.Log4jLoggerFactory").newInstance(); + clazz = this.getClass().getClassLoader() + .loadClass("org.apache.logging.slf4j.Log4jLoggerFactory"); } catch (Throwable t) { - throwable = t; + System.out.println(t.getStackTrace().toString()); } - assertNull(throwable); + assertTrue(clazz.getClassLoader().toString().contains("TestClassLoader")); } } diff --git a/sofa-ark-plugin/config-ark-plugin/pom.xml b/sofa-ark-plugin/config-ark-plugin/pom.xml index a01d393c7..cc55fd925 100644 --- a/sofa-ark-plugin/config-ark-plugin/pom.xml +++ b/sofa-ark-plugin/config-ark-plugin/pom.xml @@ -47,17 +47,6 @@ sofa-ark-api provided - - com.alipay.sofa - log-sofa-boot-starter - provided - - - org.springframework.boot - spring-boot - - - com.alipay.sofa sofa-ark-common diff --git a/sofa-ark-plugin/web-ark-plugin/pom.xml b/sofa-ark-plugin/web-ark-plugin/pom.xml index 2c6bf4d1a..90f4c2d49 100644 --- a/sofa-ark-plugin/web-ark-plugin/pom.xml +++ b/sofa-ark-plugin/web-ark-plugin/pom.xml @@ -13,7 +13,7 @@ web-ark-plugin - 3.0.9 + 3.2.1