Search in sources :

Example 11 with JarFileArchive

use of com.alipay.sofa.ark.loader.archive.JarFileArchive 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);
    }
}
Also used : EmbedClassPathArchive(com.alipay.sofa.ark.loader.EmbedClassPathArchive) BizArchive(com.alipay.sofa.ark.spi.archive.BizArchive) JarFileArchive(com.alipay.sofa.ark.loader.archive.JarFileArchive) EmbedClassPathArchive(com.alipay.sofa.ark.loader.EmbedClassPathArchive) Archive(com.alipay.sofa.ark.spi.archive.Archive) ArrayList(java.util.ArrayList) URL(java.net.URL) IOException(java.io.IOException) JarFileArchive(com.alipay.sofa.ark.loader.archive.JarFileArchive) URLClassLoader(java.net.URLClassLoader) File(java.io.File) BizArchive(com.alipay.sofa.ark.spi.archive.BizArchive) Test(org.junit.Test)

Aggregations

JarFileArchive (com.alipay.sofa.ark.loader.archive.JarFileArchive)11 File (java.io.File)10 ExecutableArkBizJar (com.alipay.sofa.ark.loader.ExecutableArkBizJar)5 Test (org.junit.Test)5 JarFile (com.alipay.sofa.ark.loader.jar.JarFile)4 JarPluginArchive (com.alipay.sofa.ark.loader.JarPluginArchive)3 BizArchive (com.alipay.sofa.ark.spi.archive.BizArchive)3 URL (java.net.URL)3 BaseTest (com.alipay.sofa.ark.container.BaseTest)2 EmbedClassPathArchive (com.alipay.sofa.ark.loader.EmbedClassPathArchive)2 ExplodedArchive (com.alipay.sofa.ark.loader.archive.ExplodedArchive)2 Archive (com.alipay.sofa.ark.spi.archive.Archive)2 PluginArchive (com.alipay.sofa.ark.spi.archive.PluginArchive)2 Plugin (com.alipay.sofa.ark.spi.model.Plugin)2 IOException (java.io.IOException)2 URI (java.net.URI)2 CodeSource (java.security.CodeSource)2 ProtectionDomain (java.security.ProtectionDomain)2 ClassPathArchive (com.alipay.sofa.ark.bootstrap.ClasspathLauncher.ClassPathArchive)1 BizModel (com.alipay.sofa.ark.container.model.BizModel)1