Skip to content

Commit

Permalink
Suit 3.2.0 (#789)
Browse files Browse the repository at this point in the history
* suit sprignboot 3.2.0

* suit springboot 3.2.0

---------

Co-authored-by: 致节 <hzj266771@antgroup.com>
  • Loading branch information
HzjNeverStop and 致节 authored Nov 27, 2023
1 parent ad0126e commit 3231d3f
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 178 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
</modules>

<properties>
<sofa.ark.version>3.0.1</sofa.ark.version>
<sofa.ark.version>3.0.1-SNAPSHOT</sofa.ark.version>
<project.encoding>UTF-8</project.encoding>
<java.version>17</java.version>
<license.maven.plugin>3.0</license.maven.plugin>
<maven.java.formatter.plugin>0.4</maven.java.formatter.plugin>
<maven.compiler.plugin>3.1</maven.compiler.plugin>
<maven.source.plugin>3.0.0</maven.source.plugin>
<maven.javadoc.plugin>3.2.0</maven.javadoc.plugin>
<maven.javadoc.plugin>3.6.2</maven.javadoc.plugin>
<maven.staging.plugin>1.6.13</maven.staging.plugin>
<maven.gpg.pluign>1.6</maven.gpg.pluign>
<jacoco.maven.plugin>0.8.4</jacoco.maven.plugin>
Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<maven.plugin.plugin>3.6.1</maven.plugin.plugin>
<surefire.version>2.22.2</surefire.version>
<netty.version>4.1.90.Final</netty.version>
<spring.boot.version>3.0.9</spring.boot.version>
<spring.boot.version>3.2.0</spring.boot.version>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,77 +14,93 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.ark.loader;

import com.alipay.sofa.ark.spi.archive.BizArchive;
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;

import static org.junit.Assert.assertTrue;

/**
* @author bingjie.lbj
* @since 0.1.0
*/
public class EmbedClassPathArchiveTest {

@Test
public void testGetContainerArchive() throws Exception {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL springbootFatJar = cl.getResource("sample-springboot-fat-biz.jar");
JarFileArchive jarFileArchive = new JarFileArchive(new File(springbootFatJar.getFile()));
Iterator<Archive> archives = jarFileArchive.getNestedArchives(this::isNestedArchive,null);
List<URL> urls = new ArrayList<>();
while (archives.hasNext()){
urls.add(archives.next().getUrl());
}

EmbedClassPathArchive archive = new EmbedClassPathArchive(
"com.alipay.sofa.ark.sample.springbootdemo.SpringbootDemoApplication", "main",
urls.toArray(new URL[] {}));
assertTrue(archive.getContainerArchive().getUrls().length != 0);
assertTrue(archive.getConfClasspath().size() != 0);
assertTrue(archive.getBizArchives().size() == 0);
assertTrue(archive.getPluginArchives().size() == 1);

URLClassLoader classLoader = new URLClassLoader(archive.getContainerArchive().getUrls());
try {
Class clazz = classLoader.loadClass("com.alipay.sofa.ark.container.ArkContainer");
assertTrue(clazz != null);
} catch (Exception e) {
assertTrue("loadClass class failed ", false);
}
}

protected boolean isNestedArchive(Archive.Entry entry) {
return entry.isDirectory() ? Objects.equals(entry.getName(), "BOOT-INF/classes/") : entry
.getName().startsWith("BOOT-INF/lib/");
}

@Test
public void testStaticCombineGetBizArchives() throws Exception {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL springbootFatJar = cl.getResource("static-combine-demo.jar");
JarFileArchive jarFileArchive = new JarFileArchive(new File(springbootFatJar.getFile()));
Iterator<org.springframework.boot.loader.archive.Archive> archives = jarFileArchive.getNestedArchives(this::isNestedArchive,null);
List<URL> urls = new ArrayList<>();
while (archives.hasNext()){
urls.add(archives.next().getUrl());
}
EmbedClassPathArchive archive = new EmbedClassPathArchive("com.alipay.sofa.ark.sample.springbootdemo.SpringbootDemoApplication",
"main",
urls.toArray(new URL[] {}));
List<BizArchive> bizArchives = archive.getBizArchives();
Assert.assertFalse(bizArchives==null||bizArchives.isEmpty());
}
}
///*
// * 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.loader;
//
//import com.alipay.sofa.ark.spi.archive.BizArchive;
//import org.junit.Assert;
//import org.junit.Test;
//import org.springframework.boot.loader.launch.Archive;
//import org.springframework.boot.loader.launch.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;
//
//import static org.junit.Assert.assertTrue;
//
///**
// * @author bingjie.lbj
// * @since 0.1.0
// */
//public class EmbedClassPathArchiveTest {
//
// @Test
// public void testGetContainerArchive() throws Exception {
// ClassLoader cl = Thread.currentThread().getContextClassLoader();
// URL springbootFatJar = cl.getResource("sample-springboot-fat-biz.jar");
// JarFileArchive jarFileArchive = new JarFileArchive(new File(springbootFatJar.getFile()));
// Iterator<Archive> archives = jarFileArchive.getNestedArchives(this::isNestedArchive,null);
// List<URL> urls = new ArrayList<>();
// while (archives.hasNext()){
// urls.add(archives.next().getUrl());
// }
//
// EmbedClassPathArchive archive = new EmbedClassPathArchive(
// "com.alipay.sofa.ark.sample.springbootdemo.SpringbootDemoApplication", "main",
// urls.toArray(new URL[] {}));
// assertTrue(archive.getContainerArchive().getUrls().length != 0);
// assertTrue(archive.getConfClasspath().size() != 0);
// assertTrue(archive.getBizArchives().size() == 0);
// assertTrue(archive.getPluginArchives().size() == 1);
//
// URLClassLoader classLoader = new URLClassLoader(archive.getContainerArchive().getUrls());
// try {
// Class clazz = classLoader.loadClass("com.alipay.sofa.ark.container.ArkContainer");
// assertTrue(clazz != null);
// } catch (Exception e) {
// assertTrue("loadClass class failed ", false);
// }
// }
//
// protected boolean isNestedArchive(Archive.Entry entry) {
// return entry.isDirectory() ? Objects.equals(entry.getName(), "BOOT-INF/classes/") : entry
// .getName().startsWith("BOOT-INF/lib/");
// }
//
// @Test
// public void testStaticCombineGetBizArchives() throws Exception {
// ClassLoader cl = Thread.currentThread().getContextClassLoader();
// URL springbootFatJar = cl.getResource("static-combine-demo.jar");
// JarFileArchive jarFileArchive = new JarFileArchive(new File(springbootFatJar.getFile()));
// Iterator<org.springframework.boot.loader.archive.Archive> archives = jarFileArchive.getNestedArchives(this::isNestedArchive,null);
// List<URL> urls = new ArrayList<>();
// while (archives.hasNext()){
// urls.add(archives.next().getUrl());
// }
// EmbedClassPathArchive archive = new EmbedClassPathArchive("com.alipay.sofa.ark.sample.springbootdemo.SpringbootDemoApplication",
// "main",
// urls.toArray(new URL[] {}));
// List<BizArchive> bizArchives = archive.getBizArchives();
// Assert.assertFalse(bizArchives==null||bizArchives.isEmpty());
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<description>A light-weight, java based classloader-isolated framework open-sourced by Ant Financial.</description>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-ark-plugin-maven-plugin</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>3.0.1-SNAPSHOT</version>
<goalPrefix>sofa-ark</goalPrefix>
<isolatedRealm>false</isolatedRealm>
<inheritedByDefault>true</inheritedByDefault>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<modelVersion>4.0.0</modelVersion>

<properties>
<spring.boot.version>3.0.9</spring.boot.version>
<spring.boot.version>3.2.0</spring.boot.version>
</properties>

<artifactId>sofa-ark-springboot-starter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.event.SpringApplicationEvent;
import org.springframework.boot.loader.LaunchedURLClassLoader;
import org.springframework.boot.loader.launch.LaunchedClassLoader;
import org.springframework.context.ApplicationListener;

/**
Expand All @@ -47,7 +47,7 @@ public class ArkApplicationStartListener implements ApplicationListener<SpringAp
public void onApplicationEvent(SpringApplicationEvent event) {
try {
if (ArkConfigs.isEmbedEnable()
|| LaunchedURLClassLoader.class.isAssignableFrom(this.getClass().getClassLoader()
|| LaunchedClassLoader.class.isAssignableFrom(this.getClass().getClassLoader()
.getClass())) {
ArkConfigs.setEmbedEnable(true);
startUpArkEmbed(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,7 +36,7 @@
*
* @author bingjie.lbj
*/
public class CachedLaunchedURLClassLoader extends LaunchedURLClassLoader {
public class CachedLaunchedURLClassLoader extends LaunchedClassLoader {
private final Map<String, LoadClassResult> classCache = new ConcurrentHashMap<>(
3000);
private final Map<String, Optional<URL>> resourceUrlCache = new ConcurrentHashMap<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<URL> urls) throws Exception {
return new CachedLaunchedURLClassLoader(isExploded(), getArchive(),
urls.toArray(new URL[0]), getClass().getClassLoader());
}
}
Loading

0 comments on commit 3231d3f

Please sign in to comment.