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

detect if dependency is actually the current project. #736

Merged
merged 4 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-736.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
fix:
description: "The `checkImplicitDependencies` task will no longer suggest a fix of the current project."
links:
- https://github.com/palantir/gradle-baseline/pull/736
- https://github.com/palantir/gradle-baseline/issues/567
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public final void checkImplicitDependencies() {
.map(BaselineExactDependencies.INDEXES::classToDependency)
.filter(Optional::isPresent)
.map(Optional::get)
.filter(x -> !isArtifactFromCurrentProject(x))
.collect(Collectors.toSet());
Set<ResolvedArtifact> declaredArtifacts = declaredDependencies.stream()
.flatMap(dependency -> dependency.getModuleArtifacts().stream())
Expand Down Expand Up @@ -112,6 +113,19 @@ private boolean isProjectArtifact(ResolvedArtifact artifact) {
return artifact.getId().getComponentIdentifier() instanceof ProjectComponentIdentifier;
}

/**
* Return true if the resolved artifact is derived from a project in the current build rather than an
* external jar.
*/
private boolean isArtifactFromCurrentProject(ResolvedArtifact artifact) {
if (!isProjectArtifact(artifact)) {
return false;
}
return ((ProjectComponentIdentifier) artifact.getId().getComponentIdentifier()).getProjectPath()
.equals(getProject().getPath());
}


/** All classes which are mentioned in this project's source code. */
private Set<String> referencedClasses() {
return Streams.stream(sourceClasses.get().iterator())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@

package com.palantir.baseline

import java.nio.file.Files
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome

import java.nio.file.Files

class BaselineExactDependenciesTest extends AbstractPluginTest {

def standardBuildFile = '''
Expand Down Expand Up @@ -125,6 +124,15 @@ class BaselineExactDependenciesTest extends AbstractPluginTest {
result.output.contains("implementation project(':sub-project-no-deps')")
}

def 'checkImplicitDependencies should not report circular dependency on current project'() {
when:
setupMultiProject()

then:
BuildResult result = with(':sub-project-with-deps:checkImplicitDependencies', ':sub-project-no-deps:checkImplicitDependencies', '--stacktrace').withDebug(true).build()
result.task(':sub-project-no-deps:checkImplicitDependencies').getOutcome() == TaskOutcome.SUCCESS
}

/**
* Sets up a multi-module project with 2 sub projects. The root project has a transitive dependency on sub-project-no-deps
* and so checkImplicitDependencies should fail on it.
Expand Down