From ffa81592a435997c940e18fca85f926e448171d6 Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Fri, 21 Aug 2020 19:36:29 -0700 Subject: [PATCH] Add configuration cache support --- .../plugin/info/InfoBrokerPlugin.groovy | 18 +------------- .../plugin/info/InfoBrokerPluginSpec.groovy | 13 ---------- .../InfoPluginConfigurationCacheSpec.groovy | 24 +++++++++++++++++++ .../DependenciesInfoPluginSpec.groovy | 1 - 4 files changed, 25 insertions(+), 31 deletions(-) create mode 100644 src/test/groovy/nebula/plugin/info/InfoPluginConfigurationCacheSpec.groovy diff --git a/src/main/groovy/nebula/plugin/info/InfoBrokerPlugin.groovy b/src/main/groovy/nebula/plugin/info/InfoBrokerPlugin.groovy index b15f8dd..f556f1f 100644 --- a/src/main/groovy/nebula/plugin/info/InfoBrokerPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/InfoBrokerPlugin.groovy @@ -17,16 +17,12 @@ package nebula.plugin.info import groovy.transform.Canonical -import org.gradle.BuildAdapter -import org.gradle.BuildResult import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project import org.slf4j.Logger import org.slf4j.LoggerFactory -import java.util.concurrent.atomic.AtomicBoolean - /** * Broker between Collectors and Reporters. Collectors report to this plugin about manifest values, * Reporters call this plugin to get values. @@ -41,8 +37,8 @@ class InfoBrokerPlugin implements Plugin { private List manifestEntries private Map> watchers private Map reportEntries - private AtomicBoolean buildFinished = new AtomicBoolean(false) private Project project + private Map test =[:] void apply(Project project) { this.manifestEntries = new ArrayList() @@ -51,14 +47,6 @@ class InfoBrokerPlugin implements Plugin { this.project = project InfoBrokerPluginExtension extension = project.getExtensions().create('infoBroker', InfoBrokerPluginExtension) - - project.rootProject.gradle.addBuildListener(new BuildAdapter() { - @Override - void buildFinished(BuildResult buildResult) { - buildFinished.set(true) - } - }) - project.afterEvaluate { filterManifestEntries(extension) } @@ -147,10 +135,6 @@ class InfoBrokerPlugin implements Plugin { throw new IllegalStateException('Build reports should only be used from the root project') } - if (!buildFinished.get()) { - throw new IllegalStateException('Cannot retrieve build reports before the build has finished') - } - return Collections.unmodifiableMap(reportEntries) } diff --git a/src/test/groovy/nebula/plugin/info/InfoBrokerPluginSpec.groovy b/src/test/groovy/nebula/plugin/info/InfoBrokerPluginSpec.groovy index 9cfdd18..3a58ef4 100644 --- a/src/test/groovy/nebula/plugin/info/InfoBrokerPluginSpec.groovy +++ b/src/test/groovy/nebula/plugin/info/InfoBrokerPluginSpec.groovy @@ -102,19 +102,6 @@ class InfoBrokerPluginSpec extends ProjectSpec { attrs3['MyKey'] == 'MyValue' // Still around } - def 'it throws an exception when build reports are requested prior to build end'() { - given: - project.apply plugin: InfoBrokerPlugin - - when: - def infoBrokerPlugin = project.plugins.getPlugin(InfoBrokerPlugin) - infoBrokerPlugin.addReport('test', 'some value') - def reports = infoBrokerPlugin.buildReports() - - then: - thrown IllegalStateException - } - def 'can not add multiple values'() { when: InfoBrokerPlugin broker = project.plugins.apply(InfoBrokerPlugin) diff --git a/src/test/groovy/nebula/plugin/info/InfoPluginConfigurationCacheSpec.groovy b/src/test/groovy/nebula/plugin/info/InfoPluginConfigurationCacheSpec.groovy new file mode 100644 index 0000000..d282543 --- /dev/null +++ b/src/test/groovy/nebula/plugin/info/InfoPluginConfigurationCacheSpec.groovy @@ -0,0 +1,24 @@ +package nebula.plugin.info + +import nebula.test.IntegrationTestKitSpec + +class InfoPluginConfigurationCacheSpec extends IntegrationTestKitSpec { + + def 'plugin applies with configuration cache'() { + buildFile << """ + plugins { + id 'nebula.info' + id 'java' + } + """ + writeHelloWorld('nebula.app') + + + when: + runTasks('--configuration-cache', 'compileJava', '-s') + def result = runTasks('--configuration-cache', 'compileJava', '-s') + + then: + result.output.contains('Reusing configuration cache') + } +} diff --git a/src/test/groovy/nebula/plugin/info/dependency/DependenciesInfoPluginSpec.groovy b/src/test/groovy/nebula/plugin/info/dependency/DependenciesInfoPluginSpec.groovy index 97410fd..fa7ca2f 100644 --- a/src/test/groovy/nebula/plugin/info/dependency/DependenciesInfoPluginSpec.groovy +++ b/src/test/groovy/nebula/plugin/info/dependency/DependenciesInfoPluginSpec.groovy @@ -62,7 +62,6 @@ class DependenciesInfoPluginSpec extends PluginProjectSpec { configurations.compileClasspath.resolve() when: - brokerPlugin.buildFinished.set(true) def reports = brokerPlugin.buildReports() then: