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);
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations