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

Print this page

        

*** 225,234 **** --- 225,235 ---- 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,250 **** if (srcFiles.isEmpty()) { continue; // nothing to process } // compile ! String loopVersion = srcDir.getName(); TzdbZoneRulesCompiler compiler = new TzdbZoneRulesCompiler(loopVersion, srcFiles, verbose); try { // compile compiler.compile(); SortedMap<String, ZoneRules> builtZones = compiler.getZones(); --- 241,252 ---- if (srcFiles.isEmpty()) { continue; // nothing to process } // compile ! 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,268 **** 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); // create totals allBuiltZones.put(loopVersion, builtZones); allRegionIds.addAll(builtZones.keySet()); allRules.addAll(builtZones.values()); } catch (Exception ex) { System.out.println("Failed: " + ex.toString()); ex.printStackTrace(); System.exit(1); } --- 255,271 ---- 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, 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,308 **** 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); } } /** * Outputs the file. */ private static void outputFile(File dstFile, String version, ! SortedMap<String, ZoneRules> builtZones) { 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); } /** * Outputs the file. */ private static void outputFile(File dstFile, Map<String, SortedMap<String, ZoneRules>> allBuiltZones, Set<String> allRegionIds, ! Set<ZoneRules> allRules) ! { try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(dstFile))) { ! outputTZEntry(jos, allBuiltZones, allRegionIds, allRules); } catch (Exception ex) { System.out.println("Failed: " + ex.toString()); ex.printStackTrace(); System.exit(1); } --- 275,314 ---- 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, allLinks); } } /** * Outputs the file. */ private static void outputFile(File dstFile, String version, ! 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()); ! 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, ! Map<String, Map<String, String>> allLinks) { try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(dstFile))) { ! outputTZEntry(jos, allBuiltZones, allRegionIds, allRules, allLinks); } catch (Exception ex) { System.out.println("Failed: " + ex.toString()); ex.printStackTrace(); System.exit(1); }
*** 312,322 **** * 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) { // this format is not publicly specified try { jos.putNextEntry(new ZipEntry("TZDB.dat")); DataOutputStream out = new DataOutputStream(jos); --- 318,329 ---- * 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, ! 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,366 **** --- 364,383 ---- 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,629 **** } private int parseYear(String str, int defaultYear) { if (YEAR.reset(str).matches()) { if (YEAR.group("min") != null) { ! return YEAR_MIN_VALUE; } else if (YEAR.group("max") != null) { return YEAR_MAX_VALUE; } else if (YEAR.group("only") != null) { return defaultYear; } --- 636,647 ---- } private int parseYear(String str, int defaultYear) { if (YEAR.reset(str).matches()) { if (YEAR.group("min") != null) { ! //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,759 **** 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 + "'"); } } builtZones.put(aliasId, realRules); } // remove UTC and GMT ! builtZones.remove("UTC"); ! builtZones.remove("GMT"); ! builtZones.remove("GMT0"); builtZones.remove("GMT+0"); builtZones.remove("GMT-0"); } //----------------------------------------------------------------------- /** * Prints a verbose message. --- 758,781 ---- 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("GMT+0"); builtZones.remove("GMT-0"); + links.remove("GMT+0"); + links.remove("GMT-0"); } //----------------------------------------------------------------------- /** * Prints a verbose message.
*** 783,793 **** 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(); --- 805,814 ----