org.jboss.shrinkwrap.api.exporter.ZipExporter Java Examples

The following examples show how to use org.jboss.shrinkwrap.api.exporter.ZipExporter. 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: FractionUsageAnalyzerTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Test
public void testDetectEmptyWarAsUndertow() throws Exception {
    JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.war");
    archive.add(EmptyAsset.INSTANCE, "nothing");
    FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer();

    final File out = Files.createTempFile(archive.getName(), ".war").toFile();
    archive.as(ZipExporter.class).exportTo(out, true);

    analyzer.source(out);
    assertThat(analyzer.detectNeededFractions()
                       .stream()
                       .filter(fd -> fd.getArtifactId().equals("undertow"))
                       .count())
            .isEqualTo(1);

    out.delete();
}
 
Example #2
Source File: SecurityTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Test
public void testFractionMatchingWebXML() throws Exception {
    JARArchive archive = ShrinkWrap.create(JARArchive.class);
    archive.addAsResource("WEB-INF/web.xml");
    FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer();

    final File out = Files.createTempFile(archive.getName(), ".war").toFile();
    out.deleteOnExit();
    archive.as(ZipExporter.class).exportTo(out, true);
    analyzer.source(out);

    assertThat(analyzer.detectNeededFractions()
                   .stream()
                   .filter(fd -> fd.getArtifactId().equals("security"))
                   .count()).isEqualTo(1);
}
 
Example #3
Source File: MockArtifactResolver.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public ArtifactSpec resolve(ArtifactSpec spec) throws Exception {
    File resolved = resolvedArtifacts.get(spec);

    if (resolved == null) {
        Archive archive = artifacts.get(spec);
        if (archive != null) {
            resolved = File.createTempFile(spec.artifactId(), ".jar");
            resolved.delete();
            resolved.deleteOnExit();
            archive.as(ZipExporter.class).exportTo(resolved);
            this.resolvedArtifacts.put(spec, resolved);
        }
    }
    spec.file = resolved;
    return spec;

}
 
Example #4
Source File: PluginLoaderImplTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
@Test
public void test_load_plugins_folder_contains_jar_file() throws Exception {
    final File pluginsFolder = temporaryFolder.newFolder("extension");
    final File pluginFolder = temporaryFolder.newFolder("extension", "plugin1");
    final File file = new File(pluginFolder, "extension.jar");
    FileUtils.writeStringToFile(pluginFolder.toPath().resolve("hivemq-extension.xml").toFile(),
            validPluginXML1,
            Charset.defaultCharset());
    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class).
            addAsServiceProviderAndClasses(ExtensionMain.class, TestExtensionMainImpl.class);

    javaArchive.as(ZipExporter.class).exportTo(file);

    when(classServiceLoader.load(eq(ExtensionMain.class), any(ClassLoader.class))).thenReturn(new ArrayList<>());

    pluginLoader.loadPlugins(pluginsFolder.toPath(), false, ExtensionMain.class);

    //Let's verify that the extension was loaded
    verify(classServiceLoader).load(any(Class.class), any(ClassLoader.class));
}
 
Example #5
Source File: BuildTool.java    From thorntail with Apache License 2.0 6 votes vote down vote up
public void repackageWar(File file) throws IOException {
    if (!filterWebInfLib) {
        return;
    }

    this.log.info("Repackaging .war: " + file);

    Path backupPath = get(file);
    move(file, backupPath, this.log);

    Archive original = ShrinkWrap.create(JavaArchive.class);
    try (InputStream inputStream = Files.newInputStream(backupPath)) {
        original.as(ZipImporter.class).importFrom(inputStream);
    }

    Archive repackaged = new WebInfLibFilteringArchive(original, this.dependencyManager);
    repackaged.as(ZipExporter.class).exportTo(file, true);
    this.log.info("Repackaged .war: " + file);
}
 
