Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/util/calendar/zi/Main.java
38855 views
/*1* Copyright (c) 2000, 2013, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425import java.util.ArrayList;26import java.util.List;2728/**29* Main class for the javazic time zone data compiler.30*31* @since 1.432*/33public class Main {3435private static boolean verbose = false;36static boolean outputDoc = false;3738private List<String> ziFiles = new ArrayList<String>();39private static String zoneNamesFile = null;40private static String versionName = "unknown";41private static String outputDir = "zoneinfo";42private static String mapFile = null;4344/**45* Parses the specified arguments and sets up the variables.46* @param argv the arguments47*/48void processArgs(String[] argv) {49for (int i = 0; i < argv.length; i++) {50String arg = argv[i];51if (arg.startsWith("-h")) {52usage();53System.exit(0);54} else if (arg.equals("-d")) {55outputDir = argv[++i];56} else if (arg.equals("-v")) {57verbose = true;58} else if (arg.equals("-V")) {59versionName = argv[++i];60} else if (arg.equals("-doc")) {61outputDoc = true;62} else if (arg.equals("-map")) {63outputDoc = true;64mapFile = argv[++i];65} else if (arg.equals("-f")) {66zoneNamesFile = argv[++i];67} else if (arg.equals("-S")) {68try {69Zoneinfo.setYear(Integer.parseInt(argv[++i]));70} catch (Exception e) {71error("invalid year: " + argv[i]);72usage();73System.exit(1);74}75} else {76boolean isStartYear = arg.equals("-s");77if (isStartYear || arg.equals("-e")) {78try {79int year = Integer.parseInt(argv[++i]);80if (isStartYear) {81Zoneinfo.setStartYear(year);82} else {83Zoneinfo.setEndYear(year);84}85} catch (Exception e) {86error("invalid year: " + argv[i]);87usage();88System.exit(1);89}90} else {91// the rest of args are zoneinfo source files92while (i < argv.length) {93ziFiles.add(argv[i++]);94}95}96}97}98}99100/**101* Parses zoneinfo source files102*/103int compile() {104int nFiles = ziFiles.size();105int status = 0;106Mappings maps = new Mappings();107BackEnd backend = BackEnd.getBackEnd();108109for (int i = 0; i < nFiles; i++) {110Zoneinfo frontend = Zoneinfo.parse(ziFiles.get(i));111112for (String key : frontend.getZones().keySet()) {113info(key);114115Timezone tz = frontend.phase2(key);116status |= backend.processZoneinfo(tz);117}118119maps.add(frontend);120}121122// special code for dealing with the conflicting name "MET"123Zone.addMET();124125maps.resolve();126127status |= backend.generateSrc(maps);128129return status;130}131132public static void main(String[] argv) {133Main zic = new Main();134135/*136* Parse args137*/138zic.processArgs(argv);139140/*141* Read target zone names142*/143if (zoneNamesFile != null) {144Zone.readZoneNames(zoneNamesFile);145}146147zic.compile();148}149150void usage() {151System.err.println("Usage: javazic [options] file...\n"+152" -f namefile file containing zone names\n"+153" to be generated (ie, generating subset)\n"+154" -d dir output directory\n"+155" -v verbose\n"+156" -V datavers specifies the tzdata version string\n"+157" (eg, \"tzdata2000g\")"+158" -S year output only SimleTimeZone data of that year\n"+159" -s year start year (default: 1900)\n"+160" -e year end year (default: 2037)\n"+161" -doc generates HTML documents\n"+162" -map mapfile generates HTML documents with map information\n"+163" file... zoneinfo source file(s)");164}165166/**167* @return the output directory path name168*/169static String getOutputDir() {170return outputDir;171}172173/**174* @return the map file's path and name175*/176static String getMapFile() {177return mapFile;178}179180/**181* Returns the time zone data version string specified by the -V182* option. If it is not specified, "unknown" is returned.183* @return the time zone data version string184*/185static String getVersionName() {186return versionName;187}188189/**190* Prints out the specified fatal error message and calls {@link191* java.lang.System#exit System.exit(1)}.192* @param msg the fatal error message193*/194static void panic(String msg) {195printMessage("fatal error", msg);196System.exit(1);197}198199/**200* Prints out the specified error message.201* @param msg the error message202*/203static void error(String msg) {204printMessage("error", msg);205}206207/**208* Prints out the specified warning message.209* @param msg the warning message210*/211static void warning(String msg) {212printMessage("warning", msg);213}214215/**216* Prints out the informative message.217* @param msg the informative message218*/219static void info(String msg) {220if (verbose) {221printMessage(null, msg);222}223}224225private static void printMessage(String type, String msg) {226if (type != null) {227type += ": ";228} else {229type = "";230}231System.err.println("javazic: " + type + msg);232}233}234235236