Search in sources :

Example 1 with EmbedClassPathArchive

use of com.alipay.sofa.ark.loader.EmbedClassPathArchive in project sofa-ark by alipay.

the class EmbedSofaArkBootstrap method launch.

public static void launch(Environment environment) {
    if (started.compareAndSet(false, true)) {
        EntryMethod entryMethod = new EntryMethod(Thread.currentThread());
        getOrSetDefault(Constants.MASTER_BIZ, environment.getProperty(Constants.MASTER_BIZ, environment.getProperty("spring.application.name")));
        getOrSetDefault(Constants.BIZ_CLASS_LOADER_HOOK_DIR, environment.getProperty(Constants.BIZ_CLASS_LOADER_HOOK_DIR));
        getOrSetDefault(Constants.PLUGIN_EXPORT_CLASS_ENABLE, environment.getProperty(Constants.PLUGIN_EXPORT_CLASS_ENABLE, "false"));
        getOrSetDefault(Constants.BIZ_CLASS_LOADER_HOOK_DIR, DelegateToMasterBizClassLoaderHook.class.getName());
        try {
            URL[] urls = getURLClassPath();
            ClasspathLauncher launcher = new ClasspathLauncher(new EmbedClassPathArchive(entryMethod.getDeclaringClassName(), entryMethod.getMethod().getName(), urls));
            launcher.launch(new String[] {}, getClasspath(urls), entryMethod.getMethod());
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : ClasspathLauncher(com.alipay.sofa.ark.bootstrap.ClasspathLauncher) EmbedClassPathArchive(com.alipay.sofa.ark.loader.EmbedClassPathArchive) DelegateToMasterBizClassLoaderHook(com.alipay.sofa.ark.support.common.DelegateToMasterBizClassLoaderHook) URL(java.net.URL)

Example 2 with EmbedClassPathArchive

use of com.alipay.sofa.ark.loader.EmbedClassPathArchive in project sofa-ark by alipay.

the class ArkContainer method main.

public static Object main(String[] args) throws ArkRuntimeException {
    if (args.length < MINIMUM_ARGS_SIZE) {
        throw new ArkRuntimeException("Please provide suitable arguments to continue !");
    }
    try {
        LaunchCommand launchCommand = LaunchCommand.parse(args);
        if (launchCommand.isExecutedByCommandLine()) {
            ExecutableArkBizJar executableArchive;
            File rootFile = new File(URLDecoder.decode(launchCommand.getExecutableArkBizJar().getFile()));
            if (rootFile.isDirectory()) {
                executableArchive = new ExecutableArkBizJar(new ExplodedArchive(rootFile));
            } else {
                executableArchive = new ExecutableArkBizJar(new JarFileArchive(rootFile, launchCommand.getExecutableArkBizJar()));
            }
            return new ArkContainer(executableArchive, launchCommand).start();
        } else {
            ClassPathArchive classPathArchive;
            if (ArkConfigs.isEmbedEnable()) {
                classPathArchive = new EmbedClassPathArchive(launchCommand.getEntryClassName(), launchCommand.getEntryMethodName(), launchCommand.getClasspath());
            } else {
                classPathArchive = new ClassPathArchive(launchCommand.getEntryClassName(), launchCommand.getEntryMethodName(), launchCommand.getClasspath());
            }
            return new ArkContainer(classPathArchive, launchCommand).start();
        }
    } catch (IOException e) {
        throw new ArkRuntimeException(String.format("SOFAArk startup failed, commandline=%s", LaunchCommand.toString(args)), e);
    }
}
Also used : ExplodedArchive(com.alipay.sofa.ark.loader.archive.ExplodedArchive) LaunchCommand(com.alipay.sofa.ark.spi.argument.LaunchCommand) EmbedClassPathArchive(com.alipay.sofa.ark.loader.EmbedClassPathArchive) ExecutableArkBizJar(com.alipay.sofa.ark.loader.ExecutableArkBizJar) JarFileArchive(com.alipay.sofa.ark.loader.archive.JarFileArchive) IOException(java.io.IOException) File(java.io.File) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException) ClassPathArchive(com.alipay.sofa.ark.bootstrap.ClasspathLauncher.ClassPathArchive) EmbedClassPathArchive(com.alipay.sofa.ark.loader.EmbedClassPathArchive)

Example 3 with EmbedClassPathArchive

use of com.alipay.sofa.ark.loader.EmbedClassPathArchive 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

EmbedClassPathArchive (com.alipay.sofa.ark.loader.EmbedClassPathArchive)3 JarFileArchive (com.alipay.sofa.ark.loader.archive.JarFileArchive)2 File (java.io.File)2 IOException (java.io.IOException)2 URL (java.net.URL)2 ClasspathLauncher (com.alipay.sofa.ark.bootstrap.ClasspathLauncher)1 ClassPathArchive (com.alipay.sofa.ark.bootstrap.ClasspathLauncher.ClassPathArchive)1 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)1 ExecutableArkBizJar (com.alipay.sofa.ark.loader.ExecutableArkBizJar)1 ExplodedArchive (com.alipay.sofa.ark.loader.archive.ExplodedArchive)1 Archive (com.alipay.sofa.ark.spi.archive.Archive)1 BizArchive (com.alipay.sofa.ark.spi.archive.BizArchive)1 LaunchCommand (com.alipay.sofa.ark.spi.argument.LaunchCommand)1 DelegateToMasterBizClassLoaderHook (com.alipay.sofa.ark.support.common.DelegateToMasterBizClassLoaderHook)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1