Skip to content

Commit

Permalink
suit springboot 3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
致节 committed Nov 24, 2023
1 parent 1cba60e commit 9476cce
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 168 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
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 @@ -34,7 +34,7 @@ public static void main(String[] args) throws Exception {

@Override
protected ClassLoader createClassLoader(Collection<URL> urls) throws Exception {
return new CachedLaunchedURLClassLoader(isExploded(), getArchive(), urls.toArray(new URL[0]), getClass()
.getClassLoader());
return new CachedLaunchedURLClassLoader(isExploded(), getArchive(),
urls.toArray(new URL[0]), getClass().getClassLoader());
}
}
Loading

0 comments on commit 9476cce

Please sign in to comment.