environmentcheck.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,376 行 · 第 1/4 页
JAVA
1,376 行
/** Prefixed to hash keys that signify serious problems. */ public static final String ERROR = "ERROR."; /** Added to descriptions that signify potential problems. */ public static final String WARNING = "WARNING."; /** Value for any error found. */ public static final String ERROR_FOUND = "At least one error was found!"; /** Prefixed to hash keys that signify version numbers. */ public static final String VERSION = "version."; /** Prefixed to hash keys that signify .jars found in classpath. */ public static final String FOUNDCLASSES = "foundclasses."; /** Marker that a class or .jar was found. */ public static final String CLASS_PRESENT = "present-unknown-version"; /** Marker that a class or .jar was not found. */ public static final String CLASS_NOTPRESENT = "not-present"; /** Listing of common .jar files that include Xalan-related classes. */ public String[] jarNames = { "xalan.jar", "xalansamples.jar", "xalanj1compat.jar", "xalanservlet.jar", "xerces.jar", // Xerces-J 1.x "xercesImpl.jar", // Xerces-J 2.x "testxsl.jar", "crimson.jar", "lotusxsl.jar", "jaxp.jar", "parser.jar", "dom.jar", "sax.jar", "xml.jar", "xml-apis.jar", "xsltc.jar" }; /** * Print out report of .jars found in a classpath. * * Takes the information encoded from a checkPathForJars() * call and dumps it out to our PrintWriter. * * @param v Vector of Hashtables of .jar file info * @param desc description to print out in header * * @return false if OK, true if any .jars were reported * as having errors * @see #checkPathForJars(String, String[]) */ protected boolean logFoundJars(Vector v, String desc) { if ((null == v) || (v.size() < 1)) return false; boolean errors = false; logMsg("#---- BEGIN Listing XML-related jars in: " + desc + " ----"); for (int i = 0; i < v.size(); i++) { Hashtable subhash = (Hashtable) v.elementAt(i); for (Enumeration enum = subhash.keys(); enum.hasMoreElements(); /* no increment portion */ ) { Object key = enum.nextElement(); String keyStr = (String) key; try { if (keyStr.startsWith(ERROR)) { errors = true; } logMsg(keyStr + "=" + subhash.get(keyStr)); } catch (Exception e) { errors = true; logMsg("Reading-" + key + "= threw: " + e.toString()); } } } logMsg("#----- END Listing XML-related jars in: " + desc + " -----"); return errors; } /** * Stylesheet extension entrypoint: Dump a basic Xalan * environment report from getEnvironmentHash() to a Node. * * <p>Copy of writeEnvironmentReport that creates a Node suitable * for other processing instead of a properties-like text output. * </p> * @param container Node to append our report to * @param factory Document providing createElement, etc. services * @param h Hash presumably from {@link #getEnvironmentHash()} * @see #writeEnvironmentReport(Hashtable) * for an equivalent that writes to a PrintWriter instead */ public void appendEnvironmentReport(Node container, Document factory, Hashtable h) { if ((null == container) || (null == factory)) { return; } try { Element envCheckNode = factory.createElement("EnvironmentCheck"); envCheckNode.setAttribute("version", "$Revision: 1.14 $"); container.appendChild(envCheckNode); if (null == h) { Element statusNode = factory.createElement("status"); statusNode.setAttribute("result", "ERROR"); statusNode.appendChild(factory.createTextNode("appendEnvironmentReport called with null Hashtable!")); envCheckNode.appendChild(statusNode); return; } boolean errors = false; Element hashNode = factory.createElement("environment"); envCheckNode.appendChild(hashNode); for (Enumeration enum = h.keys(); enum.hasMoreElements(); /* no increment portion */ ) { Object key = enum.nextElement(); String keyStr = (String) key; try { // Special processing for classes found.. if (keyStr.startsWith(FOUNDCLASSES)) { Vector v = (Vector) h.get(keyStr); // errors |= logFoundJars(v, keyStr); errors |= appendFoundJars(hashNode, factory, v, keyStr); } // ..normal processing for all other entries else { // Note: we could just check for the ERROR key by itself, // since we now set that, but since we have to go // through the whole hash anyway, do it this way, // which is safer for maintenance if (keyStr.startsWith(ERROR)) { errors = true; } Element node = factory.createElement("item"); node.setAttribute("key", keyStr); node.appendChild(factory.createTextNode((String)h.get(keyStr))); hashNode.appendChild(node); } } catch (Exception e) { errors = true; Element node = factory.createElement("item"); node.setAttribute("key", keyStr); node.appendChild(factory.createTextNode(ERROR + " Reading " + key + " threw: " + e.toString())); hashNode.appendChild(node); } } // end of for... Element statusNode = factory.createElement("status"); statusNode.setAttribute("result", (errors ? "ERROR" : "OK" )); envCheckNode.appendChild(statusNode); } catch (Exception e2) { System.err.println("appendEnvironmentReport threw: " + e2.toString()); e2.printStackTrace(); } } /** * Print out report of .jars found in a classpath. * * Takes the information encoded from a checkPathForJars() * call and dumps it out to our PrintWriter. * * @param container Node to append our report to * @param factory Document providing createElement, etc. services * @param v Vector of Hashtables of .jar file info * @param desc description to print out in header * * @return false if OK, true if any .jars were reported * as having errors * @see #checkPathForJars(String, String[]) */ protected boolean appendFoundJars(Node container, Document factory, Vector v, String desc) { if ((null == v) || (v.size() < 1)) return false; boolean errors = false; for (int i = 0; i < v.size(); i++) { Hashtable subhash = (Hashtable) v.elementAt(i); for (Enumeration enum = subhash.keys(); enum.hasMoreElements(); /* no increment portion */ ) { Object key = enum.nextElement(); try { String keyStr = (String) key; if (keyStr.startsWith(ERROR)) { errors = true; } Element node = factory.createElement("foundJar"); node.setAttribute("name", keyStr.substring(0, keyStr.indexOf("-"))); node.setAttribute("desc", keyStr.substring(keyStr.indexOf("-") + 1)); node.appendChild(factory.createTextNode((String)subhash.get(keyStr))); container.appendChild(node); } catch (Exception e) { errors = true; Element node = factory.createElement("foundJar"); node.appendChild(factory.createTextNode(ERROR + " Reading " + key + " threw: " + e.toString())); container.appendChild(node); } } } return errors; } /** * Fillin hash with info about SystemProperties. * * Logs java.class.path and other likely paths; then attempts * to search those paths for .jar files with Xalan-related classes. * * //@todo NOTE: We don't actually search java.ext.dirs for * // *.jar files therein! This should be updated * * @param h Hashtable to put information in * @see #jarNames * @see #checkPathForJars(String, String[]) */ protected void checkSystemProperties(Hashtable h) { if (null == h) h = new Hashtable(); // Grab java version for later use try { String javaVersion = System.getProperty("java.version"); h.put("java.version", javaVersion); } catch (SecurityException se) { // For applet context, etc. h.put( "java.version", "WARNING: SecurityException thrown accessing system version properties"); } // Printout jar files on classpath(s) that may affect operation // Do this in order try { // This is present in all JVM's String cp = System.getProperty("java.class.path"); h.put("java.class.path", cp); Vector classpathJars = checkPathForJars(cp, jarNames); if (null != classpathJars) h.put(FOUNDCLASSES + "java.class.path", classpathJars); // Also check for JDK 1.2+ type classpaths String othercp = System.getProperty("sun.boot.class.path"); if (null != othercp) { h.put("sun.boot.class.path", othercp); classpathJars = checkPathForJars(othercp, jarNames); if (null != classpathJars) h.put(FOUNDCLASSES + "sun.boot.class.path", classpathJars); } //@todo NOTE: We don't actually search java.ext.dirs for // *.jar files therein! This should be updated othercp = System.getProperty("java.ext.dirs"); if (null != othercp) { h.put("java.ext.dirs", othercp); classpathJars = checkPathForJars(othercp, jarNames); if (null != classpathJars) h.put(FOUNDCLASSES + "java.ext.dirs", classpathJars); } //@todo also check other System properties' paths? // v2 = checkPathForJars(System.getProperty("sun.boot.library.path"), jarNames); // ?? may not be needed // v3 = checkPathForJars(System.getProperty("java.library.path"), jarNames); // ?? may not be needed } catch (SecurityException se2) { // For applet context, etc. h.put( "java.class.path", "WARNING: SecurityException thrown accessing system classpath properties"); } } /** * Cheap-o listing of specified .jars found in the classpath. * * cp should be separated by the usual File.pathSeparator. We * then do a simplistic search of the path for any requested * .jar filenames, and return a listing of their names and * where (apparently) they came from. * * @param cp classpath to search
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?