Example #6
Source File: Swarm.java    From thorntail with Apache License 2.0 6 votes vote down vote up
private void createShrinkWrapDomain() {
    ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
    try {
        if (isFatJar()) {
            Module appModule = Module.getBootModuleLoader().loadModule(APPLICATION_MODULE_NAME);
            Thread.currentThread().setContextClassLoader(appModule.getClassLoader());
        }
        Domain domain = ShrinkWrap.getDefaultDomain();
        domain.getConfiguration().getExtensionLoader().addOverride(ZipExporter.class, ZipExporterImpl.class);
        domain.getConfiguration().getExtensionLoader().addOverride(ZipImporter.class, ZipImporterImpl.class);
        domain.getConfiguration().getExtensionLoader().addOverride(ExplodedExporter.class, ExplodedExporterImpl.class);
        domain.getConfiguration().getExtensionLoader().addOverride(ExplodedImporter.class, ExplodedImporterImpl.class);
        domain.getConfiguration().getExtensionLoader().addOverride(JavaArchive.class, JavaArchiveImpl.class);
        domain.getConfiguration().getExtensionLoader().addOverride(WebArchive.class, WebArchiveImpl.class);
    } catch (Exception e) {
        SwarmMessages.MESSAGES.shrinkwrapDomainSetupFailed(e);
    } finally {
        Thread.currentThread().setContextClassLoader(originalCl);
    }
}
 
Example #7
Source File: PluginLoaderImplTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
/*******************************
 * loadSinglePlugin(...) Tests *
 *******************************/

@Test(timeout = 5000)
public void test_load_single_plugin_load_and_instantiate_enabled() throws Throwable {

    final File pluginFolder1 = temporaryFolder.newFolder("extension", "plugin1");
    FileUtils.writeStringToFile(pluginFolder1.toPath().resolve("hivemq-extension.xml").toFile(),
            validPluginXML1,
            Charset.defaultCharset());
    final File file = new File(pluginFolder1, "extension.jar");
    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class).
            addAsServiceProviderAndClasses(ExtensionMain.class, TestExtensionMainImpl.class);
    javaArchive.as(ZipExporter.class).exportTo(file);

    final HiveMQExtension hiveMQExtension = realPluginLoader.loadSinglePlugin(
            pluginFolder1.toPath(),
            HiveMQPluginXMLReader.getPluginEntityFromXML(pluginFolder1.toPath(), true).get(),
            ExtensionMain.class);

    assertNotNull(hiveMQExtension);
    hiveMQExtension.start(super.getTestPluginStartInput(), super.getTestPluginStartOutput());
    assertTrue(hiveMQExtension.isEnabled());
}
 
Example #8
Source File: DisconnectOutboundInterceptorHandlerTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
private DisconnectOutboundInterceptor getIsolatedOutboundInterceptor(final @NotNull String name) throws Exception {
    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class)
            .addClass("com.hivemq.extensions.handler.DisconnectOutboundInterceptorHandlerTest$" + name);

    final File jarFile = temporaryFolder.newFile();
    javaArchive.as(ZipExporter.class).exportTo(jarFile, true);

    final IsolatedPluginClassloader
            cl =
            new IsolatedPluginClassloader(new URL[]{jarFile.toURI().toURL()}, this.getClass().getClassLoader());

    final Class<?> interceptorClass =
            cl.loadClass("com.hivemq.extensions.handler.DisconnectOutboundInterceptorHandlerTest$" + name);

    return (DisconnectOutboundInterceptor) interceptorClass.newInstance();
}
 
Example #9
Source File: DisconnectInboundInterceptorHandlerTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
private DisconnectInboundInterceptor getIsolatedInboundInterceptor(final @NotNull String name) throws Exception {
    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class)
            .addClass("com.hivemq.extensions.handler.DisconnectInboundInterceptorHandlerTest$" + name);

    final File jarFile = temporaryFolder.newFile();
    javaArchive.as(ZipExporter.class).exportTo(jarFile, true);

    final IsolatedPluginClassloader
            cl =
            new IsolatedPluginClassloader(new URL[]{jarFile.toURI().toURL()}, this.getClass().getClassLoader());

    final Class<?> interceptorClass =
            cl.loadClass("com.hivemq.extensions.handler.DisconnectInboundInterceptorHandlerTest$" + name);

    return (DisconnectInboundInterceptor) interceptorClass.newInstance();
}
 
