From 9141af7fc12bdff12b3050ac14a7fb39255221bc Mon Sep 17 00:00:00 2001 From: Appu Goundan Date: Mon, 9 Mar 2020 12:10:34 -0400 Subject: [PATCH 1/7] Allow more timezone formats --- .../common/PluginConfigurationProcessor.java | 17 +++++++++++-- .../PluginConfigurationProcessorTest.java | 25 ++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java b/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java index 19341e3573..f9734c6e0e 100644 --- a/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java +++ b/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java @@ -44,6 +44,7 @@ import java.nio.file.Paths; import java.time.Instant; import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; import java.time.format.DateTimeParseException; import java.util.ArrayList; import java.util.HashSet; @@ -730,9 +731,21 @@ static Instant getCreationTime(String configuredCreationTime, ProjectProperties return Instant.now(); default: - return DateTimeFormatter.ISO_DATE_TIME.parse(configuredCreationTime, Instant::from); + DateTimeFormatter formatter = + new DateTimeFormatterBuilder() + .append(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + .optionalStart() + .appendOffset("+HH:MM", "+00:00") + .optionalEnd() + .optionalStart() + .appendOffset("+HHMM", "+0000") + .optionalEnd() + .optionalStart() + .appendOffset("+HH", "Z") + .optionalEnd() + .toFormatter(); + return formatter.parse(configuredCreationTime, Instant::from); } - } catch (DateTimeParseException ex) { throw new InvalidCreationTimeException(configuredCreationTime, configuredCreationTime, ex); } diff --git a/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java b/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java index 2c4ad9813a..b6b122c755 100644 --- a/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java +++ b/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java @@ -30,6 +30,7 @@ import com.google.cloud.tools.jib.api.RegistryImage; import com.google.cloud.tools.jib.configuration.BuildContext; import com.google.cloud.tools.jib.configuration.ImageConfiguration; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.io.Resources; @@ -908,11 +909,27 @@ public void testGetCreationTime_useCurrentTimestamp() throws InvalidCreationTime @Test public void testGetCreationTime_isoDateTimeValue() throws InvalidCreationTimeException { - Instant time = - PluginConfigurationProcessor.getCreationTime( - "2011-12-03T10:15:30+09:00", projectProperties); Instant expected = DateTimeFormatter.ISO_DATE_TIME.parse("2011-12-03T01:15:30Z", Instant::from); - Assert.assertEquals(expected, time); + List validTimeStamps = + ImmutableList.of( + "2011-12-03T10:15:30+09:00", + "2011-12-03T10:15:30+0900", + "2011-12-03T10:15:30+09", + "2011-12-03T01:15:30Z"); + for (String timeString : validTimeStamps) { + Instant time = PluginConfigurationProcessor.getCreationTime(timeString, projectProperties); + Assert.assertEquals(expected, time); + } + } + + @Test + public void testGetCreationTime_isoDateTimeValueRequiresTimeZone() { + try { + PluginConfigurationProcessor.getCreationTime("2011-12-03T01:15:30", projectProperties); + Assert.fail("creationTime should fail if timezone not specified"); + } catch (InvalidCreationTimeException ex) { + // pass + } } @Test From 38c5577ccac0e05ebd23f8c6dae743ea04cf8c10 Mon Sep 17 00:00:00 2001 From: Appu Goundan Date: Mon, 9 Mar 2020 15:39:20 -0400 Subject: [PATCH 2/7] Support full iso6801 and increase test coverage --- .../common/PluginConfigurationProcessor.java | 10 ++++++++ .../PluginConfigurationProcessorTest.java | 23 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java b/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java index f9734c6e0e..67e0f10ff8 100644 --- a/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java +++ b/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java @@ -733,13 +733,23 @@ static Instant getCreationTime(String configuredCreationTime, ProjectProperties default: DateTimeFormatter formatter = new DateTimeFormatterBuilder() + .parseCaseInsensitive() .append(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + // iso 8601 strict .optionalStart() .appendOffset("+HH:MM", "+00:00") + .optionalStart() + .appendLiteral('[') + .parseCaseSensitive() + .appendZoneRegionId() + .appendLiteral(']') + .optionalEnd() .optionalEnd() + // with no ":" in tz .optionalStart() .appendOffset("+HHMM", "+0000") .optionalEnd() + // 2 digit or Z (zero) .optionalStart() .appendOffset("+HH", "Z") .optionalEnd() diff --git a/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java b/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java index b6b122c755..fdeb316c74 100644 --- a/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java +++ b/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java @@ -913,12 +913,33 @@ public void testGetCreationTime_isoDateTimeValue() throws InvalidCreationTimeExc List validTimeStamps = ImmutableList.of( "2011-12-03T10:15:30+09:00", + "2011-12-03T10:15:30+09:00[Asia/Tokyo]", + "2011-12-02T16:15:30-09:00", "2011-12-03T10:15:30+0900", + "2011-12-02T16:15:30-0900", "2011-12-03T10:15:30+09", + "2011-12-02T16:15:30-09", "2011-12-03T01:15:30Z"); for (String timeString : validTimeStamps) { Instant time = PluginConfigurationProcessor.getCreationTime(timeString, projectProperties); - Assert.assertEquals(expected, time); + Assert.assertEquals("for " + timeString, expected, time); + } + } + + @Test + public void testGetCreationTime_isoDateTimeValueTimeZoneRegionOnlyAllowedForMostStrict8601Mode() { + List invalidTimeStamps = + ImmutableList.of( + "2011-12-03T01:15:30+0900[Asia/Tokyo]", "2011-12-03T01:15:30+09[Asia/Tokyo]"); + for (String timeString : invalidTimeStamps) { + try { + PluginConfigurationProcessor.getCreationTime(timeString, projectProperties); + Assert.fail( + "creationTime should fail if region specified when zone not in HH:MM mode - " + + timeString); + } catch (InvalidCreationTimeException ex) { + // pass + } } } From a1d74145917592fe1029896c9ed096711cb0022f Mon Sep 17 00:00:00 2001 From: Appu Goundan Date: Mon, 9 Mar 2020 20:04:19 -0400 Subject: [PATCH 3/7] do a better job of custom parser --- .../common/PluginConfigurationProcessor.java | 21 +++---------------- .../PluginConfigurationProcessorTest.java | 10 ++++++++- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java b/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java index 67e0f10ff8..27da67d386 100644 --- a/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java +++ b/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java @@ -733,25 +733,10 @@ static Instant getCreationTime(String configuredCreationTime, ProjectProperties default: DateTimeFormatter formatter = new DateTimeFormatterBuilder() - .parseCaseInsensitive() - .append(DateTimeFormatter.ISO_LOCAL_DATE_TIME) - // iso 8601 strict + .append(DateTimeFormatter.ISO_DATE_TIME) // parses isoStrict + // add ability to parse with no ":" in tz .optionalStart() - .appendOffset("+HH:MM", "+00:00") - .optionalStart() - .appendLiteral('[') - .parseCaseSensitive() - .appendZoneRegionId() - .appendLiteral(']') - .optionalEnd() - .optionalEnd() - // with no ":" in tz - .optionalStart() - .appendOffset("+HHMM", "+0000") - .optionalEnd() - // 2 digit or Z (zero) - .optionalStart() - .appendOffset("+HH", "Z") + .appendOffset("+HHmm", "+0000") .optionalEnd() .toFormatter(); return formatter.parse(configuredCreationTime, Instant::from); diff --git a/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java b/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java index fdeb316c74..3219dc5721 100644 --- a/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java +++ b/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java @@ -43,6 +43,7 @@ import java.nio.file.Paths; import java.time.Instant; import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAccessor; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -934,6 +935,9 @@ public void testGetCreationTime_isoDateTimeValueTimeZoneRegionOnlyAllowedForMost for (String timeString : invalidTimeStamps) { try { PluginConfigurationProcessor.getCreationTime(timeString, projectProperties); + // this is the expected behavior, not specifically designed like this for any reason, feel + // free to change this + // behavior and update the test Assert.fail( "creationTime should fail if region specified when zone not in HH:MM mode - " + timeString); @@ -945,9 +949,13 @@ public void testGetCreationTime_isoDateTimeValueTimeZoneRegionOnlyAllowedForMost @Test public void testGetCreationTime_isoDateTimeValueRequiresTimeZone() { + TemporalAccessor x = DateTimeFormatter.ISO_DATE_TIME.parse("2011-12-03T01:15:30"); try { PluginConfigurationProcessor.getCreationTime("2011-12-03T01:15:30", projectProperties); - Assert.fail("creationTime should fail if timezone not specified"); + // this is the expected behavior, not specifically designed like this for any reason, feel + // free to change this + // behavior and update the test + Assert.fail("getCreationTime should fail if timezone not specified"); } catch (InvalidCreationTimeException ex) { // pass } From 1ded47da8061e040faaf8c4f8a5672093ac1cdba Mon Sep 17 00:00:00 2001 From: Appu Goundan Date: Tue, 10 Mar 2020 00:03:23 -0400 Subject: [PATCH 4/7] cleanup --- .../plugins/common/PluginConfigurationProcessorTest.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java b/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java index 3219dc5721..dbc9d6f0fa 100644 --- a/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java +++ b/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java @@ -43,7 +43,6 @@ import java.nio.file.Paths; import java.time.Instant; import java.time.format.DateTimeFormatter; -import java.time.temporal.TemporalAccessor; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -936,8 +935,7 @@ public void testGetCreationTime_isoDateTimeValueTimeZoneRegionOnlyAllowedForMost try { PluginConfigurationProcessor.getCreationTime(timeString, projectProperties); // this is the expected behavior, not specifically designed like this for any reason, feel - // free to change this - // behavior and update the test + // free to change this behavior and update the test Assert.fail( "creationTime should fail if region specified when zone not in HH:MM mode - " + timeString); @@ -949,12 +947,10 @@ public void testGetCreationTime_isoDateTimeValueTimeZoneRegionOnlyAllowedForMost @Test public void testGetCreationTime_isoDateTimeValueRequiresTimeZone() { - TemporalAccessor x = DateTimeFormatter.ISO_DATE_TIME.parse("2011-12-03T01:15:30"); try { PluginConfigurationProcessor.getCreationTime("2011-12-03T01:15:30", projectProperties); // this is the expected behavior, not specifically designed like this for any reason, feel - // free to change this - // behavior and update the test + // free to change this behavior and update the test Assert.fail("getCreationTime should fail if timezone not specified"); } catch (InvalidCreationTimeException ex) { // pass From 6dc5a2e8f384295aa84ec1663517e8d32d4e0711 Mon Sep 17 00:00:00 2001 From: Appu Goundan Date: Tue, 10 Mar 2020 14:21:45 -0400 Subject: [PATCH 5/7] Update CHANGELOG --- jib-gradle-plugin/CHANGELOG.md | 1 + jib-maven-plugin/CHANGELOG.md | 1 + 2 files changed, 2 insertions(+) diff --git a/jib-gradle-plugin/CHANGELOG.md b/jib-gradle-plugin/CHANGELOG.md index 0821ca7787..53282823a7 100644 --- a/jib-gradle-plugin/CHANGELOG.md +++ b/jib-gradle-plugin/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ### Added ### Changed +- `jib.container.creationTime` now accepts more timezone formats:`Z`,`+HHmm`. ([#2320](https://github.com/GoogleContainerTools/jib/issues/2260)) ### Fixed diff --git a/jib-maven-plugin/CHANGELOG.md b/jib-maven-plugin/CHANGELOG.md index acce57fe5b..1be83e7879 100644 --- a/jib-maven-plugin/CHANGELOG.md +++ b/jib-maven-plugin/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ### Added ### Changed +- `` now accepts more timezone formats:`Z`,`+HHmm`. ([#2320](https://github.com/GoogleContainerTools/jib/issues/2260)) ### Fixed From 9c9dc1bc91a49a3ba4901d5cbfcd8fa60cf681ff Mon Sep 17 00:00:00 2001 From: Appu Date: Thu, 12 Mar 2020 11:36:26 -0400 Subject: [PATCH 6/7] Update CHANGELOG.md --- jib-maven-plugin/CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jib-maven-plugin/CHANGELOG.md b/jib-maven-plugin/CHANGELOG.md index 1be83e7879..612aee55e3 100644 --- a/jib-maven-plugin/CHANGELOG.md +++ b/jib-maven-plugin/CHANGELOG.md @@ -6,13 +6,15 @@ All notable changes to this project will be documented in this file. ### Added ### Changed -- `` now accepts more timezone formats:`Z`,`+HHmm`. ([#2320](https://github.com/GoogleContainerTools/jib/issues/2260)) + +- `` now accepts more timezone formats:`+HHmm`. This allows for easier configuration of creationTime by external systems. ([#2320](https://github.com/GoogleContainerTools/jib/issues/2320)) ### Fixed ## 2.1.0 ### Added + - Additionally reads credentials from `~/.docker/.dockerconfigjson` and legacy Docker config (`~/.docker/.dockercfg`). Also searches for `$HOME/.docker/*` (in addition to current `System.get("user.home")/.docker/*`). This may help retrieve credentials, for example, on Kubernetes. ([#2260](https://github.com/GoogleContainerTools/jib/issues/2260)) - New skaffold configuration options that modify how jib's build config is presented to skaffold ([#2292](https://github.com/GoogleContainerTools/jib/pull/2292)): - ``: a list of build files to watch From cad1fe9bcd40ff3a38f33140549ec9277692985d Mon Sep 17 00:00:00 2001 From: Appu Date: Thu, 12 Mar 2020 11:37:14 -0400 Subject: [PATCH 7/7] Update CHANGELOG.md --- jib-gradle-plugin/CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jib-gradle-plugin/CHANGELOG.md b/jib-gradle-plugin/CHANGELOG.md index 53282823a7..37a8e450cc 100644 --- a/jib-gradle-plugin/CHANGELOG.md +++ b/jib-gradle-plugin/CHANGELOG.md @@ -6,13 +6,15 @@ All notable changes to this project will be documented in this file. ### Added ### Changed -- `jib.container.creationTime` now accepts more timezone formats:`Z`,`+HHmm`. ([#2320](https://github.com/GoogleContainerTools/jib/issues/2260)) + +- `jib.container.creationTime` now accepts more timezone formats:`+HHmm`. This allows for easier configuration of creationTime by external systems. ([#2320](https://github.com/GoogleContainerTools/jib/issues/2320)) ### Fixed ## 2.1.0 ### Added + - Additionally reads credentials from `~/.docker/.dockerconfigjson` and legacy Docker config (`~/.docker/.dockercfg`). Also searches for `$HOME/.docker/*` (in addition to current `System.get("user.home")/.docker/*`). This may help retrieve credentials, for example, on Kubernetes. ([#2260](https://github.com/GoogleContainerTools/jib/issues/2260)) - New skaffold configuration options that modify how jib's build config is presented to skaffold ([#2292](https://github.com/GoogleContainerTools/jib/pull/2292)): - `jib.skaffold.watch.buildIncludes`: a list of build files to watch