Search in sources :

Example 6 with JarFileArchive

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

the class PluginFactoryServiceTest method testCreatePluginWithExtensions.

@Test
public void testCreatePluginWithExtensions() throws Throwable {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    URL samplePlugin = cl.getResource("sample-plugin.jar");
    File file = new File(samplePlugin.getFile());
    JarFile pluginFile = new JarFile(file);
    JarFileArchive jarFileArchive = new JarFileArchive(pluginFile);
    JarPluginArchive jarPluginArchive = new JarPluginArchive(jarFileArchive);
    // inject
    URL[] extensions = new URL[1];
    URL sampleBiz = cl.getResource("sample-biz.jar");
    JarFile bizFile = new JarFile(new File(sampleBiz.getFile()));
    extensions[0] = bizFile.getUrl();
    // export
    Set<String> exportPackages = new HashSet<>();
    exportPackages.add("com.alipay.test.export.*");
    ArkConfigs.putStringValue(String.format(PLUGIN_EXTENSION_FORMAT, "sample-ark-plugin"), "tracer-core:3.0.10");
    Plugin plugin = pluginFactoryService.createPlugin(jarPluginArchive, extensions, exportPackages);
    Assert.assertNotNull(plugin);
    Assert.assertEquals(plugin.getExportPackages().size(), 2);
    Assert.assertTrue(Arrays.asList(plugin.getClassPath()).contains(bizFile.getUrl()));
}
Also used : JarFileArchive(com.alipay.sofa.ark.loader.archive.JarFileArchive) JarFile(com.alipay.sofa.ark.loader.jar.JarFile) JarFile(com.alipay.sofa.ark.loader.jar.JarFile) File(java.io.File) URL(java.net.URL) JarPluginArchive(com.alipay.sofa.ark.loader.JarPluginArchive) HashSet(java.util.HashSet) Plugin(com.alipay.sofa.ark.spi.model.Plugin) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 7 with JarFileArchive

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

the class BaseExecutableArchiveLauncher method createArchive.

/**
 * Returns the executable file archive
 * @return executable file archive
 * @throws Exception
 */
protected ExecutableArchive createArchive() throws Exception {
    ProtectionDomain protectionDomain = getClass().getProtectionDomain();
    CodeSource codeSource = protectionDomain.getCodeSource();
    URI location = (codeSource == null ? null : codeSource.getLocation().toURI());
    String path = (location == null ? null : location.getSchemeSpecificPart());
    if (path == null) {
        throw new IllegalStateException("Unable to determine code source archive");
    }
    File root = new File(path);
    if (!root.exists()) {
        throw new IllegalStateException("Unable to determine code source archive from " + root);
    }
    return root.isDirectory() ? new ExecutableArkBizJar(new ExplodedArchive(root)) : new ExecutableArkBizJar(new JarFileArchive(root), root.toURI().toURL());
}
Also used : ExplodedArchive(com.alipay.sofa.ark.loader.archive.ExplodedArchive) ProtectionDomain(java.security.ProtectionDomain) ExecutableArkBizJar(com.alipay.sofa.ark.loader.ExecutableArkBizJar) JarFileArchive(com.alipay.sofa.ark.loader.archive.JarFileArchive) CodeSource(java.security.CodeSource) URI(java.net.URI) File(java.io.File)

Example 8 with JarFileArchive

use of com.alipay.sofa.ark.loader.archive.JarFileArchive 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));
    }
}
Also used : BizArchive(com.alipay.sofa.ark.spi.archive.BizArchive) JarFileArchive(com.alipay.sofa.ark.loader.archive.JarFileArchive) PluginArchive(com.alipay.sofa.ark.spi.archive.PluginArchive) ContainerArchive(com.alipay.sofa.ark.spi.archive.ContainerArchive) Archive(com.alipay.sofa.ark.spi.archive.Archive) JarFileArchive(com.alipay.sofa.ark.loader.archive.JarFileArchive) File(java.io.File)

Example 9 with JarFileArchive

use of com.alipay.sofa.ark.loader.archive.JarFileArchive 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 10 with JarFileArchive

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

the class BizFactoryServiceImpl method createBiz.

@Override
public Biz createBiz(File file) throws IOException {
    BizArchive bizArchive;
    if (ArkConfigs.isEmbedEnable()) {
        File unpackFile = new File(file.getAbsolutePath() + "-unpack");
        if (!unpackFile.exists()) {
            unpackFile = FileUtils.unzip(file, file.getAbsolutePath() + "-unpack");
        }
        if (file.exists()) {
            file.delete();
        }
        file = unpackFile;
        bizArchive = new ExplodedBizArchive(unpackFile);
    } else {
        JarFile bizFile = new JarFile(file);
        JarFileArchive jarFileArchive = new JarFileArchive(bizFile);
        bizArchive = new JarBizArchive(jarFileArchive);
    }
    BizModel biz = (BizModel) createBiz(bizArchive);
    biz.setBizTempWorkDir(file);
    return biz;
}
Also used : JarBizArchive(com.alipay.sofa.ark.loader.JarBizArchive) JarFileArchive(com.alipay.sofa.ark.loader.archive.JarFileArchive) ExplodedBizArchive(com.alipay.sofa.ark.loader.ExplodedBizArchive) BizModel(com.alipay.sofa.ark.container.model.BizModel) JarFile(com.alipay.sofa.ark.loader.jar.JarFile) JarFile(com.alipay.sofa.ark.loader.jar.JarFile) File(java.io.File) BizArchive(com.alipay.sofa.ark.spi.archive.BizArchive) JarBizArchive(com.alipay.sofa.ark.loader.JarBizArchive) ExplodedBizArchive(com.alipay.sofa.ark.loader.ExplodedBizArchive)

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