From 462b0d9b420606f55bc5471a09717fb1c31353c7 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Fri, 13 Nov 2015 16:21:23 -0500 Subject: [PATCH] Include timezone in Build-Date and date format in basic info This commit changes the format of the Build-Date in the jar manifest to be formatted in ISO 8601 including the timezone offset. Additionally, for convenience, the format used to represent the Build-Date is included in the jar manifest. --- .../groovy/nebula/plugin/info/basic/BasicInfoPlugin.groovy | 5 ++++- .../reporting/InfoJarManifestPluginLauncherSpec.groovy | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/nebula/plugin/info/basic/BasicInfoPlugin.groovy b/src/main/groovy/nebula/plugin/info/basic/BasicInfoPlugin.groovy index 24421b6c..03e3927f 100644 --- a/src/main/groovy/nebula/plugin/info/basic/BasicInfoPlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/basic/BasicInfoPlugin.groovy @@ -16,6 +16,7 @@ import static java.util.jar.Attributes.Name.* *
  • Built-Status (project.status)
  • *
  • Built-By (user.name)
  • *
  • Build-Date
  • + *
  • Build-Date-Format
  • *
  • Gradle-Version (project.gradle.gradleVersion)
  • * */ @@ -48,8 +49,10 @@ class BasicInfoPlugin implements Plugin, InfoCollectorPlugin { manifestPlugin.add('Built-By', System.getProperty('user.name')) manifestPlugin.add('Built-OS', System.getProperty('os.name')) + String buildDateFormat = "yyyy-MM-dd'T'HH:mm:ssXXX" // 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', new Date().format(buildDateFormat)).changing = true + manifestPlugin.add('Build-Date-Format', buildDateFormat) manifestPlugin.add('Gradle-Version', { project.gradle.gradleVersion }) diff --git a/src/test/groovy/nebula/plugin/info/reporting/InfoJarManifestPluginLauncherSpec.groovy b/src/test/groovy/nebula/plugin/info/reporting/InfoJarManifestPluginLauncherSpec.groovy index 6ed7d547..033458a3 100644 --- a/src/test/groovy/nebula/plugin/info/reporting/InfoJarManifestPluginLauncherSpec.groovy +++ b/src/test/groovy/nebula/plugin/info/reporting/InfoJarManifestPluginLauncherSpec.groovy @@ -4,6 +4,7 @@ import nebula.plugin.info.InfoBrokerPlugin import nebula.plugin.info.basic.BasicInfoPlugin import nebula.test.IntegrationSpec +import java.text.SimpleDateFormat import java.util.jar.Attributes import java.util.jar.JarFile import java.util.jar.Manifest @@ -83,6 +84,12 @@ class InfoJarManifestPluginLauncherSpec extends IntegrationSpec { assertMainfestKeyExists(attributes, 'Built-By') assertMainfestKeyExists(attributes, 'Built-OS') assertMainfestKeyExists(attributes, 'Build-Date') + assertMainfestKeyExists(attributes, 'Build-Date-Format') + // ensure that the Build-Date can be parsed and the parsed Date formats to the Build-Date + SimpleDateFormat sdf = new SimpleDateFormat(manifestKey(attributes, 'Build-Date-Format')) + String manifestBuildDate = manifestKey(attributes, 'Build-Date') + Date buildDate = sdf.parse(manifestBuildDate) + sdf.format(buildDate) == manifestBuildDate assertMainfestKeyExists(attributes, 'Gradle-Version') }