Search in sources :

Example 6 with FractionUsageAnalyzer

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

the class MessagingTest method testFractionMatching.

@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);
}
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 7 with FractionUsageAnalyzer

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

the class StartMojo method findNeededFractions.

List<Path> findNeededFractions(final Set<Artifact> existingDeps, final Path source, final boolean scanDeps) throws MojoFailureException {
    getLog().info("Scanning for needed WildFly Swarm fractions with mode: " + fractionDetectMode);
    final Set<String> existingDepGASet = existingDeps.stream().map(d -> String.format("%s:%s", d.getGroupId(), d.getArtifactId())).collect(Collectors.toSet());
    final Set<FractionDescriptor> fractions;
    final FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer(FractionList.get()).source(source);
    if (scanDeps) {
        existingDeps.forEach(d -> analyzer.source(d.getFile()));
    }
    final Predicate<FractionDescriptor> notExistingDep = d -> !existingDepGASet.contains(String.format("%s:%s", d.getGroupId(), d.getArtifactId()));
    try {
        fractions = analyzer.detectNeededFractions().stream().filter(notExistingDep).collect(Collectors.toSet());
    } catch (IOException e) {
        throw new MojoFailureException("failed to scan for fractions", e);
    }
    getLog().info("Detected fractions: " + String.join(", ", fractions.stream().map(FractionDescriptor::av).sorted().collect(Collectors.toList())));
    fractions.addAll(this.additionalFractions.stream().map(f -> FractionDescriptor.fromGav(FractionList.get(), f)).collect(Collectors.toSet()));
    final Set<FractionDescriptor> allFractions = new HashSet<>(fractions);
    allFractions.addAll(fractions.stream().flatMap(f -> f.getDependencies().stream()).filter(notExistingDep).collect(Collectors.toSet()));
    getLog().info("Using fractions: " + String.join(", ", allFractions.stream().map(FractionDescriptor::gavOrAv).sorted().collect(Collectors.toList())));
    final Set<ArtifactSpec> specs = new HashSet<>();
    specs.addAll(existingDeps.stream().map(this::artifactToArtifactSpec).collect(Collectors.toList()));
    specs.addAll(allFractions.stream().map(ArtifactSpec::fromFractionDescriptor).collect(Collectors.toList()));
    try {
        return mavenArtifactResolvingHelper().resolveAll(specs).stream().map(s -> s.file.toPath()).collect(Collectors.toList());
    } catch (Exception e) {
        throw new MojoFailureException("failed to resolve fraction dependencies", e);
    }
}
Also used : DependencyManager(org.wildfly.swarm.tools.DependencyManager) FractionUsageAnalyzer(org.wildfly.swarm.fractions.FractionUsageAnalyzer) Parameter(org.apache.maven.plugins.annotations.Parameter) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Mojo(org.apache.maven.plugins.annotations.Mojo) StringTokenizer(java.util.StringTokenizer) Artifact(org.apache.maven.artifact.Artifact) ResolutionScope(org.apache.maven.plugins.annotations.ResolutionScope) Path(java.nio.file.Path) SwarmProcess(org.wildfly.swarm.tools.exec.SwarmProcess) Files(java.nio.file.Files) BootstrapProperties(org.wildfly.swarm.bootstrap.util.BootstrapProperties) Predicate(java.util.function.Predicate) DeclaredDependencies(org.wildfly.swarm.tools.DeclaredDependencies) SwarmExecutor(org.wildfly.swarm.tools.exec.SwarmExecutor) Set(java.util.Set) FractionDescriptor(org.wildfly.swarm.fractions.FractionDescriptor) IOException(java.io.IOException) BuildTool(org.wildfly.swarm.tools.BuildTool) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Collectors(java.util.stream.Collectors) File(java.io.File) FractionList(org.wildfly.swarm.fractions.FractionList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) TimeUnit(java.util.concurrent.TimeUnit) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) List(java.util.List) Paths(java.nio.file.Paths) TempFileManager(org.wildfly.swarm.bootstrap.util.TempFileManager) SwarmProperties(org.wildfly.swarm.spi.api.SwarmProperties) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) FractionUsageAnalyzer(org.wildfly.swarm.fractions.FractionUsageAnalyzer) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) FractionDescriptor(org.wildfly.swarm.fractions.FractionDescriptor) HashSet(java.util.HashSet)

Example 8 with FractionUsageAnalyzer

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

the class CDITest method testFractionMatching.

@Test
public void testFractionMatching() throws Exception {
    JARArchive archive = ShrinkWrap.create(JARArchive.class);
    archive.addAsResource("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);
}
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 9 with FractionUsageAnalyzer

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

the class CDITest method testFractionMatchingWEBINFClasses.

@Test
public void testFractionMatchingWEBINFClasses() throws Exception {
    JARArchive archive = ShrinkWrap.create(JARArchive.class);
    archive.addAsResource("WEB-INF/classes/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 10 with FractionUsageAnalyzer

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

the class JPATest method testFractionMatchingExploded.

@Test
public void testFractionMatchingExploded() throws Exception {
    JARArchive archive = ShrinkWrap.create(JARArchive.class);
    archive.addAsResource("META-INF/persistence.xml");
    FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer();
    File dirFile = TempFileManager.INSTANCE.newTempDirectory("jpatest", null);
    archive.as(ExplodedExporter.class).exportExplodedInto(dirFile);
    analyzer.source(dirFile);
    assertThat(analyzer.detectNeededFractions().stream().filter(fd -> fd.getArtifactId().equals("jpa")).count()).isEqualTo(1);
    TempFileManager.deleteRecursively(dirFile);
}
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) JARArchive(org.wildfly.swarm.spi.api.JARArchive) ExplodedExporter(org.jboss.shrinkwrap.api.exporter.ExplodedExporter) File(java.io.File) Test(org.junit.Test)

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