Search in sources :

Example 1 with FractionUsageAnalyzer

use of org.wildfly.swarm.fractions.FractionUsageAnalyzer in project wildfly-swarm by wildfly-swarm.

the class CDITest method testFractionMatchingMETAINF.

@Test
public void testFractionMatchingMETAINF() throws Exception {
    JARArchive archive = ShrinkWrap.create(JARArchive.class);
    archive.addAsResource("META-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);
}
Also used : ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) FractionUsageAnalyzer(org.wildfly.swarm.fractions.FractionUsageAnalyzer) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) Files(java.nio.file.Files) JARArchive(org.wildfly.swarm.spi.api.JARArchive) Test(org.junit.Test) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) File(java.io.File) FractionUsageAnalyzer(org.wildfly.swarm.fractions.FractionUsageAnalyzer) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) JARArchive(org.wildfly.swarm.spi.api.JARArchive) File(java.io.File) Test(org.junit.Test)

Example 2 with FractionUsageAnalyzer

use of org.wildfly.swarm.fractions.FractionUsageAnalyzer in project wildfly-swarm by wildfly-swarm.

the class SecurityTest method testFractionMatchingAnnotation.

@Test
public void testFractionMatchingAnnotation() throws Exception {
    JARArchive archive = ShrinkWrap.create(JARArchive.class);
    archive.addClass(SecurityEndpoint.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("security")).count()).isEqualTo(1);
}
Also used : ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) FractionUsageAnalyzer(org.wildfly.swarm.fractions.FractionUsageAnalyzer) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) Files(java.nio.file.Files) JARArchive(org.wildfly.swarm.spi.api.JARArchive) Test(org.junit.Test) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) File(java.io.File) FractionUsageAnalyzer(org.wildfly.swarm.fractions.FractionUsageAnalyzer) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) JARArchive(org.wildfly.swarm.spi.api.JARArchive) File(java.io.File) Test(org.junit.Test)

Example 3 with FractionUsageAnalyzer

use of org.wildfly.swarm.fractions.FractionUsageAnalyzer in project wildfly-swarm by wildfly-swarm.

the class SecurityTest method testFractionMatchingWebXML.

@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);
}
Also used : ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) FractionUsageAnalyzer(org.wildfly.swarm.fractions.FractionUsageAnalyzer) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) Files(java.nio.file.Files) JARArchive(org.wildfly.swarm.spi.api.JARArchive) Test(org.junit.Test) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) File(java.io.File) FractionUsageAnalyzer(org.wildfly.swarm.fractions.FractionUsageAnalyzer) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) JARArchive(org.wildfly.swarm.spi.api.JARArchive) File(java.io.File) Test(org.junit.Test)

Example 4 with FractionUsageAnalyzer

use of org.wildfly.swarm.fractions.FractionUsageAnalyzer in project wildfly-swarm by wildfly-swarm.

the class JPATest method testFractionMatching.

@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();
}
Also used : ExplodedExporter(org.jboss.shrinkwrap.api.exporter.ExplodedExporter) ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) FractionUsageAnalyzer(org.wildfly.swarm.fractions.FractionUsageAnalyzer) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) Files(java.nio.file.Files) TempFileManager(org.wildfly.swarm.bootstrap.util.TempFileManager) JARArchive(org.wildfly.swarm.spi.api.JARArchive) Test(org.junit.Test) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) File(java.io.File) FractionUsageAnalyzer(org.wildfly.swarm.fractions.FractionUsageAnalyzer) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) JARArchive(org.wildfly.swarm.spi.api.JARArchive) File(java.io.File) Test(org.junit.Test)

Example 5 with FractionUsageAnalyzer

use of org.wildfly.swarm.fractions.FractionUsageAnalyzer in project wildfly-swarm by wildfly-swarm.

the class BuildTool method detectFractions.

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()));
    this.log.info(String.format("Detected %sfractions: %s", this.fractions.isEmpty() ? "" : "additional ", String.join(", ", detectedFractions.stream().map(FractionDescriptor::av).sorted().collect(Collectors.toList()))));
    detectedFractions.stream().map(ArtifactSpec::fromFractionDescriptor).forEach(this::fraction);
}
Also used : FractionUsageAnalyzer(org.wildfly.swarm.fractions.FractionUsageAnalyzer) ZipExporter(org.jboss.shrinkwrap.api.exporter.ZipExporter) FractionDescriptor(org.wildfly.swarm.fractions.FractionDescriptor) JarFile(java.util.jar.JarFile) ZipFile(net.lingala.zip4j.core.ZipFile) File(java.io.File)

Aggregations

File (java.io.File)12 FractionUsageAnalyzer (org.wildfly.swarm.fractions.FractionUsageAnalyzer)12 Files (java.nio.file.Files)11 ZipExporter (org.jboss.shrinkwrap.api.exporter.ZipExporter)11 Assertions.assertThat (org.fest.assertions.Assertions.assertThat)10 ShrinkWrap (org.jboss.shrinkwrap.api.ShrinkWrap)10 Test (org.junit.Test)10 JARArchive (org.wildfly.swarm.spi.api.JARArchive)10 IOException (java.io.IOException)3 TempFileManager (org.wildfly.swarm.bootstrap.util.TempFileManager)3 Request (org.apache.http.client.fluent.Request)2 ExplodedExporter (org.jboss.shrinkwrap.api.exporter.ExplodedExporter)2 FractionDescriptor (org.wildfly.swarm.fractions.FractionDescriptor)2 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 StringTokenizer (java.util.StringTokenizer)1