Skip to content

Commit

Permalink
Revert dependency report changes - they cause stackoverflows when ser…
Browse files Browse the repository at this point in the history
…ialized to JSON
  • Loading branch information
DanielThomas committed Apr 6, 2018
1 parent 77057dd commit b450b5e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,69 +21,43 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.VersionInfo
import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.DefaultVersionComparator

class DependenciesInfoPlugin implements Plugin<Project>, InfoCollectorPlugin {
def versionComparator = new DefaultVersionComparator()

@Override
void apply(Project project) {
if (!project.rootProject.hasProperty('nebulaInfoDependencies')) {
project.rootProject.ext.nebulaInfoDependencies = [:]
}
if (!project.rootProject.hasProperty('nebulaInfoRequestedDependencies')) {
project.rootProject.ext.nebulaInfoRequestedDependencies = [:]
}
if (!project.rootProject.hasProperty('nebulaInfoExcludes')) {
project.rootProject.ext.nebulaInfoExcludes = [:]
}
if (!project.rootProject.hasProperty('nebulaInfoResolutionStrategies')) {
project.rootProject.ext.nebulaInfoResolutionStrategies = [:]
}
def dependencyMap = project.rootProject.property('nebulaInfoDependencies')
def dependencies = [:]
def requestedDependencyMap = project.rootProject.property('nebulaInfoRequestedDependencies')
def requestedDependencies = [:]
def excludeMap = project.rootProject.property('nebulaInfoExcludes')
def excludes = [:]
def resolutionStrategyMap = project.rootProject.property('nebulaInfoResolutionStrategies')
def resolutionStrategies = [:]

project.plugins.withType(InfoBrokerPlugin) { InfoBrokerPlugin manifestPlugin ->
project.configurations.all( { Configuration conf ->
conf.incoming.afterResolve { resolvableDependencies ->
conf.incoming.afterResolve {
if (project.configurations.contains(conf)) {
def requested = resolvableDependencies.dependencies

excludes.put(
conf.name,
conf.excludeRules
)

resolutionStrategies.put(
conf.name,
conf.resolutionStrategy
)

requestedDependencies
.put(conf.name, requested)

def resolvedDependencies = resolvableDependencies.resolutionResult.allComponents.findAll {
def resolvedDependencies = it.resolutionResult.allComponents.findAll {
it.id instanceof ModuleComponentIdentifier
}
}*.moduleVersion
.sort(true, { m1, m2 ->
if (m1.group != m2.group)
return m1.group <=> m2.group ?: -1
if (m1.name != m2.name)
return m1.name <=> m2.name // name is required
versionComparator.compare(new VersionInfo(m1.version), new VersionInfo(m2.version))
})*.toString().join(',')
if (resolvedDependencies) {
dependencies.put(resolvableDependencies.name, resolvedDependencies)
dependencies.put("Resolved-Dependencies-${it.name.capitalize()}", resolvedDependencies)
}
}
}
})

dependencyMap[project.name] = dependencies
resolutionStrategyMap[project.name] = resolutionStrategies
excludeMap[project.name] = excludes
requestedDependencyMap[project.name] = requestedDependencies
dependencyMap["${project.name}-dependencies".toString()] = dependencies
if (project == project.rootProject) {
manifestPlugin.addReport('resolvedDependencies', dependencyMap)
manifestPlugin.addReport('requestedDependencies', requestedDependencyMap)
manifestPlugin.addReport('resolutionStrategies', resolutionStrategyMap)
manifestPlugin.addReport('excludes', excludeMap)
manifestPlugin.addReport('resolved-dependencies', dependencyMap)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class InfoPluginIntegrationSpec extends IntegrationSpec {
def broker = project.plugins.getPlugin(${InfoBrokerPlugin.name})
gradle.buildFinished {
println broker.buildReports().get('resolvedDependencies')
println broker.buildReports().get('resolved-dependencies')
}
""".stripIndent()

Expand All @@ -42,7 +42,7 @@ class InfoPluginIntegrationSpec extends IntegrationSpec {
ExecutionResult result = runTasksSuccessfully('assemble')

then:
result.standardOutput.contains('{it-returns-build-reports-at-the-end-of-the-build={compileClasspath=[com.google.guava:guava:18.0]}}')
result.standardOutput.contains('-dependencies={Resolved-Dependencies-CompileClasspath=com.google.guava:guava:18.0}}')
}

def 'it returns build reports at the end of multiproject build'() {
Expand All @@ -59,7 +59,7 @@ class InfoPluginIntegrationSpec extends IntegrationSpec {
def broker = project.plugins.getPlugin(${InfoBrokerPlugin.name})
gradle.buildFinished {
println broker.buildReports().get('resolvedDependencies')
println broker.buildReports().get('resolved-dependencies')
}
""".stripIndent()
def common = addSubproject('common', '''\
Expand All @@ -81,6 +81,7 @@ class InfoPluginIntegrationSpec extends IntegrationSpec {
ExecutionResult result = runTasksSuccessfully('build')

then:
result.standardOutput.contains('{it-returns-build-reports-at-the-end-of-multiproject-build={}, app={compileClasspath=[com.google.guava:guava:19.0]}, common={compileClasspath=[com.google.guava:guava:18.0]}}')
result.standardOutput.contains('common-dependencies={Resolved-Dependencies-CompileClasspath=com.google.guava:guava:18.0}')
result.standardOutput.contains('app-dependencies={Resolved-Dependencies-CompileClasspath=com.google.guava:guava:19.0}')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,75 +18,23 @@ package nebula.plugin.info.dependency
import nebula.plugin.info.InfoBrokerPlugin
import nebula.plugin.info.dependencies.DependenciesInfoPlugin
import nebula.test.PluginProjectSpec
import org.gradle.api.internal.artifacts.configurations.ConflictResolution
import org.gradle.api.artifacts.ResolveException
import spock.lang.Unroll

class DependenciesInfoPluginSpec extends PluginProjectSpec {
def 'reports requestedDependencies if zero-sized'() {
def 'omits manifest entry if no dependencies'() {
setup:
project.apply plugin: 'java'
def brokerPlugin = project.plugins.apply(InfoBrokerPlugin)
project.apply plugin: DependenciesInfoPlugin
project.configurations.compile.resolve()


when:
brokerPlugin.buildFinished.set(true)
def reports = brokerPlugin.buildReports()

then:
noExceptionThrown()
reports.containsKey('requestedDependencies')
}

def 'reports resolvedDependencies if zero-sized'() {
setup:
project.apply plugin: 'java'
def brokerPlugin = project.plugins.apply(InfoBrokerPlugin)
project.apply plugin: DependenciesInfoPlugin
project.configurations.compile.resolve()


when:
brokerPlugin.buildFinished.set(true)
def reports = brokerPlugin.buildReports()

then:
noExceptionThrown()
reports.containsKey('resolvedDependencies')
}

def 'reports excludes if zero-sized'() {
setup:
project.apply plugin: 'java'
def brokerPlugin = project.plugins.apply(InfoBrokerPlugin)
project.apply plugin: DependenciesInfoPlugin
project.configurations.compile.resolve()


when:
brokerPlugin.buildFinished.set(true)
def reports = brokerPlugin.buildReports()

then:
noExceptionThrown()
reports.containsKey('excludes')
}

def 'reports resolutionStrategies if zero-sized'() {
setup:
project.apply plugin: 'java'
def brokerPlugin = project.plugins.apply(InfoBrokerPlugin)
project.apply plugin: DependenciesInfoPlugin
project.configurations.compile.resolve()


when:
brokerPlugin.buildFinished.set(true)
def reports = brokerPlugin.buildReports()
def manifest = brokerPlugin.buildManifest()

then:
noExceptionThrown()
reports.containsKey('resolutionStrategies')
!manifest.containsKey('Resolved-Dependencies-Compile')
}

def 'only includes configurations on configuration container'() {
Expand Down Expand Up @@ -115,142 +63,7 @@ class DependenciesInfoPluginSpec extends PluginProjectSpec {
def reports = brokerPlugin.buildReports()

then:
reports['resolvedDependencies']['only-includes-configurations-on-configuration-container'].size() == 1
}

def 'reports requestedDependencies'() {
setup:
project.apply plugin: 'java'
def brokerPlugin = project.plugins.apply(InfoBrokerPlugin)
project.apply plugin: DependenciesInfoPlugin

def spark = project.dependencies.create('org.apache.spark:spark-parent:1.2.2')

project.repositories.add(project.repositories.mavenCentral())

def configurations = project.configurations

def compile = configurations.compile
compile.dependencies.add(spark)

compile.resolve()

when:
brokerPlugin.buildFinished.set(true)
def reports = brokerPlugin.buildReports()

then:
noExceptionThrown()
reports['requestedDependencies']['reports-requestedDependencies']['compile'].size() == 1
}

def 'reports resolvedDependencies'() {
setup:
project.apply plugin: 'java'
def brokerPlugin = project.plugins.apply(InfoBrokerPlugin)
project.apply plugin: DependenciesInfoPlugin

def spark = project.dependencies.create('org.apache.spark:spark-parent:1.2.2')

project.repositories.add(project.repositories.mavenCentral())

def configurations = project.configurations

def compile = configurations.compile
compile.dependencies.add(spark)

compile.resolve()

when:
brokerPlugin.buildFinished.set(true)
def reports = brokerPlugin.buildReports()

then:
noExceptionThrown()
reports['resolvedDependencies']['reports-resolvedDependencies']['compile']
.findAll { it.moduleVersion.id.toString() == 'org.apache.spark:spark-parent' }
.size() == 1

}

def 'reports the dependency model per Gradle without transforming it'() {
setup:
project.apply plugin: 'java'
def brokerPlugin = project.plugins.apply(InfoBrokerPlugin)
project.apply plugin: DependenciesInfoPlugin

def spark = project.dependencies.create('org.apache.spark:spark-parent:1.2.2', {
exclude group: 'org.apache.spark', module: 'unused'
})

project.repositories.add(project.repositories.mavenCentral())

def configurations = project.configurations

def compile = configurations.compile
compile.dependencies.add(spark)

compile.resolve()

when:
brokerPlugin.buildFinished.set(true)
def reports = brokerPlugin.buildReports()

then:
noExceptionThrown()
// the excludes are attached via Gradle's own internal model
reports['requestedDependencies']['reports-the-dependency-model-per-Gradle-without-transforming-it']['compile'][0]
.getExcludeRules()
.size() == 1
}

def 'reports excludes'() {
project.apply plugin: 'java'
def brokerPlugin = project.plugins.apply(InfoBrokerPlugin)
project.apply plugin: DependenciesInfoPlugin

project.repositories.add(project.repositories.mavenCentral())

def configurations = project.configurations

def compile = configurations.compile
compile.exclude(["group": "org.apache.spark", "module": "spark-parent"])
compile.resolve()

when:
brokerPlugin.buildFinished.set(true)
def reports = brokerPlugin.buildReports()

then:
noExceptionThrown()
// the excludes are attached via Gradle's own internal model
reports['excludes']['reports-excludes']['compile'].size() == 1
}

def 'reports resolution strategies'() {
project.apply plugin: 'java'
def brokerPlugin = project.plugins.apply(InfoBrokerPlugin)
project.apply plugin: DependenciesInfoPlugin

project.repositories.add(project.repositories.mavenCentral())

def configurations = project.configurations

def compile = configurations.compile
compile.resolutionStrategy {
failOnVersionConflict()
}
compile.resolve()

when:
brokerPlugin.buildFinished.set(true)
def reports = brokerPlugin.buildReports()

then:
noExceptionThrown()
reports['resolutionStrategies']['reports-resolution-strategies']['compile']
.conflictResolution == ConflictResolution.strict

reports['resolved-dependencies']['only-includes-configurations-on-configuration-container-dependencies'].size() == 1
}

@Override
Expand Down

0 comments on commit b450b5e

Please sign in to comment.