Skip to content

Commit

Permalink
Merge pull request #78 from nebula-plugins/dannyt-normalize-properties
Browse files Browse the repository at this point in the history
Also apply property ignores to metaInf normalization
  • Loading branch information
DanielThomas authored Aug 27, 2020
2 parents af3bb1e + abd3ffb commit 04a5316
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 32 deletions.
24 changes: 24 additions & 0 deletions src/main/groovy/nebula/plugin/info/InfoPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,30 @@ import org.gradle.api.Project
*/
class InfoPlugin implements Plugin<Project> {

public static final List<String> 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<String>

void apply(Project project) {

// Broker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,51 +32,27 @@ import org.gradle.normalization.MetaInfNormalization
*/
class InfoJarManifestPlugin implements Plugin<Project>, InfoReporterPlugin {

private static final List<String> 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<String>

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<String,String> attrs = manifestPlugin.buildManifest()
Map<String, String> 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<MetaInfNormalization>() {
@Override
void execute(MetaInfNormalization metaInfNormalization) {
ATTRIBUTES_TO_IGNORE_FOR_META_INF_NORMALIZATION.each { attribute ->
InfoPlugin.NORMALIZATION_IGNORED_PROPERTY_NAMES.each { attribute ->
metaInfNormalization.ignoreAttribute(attribute)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,6 +72,20 @@ class InfoJarPropertiesFilePlugin implements Plugin<Project>, InfoReporterPlugin
}
}

if (GradleKt.versionGreaterThan(project.gradle, "6.6-rc-1")) {
configureMetaInfNormalization(project)
}
}
}

private static void configureMetaInfNormalization(Project project) {
project.normalization.runtimeClasspath.metaInf(new Action<MetaInfNormalization>() {
@Override
void execute(MetaInfNormalization metaInfNormalization) {
InfoPlugin.NORMALIZATION_IGNORED_PROPERTY_NAMES.each { attribute ->
metaInfNormalization.ignoreProperty(attribute)
}
}
})
}
}

0 comments on commit 04a5316

Please sign in to comment.