use of org.wildfly.swarm.fractions.FractionDescriptor 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);
}
use of org.wildfly.swarm.fractions.FractionDescriptor 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);
}
}
Aggregations