Example #10
Source File: UnsubscribeInboundInterceptorHandlerTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
private @NotNull UnsubscribeInboundInterceptor getIsolatedInboundInterceptor(final @NotNull String name)
        throws Exception {
    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class)
            .addClass("com.hivemq.extensions.handler.UnsubscribeInboundInterceptorHandlerTest$" + name);

    final File jarFile = temporaryFolder.newFile();
    javaArchive.as(ZipExporter.class).exportTo(jarFile, true);

    final IsolatedPluginClassloader
            cl =
            new IsolatedPluginClassloader(new URL[]{jarFile.toURI().toURL()}, this.getClass().getClassLoader());

    final Class<?> interceptorClass =
            cl.loadClass("com.hivemq.extensions.handler.UnsubscribeInboundInterceptorHandlerTest$" + name);

    return (UnsubscribeInboundInterceptor) interceptorClass.newInstance();
}
 
Example #11
Source File: SubackOutboundInterceptorHandlerTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
private SubackOutboundInterceptor getIsolatedOutboundInterceptor(final @NotNull String name) throws Exception {
    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class)
            .addClass("com.hivemq.extensions.handler.SubackOutboundInterceptorHandlerTest$" + name);

    final File jarFile = temporaryFolder.newFile();
    javaArchive.as(ZipExporter.class).exportTo(jarFile, true);

    final IsolatedPluginClassloader
            cl =
            new IsolatedPluginClassloader(new URL[]{jarFile.toURI().toURL()}, this.getClass().getClassLoader());

    final Class<?> interceptorClass =
            cl.loadClass("com.hivemq.extensions.handler.SubackOutboundInterceptorHandlerTest$" + name);

    return (SubackOutboundInterceptor) interceptorClass.newInstance();
}
 
Example #12
Source File: JPATest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Test
public void testFractionMatching() throws Exception {
    JARArchive archive = ShrinkWrap.create(JARArchive.class);
    archive.addAsResource("META-INF/persistence.xml");
    FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer();

    File out = Files.createTempFile(archive.getName(), ".war").toFile();
    archive.as(ZipExporter.class).exportTo(out, true);

    analyzer.source(out);
    assertThat(analyzer.detectNeededFractions()
                   .stream()
                   .filter(fd -> fd.getArtifactId().equals("jpa"))
                   .count()).isEqualTo(1);

    out.delete();
}
 
Example #13
Source File: PubackInterceptorHandlerTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
@NotNull
private PubackInboundInterceptor getInboundInterceptor(@NotNull final String name) throws Exception {

    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class)
            .addClass("com.hivemq.extensions.handler.PubackInterceptorHandlerTest$" + name);

    final File jarFile = temporaryFolder.newFile();
    javaArchive.as(ZipExporter.class).exportTo(jarFile, true);

    //This classloader contains the classes from the jar file
    final IsolatedPluginClassloader
            cl =
            new IsolatedPluginClassloader(new URL[]{jarFile.toURI().toURL()}, this.getClass().getClassLoader());

    final Class<?> interceptorClass =
            cl.loadClass("com.hivemq.extensions.handler.PubackInterceptorHandlerTest$" + name);

    return (PubackInboundInterceptor) interceptorClass.newInstance();
}
 
Example #14
Source File: CDITest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Test
public void testFractionMatching() throws Exception {
    JARArchive archive = ShrinkWrap.create(JARArchive.class);
    archive.addAsResource(EmptyAsset.INSTANCE,"WEB-INF/beans.xml");
    FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer();

    final File out = Files.createTempFile(archive.getName(), ".war").toFile();
    out.deleteOnExit();
    archive.as(ZipExporter.class).exportTo(out, true);
    analyzer.source(out);

    assertThat(analyzer.detectNeededFractions()
                   .stream()
                   .filter(fd -> fd.getArtifactId().equals("cdi"))
                   .count()).isEqualTo(1);
}
 
