From e32c01a21d8be889fc8faf33bf18b8525d656bd9 Mon Sep 17 00:00:00 2001 From: Jaikiran Pai Date: Fri, 8 Nov 2019 11:50:02 +0530 Subject: [PATCH] Introduce ability to specify which timezones to include in the native-image --- .../svm/core/jdk/TimeZoneSubstitutions.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/TimeZoneSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/TimeZoneSubstitutions.java index 133e61b06e88..1fca7379397a 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/TimeZoneSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/TimeZoneSubstitutions.java @@ -76,18 +76,27 @@ public static TimeZone getTimeZone(String id) { @AutomaticFeature final class TimeZoneFeature implements Feature { static class Options { + private static final TimeZone defaultZone = TimeZone.getDefault(); + @Option(help = "When true, all time zones will be pre-initialized in the image.")// public static final HostedOptionKey IncludeAllTimeZones = new HostedOptionKey<>(false); + + @Option(help = "The time zones, in addition to the default zone of the host, that will be pre-initialized in the image.")// + public static final HostedOptionKey IncludeTimeZones = new HostedOptionKey<>(new String[]{"GMT", "UTC", defaultZone.getID()}); } @Override public void afterRegistration(AfterRegistrationAccess access) { - TimeZone defaultZone = TimeZone.getDefault(); - String[] supportedZoneIDs = Options.IncludeAllTimeZones.getValue() ? TimeZone.getAvailableIDs() : new String[]{"GMT", "UTC", defaultZone.getID()}; + final String[] supportedZoneIDs; + if (Options.IncludeAllTimeZones.getValue()) { + supportedZoneIDs = TimeZone.getAvailableIDs(); + } else { + supportedZoneIDs = Options.IncludeTimeZones.getValue(); + } Map supportedZones = Arrays.stream(supportedZoneIDs) .map(TimeZone::getTimeZone) .collect(toMap(TimeZone::getID, tz -> tz, (tz1, tz2) -> tz1)); - ImageSingletons.add(TimeZoneSupport.class, new TimeZoneSupport(supportedZones, defaultZone)); + ImageSingletons.add(TimeZoneSupport.class, new TimeZoneSupport(supportedZones, Options.defaultZone)); } }