📄 main.java
字号:
/* Derby - Class org.apache.derby.impl.tools.sysinfo.Main Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derby.impl.tools.sysinfo;import java.util.Locale;import java.io.IOException;import java.io.UnsupportedEncodingException;import java.io.InputStream;import java.util.Properties;import java.io.BufferedReader;import java.io.InputStreamReader;import java.util.Locale;import java.util.MissingResourceException;import java.util.ResourceBundle;import java.util.StringTokenizer;import java.io.File;import java.util.zip.ZipFile;import java.io.IOException;import java.util.zip.ZipEntry;import java.io.FileInputStream;import java.util.Vector;import java.io.InputStream;import java.lang.reflect.Method;import org.apache.derby.iapi.services.info.PropertyNames;import org.apache.derby.iapi.services.info.ProductVersionHolder;import org.apache.derby.iapi.services.info.ProductGenusNames;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.tools.i18n.*;/** <i>Copyright © 1998, Cloudscape, Inc. All rights reserved.</i> <P> SysInfo reports values relevant to the Cloudscape product found on the CLASSPATH. It looks for a file called sysinfo.properties in the CLASSPATH using getResourceAsStream. If the file is not found, or some other exception occurs, the value returned will be that set for the key SysInfo.failureTag, or be the value "<info unavailable>". <P> This class can be used to print out system information at the command line by issuing the command: <PRE> java org.apache.derby.tools.sysinfo </PRE> Alternatively, you can use SysInfo within your program to display Cloudscape information; a Cloudscape version string is returned by this Java code: <PRE> new Main().toString(); </PRE> */public final class Main { /** Application entry point for SysInfo. This will print out the Cloudscape product information as well as a snapshot of the System properties. */ public static void main(String args[]) { // adjust the application in accordance with derby.ui.locale and derby.ui.codeset LocalizedResource.getInstance(); LocalizedOutput out; //using AppStreamReader(extends InputStreamReader) for conversion into specific codeset out = LocalizedResource.OutputWriter(); // because we're in a static method, we need to // get our own instance variable parseArgs (args); if (cptester == true) getClasspathInfo (args, out); else getMainInfo (out, setPause); } // end of main (String args[])public static void getMainInfo (java.io.PrintWriter aw, boolean pause) { aw.println (javaSep); reportJavaInfo (aw); aw.println (jbmsSep); reportCloudscape (aw); aw.println (sep); // Locales info try { reportLocales (aw); } catch (Exception e) { aw.println (Main.getTextMessage ("SIF01.Q")); aw.println (Main.getTextMessage ("SIF01.B")); } if (pause) { pause(); } } // end of getMainInfo (AppStreamWriter aw, boolean printLicense, boolean pause) private static boolean setPause = false; private static boolean setLicense = false; private static boolean cptester = false; private static void parseArgs (String args[]) { if (args == null) { return; } for (int i = 0; i < args.length; i++) { if (args[i].equals ("-pause")) { setPause = true; } if (args[i].equals ("-cp")) { cptester=true; } } // end for } // end of parseArgs (String args[]) /** For the benefit of DOS box users, this method waits for input before returning */ private static void pause () { try { System.out.print (Main.getTextMessage ("SIF01.C")); BufferedReader br = new BufferedReader (new InputStreamReader (System.in)); br.readLine (); } catch (IOException ioe) { //just return } } // end of pause () /** prints out the jbms info to the specified AppStreamWriter. @param localAW the AppStreamWriter to use. If null, System.out is used */ private static void reportCloudscape (java.io.PrintWriter localAW) { localAW.println("JRE - JDBC: " + org.apache.derby.iapi.services.info.JVMInfo.derbyVMLevel()); String classpath; try { classpath = System.getProperty("java.class.path"); } catch (SecurityException se) { classpath = null; } ZipInfoProperties zip[]= Main.getAllInfo (classpath); if (zip != null) { for (int i = 0; i < zip.length; i++) { String thisInfo = "[" + zip[i].getLocation () + "] " + zip[i].getVersionBuildInfo (); localAW.println (thisInfo); } } else { localAW.println (Main.getTextMessage ("SIF01.D")); } } // end of reportCloudscape /** Writes out the relevant info about the Java environment to the specified AppStreamWriter. @param localAW The AppStreamWriter to write info out to. If this is null, the info is written to System.out */ private static void reportJavaInfo (java.io.PrintWriter localAW) { localAW.println (Main.getTextMessage ("SIF02.A", getJavaProperty ("java.version"))); localAW.println (Main.getTextMessage ("SIF02.B", getJavaProperty ("java.vendor"))); localAW.println (Main.getTextMessage ("SIF02.C", getJavaProperty ("java.home"))); localAW.println (Main.getTextMessage ("SIF02.D", getJavaProperty ("java.class.path"))); localAW.println (Main.getTextMessage ("SIF02.E", getJavaProperty ("os.name"))); localAW.println (Main.getTextMessage ("SIF02.F", getJavaProperty ("os.arch"))); localAW.println (Main.getTextMessage ("SIF02.G", getJavaProperty ("os.version"))); localAW.println (Main.getTextMessage ("SIF02.H", getJavaProperty ("user.name"))); localAW.println (Main.getTextMessage ("SIF02.I", getJavaProperty ("user.home"))); localAW.println (Main.getTextMessage ("SIF02.J", getJavaProperty ("user.dir"))); localAW.println("java.specification.name: " + getJavaProperty("java.specification.name")); localAW.println("java.specification.version: " + getJavaProperty("java.specification.version")); } // end of reportJavaInfo /** Return Java properties from java.lang.System. Will catch SecurityExceptions and note them for displaying information. @return the Java property value or a string capturing a security exception. */ private static String getJavaProperty (String whichProperty) { String property; String unavailable = Main.getTextMessage ("SIF01.H"); try { property = System.getProperty (whichProperty, unavailable); return property; } catch (SecurityException se) { return Main.getTextMessage ("SIF01.I", se); } } // end of getJavaProperty (String whichProperty) /** for use by the main () method */ private final static String sep = "------------------------------------------------------"; private final static String javaSep = Main.getTextMessage ("SIF01.L"); private final static String jbmsSep = Main.getTextMessage ("SIF01.M"); private final static String licSep = Main.getTextMessage ("SIF01.N"); private final static String locSep = Main.getTextMessage ("SIF01.P"); private final static String curLoc = Main.getTextMessage ("SIF01.T"); /** The name of the failure tag in the information file. The failure tag's value provides a default value if any other properties are missing. */ private final static String failureTag = Main.getTextMessage ("SIF01.J"); private static void getClasspathInfo (String args[], java.io.PrintWriter aw) { Main.useMe (args, aw); } /** Writes out information about the locales with the product. @param localAW the AppStreamWriter to which the info is written. If this value is null, the info is written to System.out */ private static void reportLocales (java.io.PrintWriter localAW) { // throws StandardException { boolean cur_loc = true; localAW.println (locSep); // Read all the possible locales, and test for each one, if it loads. // If so, then read the properties, and print them out. Locale[] supportedLocales = Locale.getAvailableLocales(); String[] stringLocales = new String[supportedLocales.length]; for (int i = 0; i < supportedLocales.length; i++) { stringLocales[i] = supportedLocales[i].toString(); } java.util.Arrays.sort(stringLocales); Properties p = new Properties (); for (int i = 0; i < stringLocales.length; i++) { String localeResource = "/org/apache/derby/info/locale_" + stringLocales[i] + ".properties"; try { InputStream is = p.getClass().getResourceAsStream (localeResource); if (is == null) {// localAW.println("resource is null: " + localeResource); } else { try { p.clear(); p.load (is); //Displaying Current Locale if (cur_loc) { Locale loc = null; loc = Locale.getDefault(); localAW.println(Main.getTextMessage ("SIF01.T") + " [" + loc.getDisplayLanguage() + "/" + loc.getDisplayCountry() + " [" + loc + "]]"); cur_loc = false; } //Beetle 5079: do not print unlocalized locale names to console, only print locale code. String localeName = p.getProperty("derby.locale.external.name"); localeName = localeName.substring(localeName.indexOf("[")+1); localeName = localeName.substring(0,localeName.indexOf("]")); localAW.println (Main.getTextMessage ("SIF01.R", localeName)); int major = Integer.valueOf(p.getProperty ("derby.locale.version.major")).intValue(); int minor = Integer.valueOf(p.getProperty ("derby.locale.version.minor")).intValue(); int maint = Integer.valueOf(p.getProperty ("derby.locale.version.maint")).intValue(); String build = p.getProperty ("derby.locale.build.number"); String lv = ProductVersionHolder.fullVersionString(major, minor, maint, false, build); localAW.println (Main.getTextMessage ("SIF01.S", lv)); } catch (IOException ioe) { //This case is a bit ugly. If we get an IOException, we return //null. Though this correctly reflects that the product is not //available for use, it may be confusing to users that we swallow //the IO error here. localAW.println("Could not get locale properties from : " + is); } } } catch (Throwable t) { localAW.println ("Could not load resource: " + localeResource); localAW.println ("Exception: " + t); } } localAW.println (sep); } // end of reportLocales /* for arguments, choose from one of:*/ private static final String EMBEDDED = "embedded"; /* you can add this if you like*/ private static final String TOOLS = "tools"; private static final String NET = "server"; private static final String CLIENT = "client"; /* you can add this if you like */ private static final String MAINUSAGESTRING = "java org.apache.derby.tools.sysinfo -cp"; private static final String USAGESTRINGPARTA = MAINUSAGESTRING + " [ [ " + EMBEDDED + " ][ " + NET + " ][ " + CLIENT + "] [ " + TOOLS + " ] [ "; private static final String USAGESTRINGPARTB = ".class ] ]"; static void useMe(String[] args, java.io.PrintWriter pw) { java.io.PrintWriter localPW = pw; if (localPW == null) { localPW = new java.io.PrintWriter(System.out); } int length = args.length; if (length==1) { try { tryAllClasspaths(localPW); } catch (Throwable t) { } } else { try { trySomeClasspaths(args, localPW); } catch (Throwable t) { } } } private static void tryAllClasspaths(java.io.PrintWriter localPW) throws Throwable { localPW.println(Main.getTextMessage("SIF08.B")); localPW.println(Main.getTextMessage("SIF08.C", MAINUSAGESTRING + " args")); StringBuffer successes = new StringBuffer(Main.getTextMessage("SIF08.D")+ crLf()); StringBuffer failures = new StringBuffer(crLf() + Main.getTextMessage("SIF08.E") + crLf()); tryCoreClasspath(successes, failures);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -