From abd3ffb1c7ec612eed55c8dbbcd5668e6df459fb Mon Sep 17 00:00:00 2001 From: Danny Thomas Date: Thu, 27 Aug 2020 10:36:15 +1000 Subject: [PATCH] Also apply property ignores to metaInf normalization --- .../nebula/plugin/info/InfoPlugin.groovy | 24 ++++++++++++ .../reporting/InfoJarManifestPlugin.groovy | 37 +++---------------- .../InfoJarPropertiesFilePlugin.groovy | 18 +++++++++ 3 files changed, 47 insertions(+), 32 deletions(-) diff --git a/src/main/groovy/nebula/plugin/info/InfoPlugin.groovy b/src/main/groovy/nebula/plugin/info/InfoPlugin.groovy index 030f307..bf40c15 100644 --- a/src/main/groovy/nebula/plugin/info/InfoPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/InfoPlugin.groovy @@ -33,6 +33,30 @@ import org.gradle.api.Project */ class InfoPlugin implements Plugin { + public static final List NORMALIZATION_IGNORED_PROPERTY_NAMES = [ + 'Module-Owner', + 'Module-Email', + 'Nebula-Version', + BasicInfoPlugin.BUILT_BY_PROPERTY, + BasicInfoPlugin.BUILT_OS_PROPERTY, + BasicInfoPlugin.BUILD_DATE_PROPERTY, + BasicInfoPlugin.GRADLE_VERSION_PROPERTY, + BasicInfoPlugin.BUILD_STATUS_PROPERTY, + InfoJavaPlugin.CREATED_PROPERTY, + InfoJavaPlugin.JDK_PROPERTY, + InfoJavaPlugin.SOURCE_PROPERTY, + InfoJavaPlugin.TARGET_PROPERTY, + ContinuousIntegrationInfoPlugin.BUILD_NUMBER_PROPERTY, + ContinuousIntegrationInfoPlugin.BUILD_HOST_PROPERTY, + ContinuousIntegrationInfoPlugin.BUILD_JOB_PROPERTY, + ContinuousIntegrationInfoPlugin.BUILD_ID_PROPERTY, + ScmInfoPlugin.MODULE_SOURCE_PROPERTY, + ScmInfoPlugin.MODULE_ORIGIN_PROPERTY, + ScmInfoPlugin.CHANGE_PROPERTY, + ScmInfoPlugin.FULL_CHANGE_PROPERTY, + ScmInfoPlugin.BRANCH_PROPERTY + ] as List + void apply(Project project) { // Broker diff --git a/src/main/groovy/nebula/plugin/info/reporting/InfoJarManifestPlugin.groovy b/src/main/groovy/nebula/plugin/info/reporting/InfoJarManifestPlugin.groovy index 0e1bd53..99182ae 100644 --- a/src/main/groovy/nebula/plugin/info/reporting/InfoJarManifestPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/reporting/InfoJarManifestPlugin.groovy @@ -18,11 +18,8 @@ package nebula.plugin.info.reporting import com.netflix.nebula.interop.GradleKt import nebula.plugin.info.InfoBrokerPlugin +import nebula.plugin.info.InfoPlugin import nebula.plugin.info.InfoReporterPlugin -import nebula.plugin.info.basic.BasicInfoPlugin -import nebula.plugin.info.ci.ContinuousIntegrationInfoPlugin -import nebula.plugin.info.java.InfoJavaPlugin -import nebula.plugin.info.scm.ScmInfoPlugin import org.gradle.api.Action import org.gradle.api.Plugin import org.gradle.api.Project @@ -35,51 +32,27 @@ import org.gradle.normalization.MetaInfNormalization */ class InfoJarManifestPlugin implements Plugin, InfoReporterPlugin { - private static final List ATTRIBUTES_TO_IGNORE_FOR_META_INF_NORMALIZATION = [ - 'Module-Owner', - 'Module-Email', - 'Nebula-Version', - BasicInfoPlugin.BUILT_BY_PROPERTY, - BasicInfoPlugin.BUILT_OS_PROPERTY, - BasicInfoPlugin.BUILD_DATE_PROPERTY, - BasicInfoPlugin.GRADLE_VERSION_PROPERTY, - BasicInfoPlugin.BUILD_STATUS_PROPERTY, - InfoJavaPlugin.CREATED_PROPERTY, - InfoJavaPlugin.JDK_PROPERTY, - InfoJavaPlugin.SOURCE_PROPERTY, - InfoJavaPlugin.TARGET_PROPERTY, - ContinuousIntegrationInfoPlugin.BUILD_NUMBER_PROPERTY, - ContinuousIntegrationInfoPlugin.BUILD_HOST_PROPERTY, - ContinuousIntegrationInfoPlugin.BUILD_JOB_PROPERTY, - ContinuousIntegrationInfoPlugin.BUILD_ID_PROPERTY, - ScmInfoPlugin.MODULE_SOURCE_PROPERTY, - ScmInfoPlugin.MODULE_ORIGIN_PROPERTY, - ScmInfoPlugin.CHANGE_PROPERTY, - ScmInfoPlugin.FULL_CHANGE_PROPERTY, - ScmInfoPlugin.BRANCH_PROPERTY - ] as List - void apply(Project project) { 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).configureEach { Jar jarTask -> jarTask.doFirst { - Map attrs = manifestPlugin.buildManifest() + Map attrs = manifestPlugin.buildManifest() jarTask.manifest.attributes.putAll(attrs) } } - if(GradleKt.versionGreaterThan(project.gradle, "6.6-rc-1")) { + if (GradleKt.versionGreaterThan(project.gradle, "6.6-rc-1")) { configureMetaInfNormalization(project) } } } - private void configureMetaInfNormalization(Project project) { + private static void configureMetaInfNormalization(Project project) { project.normalization.runtimeClasspath.metaInf(new Action() { @Override void execute(MetaInfNormalization metaInfNormalization) { - ATTRIBUTES_TO_IGNORE_FOR_META_INF_NORMALIZATION.each { attribute -> + InfoPlugin.NORMALIZATION_IGNORED_PROPERTY_NAMES.each { attribute -> metaInfNormalization.ignoreAttribute(attribute) } } diff --git a/src/main/groovy/nebula/plugin/info/reporting/InfoJarPropertiesFilePlugin.groovy b/src/main/groovy/nebula/plugin/info/reporting/InfoJarPropertiesFilePlugin.groovy index 6036966..c05e949 100644 --- a/src/main/groovy/nebula/plugin/info/reporting/InfoJarPropertiesFilePlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/reporting/InfoJarPropertiesFilePlugin.groovy @@ -16,15 +16,19 @@ package nebula.plugin.info.reporting +import com.netflix.nebula.interop.GradleKt import groovy.transform.CompileDynamic import nebula.plugin.info.InfoBrokerPlugin +import nebula.plugin.info.InfoPlugin import nebula.plugin.info.InfoReporterPlugin +import org.gradle.api.Action import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.file.CopySpec import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.bundling.Jar +import org.gradle.normalization.MetaInfNormalization /** * Inject a properties file into the jar file will the info values, using the InfoPropertiesFilePlugin @@ -68,6 +72,20 @@ class InfoJarPropertiesFilePlugin implements Plugin, InfoReporterPlugin } } + if (GradleKt.versionGreaterThan(project.gradle, "6.6-rc-1")) { + configureMetaInfNormalization(project) + } } } + + private static void configureMetaInfNormalization(Project project) { + project.normalization.runtimeClasspath.metaInf(new Action() { + @Override + void execute(MetaInfNormalization metaInfNormalization) { + InfoPlugin.NORMALIZATION_IGNORED_PROPERTY_NAMES.each { attribute -> + metaInfNormalization.ignoreProperty(attribute) + } + } + }) + } } \ No newline at end of file