Java Code Examples for org.jboss.shrinkwrap.api.spec.JavaArchive#getName()

The following examples show how to use org.jboss.shrinkwrap.api.spec.JavaArchive#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExportUtil.java    From quarkus with Apache License 2.0 6 votes vote down vote up
static void exportToQuarkusDeploymentPath(JavaArchive archive) throws IOException {
    String exportPath = System.getProperty("quarkus.deploymentExportPath");
    if (exportPath == null) {
        return;
    }
    File exportDir = new File(exportPath);
    if (exportDir.exists()) {
        if (!exportDir.isDirectory()) {
            throw new IllegalStateException("Export path is not a directory: " + exportPath);
        }
        try (Stream<Path> stream = Files.walk(exportDir.toPath())) {
            stream.sorted(Comparator.reverseOrder()).map(Path::toFile)
                    .forEach(File::delete);
        }
    } else if (!exportDir.mkdirs()) {
        throw new IllegalStateException("Export path could not be created: " + exportPath);
    }
    File exportFile = new File(exportDir, archive.getName());
    archive.as(ZipExporter.class).exportTo(exportFile);
}
 
Example 2
Source File: ChildFirstClassLoadingTest.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@BeforeClass
public static void createJars() throws Exception {
    String tempDir = System.getProperty("java.io.tmpdir");

    JavaArchive childJar = ShrinkWrap.create(JavaArchive.class, "child.jar").addClasses(WelcomeChild.class).addAsServiceProvider(Welcome.class, WelcomeChild.class);
    File childFile = new File(tempDir + File.separator + childJar.getName());
    new ZipExporterImpl(childJar).exportTo(childFile, true);
    childJarURL = childFile.toURI().toURL();
    childFile.deleteOnExit();

    JavaArchive parentJar = ShrinkWrap.create(JavaArchive.class, "parent.jar").addClasses(WelcomeParent.class).addAsServiceProvider(Welcome.class, WelcomeParent.class);
    File parentFile = new File(tempDir + File.separator + parentJar.getName());
    new ZipExporterImpl(parentJar).exportTo(parentFile, true);
    parentJarURL = parentFile.toURI().toURL();
    parentFile.deleteOnExit();
}
 
Example 3
Source File: QuarkusProdModeTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private void exportArchive(Path deploymentDir, Class<?> testClass) {
    try {
        JavaArchive archive = getArchiveProducerOrDefault();
        if (customApplicationProperties != null) {
            archive.add(new PropertiesAsset(customApplicationProperties), "application.properties");
        }
        archive.as(ExplodedExporter.class).exportExplodedInto(deploymentDir.toFile());

        String exportPath = System.getProperty("quarkus.deploymentExportPath");
        if (exportPath != null) {
            File exportDir = new File(exportPath);
            if (exportDir.exists()) {
                if (!exportDir.isDirectory()) {
                    throw new IllegalStateException("Export path is not a directory: " + exportPath);
                }
                try (Stream<Path> stream = Files.walk(exportDir.toPath())) {
                    stream.sorted(Comparator.reverseOrder()).map(Path::toFile)
                            .forEach(File::delete);
                }
            } else if (!exportDir.mkdirs()) {
                throw new IllegalStateException("Export path could not be created: " + exportPath);
            }
            File exportFile = new File(exportDir, archive.getName());
            archive.as(ZipExporter.class).exportTo(exportFile);
        }
    } catch (Exception e) {
        throw new RuntimeException("Unable to create the archive", e);
    }
}
 
Example 4
Source File: CamelProjectComponentTestIT.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
private File createTestArchive(String filename) throws IOException {
    JavaArchive archive = ShrinkWrap.create(JavaArchive.class, filename)
        .addClasses(CamelService.class);
    File file = new File(root, archive.getName());
    file.deleteOnExit();
    archive.as(ZipExporter.class).exportTo(file, true);
    return file;
}
 
Example 5
Source File: ChildFirstClassLoadingTest.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testSingleClassFromJar() throws Exception {
    JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "single-class-from-jar-test.jar")
            .addClasses(SingleChildFirst1.class, SingleChildFirst2.class, SingleParentFirst.class);
    String tempDir = System.getProperty("java.io.tmpdir");

    File file = new File(tempDir + File.separator + jar.getName());
    try {
        new ZipExporterImpl(jar).exportTo(file, true);
        URLClassLoader tmp = new ChildFirstClassLoaderBuilder(false)
                .addURL(file.toURI().toURL())
                .build();
        Class<?> scf1 = tmp.loadClass(SingleChildFirst1.class.getName());
        Assert.assertSame(tmp, scf1.getClassLoader());
        Class<?> scf2 = tmp.loadClass(SingleChildFirst2.class.getName());
        Assert.assertSame(tmp, scf2.getClassLoader());

        URLClassLoader loader = new ChildFirstClassLoaderBuilder(false)
                .addSingleChildFirstClass(scf1, scf2)
                .build();
        Assert.assertSame(loader, loader.loadClass(SingleChildFirst1.class.getName()).getClassLoader());
        Assert.assertSame(loader, loader.loadClass(SingleChildFirst2.class.getName()).getClassLoader());
        Assert.assertNotSame(loader, loader.loadClass(SingleParentFirst.class.getName()).getClassLoader());
        loader.close();
    } finally {
        file.delete();
    }
}