Path: blob/master/test/jdk/sun/util/calendar/zi/Main.java
41153 views
/*1* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.util.ArrayList;24import java.util.List;2526/**27* Main class for the javazic time zone data compiler.28*29* @since 1.430*/31public class Main {3233private static boolean verbose = false;34static boolean outputDoc = false;3536private List<String> ziFiles = new ArrayList<String>();37private static String zoneNamesFile = null;38private static String versionName = "unknown";39private static String outputDir = "zoneinfo";40private static String mapFile = null;4142/**43* Parses the specified arguments and sets up the variables.44* @param argv the arguments45*/46void processArgs(String[] argv) {47for (int i = 0; i < argv.length; i++) {48String arg = argv[i];49if (arg.startsWith("-h")) {50usage();51System.exit(0);52} else if (arg.equals("-d")) {53outputDir = argv[++i];54} else if (arg.equals("-v")) {55verbose = true;56} else if (arg.equals("-V")) {57versionName = argv[++i];58} else if (arg.equals("-doc")) {59outputDoc = true;60} else if (arg.equals("-map")) {61outputDoc = true;62mapFile = argv[++i];63} else if (arg.equals("-f")) {64zoneNamesFile = argv[++i];65} else if (arg.equals("-S")) {66try {67Zoneinfo.setYear(Integer.parseInt(argv[++i]));68} catch (Exception e) {69error("invalid year: " + argv[i]);70usage();71System.exit(1);72}73} else {74boolean isStartYear = arg.equals("-s");75if (isStartYear || arg.equals("-e")) {76try {77int year = Integer.parseInt(argv[++i]);78if (isStartYear) {79Zoneinfo.setStartYear(year);80} else {81Zoneinfo.setEndYear(year);82}83} catch (Exception e) {84error("invalid year: " + argv[i]);85usage();86System.exit(1);87}88} else {89// the rest of args are zoneinfo source files90while (i < argv.length) {91ziFiles.add(argv[i++]);92}93}94}95}96}9798/**99* Parses zoneinfo source files100*/101int compile() {102int nFiles = ziFiles.size();103int status = 0;104Mappings maps = new Mappings();105BackEnd backend = BackEnd.getBackEnd();106107for (int i = 0; i < nFiles; i++) {108Zoneinfo frontend = Zoneinfo.parse(ziFiles.get(i));109110for (String key : frontend.getZones().keySet()) {111info(key);112113Timezone tz = frontend.phase2(key);114status |= backend.processZoneinfo(tz);115}116117maps.add(frontend);118}119120// special code for dealing with the conflicting name "MET"121Zone.addMET();122123maps.resolve();124125status |= backend.generateSrc(maps);126127return status;128}129130public static void main(String[] argv) {131Main zic = new Main();132133/*134* Parse args135*/136zic.processArgs(argv);137138/*139* Read target zone names140*/141if (zoneNamesFile != null) {142Zone.readZoneNames(zoneNamesFile);143}144145zic.compile();146}147148void usage() {149System.err.println("Usage: javazic [options] file...\n"+150" -f namefile file containing zone names\n"+151" to be generated (ie, generating subset)\n"+152" -d dir output directory\n"+153" -v verbose\n"+154" -V datavers specifies the tzdata version string\n"+155" (eg, \"tzdata2000g\")"+156" -S year output only SimleTimeZone data of that year\n"+157" -s year start year (default: 1900)\n"+158" -e year end year (default: 2037)\n"+159" -doc generates HTML documents\n"+160" -map mapfile generates HTML documents with map information\n"+161" file... zoneinfo source file(s)");162}163164/**165* @return the output directory path name166*/167static String getOutputDir() {168return outputDir;169}170171/**172* @return the map file's path and name173*/174static String getMapFile() {175return mapFile;176}177178/**179* Returns the time zone data version string specified by the -V180* option. If it is not specified, "unknown" is returned.181* @return the time zone data version string182*/183static String getVersionName() {184return versionName;185}186187/**188* Prints out the specified fatal error message and calls {@link189* java.lang.System#exit System.exit(1)}.190* @param msg the fatal error message191*/192static void panic(String msg) {193printMessage("fatal error", msg);194System.exit(1);195}196197/**198* Prints out the specified error message.199* @param msg the error message200*/201static void error(String msg) {202printMessage("error", msg);203}204205/**206* Prints out the specified warning message.207* @param msg the warning message208*/209static void warning(String msg) {210printMessage("warning", msg);211}212213/**214* Prints out the informative message.215* @param msg the informative message216*/217static void info(String msg) {218if (verbose) {219printMessage(null, msg);220}221}222223private static void printMessage(String type, String msg) {224if (type != null) {225type += ": ";226} else {227type = "";228}229System.err.println("javazic: " + type + msg);230}231}232233234