private List getClassPathEntries()

in plugins/gradle/gradle-plugin/src/main/java/org/wildfly/swarm/plugin/gradle/StartTask.java [216:303]


    private List<Path> getClassPathEntries(List<Path> sourcePaths, boolean scanDependencies) {
        Collection<ArtifactSpec> allDependencies = GradleToolingHelper
                .toDeclaredDependencies(extension.getDependencies()).getRuntimeExplicitAndTransientDependencies();
        getLogger().info("Original dependencies including transitive:\n  {}",
                allDependencies.stream().map(ArtifactSpec::toString).collect(Collectors.joining(INDENTATION_DELIMITER)));

        final List<Path> classpathEntries = allDependencies.stream()
                .map(artifactSpec -> artifactSpec.file.toPath())
                .collect(Collectors.toList());

        final boolean hasThorntailDeps = allDependencies.stream()
                .anyMatch(a -> FractionDescriptor.THORNTAIL_GROUP_ID.equals(a.groupId())
                        && DependencyManager.WILDFLY_SWARM_BOOTSTRAP_ARTIFACT_ID.equals(a.artifactId()));
        getLogger().info("Thorntail dependencies detected: {}", hasThorntailDeps);

        // automatic fraction detection
        if (extension.getFractionDetectionMode() != BuildTool.FractionDetectionMode.never
                && (extension.getFractionDetectionMode() == BuildTool.FractionDetectionMode.force
                || !hasThorntailDeps)) {
            getLogger().info("Detecting fractions.");

            final FractionUsageAnalyzer analyzer = new FractionUsageAnalyzer(FractionList.get());
            // always scan application source files
            sourcePaths.forEach(analyzer::source);
            // scan dependencies if indicated
            if (scanDependencies) {
                classpathEntries.forEach(analyzer::source);
            }

            final Set<FractionDescriptor> detectedFractions;
            try {
                detectedFractions = analyzer.detectNeededFractions()
                        .stream()
                        // filter out fractions already on classpath
                        .filter(fd -> !allDependencies.contains(ArtifactSpec.fromFractionDescriptor(fd)))
                        .collect(Collectors.toSet());
                getLogger().info("Detected fractions:\n  {}",
                        detectedFractions.stream().map(FractionDescriptor::gav)
                                .collect(Collectors.joining(INDENTATION_DELIMITER)));
            } catch (IOException e) {
                throw new GradleException("Failed to scan for fractions.", e);
            }

            // exclude or add further fractions according to user config
            extension.getFractions().forEach(f -> {
                if (f.startsWith(EXCLUDE_PREFIX)) {
                    FractionDescriptor toRemove = FractionDescriptor.fromGav(FractionList.get(), f.substring(1));
                    getLogger().info("Excluding from detected fractions: {}", toRemove);
                    detectedFractions.remove(toRemove);
                } else {
                    FractionDescriptor toAdd = FractionDescriptor.fromGav(FractionList.get(), f);
                    getLogger().info("Adding to detected fractions: {}", toAdd);
                    detectedFractions.add(toAdd);
                }
            });

            // combine detected fractions with their dependent fractions
            final Set<FractionDescriptor> fractionsWithDependencies = new HashSet<>(detectedFractions);
            fractionsWithDependencies.addAll(detectedFractions.stream()
                    .flatMap(f -> f.getDependencies().stream())
                    .collect(Collectors.toSet()));

            getLogger().info("Detected fractions including dependencies:\n  {}",
                    fractionsWithDependencies.stream()
                            .map(FractionDescriptor::gav)
                            .sorted()
                            .collect(Collectors.joining(INDENTATION_DELIMITER)));

            final Set<ArtifactSpec> fractionsSpecs = fractionsWithDependencies.stream()
                    .map(ArtifactSpec::fromFractionDescriptor)
                    .collect(Collectors.toSet());

            // resolve fraction artifacts and include into classpath entries
            try {
                List<Path> resolvedPaths = artifactResolvingHelper().resolveAll(fractionsSpecs).stream()
                        .map(s -> s.file.toPath())
                        .collect(Collectors.toList());
                classpathEntries.addAll(resolvedPaths);
            } catch (Exception e) {
                throw new GradleException("Failed to resolve fraction dependencies.", e);
            }
        }

        getLogger().info("Computed classpath entries:\n  {}",
                classpathEntries.stream().map(Path::toString).collect(Collectors.joining(INDENTATION_DELIMITER)));

        return classpathEntries;
    }