From 16ddbe7f53ac835234a17e9e12f38d6108a45940 Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Wed, 18 Sep 2019 15:01:50 -0700 Subject: [PATCH 1/3] Introduce static compilation --- build.gradle | 2 ++ src/groovyCompile/groovycConfig.groovy | 6 +++++ .../plugin/info/InfoBrokerPlugin.groovy | 6 ++--- .../plugin/info/basic/BasicInfoPlugin.groovy | 9 ++++++- .../info/basic/ManifestOwnersPlugin.groovy | 1 + .../ci/ContinuousIntegrationInfoPlugin.groovy | 21 ++++++++++------ .../nebula/plugin/info/ci/POSIXUtil.groovy | 5 ++-- .../DependenciesInfoPlugin.groovy | 25 +++++++++++++------ .../reporting/InfoJarManifestPlugin.groovy | 4 +-- .../InfoJarPropertiesFilePlugin.groovy | 9 ++++--- .../info/reporting/InfoPropertiesFile.groovy | 4 +-- .../plugin/info/scm/GitScmProvider.groovy | 2 +- .../info/scm/PerforceScmProvider.groovy | 12 ++++----- .../plugin/info/scm/ScmInfoPlugin.groovy | 22 ++++++++++------ .../plugin/info/scm/SvnScmProvider.groovy | 4 +-- 15 files changed, 85 insertions(+), 47 deletions(-) create mode 100644 src/groovyCompile/groovycConfig.groovy diff --git a/build.gradle b/build.gradle index c89dbcc..ea49355 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,8 @@ plugins { id 'nebula.plugin-plugin' version '12.3.5' } +compileGroovy.groovyOptions.configurationScript = file('src/groovyCompile/groovycConfig.groovy') + description 'Gradle plugin collect and provide information about the environment' contacts { diff --git a/src/groovyCompile/groovycConfig.groovy b/src/groovyCompile/groovycConfig.groovy new file mode 100644 index 0000000..19ca2df --- /dev/null +++ b/src/groovyCompile/groovycConfig.groovy @@ -0,0 +1,6 @@ +import org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder +import groovy.transform.CompileStatic + +CompilerCustomizationBuilder.withConfig(configuration) { + ast(CompileStatic) +} \ No newline at end of file diff --git a/src/main/groovy/nebula/plugin/info/InfoBrokerPlugin.groovy b/src/main/groovy/nebula/plugin/info/InfoBrokerPlugin.groovy index 87453f2..191848c 100644 --- a/src/main/groovy/nebula/plugin/info/InfoBrokerPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/InfoBrokerPlugin.groovy @@ -55,7 +55,7 @@ class InfoBrokerPlugin implements Plugin { project.rootProject.gradle.addBuildListener(new BuildAdapter() { @Override void buildFinished(BuildResult buildResult) { - this.buildFinished.set(true) + buildFinished.set(true) } }) @@ -94,12 +94,12 @@ class InfoBrokerPlugin implements Plugin { manifestEntries = filteredManifestEntries } - def add(String key, Closure closure) { + ManifestEntry add(String key, Closure closure) { def entry = new ManifestEntry(key, closure) addEntry(entry) } - def add(String key, Object value) { + ManifestEntry add(String key, Object value) { def entry = new ManifestEntry(key, value) addEntry(entry) } diff --git a/src/main/groovy/nebula/plugin/info/basic/BasicInfoPlugin.groovy b/src/main/groovy/nebula/plugin/info/basic/BasicInfoPlugin.groovy index 14b3acb..476b1f3 100644 --- a/src/main/groovy/nebula/plugin/info/basic/BasicInfoPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/basic/BasicInfoPlugin.groovy @@ -21,6 +21,8 @@ import nebula.plugin.info.InfoCollectorPlugin import org.gradle.api.Plugin import org.gradle.api.Project +import java.text.SimpleDateFormat + import static java.util.jar.Attributes.Name.* /** * Simple provider, for common fields, like build status. Current values: @@ -36,6 +38,7 @@ import static java.util.jar.Attributes.Name.* * */ class BasicInfoPlugin implements Plugin, InfoCollectorPlugin { + private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat('yyyy-MM-dd_HH:mm:ss') // Sample from commons-lang, and hence via Maven // Manifest-Version: 1.0 @@ -65,11 +68,15 @@ class BasicInfoPlugin implements Plugin, InfoCollectorPlugin { manifestPlugin.add('Built-OS', System.getProperty('os.name')) // Makes list of attributes not idempotent, which can throw off "changed" checks - manifestPlugin.add('Build-Date', new Date().format('yyyy-MM-dd_HH:mm:ss')).changing = true + manifestPlugin.add('Build-Date', formattedBuildDate()).changing = true manifestPlugin.add('Gradle-Version', { project.gradle.gradleVersion }) // TODO Include hostname } } + + private static String formattedBuildDate() { + DATE_FORMATTER.format(new Date()) + } } diff --git a/src/main/groovy/nebula/plugin/info/basic/ManifestOwnersPlugin.groovy b/src/main/groovy/nebula/plugin/info/basic/ManifestOwnersPlugin.groovy index c5b7ce6..d1bd863 100644 --- a/src/main/groovy/nebula/plugin/info/basic/ManifestOwnersPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/basic/ManifestOwnersPlugin.groovy @@ -16,6 +16,7 @@ package nebula.plugin.info.basic + import nebula.plugin.contacts.BaseContactsPlugin import nebula.plugin.info.InfoBrokerPlugin import org.gradle.api.Plugin diff --git a/src/main/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPlugin.groovy b/src/main/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPlugin.groovy index 5b60662..5c9eed5 100644 --- a/src/main/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPlugin.groovy @@ -16,10 +16,12 @@ package nebula.plugin.info.ci +import groovy.transform.CompileDynamic import nebula.plugin.info.InfoBrokerPlugin import nebula.plugin.info.InfoCollectorPlugin import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.internal.ConventionMapping import org.gradle.api.internal.IConventionAware class ContinuousIntegrationInfoPlugin implements Plugin, InfoCollectorPlugin { @@ -32,18 +34,14 @@ class ContinuousIntegrationInfoPlugin implements Plugin, InfoCollectorP void apply(Project project) { this.project = project - providers = [new DroneProvider(), new GitlabProvider(), new JenkinsProvider(), new TravisProvider(), new UnknownContinuousIntegrationProvider()] + providers = [new DroneProvider(), new GitlabProvider(), new JenkinsProvider(), new TravisProvider(), new UnknownContinuousIntegrationProvider()] as List selectedProvider = findProvider() extension = project.extensions.create('ciinfo', ContinuousIntegrationInfoExtension) - def extMapping = ((IConventionAware) extension).getConventionMapping() - extMapping.host = { selectedProvider.calculateHost(project) } - extMapping.job = { selectedProvider.calculateJob(project) } - extMapping.buildNumber = { selectedProvider.calculateBuildNumber(project) } - extMapping.buildId = { selectedProvider.calculateBuildId(project) } + configureExtMapping() - project.plugins.withType(InfoBrokerPlugin) { manifestPlugin -> + project.plugins.withType(InfoBrokerPlugin) { InfoBrokerPlugin manifestPlugin -> manifestPlugin.add('Build-Host') { extension.host } manifestPlugin.add('Build-Job') { extension.job } manifestPlugin.add('Build-Number') { extension.buildNumber } @@ -52,6 +50,15 @@ class ContinuousIntegrationInfoPlugin implements Plugin, InfoCollectorP } + @CompileDynamic + private void configureExtMapping() { + ConventionMapping extMapping = ((IConventionAware) extension).getConventionMapping() + extMapping.host = { selectedProvider.calculateHost(project) } + extMapping.job = { selectedProvider.calculateJob(project) } + extMapping.buildNumber = { selectedProvider.calculateBuildNumber(project) } + extMapping.buildId = { selectedProvider.calculateBuildId(project) } + } + ContinuousIntegrationInfoProvider findProvider() { def provider = providers.find { it.supports(project) } if (provider) { diff --git a/src/main/groovy/nebula/plugin/info/ci/POSIXUtil.groovy b/src/main/groovy/nebula/plugin/info/ci/POSIXUtil.groovy index af545ab..7c1875c 100644 --- a/src/main/groovy/nebula/plugin/info/ci/POSIXUtil.groovy +++ b/src/main/groovy/nebula/plugin/info/ci/POSIXUtil.groovy @@ -19,15 +19,14 @@ package nebula.plugin.info.ci import com.sun.jna.LastErrorException import com.sun.jna.Library import com.sun.jna.Native - class POSIXUtil { private static final C c = (C) Native.loadLibrary("c", C.class); private static interface C extends Library { - public int gethostname(byte[] name, int size_t) throws LastErrorException; + int gethostname(byte[] name, int size_t) throws LastErrorException; } - public static String getHostName() { + static String getHostName() { byte[] hostname = new byte[256]; c.gethostname(hostname, hostname.length) return Native.toString(hostname) diff --git a/src/main/groovy/nebula/plugin/info/dependencies/DependenciesInfoPlugin.groovy b/src/main/groovy/nebula/plugin/info/dependencies/DependenciesInfoPlugin.groovy index 365e776..477a2c5 100644 --- a/src/main/groovy/nebula/plugin/info/dependencies/DependenciesInfoPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/dependencies/DependenciesInfoPlugin.groovy @@ -15,30 +15,32 @@ */ package nebula.plugin.info.dependencies +import groovy.transform.CompileDynamic import nebula.plugin.info.InfoBrokerPlugin import nebula.plugin.info.InfoCollectorPlugin import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.artifacts.Configuration +import org.gradle.api.artifacts.ResolvableDependencies 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 +import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionParser class DependenciesInfoPlugin implements Plugin, InfoCollectorPlugin { - def versionComparator = new DefaultVersionComparator() + private final DefaultVersionComparator versionComparator = new DefaultVersionComparator() + private final VersionParser versionParser = new VersionParser() @Override void apply(Project project) { - if (!project.rootProject.hasProperty('nebulaInfoDependencies')) { - project.rootProject.ext.nebulaInfoDependencies = [:] - } + setInfoDependencies(project) def dependencyMap = project.rootProject.property('nebulaInfoDependencies') def dependencies = [:] project.plugins.withType(InfoBrokerPlugin) { InfoBrokerPlugin manifestPlugin -> project.configurations.all( { Configuration conf -> - conf.incoming.afterResolve { + conf.incoming.afterResolve { ResolvableDependencies resolvableDependencies -> if (project.configurations.contains(conf)) { - def resolvedDependencies = it.resolutionResult.allComponents.findAll { + def resolvedDependencies = resolvableDependencies.resolutionResult.allComponents.findAll { it.id instanceof ModuleComponentIdentifier }*.moduleVersion .sort(true, { m1, m2 -> @@ -46,10 +48,10 @@ class DependenciesInfoPlugin implements Plugin, InfoCollectorPlugin { 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)) + versionComparator.compare(new VersionInfo(versionParser.transform(m1.version)), new VersionInfo(versionParser.transform(m2.version))) })*.toString().join(',') if (resolvedDependencies) { - dependencies.put("Resolved-Dependencies-${it.name.capitalize()}", resolvedDependencies) + dependencies.put("Resolved-Dependencies-${resolvableDependencies.name.capitalize()}", resolvedDependencies) } } } @@ -61,4 +63,11 @@ class DependenciesInfoPlugin implements Plugin, InfoCollectorPlugin { } } } + + @CompileDynamic + private void setInfoDependencies(Project project) { + if (!project.rootProject.hasProperty('nebulaInfoDependencies')) { + project.rootProject.ext.nebulaInfoDependencies = [:] + } + } } diff --git a/src/main/groovy/nebula/plugin/info/reporting/InfoJarManifestPlugin.groovy b/src/main/groovy/nebula/plugin/info/reporting/InfoJarManifestPlugin.groovy index 385253d..8a9b5d0 100644 --- a/src/main/groovy/nebula/plugin/info/reporting/InfoJarManifestPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/reporting/InfoJarManifestPlugin.groovy @@ -18,10 +18,8 @@ package nebula.plugin.info.reporting import nebula.plugin.info.InfoBrokerPlugin import nebula.plugin.info.InfoReporterPlugin -import org.gradle.api.InvalidUserDataException import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.Task import org.gradle.api.tasks.bundling.Jar /** @@ -32,7 +30,7 @@ class InfoJarManifestPlugin implements Plugin, InfoReporterPlugin { void apply(Project project) { - project.plugins.withType(InfoBrokerPlugin) { manifestPlugin -> + project.plugins.withType(InfoBrokerPlugin) { InfoBrokerPlugin manifestPlugin -> // Searching the Gradle code base shows that Archive Tasks are the primary consumers of project.version project.tasks.withType(Jar) { Jar jarTask -> project.afterEvaluate { diff --git a/src/main/groovy/nebula/plugin/info/reporting/InfoJarPropertiesFilePlugin.groovy b/src/main/groovy/nebula/plugin/info/reporting/InfoJarPropertiesFilePlugin.groovy index dcd8cd9..76a2e41 100644 --- a/src/main/groovy/nebula/plugin/info/reporting/InfoJarPropertiesFilePlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/reporting/InfoJarPropertiesFilePlugin.groovy @@ -20,6 +20,7 @@ import nebula.plugin.info.InfoBrokerPlugin import nebula.plugin.info.InfoReporterPlugin import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.internal.file.copy.CopySpecWrapper import org.gradle.api.tasks.bundling.Jar /** @@ -30,12 +31,12 @@ class InfoJarPropertiesFilePlugin implements Plugin, InfoReporterPlugin void apply(Project project) { project.plugins.withType(InfoBrokerPlugin) { manifestPlugin -> - def propFilePlugin = project.plugins.apply(InfoPropertiesFilePlugin) - def manifestTask = propFilePlugin.getManifestTask() + InfoPropertiesFilePlugin propFilePlugin = project.plugins.apply(InfoPropertiesFilePlugin) as InfoPropertiesFilePlugin + InfoPropertiesFile manifestTask = propFilePlugin.getManifestTask() project.tasks.withType(Jar) { Jar jarTask -> - jarTask.from(manifestTask.outputs) { - into "META-INF" + jarTask.from(manifestTask.outputs) { CopySpecWrapper copySpecWrapper -> + copySpecWrapper.into "META-INF" } } } diff --git a/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFile.groovy b/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFile.groovy index f974996..cd17821 100644 --- a/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFile.groovy +++ b/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFile.groovy @@ -29,7 +29,7 @@ class InfoPropertiesFile extends ConventionTask { @Input Map getManifest() { - InfoBrokerPlugin manifestPlugin = project.plugins.getPlugin(InfoBrokerPlugin) + InfoBrokerPlugin manifestPlugin = project.plugins.getPlugin(InfoBrokerPlugin) as InfoBrokerPlugin def entireMap = manifestPlugin.buildNonChangingManifest() @@ -41,7 +41,7 @@ class InfoPropertiesFile extends ConventionTask { @TaskAction def writeOut() { - InfoBrokerPlugin basePlugin = project.plugins.getPlugin(InfoBrokerPlugin) + InfoBrokerPlugin basePlugin = project.plugins.getPlugin(InfoBrokerPlugin) as InfoBrokerPlugin // Gather all values, in contrast to buildNonChangingManifest def attrs = basePlugin.buildManifest() diff --git a/src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy b/src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy index 9ea4e72..8ebb5d8 100644 --- a/src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy +++ b/src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy @@ -55,7 +55,7 @@ class GitScmProvider extends AbstractScmProvider { def hash = System.getenv('GIT_COMMIT') // From Jenkins if (hash==null) { def head = getRepository(projectDir).resolve(Constants.HEAD) - if (head==null) { + if (!head) { return null } hash = head.name diff --git a/src/main/groovy/nebula/plugin/info/scm/PerforceScmProvider.groovy b/src/main/groovy/nebula/plugin/info/scm/PerforceScmProvider.groovy index 8e0d74c..cacf8ce 100644 --- a/src/main/groovy/nebula/plugin/info/scm/PerforceScmProvider.groovy +++ b/src/main/groovy/nebula/plugin/info/scm/PerforceScmProvider.groovy @@ -135,21 +135,21 @@ class PerforceScmProvider extends AbstractScmProvider { } @PackageScope - def Map perforceDefaults(File projectDir) { + Map perforceDefaults(File projectDir) { // Set some default values then look for overrides - def defaults = [ + Map defaults = [ P4CLIENT: null, P4USER: 'rolem', P4PASSWD: '', P4PORT: 'perforce:1666' - ] + ] as Map // First look for P4CONFIG name findP4Config(projectDir) // Might be noop if (p4configFile) { def props = new Properties() props.load(new FileReader(p4configFile)) - defaults = overrideFromMap(defaults, props) + defaults = overrideFromMap(defaults, props as Map) } // Second user environment variables @@ -159,8 +159,8 @@ class PerforceScmProvider extends AbstractScmProvider { } @PackageScope - def Map overrideFromMap(Map orig, Map override) { - def dest = [:] + Map overrideFromMap(Map orig, Map override) { + Map dest = [:] orig.keySet().each { String key -> dest[key] = override.keySet().contains(key) ? override[key] : orig[key] } diff --git a/src/main/groovy/nebula/plugin/info/scm/ScmInfoPlugin.groovy b/src/main/groovy/nebula/plugin/info/scm/ScmInfoPlugin.groovy index eeb842b..96039bd 100644 --- a/src/main/groovy/nebula/plugin/info/scm/ScmInfoPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/scm/ScmInfoPlugin.groovy @@ -16,10 +16,12 @@ package nebula.plugin.info.scm +import groovy.transform.CompileDynamic import nebula.plugin.info.InfoBrokerPlugin import nebula.plugin.info.InfoCollectorPlugin import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.internal.ConventionMapping import org.gradle.api.internal.IConventionAware import org.gradle.api.logging.Logger import org.gradle.api.logging.Logging @@ -37,18 +39,14 @@ class ScmInfoPlugin implements Plugin, InfoCollectorPlugin { this.project = project // TODO Delay findProvider() as long as possible - providers = [new GitScmProvider(), new PerforceScmProvider(), new SvnScmProvider(), new UnknownScmProvider()] + providers = [new GitScmProvider(), new PerforceScmProvider(), new SvnScmProvider(), new UnknownScmProvider()] as List selectedProvider = findProvider() extension = project.extensions.create('scminfo', ScmInfoExtension) - def extMapping = ((IConventionAware) extension).getConventionMapping() - extMapping.origin = { selectedProvider.calculateOrigin(project) } - extMapping.source = { selectedProvider.calculateSource(project)?.replace(File.separatorChar, '/' as char) } - extMapping.change = { selectedProvider.calculateChange(project) } - extMapping.branch = { selectedProvider.calculateBranch(project) } + configureExtMapping() - project.plugins.withType(InfoBrokerPlugin) { manifestPlugin -> + project.plugins.withType(InfoBrokerPlugin) { InfoBrokerPlugin manifestPlugin -> manifestPlugin.add('Module-Source') { extension.source } manifestPlugin.add('Module-Origin') { extension.origin } manifestPlugin.add('Change') { extension.change } @@ -56,6 +54,16 @@ class ScmInfoPlugin implements Plugin, InfoCollectorPlugin { } } + @CompileDynamic + private void configureExtMapping() { + ConventionMapping extMapping = ((IConventionAware) extension).getConventionMapping() + extMapping.origin = { selectedProvider.calculateOrigin(project) } + extMapping.source = { selectedProvider.calculateSource(project)?.replace(File.separatorChar, '/' as char) } + extMapping.change = { selectedProvider.calculateChange(project) } + extMapping.branch = { selectedProvider.calculateBranch(project) } + + } + ScmInfoProvider findProvider() { def provider = providers.find { it.supports(project) } if (provider) { diff --git a/src/main/groovy/nebula/plugin/info/scm/SvnScmProvider.groovy b/src/main/groovy/nebula/plugin/info/scm/SvnScmProvider.groovy index c88e590..5b87055 100644 --- a/src/main/groovy/nebula/plugin/info/scm/SvnScmProvider.groovy +++ b/src/main/groovy/nebula/plugin/info/scm/SvnScmProvider.groovy @@ -55,9 +55,9 @@ class SvnScmProvider extends AbstractScmProvider { @Override String calculateChange(File projectDir) { def revision = System.getenv('SVN_REVISION') // From Jenkins - if (revision==null) { + if (!revision) { def base = getInfo(projectDir).getRevision() - if (base==null) { + if (!base) { return null } revision = base.getNumber() From e17533808d72d7ff176ffe837131731cfc96b94e Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Wed, 18 Sep 2019 15:01:50 -0700 Subject: [PATCH 2/3] Introduce static compilation --- build.gradle | 2 ++ src/groovyCompile/groovycConfig.groovy | 6 +++++ .../plugin/info/InfoBrokerPlugin.groovy | 6 ++--- .../plugin/info/basic/BasicInfoPlugin.groovy | 5 +++- .../info/basic/ManifestOwnersPlugin.groovy | 1 + .../ci/ContinuousIntegrationInfoPlugin.groovy | 21 ++++++++++------ .../nebula/plugin/info/ci/POSIXUtil.groovy | 5 ++-- .../DependenciesInfoPlugin.groovy | 25 +++++++++++++------ .../reporting/InfoJarManifestPlugin.groovy | 4 +-- .../InfoJarPropertiesFilePlugin.groovy | 9 ++++--- .../info/reporting/InfoPropertiesFile.groovy | 4 +-- .../plugin/info/scm/GitScmProvider.groovy | 2 +- .../info/scm/PerforceScmProvider.groovy | 12 ++++----- .../plugin/info/scm/ScmInfoPlugin.groovy | 22 ++++++++++------ .../plugin/info/scm/SvnScmProvider.groovy | 4 +-- 15 files changed, 81 insertions(+), 47 deletions(-) create mode 100644 src/groovyCompile/groovycConfig.groovy diff --git a/build.gradle b/build.gradle index c89dbcc..ea49355 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,8 @@ plugins { id 'nebula.plugin-plugin' version '12.3.5' } +compileGroovy.groovyOptions.configurationScript = file('src/groovyCompile/groovycConfig.groovy') + description 'Gradle plugin collect and provide information about the environment' contacts { diff --git a/src/groovyCompile/groovycConfig.groovy b/src/groovyCompile/groovycConfig.groovy new file mode 100644 index 0000000..19ca2df --- /dev/null +++ b/src/groovyCompile/groovycConfig.groovy @@ -0,0 +1,6 @@ +import org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder +import groovy.transform.CompileStatic + +CompilerCustomizationBuilder.withConfig(configuration) { + ast(CompileStatic) +} \ No newline at end of file diff --git a/src/main/groovy/nebula/plugin/info/InfoBrokerPlugin.groovy b/src/main/groovy/nebula/plugin/info/InfoBrokerPlugin.groovy index 87453f2..191848c 100644 --- a/src/main/groovy/nebula/plugin/info/InfoBrokerPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/InfoBrokerPlugin.groovy @@ -55,7 +55,7 @@ class InfoBrokerPlugin implements Plugin { project.rootProject.gradle.addBuildListener(new BuildAdapter() { @Override void buildFinished(BuildResult buildResult) { - this.buildFinished.set(true) + buildFinished.set(true) } }) @@ -94,12 +94,12 @@ class InfoBrokerPlugin implements Plugin { manifestEntries = filteredManifestEntries } - def add(String key, Closure closure) { + ManifestEntry add(String key, Closure closure) { def entry = new ManifestEntry(key, closure) addEntry(entry) } - def add(String key, Object value) { + ManifestEntry add(String key, Object value) { def entry = new ManifestEntry(key, value) addEntry(entry) } diff --git a/src/main/groovy/nebula/plugin/info/basic/BasicInfoPlugin.groovy b/src/main/groovy/nebula/plugin/info/basic/BasicInfoPlugin.groovy index 14b3acb..3251a71 100644 --- a/src/main/groovy/nebula/plugin/info/basic/BasicInfoPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/basic/BasicInfoPlugin.groovy @@ -21,6 +21,8 @@ import nebula.plugin.info.InfoCollectorPlugin import org.gradle.api.Plugin import org.gradle.api.Project +import java.text.SimpleDateFormat + import static java.util.jar.Attributes.Name.* /** * Simple provider, for common fields, like build status. Current values: @@ -36,6 +38,7 @@ import static java.util.jar.Attributes.Name.* * */ class BasicInfoPlugin implements Plugin, InfoCollectorPlugin { + private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat('yyyy-MM-dd_HH:mm:ss') // Sample from commons-lang, and hence via Maven // Manifest-Version: 1.0 @@ -65,7 +68,7 @@ class BasicInfoPlugin implements Plugin, InfoCollectorPlugin { manifestPlugin.add('Built-OS', System.getProperty('os.name')) // Makes list of attributes not idempotent, which can throw off "changed" checks - manifestPlugin.add('Build-Date', new Date().format('yyyy-MM-dd_HH:mm:ss')).changing = true + manifestPlugin.add('Build-Date', DATE_FORMATTER.format(new Date())).changing = true manifestPlugin.add('Gradle-Version', { project.gradle.gradleVersion }) diff --git a/src/main/groovy/nebula/plugin/info/basic/ManifestOwnersPlugin.groovy b/src/main/groovy/nebula/plugin/info/basic/ManifestOwnersPlugin.groovy index c5b7ce6..d1bd863 100644 --- a/src/main/groovy/nebula/plugin/info/basic/ManifestOwnersPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/basic/ManifestOwnersPlugin.groovy @@ -16,6 +16,7 @@ package nebula.plugin.info.basic + import nebula.plugin.contacts.BaseContactsPlugin import nebula.plugin.info.InfoBrokerPlugin import org.gradle.api.Plugin diff --git a/src/main/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPlugin.groovy b/src/main/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPlugin.groovy index 5b60662..5c9eed5 100644 --- a/src/main/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPlugin.groovy @@ -16,10 +16,12 @@ package nebula.plugin.info.ci +import groovy.transform.CompileDynamic import nebula.plugin.info.InfoBrokerPlugin import nebula.plugin.info.InfoCollectorPlugin import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.internal.ConventionMapping import org.gradle.api.internal.IConventionAware class ContinuousIntegrationInfoPlugin implements Plugin, InfoCollectorPlugin { @@ -32,18 +34,14 @@ class ContinuousIntegrationInfoPlugin implements Plugin, InfoCollectorP void apply(Project project) { this.project = project - providers = [new DroneProvider(), new GitlabProvider(), new JenkinsProvider(), new TravisProvider(), new UnknownContinuousIntegrationProvider()] + providers = [new DroneProvider(), new GitlabProvider(), new JenkinsProvider(), new TravisProvider(), new UnknownContinuousIntegrationProvider()] as List selectedProvider = findProvider() extension = project.extensions.create('ciinfo', ContinuousIntegrationInfoExtension) - def extMapping = ((IConventionAware) extension).getConventionMapping() - extMapping.host = { selectedProvider.calculateHost(project) } - extMapping.job = { selectedProvider.calculateJob(project) } - extMapping.buildNumber = { selectedProvider.calculateBuildNumber(project) } - extMapping.buildId = { selectedProvider.calculateBuildId(project) } + configureExtMapping() - project.plugins.withType(InfoBrokerPlugin) { manifestPlugin -> + project.plugins.withType(InfoBrokerPlugin) { InfoBrokerPlugin manifestPlugin -> manifestPlugin.add('Build-Host') { extension.host } manifestPlugin.add('Build-Job') { extension.job } manifestPlugin.add('Build-Number') { extension.buildNumber } @@ -52,6 +50,15 @@ class ContinuousIntegrationInfoPlugin implements Plugin, InfoCollectorP } + @CompileDynamic + private void configureExtMapping() { + ConventionMapping extMapping = ((IConventionAware) extension).getConventionMapping() + extMapping.host = { selectedProvider.calculateHost(project) } + extMapping.job = { selectedProvider.calculateJob(project) } + extMapping.buildNumber = { selectedProvider.calculateBuildNumber(project) } + extMapping.buildId = { selectedProvider.calculateBuildId(project) } + } + ContinuousIntegrationInfoProvider findProvider() { def provider = providers.find { it.supports(project) } if (provider) { diff --git a/src/main/groovy/nebula/plugin/info/ci/POSIXUtil.groovy b/src/main/groovy/nebula/plugin/info/ci/POSIXUtil.groovy index af545ab..7c1875c 100644 --- a/src/main/groovy/nebula/plugin/info/ci/POSIXUtil.groovy +++ b/src/main/groovy/nebula/plugin/info/ci/POSIXUtil.groovy @@ -19,15 +19,14 @@ package nebula.plugin.info.ci import com.sun.jna.LastErrorException import com.sun.jna.Library import com.sun.jna.Native - class POSIXUtil { private static final C c = (C) Native.loadLibrary("c", C.class); private static interface C extends Library { - public int gethostname(byte[] name, int size_t) throws LastErrorException; + int gethostname(byte[] name, int size_t) throws LastErrorException; } - public static String getHostName() { + static String getHostName() { byte[] hostname = new byte[256]; c.gethostname(hostname, hostname.length) return Native.toString(hostname) diff --git a/src/main/groovy/nebula/plugin/info/dependencies/DependenciesInfoPlugin.groovy b/src/main/groovy/nebula/plugin/info/dependencies/DependenciesInfoPlugin.groovy index 365e776..477a2c5 100644 --- a/src/main/groovy/nebula/plugin/info/dependencies/DependenciesInfoPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/dependencies/DependenciesInfoPlugin.groovy @@ -15,30 +15,32 @@ */ package nebula.plugin.info.dependencies +import groovy.transform.CompileDynamic import nebula.plugin.info.InfoBrokerPlugin import nebula.plugin.info.InfoCollectorPlugin import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.artifacts.Configuration +import org.gradle.api.artifacts.ResolvableDependencies 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 +import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionParser class DependenciesInfoPlugin implements Plugin, InfoCollectorPlugin { - def versionComparator = new DefaultVersionComparator() + private final DefaultVersionComparator versionComparator = new DefaultVersionComparator() + private final VersionParser versionParser = new VersionParser() @Override void apply(Project project) { - if (!project.rootProject.hasProperty('nebulaInfoDependencies')) { - project.rootProject.ext.nebulaInfoDependencies = [:] - } + setInfoDependencies(project) def dependencyMap = project.rootProject.property('nebulaInfoDependencies') def dependencies = [:] project.plugins.withType(InfoBrokerPlugin) { InfoBrokerPlugin manifestPlugin -> project.configurations.all( { Configuration conf -> - conf.incoming.afterResolve { + conf.incoming.afterResolve { ResolvableDependencies resolvableDependencies -> if (project.configurations.contains(conf)) { - def resolvedDependencies = it.resolutionResult.allComponents.findAll { + def resolvedDependencies = resolvableDependencies.resolutionResult.allComponents.findAll { it.id instanceof ModuleComponentIdentifier }*.moduleVersion .sort(true, { m1, m2 -> @@ -46,10 +48,10 @@ class DependenciesInfoPlugin implements Plugin, InfoCollectorPlugin { 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)) + versionComparator.compare(new VersionInfo(versionParser.transform(m1.version)), new VersionInfo(versionParser.transform(m2.version))) })*.toString().join(',') if (resolvedDependencies) { - dependencies.put("Resolved-Dependencies-${it.name.capitalize()}", resolvedDependencies) + dependencies.put("Resolved-Dependencies-${resolvableDependencies.name.capitalize()}", resolvedDependencies) } } } @@ -61,4 +63,11 @@ class DependenciesInfoPlugin implements Plugin, InfoCollectorPlugin { } } } + + @CompileDynamic + private void setInfoDependencies(Project project) { + if (!project.rootProject.hasProperty('nebulaInfoDependencies')) { + project.rootProject.ext.nebulaInfoDependencies = [:] + } + } } diff --git a/src/main/groovy/nebula/plugin/info/reporting/InfoJarManifestPlugin.groovy b/src/main/groovy/nebula/plugin/info/reporting/InfoJarManifestPlugin.groovy index 385253d..8a9b5d0 100644 --- a/src/main/groovy/nebula/plugin/info/reporting/InfoJarManifestPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/reporting/InfoJarManifestPlugin.groovy @@ -18,10 +18,8 @@ package nebula.plugin.info.reporting import nebula.plugin.info.InfoBrokerPlugin import nebula.plugin.info.InfoReporterPlugin -import org.gradle.api.InvalidUserDataException import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.Task import org.gradle.api.tasks.bundling.Jar /** @@ -32,7 +30,7 @@ class InfoJarManifestPlugin implements Plugin, InfoReporterPlugin { void apply(Project project) { - project.plugins.withType(InfoBrokerPlugin) { manifestPlugin -> + project.plugins.withType(InfoBrokerPlugin) { InfoBrokerPlugin manifestPlugin -> // Searching the Gradle code base shows that Archive Tasks are the primary consumers of project.version project.tasks.withType(Jar) { Jar jarTask -> project.afterEvaluate { diff --git a/src/main/groovy/nebula/plugin/info/reporting/InfoJarPropertiesFilePlugin.groovy b/src/main/groovy/nebula/plugin/info/reporting/InfoJarPropertiesFilePlugin.groovy index dcd8cd9..76a2e41 100644 --- a/src/main/groovy/nebula/plugin/info/reporting/InfoJarPropertiesFilePlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/reporting/InfoJarPropertiesFilePlugin.groovy @@ -20,6 +20,7 @@ import nebula.plugin.info.InfoBrokerPlugin import nebula.plugin.info.InfoReporterPlugin import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.internal.file.copy.CopySpecWrapper import org.gradle.api.tasks.bundling.Jar /** @@ -30,12 +31,12 @@ class InfoJarPropertiesFilePlugin implements Plugin, InfoReporterPlugin void apply(Project project) { project.plugins.withType(InfoBrokerPlugin) { manifestPlugin -> - def propFilePlugin = project.plugins.apply(InfoPropertiesFilePlugin) - def manifestTask = propFilePlugin.getManifestTask() + InfoPropertiesFilePlugin propFilePlugin = project.plugins.apply(InfoPropertiesFilePlugin) as InfoPropertiesFilePlugin + InfoPropertiesFile manifestTask = propFilePlugin.getManifestTask() project.tasks.withType(Jar) { Jar jarTask -> - jarTask.from(manifestTask.outputs) { - into "META-INF" + jarTask.from(manifestTask.outputs) { CopySpecWrapper copySpecWrapper -> + copySpecWrapper.into "META-INF" } } } diff --git a/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFile.groovy b/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFile.groovy index f974996..cd17821 100644 --- a/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFile.groovy +++ b/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFile.groovy @@ -29,7 +29,7 @@ class InfoPropertiesFile extends ConventionTask { @Input Map getManifest() { - InfoBrokerPlugin manifestPlugin = project.plugins.getPlugin(InfoBrokerPlugin) + InfoBrokerPlugin manifestPlugin = project.plugins.getPlugin(InfoBrokerPlugin) as InfoBrokerPlugin def entireMap = manifestPlugin.buildNonChangingManifest() @@ -41,7 +41,7 @@ class InfoPropertiesFile extends ConventionTask { @TaskAction def writeOut() { - InfoBrokerPlugin basePlugin = project.plugins.getPlugin(InfoBrokerPlugin) + InfoBrokerPlugin basePlugin = project.plugins.getPlugin(InfoBrokerPlugin) as InfoBrokerPlugin // Gather all values, in contrast to buildNonChangingManifest def attrs = basePlugin.buildManifest() diff --git a/src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy b/src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy index 9ea4e72..8ebb5d8 100644 --- a/src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy +++ b/src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy @@ -55,7 +55,7 @@ class GitScmProvider extends AbstractScmProvider { def hash = System.getenv('GIT_COMMIT') // From Jenkins if (hash==null) { def head = getRepository(projectDir).resolve(Constants.HEAD) - if (head==null) { + if (!head) { return null } hash = head.name diff --git a/src/main/groovy/nebula/plugin/info/scm/PerforceScmProvider.groovy b/src/main/groovy/nebula/plugin/info/scm/PerforceScmProvider.groovy index 8e0d74c..cacf8ce 100644 --- a/src/main/groovy/nebula/plugin/info/scm/PerforceScmProvider.groovy +++ b/src/main/groovy/nebula/plugin/info/scm/PerforceScmProvider.groovy @@ -135,21 +135,21 @@ class PerforceScmProvider extends AbstractScmProvider { } @PackageScope - def Map perforceDefaults(File projectDir) { + Map perforceDefaults(File projectDir) { // Set some default values then look for overrides - def defaults = [ + Map defaults = [ P4CLIENT: null, P4USER: 'rolem', P4PASSWD: '', P4PORT: 'perforce:1666' - ] + ] as Map // First look for P4CONFIG name findP4Config(projectDir) // Might be noop if (p4configFile) { def props = new Properties() props.load(new FileReader(p4configFile)) - defaults = overrideFromMap(defaults, props) + defaults = overrideFromMap(defaults, props as Map) } // Second user environment variables @@ -159,8 +159,8 @@ class PerforceScmProvider extends AbstractScmProvider { } @PackageScope - def Map overrideFromMap(Map orig, Map override) { - def dest = [:] + Map overrideFromMap(Map orig, Map override) { + Map dest = [:] orig.keySet().each { String key -> dest[key] = override.keySet().contains(key) ? override[key] : orig[key] } diff --git a/src/main/groovy/nebula/plugin/info/scm/ScmInfoPlugin.groovy b/src/main/groovy/nebula/plugin/info/scm/ScmInfoPlugin.groovy index eeb842b..96039bd 100644 --- a/src/main/groovy/nebula/plugin/info/scm/ScmInfoPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/scm/ScmInfoPlugin.groovy @@ -16,10 +16,12 @@ package nebula.plugin.info.scm +import groovy.transform.CompileDynamic import nebula.plugin.info.InfoBrokerPlugin import nebula.plugin.info.InfoCollectorPlugin import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.internal.ConventionMapping import org.gradle.api.internal.IConventionAware import org.gradle.api.logging.Logger import org.gradle.api.logging.Logging @@ -37,18 +39,14 @@ class ScmInfoPlugin implements Plugin, InfoCollectorPlugin { this.project = project // TODO Delay findProvider() as long as possible - providers = [new GitScmProvider(), new PerforceScmProvider(), new SvnScmProvider(), new UnknownScmProvider()] + providers = [new GitScmProvider(), new PerforceScmProvider(), new SvnScmProvider(), new UnknownScmProvider()] as List selectedProvider = findProvider() extension = project.extensions.create('scminfo', ScmInfoExtension) - def extMapping = ((IConventionAware) extension).getConventionMapping() - extMapping.origin = { selectedProvider.calculateOrigin(project) } - extMapping.source = { selectedProvider.calculateSource(project)?.replace(File.separatorChar, '/' as char) } - extMapping.change = { selectedProvider.calculateChange(project) } - extMapping.branch = { selectedProvider.calculateBranch(project) } + configureExtMapping() - project.plugins.withType(InfoBrokerPlugin) { manifestPlugin -> + project.plugins.withType(InfoBrokerPlugin) { InfoBrokerPlugin manifestPlugin -> manifestPlugin.add('Module-Source') { extension.source } manifestPlugin.add('Module-Origin') { extension.origin } manifestPlugin.add('Change') { extension.change } @@ -56,6 +54,16 @@ class ScmInfoPlugin implements Plugin, InfoCollectorPlugin { } } + @CompileDynamic + private void configureExtMapping() { + ConventionMapping extMapping = ((IConventionAware) extension).getConventionMapping() + extMapping.origin = { selectedProvider.calculateOrigin(project) } + extMapping.source = { selectedProvider.calculateSource(project)?.replace(File.separatorChar, '/' as char) } + extMapping.change = { selectedProvider.calculateChange(project) } + extMapping.branch = { selectedProvider.calculateBranch(project) } + + } + ScmInfoProvider findProvider() { def provider = providers.find { it.supports(project) } if (provider) { diff --git a/src/main/groovy/nebula/plugin/info/scm/SvnScmProvider.groovy b/src/main/groovy/nebula/plugin/info/scm/SvnScmProvider.groovy index c88e590..5b87055 100644 --- a/src/main/groovy/nebula/plugin/info/scm/SvnScmProvider.groovy +++ b/src/main/groovy/nebula/plugin/info/scm/SvnScmProvider.groovy @@ -55,9 +55,9 @@ class SvnScmProvider extends AbstractScmProvider { @Override String calculateChange(File projectDir) { def revision = System.getenv('SVN_REVISION') // From Jenkins - if (revision==null) { + if (!revision) { def base = getInfo(projectDir).getRevision() - if (base==null) { + if (!base) { return null } revision = base.getNumber() From 3022657dfa5853bde0ebe88b6fbe48f81763b2c3 Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Wed, 18 Sep 2019 15:29:07 -0700 Subject: [PATCH 3/3] more strong typing for the plugin --- .../plugin/info/InfoBrokerPlugin.groovy | 20 ++++----- ...stractContinuousIntegrationProvider.groovy | 2 +- .../ci/ContinuousIntegrationInfoPlugin.groovy | 2 +- .../DependenciesInfoPlugin.groovy | 4 +- .../reporting/InfoJarManifestPlugin.groovy | 2 +- .../info/reporting/InfoPropertiesFile.groovy | 8 ++-- .../info/scm/AbstractScmProvider.groovy | 4 +- .../plugin/info/scm/GitScmProvider.groovy | 22 +++++----- .../info/scm/PerforceScmProvider.groovy | 41 +++---------------- .../plugin/info/scm/ScmInfoPlugin.groovy | 2 +- .../plugin/info/scm/SvnScmProvider.groovy | 27 ++++++------ .../plugin/info/scm/UnknownScmProvider.groovy | 6 +-- 12 files changed, 53 insertions(+), 87 deletions(-) diff --git a/src/main/groovy/nebula/plugin/info/InfoBrokerPlugin.groovy b/src/main/groovy/nebula/plugin/info/InfoBrokerPlugin.groovy index 191848c..b15f8dd 100644 --- a/src/main/groovy/nebula/plugin/info/InfoBrokerPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/InfoBrokerPlugin.groovy @@ -95,16 +95,16 @@ class InfoBrokerPlugin implements Plugin { } ManifestEntry add(String key, Closure closure) { - def entry = new ManifestEntry(key, closure) + ManifestEntry entry = new ManifestEntry(key, closure) addEntry(entry) } ManifestEntry add(String key, Object value) { - def entry = new ManifestEntry(key, value) + ManifestEntry entry = new ManifestEntry(key, value) addEntry(entry) } - def addReport(String reportName, Object value) { + void addReport(String reportName, Object value) { if (project != project.rootProject) { throw new IllegalStateException('Build reports should only be used from the root project') } @@ -118,7 +118,7 @@ class InfoBrokerPlugin implements Plugin { } private ManifestEntry addEntry(ManifestEntry entry) { - def existing = manifestEntries.find { it.name == entry.name } + ManifestEntry existing = manifestEntries.find { it.name == entry.name } if (existing) { resolve(existing) throw new IllegalStateException("A entry with the key ${entry.name} already exists, with the value \"${existing.value}\"") @@ -190,14 +190,14 @@ class InfoBrokerPlugin implements Plugin { } String buildManifestString() { - def attrs = buildManifest() - def manifestStr = attrs.collect { "${it.key}: ${it.value}"}.join('\n ') + Map attrs = buildManifest() + String manifestStr = attrs.collect { "${it.key}: ${it.value}"}.join('\n ') return manifestStr } String buildString(String indent = '') { - def attrs = buildManifest() - def manifestStr = attrs.collect { "${indent}${it.key}: ${it.value}"}.join('\n') + Map attrs = buildManifest() + String manifestStr = attrs.collect { "${indent}${it.key}: ${it.value}"}.join('\n') return manifestStr } @@ -208,7 +208,7 @@ class InfoBrokerPlugin implements Plugin { * @return String based value of entry */ String buildEntry(String key) { - def entry = manifestEntries.find { it.name == key } + ManifestEntry entry = manifestEntries.find { it.name == key } if (!entry) throw new IllegalArgumentException("Unable to find $key") resolve(entry) @@ -217,7 +217,7 @@ class InfoBrokerPlugin implements Plugin { def watch(String key, Closure reaction) { // If we have the key already, we can process it now - def entry = manifestEntries.find { it.name == key } + ManifestEntry entry = manifestEntries.find { it.name == key } if (entry) { callWatcher(entry, reaction) } else { diff --git a/src/main/groovy/nebula/plugin/info/ci/AbstractContinuousIntegrationProvider.groovy b/src/main/groovy/nebula/plugin/info/ci/AbstractContinuousIntegrationProvider.groovy index 040f1e5..e29e417 100644 --- a/src/main/groovy/nebula/plugin/info/ci/AbstractContinuousIntegrationProvider.groovy +++ b/src/main/groovy/nebula/plugin/info/ci/AbstractContinuousIntegrationProvider.groovy @@ -29,7 +29,7 @@ abstract class AbstractContinuousIntegrationProvider implements ContinuousIntegr } protected static String hostname() { - def currentOs = OperatingSystem.current() + OperatingSystem currentOs = OperatingSystem.current() if (currentOs.isWindows()) { try { return Kernel32Util.getComputerName() diff --git a/src/main/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPlugin.groovy b/src/main/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPlugin.groovy index 5c9eed5..e5acfb3 100644 --- a/src/main/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPlugin.groovy @@ -60,7 +60,7 @@ class ContinuousIntegrationInfoPlugin implements Plugin, InfoCollectorP } ContinuousIntegrationInfoProvider findProvider() { - def provider = providers.find { it.supports(project) } + ContinuousIntegrationInfoProvider provider = providers.find { it.supports(project) } if (provider) { return provider } else { diff --git a/src/main/groovy/nebula/plugin/info/dependencies/DependenciesInfoPlugin.groovy b/src/main/groovy/nebula/plugin/info/dependencies/DependenciesInfoPlugin.groovy index 477a2c5..d7e30c5 100644 --- a/src/main/groovy/nebula/plugin/info/dependencies/DependenciesInfoPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/dependencies/DependenciesInfoPlugin.groovy @@ -35,12 +35,12 @@ class DependenciesInfoPlugin implements Plugin, InfoCollectorPlugin { void apply(Project project) { setInfoDependencies(project) def dependencyMap = project.rootProject.property('nebulaInfoDependencies') - def dependencies = [:] + Map dependencies = [:] project.plugins.withType(InfoBrokerPlugin) { InfoBrokerPlugin manifestPlugin -> project.configurations.all( { Configuration conf -> conf.incoming.afterResolve { ResolvableDependencies resolvableDependencies -> if (project.configurations.contains(conf)) { - def resolvedDependencies = resolvableDependencies.resolutionResult.allComponents.findAll { + String resolvedDependencies = resolvableDependencies.resolutionResult.allComponents.findAll { it.id instanceof ModuleComponentIdentifier }*.moduleVersion .sort(true, { m1, m2 -> diff --git a/src/main/groovy/nebula/plugin/info/reporting/InfoJarManifestPlugin.groovy b/src/main/groovy/nebula/plugin/info/reporting/InfoJarManifestPlugin.groovy index 8a9b5d0..17ce522 100644 --- a/src/main/groovy/nebula/plugin/info/reporting/InfoJarManifestPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/reporting/InfoJarManifestPlugin.groovy @@ -34,7 +34,7 @@ class InfoJarManifestPlugin implements Plugin, InfoReporterPlugin { // Searching the Gradle code base shows that Archive Tasks are the primary consumers of project.version project.tasks.withType(Jar) { Jar jarTask -> project.afterEvaluate { - def entireMap = manifestPlugin.buildNonChangingManifest() + Map entireMap = manifestPlugin.buildNonChangingManifest() jarTask.inputs.properties(entireMap) } diff --git a/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFile.groovy b/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFile.groovy index cd17821..c0d5a4b 100644 --- a/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFile.groovy +++ b/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFile.groovy @@ -31,7 +31,7 @@ class InfoPropertiesFile extends ConventionTask { Map getManifest() { InfoBrokerPlugin manifestPlugin = project.plugins.getPlugin(InfoBrokerPlugin) as InfoBrokerPlugin - def entireMap = manifestPlugin.buildNonChangingManifest() + Map entireMap = manifestPlugin.buildNonChangingManifest() return entireMap } @@ -40,15 +40,15 @@ class InfoPropertiesFile extends ConventionTask { File propertiesFile @TaskAction - def writeOut() { + void writeOut() { InfoBrokerPlugin basePlugin = project.plugins.getPlugin(InfoBrokerPlugin) as InfoBrokerPlugin // Gather all values, in contrast to buildNonChangingManifest - def attrs = basePlugin.buildManifest() + Map attrs = basePlugin.buildManifest() logger.info("Writing manifest values to ${getPropertiesFile()}") - def manifestStr = attrs.collect { "${it.key}=${it.value}"}.join('\n') + String manifestStr = attrs.collect { "${it.key}=${it.value}"}.join('\n') getPropertiesFile().text = manifestStr } } diff --git a/src/main/groovy/nebula/plugin/info/scm/AbstractScmProvider.groovy b/src/main/groovy/nebula/plugin/info/scm/AbstractScmProvider.groovy index d2ebcb2..81b1629 100644 --- a/src/main/groovy/nebula/plugin/info/scm/AbstractScmProvider.groovy +++ b/src/main/groovy/nebula/plugin/info/scm/AbstractScmProvider.groovy @@ -33,9 +33,9 @@ abstract class AbstractScmProvider implements ScmInfoProvider { return null } - def dirToLookIn = starting + File dirToLookIn = starting while(dirToLookIn) { - def p4configFile = new File(dirToLookIn, filename) + File p4configFile = new File(dirToLookIn, filename) if (p4configFile.exists()) { return p4configFile } diff --git a/src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy b/src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy index 8ebb5d8..6ffa17a 100644 --- a/src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy +++ b/src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy @@ -35,37 +35,35 @@ class GitScmProvider extends AbstractScmProvider { } @Override - def calculateModuleOrigin(File projectDir) { + String calculateModuleOrigin(File projectDir) { Repository repository = getRepository(projectDir) - Config storedConfig = repository.getConfig(); - String url = storedConfig.getString('remote', 'origin', 'url'); - return url + Config storedConfig = repository.getConfig() + return storedConfig.getString('remote', 'origin', 'url') } @Override - def calculateModuleSource(File projectDir) { + String calculateModuleSource(File projectDir) { Repository repository = getRepository(projectDir) - def gitDir = repository.directory - def relative = projectDir.absolutePath - gitDir.parentFile.absolutePath - return relative + File gitDir = repository.directory + return projectDir.absolutePath - gitDir.parentFile.absolutePath } @Override String calculateChange(File projectDir) { - def hash = System.getenv('GIT_COMMIT') // From Jenkins - if (hash==null) { + String hash = System.getenv('GIT_COMMIT') // From Jenkins + if (!hash) { def head = getRepository(projectDir).resolve(Constants.HEAD) if (!head) { return null } hash = head.name } - def shortHash = hash?.substring(0,7) + String shortHash = hash?.substring(0,7) return shortHash } @Override - def calculateBranch(File projectDir) { + String calculateBranch(File projectDir) { return getRepository(projectDir).branch } } diff --git a/src/main/groovy/nebula/plugin/info/scm/PerforceScmProvider.groovy b/src/main/groovy/nebula/plugin/info/scm/PerforceScmProvider.groovy index cacf8ce..bc3be4d 100644 --- a/src/main/groovy/nebula/plugin/info/scm/PerforceScmProvider.groovy +++ b/src/main/groovy/nebula/plugin/info/scm/PerforceScmProvider.groovy @@ -36,45 +36,16 @@ class PerforceScmProvider extends AbstractScmProvider { @Override String calculateModuleSource(File projectDir) { - def workspace = new File(System.getenv('WORKSPACE')) + File workspace = new File(System.getenv('WORKSPACE')) return calculateModuleSource(workspace, projectDir) } + String calculateModuleSource(File workspace, File projectDir) { // TODO Don't hardcode depot - def relativePath = projectDir.getAbsolutePath() - (workspace.getAbsolutePath() + '/') + String relativePath = projectDir.getAbsolutePath() - (workspace.getAbsolutePath() + '/') return "//depot/${relativePath}" -// withPerforce(projectDir) { IServer server, IClient client -> -// def relativePath = projectDir.getAbsolutePath() - (workspace.getAbsolutePath() + '/') -// List specs = FileSpecBuilder.makeFileSpecList(relativePath) -// List mapped = client.where(specs) -// mapped.each { IFileSpec spec -> -// println spec.getClientPathString() -// println spec.getDepotPathString() -// } -// } } -// def scmBase() { -// // TOOD use p4java instead of command line call -// Process process = "p4 workspace -o".execute(null, project.rootDir) -// def output = process.text // Potential save for later -// def matcher = output =~ /Root:\s+(\S+)\n/ -// if(matcher) { -// return matcher[0][1] -// } -// -// return null -// } -// /** -// * macro.xml -> viewFromPath -// */ -// def viewFromPath(File baseDir, String depot) { -// // TODO Previously used workspace, which then made a relative path from that location prepended with depot -// // We always knew workspace because if it wasn't provided we could -// baseDir.absoluteFile -// } - - @Override String calculateModuleOrigin(File projectDir) { Map defaults = perforceDefaults(projectDir) @@ -87,14 +58,14 @@ class PerforceScmProvider extends AbstractScmProvider { } @Override - def calculateBranch(File projectDir) { + String calculateBranch(File projectDir) { return null // unsupported in perforce } @PackageScope T withPerforce(File projectDir, Closure closure) { Map defaults = perforceDefaults(projectDir) - def uri = getUrl(defaults) + String uri = getUrl(defaults) IServer server = ServerFactory.getServer(uri, null); server.connect() if (defaults.P4PASSWD) { @@ -147,7 +118,7 @@ class PerforceScmProvider extends AbstractScmProvider { // First look for P4CONFIG name findP4Config(projectDir) // Might be noop if (p4configFile) { - def props = new Properties() + Properties props = new Properties() props.load(new FileReader(p4configFile)) defaults = overrideFromMap(defaults, props as Map) } diff --git a/src/main/groovy/nebula/plugin/info/scm/ScmInfoPlugin.groovy b/src/main/groovy/nebula/plugin/info/scm/ScmInfoPlugin.groovy index 96039bd..f5b37ed 100644 --- a/src/main/groovy/nebula/plugin/info/scm/ScmInfoPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/scm/ScmInfoPlugin.groovy @@ -65,7 +65,7 @@ class ScmInfoPlugin implements Plugin, InfoCollectorPlugin { } ScmInfoProvider findProvider() { - def provider = providers.find { it.supports(project) } + ScmInfoProvider provider = providers.find { it.supports(project) } if (provider) { return provider } else { diff --git a/src/main/groovy/nebula/plugin/info/scm/SvnScmProvider.groovy b/src/main/groovy/nebula/plugin/info/scm/SvnScmProvider.groovy index 5b87055..8ce3531 100644 --- a/src/main/groovy/nebula/plugin/info/scm/SvnScmProvider.groovy +++ b/src/main/groovy/nebula/plugin/info/scm/SvnScmProvider.groovy @@ -17,6 +17,7 @@ package nebula.plugin.info.scm import org.gradle.api.Project +import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions import org.tmatesoft.svn.core.wc.* class SvnScmProvider extends AbstractScmProvider { @@ -28,33 +29,29 @@ class SvnScmProvider extends AbstractScmProvider { } private SVNWCClient getWorkingCopyClient() { - def options = SVNWCUtil.createDefaultOptions(true); - def clientManager = SVNClientManager.newInstance(options); - def client = clientManager.getWCClient() - return client + DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true); + SVNClientManager clientManager = SVNClientManager.newInstance(options); + return clientManager.getWCClient() } private SVNInfo getInfo(File projectDir) { - def info = getWorkingCopyClient().doInfo(projectDir, SVNRevision.WORKING) - return info + return getWorkingCopyClient().doInfo(projectDir, SVNRevision.WORKING) } @Override - def calculateModuleOrigin(File projectDir) { - def url = getInfo(projectDir).getURL().toString() - return url + String calculateModuleOrigin(File projectDir) { + return getInfo(projectDir).getURL().toString() } @Override - def calculateModuleSource(File projectDir) { - def svnDir = getInfo(projectDir).getWorkingCopyRoot() - def relative = projectDir.absolutePath - svnDir.parentFile.absolutePath - return relative + String calculateModuleSource(File projectDir) { + File svnDir = getInfo(projectDir).getWorkingCopyRoot() + return projectDir.absolutePath - svnDir.parentFile.absolutePath } @Override String calculateChange(File projectDir) { - def revision = System.getenv('SVN_REVISION') // From Jenkins + String revision = System.getenv('SVN_REVISION') // From Jenkins if (!revision) { def base = getInfo(projectDir).getRevision() if (!base) { @@ -66,7 +63,7 @@ class SvnScmProvider extends AbstractScmProvider { } @Override - def calculateBranch(File projectDir) { + String calculateBranch(File projectDir) { return null // unsupported in svn } } diff --git a/src/main/groovy/nebula/plugin/info/scm/UnknownScmProvider.groovy b/src/main/groovy/nebula/plugin/info/scm/UnknownScmProvider.groovy index aa9a7fa..d2f6b1d 100644 --- a/src/main/groovy/nebula/plugin/info/scm/UnknownScmProvider.groovy +++ b/src/main/groovy/nebula/plugin/info/scm/UnknownScmProvider.groovy @@ -28,12 +28,12 @@ class UnknownScmProvider extends AbstractScmProvider { } @Override - def calculateModuleOrigin(File projectDir) { + String calculateModuleOrigin(File projectDir) { return LOCAL } @Override - def calculateModuleSource(File projectDir) { + String calculateModuleSource(File projectDir) { return projectDir.absolutePath } @@ -43,7 +43,7 @@ class UnknownScmProvider extends AbstractScmProvider { } @Override - def calculateBranch(File projectDir) { + String calculateBranch(File projectDir) { return null } }