use of com.alipay.sofa.ark.spi.archive.Archive in project sofa-ark by alipay.
the class EmbedClassPathArchive method getUrlJarFileArchive.
protected JarFileArchive getUrlJarFileArchive(URL url) throws IOException {
String file = url.getFile();
if (file.contains(FILE_IN_JAR)) {
int pos = file.indexOf(FILE_IN_JAR);
File fatJarFile = new File(file.substring(0, pos));
String nestedJar = file.substring(file.lastIndexOf("/") + 1);
JarFileArchive fatJarFileArchive = new JarFileArchive(fatJarFile);
List<Archive> matched = fatJarFileArchive.getNestedArchives(entry -> entry.getName().contains(nestedJar));
return (JarFileArchive) matched.get(0);
} else {
return new JarFileArchive(new File(file));
}
}
use of com.alipay.sofa.ark.spi.archive.Archive in project sofa-ark by alipay.
the class ClasspathLauncherTest method testSpringBootFatJar.
@Test
public void testSpringBootFatJar() throws Exception {
URL url = this.getClass().getClassLoader().getResource("sample-springboot-fat-biz.jar");
URL[] agentUrl = ClassLoaderUtils.getAgentClassPath();
Assert.assertEquals(1, agentUrl.length);
List<URL> urls = new ArrayList<>();
JarFileArchive jarFileArchive = new JarFileArchive(new File(url.getFile()));
List<Archive> archives = jarFileArchive.getNestedArchives(this::isNestedArchive);
for (Archive archive : archives) {
urls.add(archive.getUrl());
}
urls.addAll(Arrays.asList(agentUrl));
EmbedClassPathArchive classPathArchive = new EmbedClassPathArchive(this.getClass().getCanonicalName(), null, urls.toArray(new URL[] {}));
List<BizArchive> bizArchives = classPathArchive.getBizArchives();
Assert.assertEquals(0, bizArchives.size());
Assert.assertNotNull(classPathArchive.getContainerArchive());
Assert.assertEquals(1, classPathArchive.getPluginArchives().size());
Assert.assertEquals(archives.size() + 1, urls.size());
Assert.assertEquals(3, classPathArchive.getConfClasspath().size());
URLClassLoader classLoader = new URLClassLoader(classPathArchive.getContainerArchive().getUrls());
try {
Class clazz = classLoader.loadClass("com.alipay.sofa.ark.bootstrap.ArkLauncher");
Assert.assertTrue(clazz != null);
} catch (Exception e) {
Assert.assertTrue("loadClass class failed ", false);
}
}
Aggregations