Example #15
Source File: PingInterceptorHandlerTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
private @NotNull PingRespOutboundInterceptor getIsolatedOutboundInterceptor(final @NotNull String name)
        throws Exception {
    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class)
            .addClass("com.hivemq.extensions.handler.PingInterceptorHandlerTest$" + name);

    final File jarFile = temporaryFolder.newFile();
    javaArchive.as(ZipExporter.class).exportTo(jarFile, true);

    final IsolatedPluginClassloader
            cl =
            new IsolatedPluginClassloader(new URL[]{jarFile.toURI().toURL()}, this.getClass().getClassLoader());

    final Class<?> interceptorClass =
            cl.loadClass("com.hivemq.extensions.handler.PingInterceptorHandlerTest$" + name);

    final PingRespOutboundInterceptor interceptor =
            (PingRespOutboundInterceptor) interceptorClass.newInstance();

    return interceptor;
}
 
Example #16
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 #17
Source File: SwarmContentRepository.java    From thorntail with Apache License 2.0 6 votes vote down vote up
public byte[] addContent(Archive<?> archive) throws IOException, URISyntaxException {
    try {
        MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
        byte[] sha1Bytes;
        messageDigest.reset();
        BufferedInputStream bis = new BufferedInputStream(archive.as(ZipExporter.class).exportAsInputStream());
        byte[] bytes = new byte[8192];
        int read;
        while ((read = bis.read(bytes)) > -1) {
            messageDigest.update(bytes, 0, read);
        }
        sha1Bytes = messageDigest.digest();
        String key = toKey(sha1Bytes);
        this.fs.addArchive(archive.getName(), archive);
        this.index.put(key, this.fsMount.getChild(archive.getName()).toURI());
        return sha1Bytes;
    } catch (NoSuchAlgorithmException e) {
        throw new IOException(e);
    }
}
 
Example #18
Source File: PubcompInterceptorHandlerTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
@NotNull
private PubcompOutboundInterceptor getOutboundInterceptor(@NotNull final String name) throws Exception {

    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class)
            .addClass("com.hivemq.extensions.handler.PubcompInterceptorHandlerTest$" + name);

    final File jarFile = temporaryFolder.newFile();
    javaArchive.as(ZipExporter.class).exportTo(jarFile, true);

    //This classloader contains the classes from the jar file
    final IsolatedPluginClassloader
            cl =
            new IsolatedPluginClassloader(new URL[]{jarFile.toURI().toURL()}, this.getClass().getClassLoader());

    final Class<?> interceptorClass =
            cl.loadClass("com.hivemq.extensions.handler.PubcompInterceptorHandlerTest$" + name);

    return (PubcompOutboundInterceptor) interceptorClass.newInstance();
}
 
Example #19
Source File: PubcompInterceptorHandlerTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
@NotNull
private PubcompInboundInterceptor getInboundInterceptor(@NotNull final String name) throws Exception {

    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class)
            .addClass("com.hivemq.extensions.handler.PubcompInterceptorHandlerTest$" + name);

    final File jarFile = temporaryFolder.newFile();
    javaArchive.as(ZipExporter.class).exportTo(jarFile, true);

    //This classloader contains the classes from the jar file
    final IsolatedPluginClassloader
            cl =
            new IsolatedPluginClassloader(new URL[]{jarFile.toURI().toURL()}, this.getClass().getClassLoader());

    final Class<?> interceptorClass =
            cl.loadClass("com.hivemq.extensions.handler.PubcompInterceptorHandlerTest$" + name);

    return (PubcompInboundInterceptor) interceptorClass.newInstance();
}
 
Example #20
Source File: PingInterceptorHandlerTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
private @NotNull PingReqInboundInterceptor getIsolatedInboundInterceptor(final @NotNull String name) throws Exception {
    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class)
            .addClass("com.hivemq.extensions.handler.PingInterceptorHandlerTest$" + name);

    final File jarFile = temporaryFolder.newFile();
    javaArchive.as(ZipExporter.class).exportTo(jarFile, true);

    final IsolatedPluginClassloader
            cl =
            new IsolatedPluginClassloader(new URL[]{jarFile.toURI().toURL()}, this.getClass().getClassLoader());

    final Class<?> interceptorClass =
            cl.loadClass("com.hivemq.extensions.handler.PingInterceptorHandlerTest$" + name);

    final PingReqInboundInterceptor interceptor =
            (PingReqInboundInterceptor) interceptorClass.newInstance();

    return interceptor;
}
 
