List findNeededFractions()

in plugins/maven/src/main/java/org/wildfly/swarm/plugin/maven/StartMojo.java [239:305]


    List<Path> findNeededFractions(final List<Artifact> existingDeps,
                                   final Path source,
                                   final boolean scanDeps) throws MojoFailureException {
        getLog().info("Scanning for needed Thorntail 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> detectedFractions;
        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 {
            detectedFractions = 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(", ", detectedFractions.stream()
                .map(FractionDescriptor::av)
                .sorted()
                .collect(Collectors.toList())));

        this.fractions.forEach(f -> {
            if (f.startsWith(EXCLUDE_PREFIX)) {
                FractionDescriptor descriptor = FractionDescriptor.fromGav(FractionList.get(), f.substring(1));
                getLog().info("Excluding detected fraction:" + descriptor);
                detectedFractions.remove(descriptor);
            } else {
                detectedFractions.add(FractionDescriptor.fromGav(FractionList.get(), f));
            }
        });

        final Set<FractionDescriptor> allFractions = new HashSet<>(detectedFractions);
        allFractions.addAll(detectedFractions.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);
        }
    }