Skip to content

Commit

Permalink
Add dynamic discovery of ical zoneinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed Jun 28, 2024
1 parent a18f2bf commit 9d703db
Showing 1 changed file with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
*/
package org.apache.camel.quarkus.component.ical.deployment;

import java.util.stream.Stream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.Properties;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
Expand All @@ -27,9 +30,10 @@
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import net.fortuna.ical4j.model.TimeZoneRegistryImpl;
import net.fortuna.ical4j.util.MapTimeZoneCache;
import org.jboss.logging.Logger;

class IcalProcessor {

private static final Logger LOG = Logger.getLogger(IcalProcessor.class);
private static final String FEATURE = "camel-ical";

@BuildStep
Expand All @@ -50,21 +54,23 @@ void nativeResources(

nativeResources.produce(new NativeImageResourceBuildItem("net/fortuna/ical4j/model/tz.alias"));

Stream.of("zoneinfo/Africa",
"zoneinfo/America",
"zoneinfo/America/Argentina",
"zoneinfo/America/Indiana",
"zoneinfo/America/Kentucky",
"zoneinfo/America/North_Dakota",
"zoneinfo/Antarctica",
"zoneinfo/Arctic",
"zoneinfo/Asia",
"zoneinfo/Atlantic",
"zoneinfo/Australia",
"zoneinfo/Europe",
"zoneinfo/Indian",
"zoneinfo/Pacific")
.forEach(path -> nativeResourceDirs.produce(new NativeImageResourceDirectoryBuildItem(path)));
try (InputStream stream = Thread.currentThread().getContextClassLoader()
.getResourceAsStream("net/fortuna/ical4j/model/tz.alias")) {
Properties timezoneData = new Properties();
timezoneData.load(stream);
timezoneData.values()
.stream()
.map(Objects::toString)
.map(timeZone -> timeZone.split("/")[0])
.distinct()
.forEach(region -> {
nativeResourceDirs.produce(new NativeImageResourceDirectoryBuildItem("zoneinfo/" + region));
nativeResourceDirs.produce(new NativeImageResourceDirectoryBuildItem("zoneinfo-global/" + region));
});

} catch (IOException e) {
throw new RuntimeException("Failed reading ical tz.alias");
}
}

@BuildStep
Expand Down

0 comments on commit 9d703db

Please sign in to comment.