Skip to content

Commit

Permalink
Polish dependency insight report error handling
Browse files Browse the repository at this point in the history
- Make it resilient to unknown error types
- Add test coverage for rejected dependencies
- Make dependency locking integration tests use the actual output
  • Loading branch information
melix committed May 30, 2018
1 parent e5aa852 commit 3559bc6
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.gradle.integtests.resolve.locking

import org.gradle.integtests.fixtures.AbstractDependencyResolutionTest
import spock.lang.Ignore

class DependencyLockingIntegrationTest extends AbstractDependencyResolutionTest {

Expand Down Expand Up @@ -116,8 +115,7 @@ dependencies {
lockfileFixture.expectMissing('unlockedConf')
}

@Ignore("details are going to be available later")
def 'fails with out-of-date lock file'() {
def 'dependency report passes with failed dependencies using out-of-date lock file'() {
mavenRepo.module('org', 'foo', '1.0').publish()
mavenRepo.module('org', 'foo', '1.1').publish()

Expand Down Expand Up @@ -151,13 +149,13 @@ dependencies {
lockfileFixture.createLockfile('lockedConf',['org:foo:1.0'])

when:
fails 'dependencies'
run 'dependencies'

then:
failure.assertHasCause("Cannot find a version of 'org:foo' that satisfies the version constraints: \n" +
" Dependency path ':depLock:unspecified' --> 'org:foo' prefers '1.+'\n" +
" Constraint path ':depLock:unspecified' --> 'org:foo' prefers '1.1'\n" +
" Constraint path ':depLock:unspecified' --> 'org:foo' prefers '1.0', rejects ']1.0,)' because of the following reason: dependency was locked to version '1.0'")
outputContains """lockedConf
+--- org:foo:1.+ FAILED
+--- org:foo:1.1 FAILED
\\--- org:foo:1.0 FAILED"""
}

def 'fails when lock file entry not resolved'() {
Expand Down Expand Up @@ -260,8 +258,7 @@ dependencies {
lockfileFixture.verifyLockfile('lockedConf', ['org:foo:1.1'])
}

@Ignore("details are going to be available later")
def 'fails and details all out lock issues'() {
def 'dependency report passes with FAILED dependencies for all out lock issues'() {
mavenRepo.module('org', 'foo', '1.0').publish()
mavenRepo.module('org', 'foo', '1.1').publish()
mavenRepo.module('org', 'bar', '1.0').publish()
Expand Down Expand Up @@ -296,16 +293,13 @@ dependencies {
lockfileFixture.createLockfile('lockedConf',['org:bar:1.0', 'org:foo:1.0'])

when:
fails 'dependencies'
run 'dependencies'

then:
failure.assertHasCause("Cannot find a version of 'org:foo' that satisfies the version constraints: \n" +
" Dependency path ':depLock:unspecified' --> 'org:foo' prefers '[1.0, 1.1]'\n" +
" Constraint path ':depLock:unspecified' --> 'org:foo' prefers '1.1'\n" +
" Constraint path ':depLock:unspecified' --> 'org:foo' prefers '1.0', rejects ']1.0,)' because of the following reason: dependency was locked to version '1.0'")
// failure.assertHasCause("Dependency lock out of date:\n" +
// "\tLock file contained 'org:bar:1.0' but it is not part of the resolved modules\n" +
// "\tLock file expected 'org:foo:1.0' but resolution result was 'org:foo:1.1'")
outputContains """lockedConf
+--- org:foo:[1.0, 1.1] FAILED
+--- org:foo:1.1 FAILED
\\--- org:foo:1.0 FAILED"""
}

def 'fails when new dependencies appear'() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void execute(Throwable throwable) {
throw UncheckedException.throwAsUncheckedException(throwable);
}
};

private final ConfigurationResolver resolver;
private final ListenerManager listenerManager;
private final DependencyMetaDataProvider metaDataProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,60 @@ org:leaf2:1.0
(*) - dependencies omitted (listed previously)
A web-based, searchable dependency report is available by adding the --scan option.
"""
}

def "renders multiple rejected modules"() {
given:
mavenRepo.module("org", "foo", "1.0").publish()
mavenRepo.module("org", "foo", "1.1").publish()
mavenRepo.module("org", "foo", "1.2").publish()
mavenRepo.module("org", "bar", "1.0").publish()
mavenRepo.module("org", "bar", "1.1").publish()
mavenRepo.module("org", "bar", "1.2").publish()


file("build.gradle") << """
apply plugin: 'java-library'
repositories {
maven { url "${mavenRepo.uri}" }
}
dependencies {
constraints {
implementation('org:foo') {
version {
reject '1.0', '1.1', '1.2'
}
}
implementation('org:bar') {
version {
rejectAll()
}
because "Nope, you won't use this"
}
}
implementation 'org:foo:[1.0,)'
implementation 'org:bar:[1.0,)'
}
"""

when:
run "dependencyInsight", "--dependency", "org"

then:
outputContains """org:bar (via constraint, Nope, you won't use this) FAILED
\\--- compileClasspath
org:bar:[1.0,) FAILED
\\--- compileClasspath
org:foo (via constraint) FAILED
\\--- compileClasspath
org:foo:[1.0,) FAILED
\\--- compileClasspath
"""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.gradle.api.tasks.diagnostics.internal.insight.DependencyInsightReporter;
import org.gradle.api.tasks.options.Option;
import org.gradle.initialization.StartParameterBuildOptions;
import org.gradle.internal.UncheckedException;
import org.gradle.internal.component.external.model.DefaultModuleComponentSelector;
import org.gradle.internal.graph.GraphRenderer;
import org.gradle.internal.locking.LockOutOfDateException;
Expand Down Expand Up @@ -272,6 +273,10 @@ private void handleResolutionError(Throwable cause, StyledTextOutput output) {
handleConflict((VersionConflictException) cause, output);
} else if (cause instanceof LockOutOfDateException) {
handleOutOfDateLocks((LockOutOfDateException) cause, output);
} else {
// Fallback to failing the task in case we don't know anything special
// about the error
throw UncheckedException.throwAsUncheckedException(cause);
}
}

Expand Down

0 comments on commit 3559bc6

Please sign in to comment.