Example #21
Source File: PluginAuthorizerServiceImplTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
private AuthorizerProvider getTestAuthorizerProvider(final String name, final CountDownLatch countDownLatch)
        throws Exception {

    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class)
            .addClass("com.hivemq.extensions.handler.testextensions." + name)
            .addClass("com.hivemq.extensions.handler.testextensions." + name + "$1");

    final File jarFile = temporaryFolder.newFile();
    javaArchive.as(ZipExporter.class).exportTo(jarFile, true);

    //This classloader contains the classes from the jar file
    final IsolatedPluginClassloader cl =
            new IsolatedPluginClassloader(new URL[]{jarFile.toURI().toURL()}, this.getClass().getClassLoader());

    final Class<?> providerClass = cl.loadClass("com.hivemq.extensions.handler.testextensions." + name);

    final AuthorizerProvider testProvider =
            (AuthorizerProvider) providerClass.getDeclaredConstructor(CountDownLatch.class)
                    .newInstance(countDownLatch);
    return testProvider;
}
 
Example #22
Source File: PubrelInterceptorHandlerTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
@NotNull
private PubrelOutboundInterceptor getOutboundInterceptor(@NotNull final String name) throws Exception {

    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class)
            .addClass("com.hivemq.extensions.handler.PubrelInterceptorHandlerTest$" + name);

    final File jarFile = temporaryFolder.newFile();
    javaArchive.as(ZipExporter.class).exportTo(jarFile, true);

    //This classloader contains the classes from the jar file
    final IsolatedPluginClassloader
            cl =
            new IsolatedPluginClassloader(new URL[]{jarFile.toURI().toURL()}, this.getClass().getClassLoader());

    final Class<?> interceptorClass =
            cl.loadClass("com.hivemq.extensions.handler.PubrelInterceptorHandlerTest$" + name);

    return (PubrelOutboundInterceptor) interceptorClass.newInstance();
}
 
Example #23
Source File: PubrelInterceptorHandlerTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
@NotNull
private PubrelInboundInterceptor getInboundInterceptor(@NotNull final String name) throws Exception {

    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class)
            .addClass("com.hivemq.extensions.handler.PubrelInterceptorHandlerTest$" + name);

    final File jarFile = temporaryFolder.newFile();
    javaArchive.as(ZipExporter.class).exportTo(jarFile, true);

    //This classloader contains the classes from the jar file
    final IsolatedPluginClassloader
            cl =
            new IsolatedPluginClassloader(new URL[]{jarFile.toURI().toURL()}, this.getClass().getClassLoader());

    final Class<?> interceptorClass =
            cl.loadClass("com.hivemq.extensions.handler.PubrelInterceptorHandlerTest$" + name);

    return (PubrelInboundInterceptor) interceptorClass.newInstance();
}
 
Example #24
Source File: PubrecInterceptorHandlerTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
@NotNull
private PubrecOutboundInterceptor getOutboundInterceptor(@NotNull final String name) throws Exception {

    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class)
            .addClass("com.hivemq.extensions.handler.PubrecInterceptorHandlerTest$" + name);

    final File jarFile = temporaryFolder.newFile();
    javaArchive.as(ZipExporter.class).exportTo(jarFile, true);

    //This classloader contains the classes from the jar file
    final IsolatedPluginClassloader
            cl =
            new IsolatedPluginClassloader(new URL[]{jarFile.toURI().toURL()}, this.getClass().getClassLoader());

    final Class<?> interceptorClass =
            cl.loadClass("com.hivemq.extensions.handler.PubrecInterceptorHandlerTest$" + name);

    return (PubrecOutboundInterceptor) interceptorClass.newInstance();
}
 
