make/tools/src/build/tools/tzdb/TzdbZoneRulesCompiler.java

Print this page

        

@@ -225,10 +225,11 @@
     private static void process(List<File> srcDirs, List<String> srcFileNames, File dstDir, String version, boolean verbose) {
         // build actual jar files
         Map<String, SortedMap<String, ZoneRules>> allBuiltZones = new TreeMap<>();
         Set<String> allRegionIds = new TreeSet<String>();
         Set<ZoneRules> allRules = new HashSet<ZoneRules>();
+        Map<String, Map<String, String>> allLinks = new TreeMap<>();
 
         for (File srcDir : srcDirs) {
             // source files in this directory
             List<File> srcFiles = new ArrayList<>();
             for (String srcFileName : srcFileNames) {

@@ -240,11 +241,12 @@
             if (srcFiles.isEmpty()) {
                 continue;  // nothing to process
             }
 
             // compile
-            String loopVersion = srcDir.getName();
+            String loopVersion = (srcDirs.size() == 1 && version != null)
+                                 ? version : srcDir.getName();
             TzdbZoneRulesCompiler compiler = new TzdbZoneRulesCompiler(loopVersion, srcFiles, verbose);
             try {
                 // compile
                 compiler.compile();
                 SortedMap<String, ZoneRules> builtZones = compiler.getZones();

@@ -253,16 +255,17 @@
                 File dstFile = version == null ? new File(dstDir, "tzdb" + loopVersion + ".jar")
                                                : new File(dstDir, "tzdb.jar");
                 if (verbose) {
                     System.out.println("Outputting file: " + dstFile);
                 }
-                outputFile(dstFile, loopVersion, builtZones);
+                outputFile(dstFile, loopVersion, builtZones, compiler.links);
 
                 // create totals
                 allBuiltZones.put(loopVersion, builtZones);
                 allRegionIds.addAll(builtZones.keySet());
                 allRules.addAll(builtZones.values());
+                allLinks.put(loopVersion, compiler.links);
             } catch (Exception ex) {
                 System.out.println("Failed: " + ex.toString());
                 ex.printStackTrace();
                 System.exit(1);
             }

@@ -272,37 +275,40 @@
         if (version == null) {
             File dstFile = new File(dstDir, "tzdb-all.jar");
             if (verbose) {
                 System.out.println("Outputting combined file: " + dstFile);
             }
-            outputFile(dstFile, allBuiltZones, allRegionIds, allRules);
+            outputFile(dstFile, allBuiltZones, allRegionIds, allRules, allLinks);
         }
     }
 
     /**
      * Outputs the file.
      */
     private static void outputFile(File dstFile,
                                    String version,
-                                   SortedMap<String, ZoneRules> builtZones) {
+                                   SortedMap<String, ZoneRules> builtZones,
+                                   Map<String, String> links) {
         Map<String, SortedMap<String, ZoneRules>> loopAllBuiltZones = new TreeMap<>();
         loopAllBuiltZones.put(version, builtZones);
         Set<String> loopAllRegionIds = new TreeSet<String>(builtZones.keySet());
         Set<ZoneRules> loopAllRules = new HashSet<ZoneRules>(builtZones.values());
-        outputFile(dstFile, loopAllBuiltZones, loopAllRegionIds, loopAllRules);
+        Map<String, Map<String, String>> loopAllLinks = new TreeMap<>();
+        loopAllLinks.put(version, links);
+        outputFile(dstFile, loopAllBuiltZones, loopAllRegionIds, loopAllRules, loopAllLinks);
     }
 
     /**
      * Outputs the file.
      */
     private static void outputFile(File dstFile,
                                    Map<String, SortedMap<String, ZoneRules>> allBuiltZones,
                                    Set<String> allRegionIds,
-                                   Set<ZoneRules> allRules)
-    {
+                                   Set<ZoneRules> allRules,
+                                   Map<String, Map<String, String>> allLinks) {
         try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(dstFile))) {
-            outputTZEntry(jos, allBuiltZones, allRegionIds, allRules);
+            outputTZEntry(jos, allBuiltZones, allRegionIds, allRules, allLinks);
         } catch (Exception ex) {
             System.out.println("Failed: " + ex.toString());
             ex.printStackTrace();
             System.exit(1);
         }

@@ -312,11 +318,12 @@
      * Outputs the timezone entry in the JAR file.
      */
     private static void outputTZEntry(JarOutputStream jos,
                                       Map<String, SortedMap<String, ZoneRules>> allBuiltZones,
                                       Set<String> allRegionIds,
-                                      Set<ZoneRules> allRules) {
+                                      Set<ZoneRules> allRules,
+                                      Map<String, Map<String, String>> allLinks) {
         // this format is not publicly specified
         try {
             jos.putNextEntry(new ZipEntry("TZDB.dat"));
             DataOutputStream out = new DataOutputStream(jos);
 

@@ -357,10 +364,20 @@
                      int rulesIndex = rulesList.indexOf(entry.getValue());
                      out.writeShort(regionIndex);
                      out.writeShort(rulesIndex);
                 }
             }
+            // alias-region
+            for (String version : allLinks.keySet()) {
+                out.writeShort(allLinks.get(version).size());
+                for (Map.Entry<String, String> entry : allLinks.get(version).entrySet()) {
+                     int aliasIndex = Arrays.binarySearch(regionArray, entry.getKey());
+                     int regionIndex = Arrays.binarySearch(regionArray, entry.getValue());
+                     out.writeShort(aliasIndex);
+                     out.writeShort(regionIndex);
+                }
+            }
             out.flush();
             jos.closeEntry();
         } catch (Exception ex) {
             System.out.println("Failed: " + ex.toString());
             ex.printStackTrace();

@@ -619,11 +636,12 @@
     }
 
     private int parseYear(String str, int defaultYear) {
         if (YEAR.reset(str).matches()) {
             if (YEAR.group("min") != null) {
-                return YEAR_MIN_VALUE;
+                //return YEAR_MIN_VALUE;
+                return 1900;  // systemv has min
             } else if (YEAR.group("max") != null) {
                 return YEAR_MAX_VALUE;
             } else if (YEAR.group("only") != null) {
                 return defaultYear;
             }

@@ -740,20 +758,24 @@
                 printVerbose("Relinking alias " + aliasId + " to " + realId);
                 realRules = builtZones.get(realId);
                 if (realRules == null) {
                     throw new IllegalArgumentException("Alias '" + aliasId + "' links to invalid zone '" + realId + "' for '" + version + "'");
                 }
+                links.put(aliasId, realId);
+
             }
             builtZones.put(aliasId, realRules);
         }
 
         // remove UTC and GMT
-        builtZones.remove("UTC");
-        builtZones.remove("GMT");
-        builtZones.remove("GMT0");
+        //builtZones.remove("UTC");
+        //builtZones.remove("GMT");
+        //builtZones.remove("GMT0");
         builtZones.remove("GMT+0");
         builtZones.remove("GMT-0");
+        links.remove("GMT+0");
+        links.remove("GMT-0");
     }
 
     //-----------------------------------------------------------------------
     /**
      * Prints a verbose message.

@@ -783,11 +805,10 @@
         LocalTime time = LocalTime.MIDNIGHT;
         /** Whether this is midnight end of day. */
         boolean endOfDay;
         /** The time of the cutover. */
         TimeDefinition timeDefinition = TimeDefinition.WALL;
-
         void adjustToFowards(int year) {
             if (adjustForwards == false && dayOfMonth > 0) {
                 LocalDate adjustedDate = LocalDate.of(year, month, dayOfMonth).minusDays(6);
                 dayOfMonth = adjustedDate.getDayOfMonth();
                 month = adjustedDate.getMonth();