private void analyzeRemovableDependencies()

in tools/src/main/java/org/wildfly/swarm/tools/DependencyManager.java [273:329]


    private void analyzeRemovableDependencies(DeclaredDependencies declaredDependencies) throws Exception {

        Collection<ArtifactSpec> bootstrapDeps = this.dependencies.stream()
                .filter(e -> isFractionJar(e.file))
                .collect(Collectors.toSet());
        if (removeAllThorntailLibs) {
            String whitelistProperty = System.getProperty("thorntail.runner.user-dependencies");
            Set<String> whitelist = new HashSet<>();
            if (whitelistProperty != null) {
                whitelist.addAll(asList(whitelistProperty.split(",")));
            }
            Set<String> uniqueMavenDependencies = new HashSet<>();
            this.dependencies.stream()
                    .map(e -> e.file)
                    .flatMap(e -> mavenDependencies(e).stream())
                    .forEach(uniqueMavenDependencies::add);
            this.fractionManifests.stream()
                    .flatMap(manifest -> manifest.getMavenDependencies().stream())
                    .forEach(uniqueMavenDependencies::add);

            uniqueMavenDependencies
                    .stream()
                    .map(ArtifactSpec::fromMavenDependencyDescription)
                    .forEach(this.removableDependencies::add);

            removableDependencies.addAll(bootstrapDeps);

            removableDependencies.removeIf(dep -> whitelist.contains(dep.mscGav()));
        } else {
            List<ArtifactSpec> nonBootstrapDeps = new ArrayList<>();
            nonBootstrapDeps.addAll(declaredDependencies.getDirectDependencies());
            nonBootstrapDeps.removeAll(bootstrapDeps);
            Collection<ArtifactSpec> nonBootstrapTransitive;
            // re-resolve the application's dependencies minus any of our swarm dependencies
            if (declaredDependencies.isPresolved()) {
                // Add the dependencies without querying for anything else.
                nonBootstrapTransitive = new HashSet<>();
                nonBootstrapDeps.stream()
                        .filter(s -> !FractionDescriptor.THORNTAIL_GROUP_ID.equals(s.groupId()))
                        .forEach(s -> {
                            nonBootstrapTransitive.add(s);
                            nonBootstrapTransitive.addAll(declaredDependencies.getTransientDependencies(s));
                        });
            } else {
                nonBootstrapTransitive = resolver.resolveAllArtifactsTransitively(nonBootstrapDeps, true);
            }

            // do not remove .war or .rar or anything else weird-o like.
            Set<ArtifactSpec> justJars = this.dependencies
                    .stream()
                    .filter(e -> e.type().equals(JAR))
                    .collect(Collectors.toSet());

            this.removableDependencies.addAll(justJars);
            this.removableDependencies.removeAll(nonBootstrapTransitive);
        }
    }