use of com.alipay.sofa.ark.loader.jar.JarFile in project sofa-ark by alipay.
the class JarFileTest method testJarFile.
@Test
public void testJarFile() throws IOException {
JarFile jarFile = new JarFile(getTempDemoZip());
Manifest manifest = jarFile.getManifest();
Assert.assertTrue(manifest.getMainAttributes().getValue("k1").equals("v1"));
Assert.assertTrue(manifest.getMainAttributes().getValue("k2").equals("v2"));
Assert.assertTrue(jarFile.containsEntry(TEST_ENTRY));
ZipEntry zipEntry = jarFile.getEntry(TEST_ENTRY);
Assert.assertTrue(zipEntry.getName().equals(TEST_ENTRY));
Assert.assertTrue(zipEntry.getComment().equals(TEST_ENTRY_COMMENT));
Assert.assertTrue(compareByteArray(zipEntry.getExtra(), TEST_ENTRY_EXTRA.getBytes()));
JarEntry jarEntry = jarFile.getJarEntry("lib/junit-4.12.jar");
JarFile nestJarFile = jarFile.getNestedJarFile(jarEntry);
Manifest nestManifest = nestJarFile.getManifest();
Assert.assertTrue(nestManifest.getMainAttributes().getValue("Implementation-Title").equals("JUnit"));
Assert.assertTrue(nestManifest.getMainAttributes().getValue("Implementation-Version").equals("4.12"));
}
use of com.alipay.sofa.ark.loader.jar.JarFile in project sofa-ark by alipay.
the class PluginFactoryServiceImpl method createPlugin.
@Override
public Plugin createPlugin(File file) throws IOException {
JarFile pluginFile = new JarFile(file);
JarFileArchive jarFileArchive = new JarFileArchive(pluginFile);
JarPluginArchive jarPluginArchive = new JarPluginArchive(jarFileArchive);
return createPlugin(jarPluginArchive);
}
use of com.alipay.sofa.ark.loader.jar.JarFile 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()));
}
use of com.alipay.sofa.ark.loader.jar.JarFile 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;
}
Aggregations