Example #25
Source File: PubrecInterceptorHandlerTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
@NotNull
private PubrecInboundInterceptor getInboundInterceptor(@NotNull final String name) throws Exception {

    final JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class)
            .addClass("com.hivemq.extensions.handler.PubrecInterceptorHandlerTest$" + name);

    final File jarFile = temporaryFolder.newFile();
    javaArchive.as(ZipExporter.class).exportTo(jarFile, true);

    //This classloader contains the classes from the jar file
    final IsolatedPluginClassloader
            cl =
            new IsolatedPluginClassloader(new URL[]{jarFile.toURI().toURL()}, this.getClass().getClassLoader());

    final Class<?> interceptorClass =
            cl.loadClass("com.hivemq.extensions.handler.PubrecInterceptorHandlerTest$" + name);

    return (PubrecInboundInterceptor) interceptorClass.newInstance();
}
 
Example #26
Source File: MessagingTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Test
public void testFractionMatching() throws Exception {
    JARArchive archive = ShrinkWrap.create(JARArchive.class);
    archive.addClass(MyTopicMDB.class);
    FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer();

    final File out = Files.createTempFile(archive.getName(), ".war").toFile();
    out.deleteOnExit();
    archive.as(ZipExporter.class).exportTo(out, true);

    analyzer.source(out);
    assertThat(analyzer.detectNeededFractions()
                       .stream()
                       .filter(fd -> fd.getArtifactId().equals("messaging"))
                       .count()).isEqualTo(1);
}
 
Example #27
Source File: TestDeploymentPackager.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
public Archive<?> generateDeployment(TestDeployment testDeployment, Collection<ProtocolArchiveProcessor> collection) {
    Archive<?> applicationArchive = testDeployment.getApplicationArchive();
    boolean isClassPath = ClassPath.isRepresentedBy(applicationArchive);
    for (Archive<?> auxiliaryArchive : testDeployment.getAuxiliaryArchives()) {
        if (isClassPath) {
            applicationArchive.add(auxiliaryArchive, ClassPath.ROOT_ARCHIVE_PATH, ZipExporter.class);
        } else {
            applicationArchive.merge(auxiliaryArchive);
        }
    }
    return applicationArchive;
}
 
Example #28
Source File: EurostagImpactAnalysis.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
private void writeWp43Configs(Domain domain, List<Contingency> contingencies, OutputStream os) throws IOException, ConfigurationException {
    // copy wp43 configuration files
    GenericArchive archive = domain.getArchiveFactory().create(GenericArchive.class);
    try (FileSystem fileSystem = ShrinkWrapFileSystems.newFileSystem(archive)) {
        Path rootDir = fileSystem.getPath("/");
        writeWp43Configs(contingencies, rootDir);
    }
    archive.as(ZipExporter.class).exportTo(os);
}
 
Example #29
Source File: BuildTool.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private void detectFractions() throws Exception {
    final File tmpFile = File.createTempFile("buildtool", this.projectAsset.getName().replace("/", "_"));
    tmpFile.deleteOnExit();
    this.projectAsset.getArchive().as(ZipExporter.class).exportTo(tmpFile, true);
    final FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer()
            .logger(log)
            .source(tmpFile);

    if (testClass != null && !"".equals(testClass)) {
        analyzer.testClass(testClass);
    }

    final Collection<FractionDescriptor> detectedFractions = analyzer.detectNeededFractions();

    //don't overwrite fractions added by the user
    detectedFractions.removeAll(this.fractions.stream()
            .map(ArtifactSpec::toFractionDescriptor)
            .collect(Collectors.toSet()));

    // Remove explicitly excluded fractions
    detectedFractions.removeAll(this.excludedFractions.stream().map(ArtifactSpec::toFractionDescriptor).collect(Collectors.toSet()));

    this.log.info(String.format("Detected %sfractions: %s",
            this.fractions.isEmpty() ? "" : "additional ",
            detectedFractions.stream()
                    .map(FractionDescriptor::av)
                    .sorted()
                    .collect(Collectors.joining(", "))));
    detectedFractions.stream()
            .map(ArtifactSpec::fromFractionDescriptor)
            .forEach(this::fraction);
}
 
Example #30
Source File: ShrinkWrapFileSystem.java    From thorntail with Apache License 2.0 5 votes vote down vote up
File getFile(Entry entry) {
    if (entry.file == null) {
        try {
            entry.file = this.tempDir.createFile(entry.archive.getName(), entry.archive.as(ZipExporter.class).exportAsInputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return entry.file;
}