Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Filter out pom only artifacts from dependnecies in checkUnusedDependencies #773

Merged
merged 2 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-773.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: fix
fix:
description: Remove pom only dependencies from analysis in checkUnusedDependencies
links:
- https://github.com/palantir/gradle-baseline/pull/773
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.palantir.baseline.plugins;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import com.palantir.baseline.tasks.CheckImplicitDependenciesTask;
import com.palantir.baseline.tasks.CheckUnusedDependenciesTask;
import java.io.File;
Expand Down Expand Up @@ -50,6 +51,7 @@ public final class BaselineExactDependencies implements Plugin<Project> {
// All applications of this plugin share a single static 'Indexes' instance, because the classes
// contained in a particular jar are immutable.
public static final Indexes INDEXES = new Indexes();
public static final ImmutableSet<String> VALID_ARTIFACT_EXTENSIONS = ImmutableSet.of("jar", "");

@Override
public void apply(Project project) {
Expand Down Expand Up @@ -98,6 +100,7 @@ public static final class Indexes {
public void populateIndexes(Set<ResolvedDependency> declaredDependencies) {
Set<ResolvedArtifact> allArtifacts = declaredDependencies.stream()
.flatMap(dependency -> dependency.getAllModuleArtifacts().stream())
.filter(dependency -> VALID_ARTIFACT_EXTENSIONS.contains(dependency.getExtension()))
.collect(Collectors.toSet());

allArtifacts.forEach(artifact -> {
Expand All @@ -111,10 +114,8 @@ public void populateIndexes(Set<ResolvedDependency> declaredDependencies) {
}
});

declaredDependencies.stream().forEach(dependency -> {
Set<ResolvedArtifact> artifacts = dependency.getModuleArtifacts();
artifacts.forEach(artifact -> artifactsFromDependency.put(artifact, dependency));
});
declaredDependencies.forEach(dependency -> dependency.getModuleArtifacts()
.forEach(artifact -> artifactsFromDependency.put(artifact, dependency)));
}

/** Given a class, what dependency brought it in. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public final void checkUnusedDependencies() {
.collect(Collectors.toSet());
Set<ResolvedArtifact> declaredArtifacts = declaredDependencies.stream()
.flatMap(dependency -> dependency.getModuleArtifacts().stream())
.filter(dependency -> BaselineExactDependencies.VALID_ARTIFACT_EXTENSIONS
.contains(dependency.getExtension()))
.collect(Collectors.toSet());

List<ResolvedArtifact> declaredButUnused = Sets.difference(declaredArtifacts, necessaryArtifacts).stream()
Expand All @@ -93,6 +95,8 @@ public final void checkUnusedDependencies() {
ResolvedDependency dependency = BaselineExactDependencies.INDEXES
.artifactsFromDependency(resolvedArtifact);
Set<ResolvedArtifact> didYouMean = dependency.getAllModuleArtifacts().stream()
.filter(artifact -> BaselineExactDependencies.VALID_ARTIFACT_EXTENSIONS
.contains(artifact.getExtension()))
.flatMap(BaselineExactDependencies.INDEXES::classesFromArtifact)
.filter(referencedClasses()::contains)
.map(BaselineExactDependencies.INDEXES::classToDependency)
Expand Down