environmentcheck.java

来自「java jdk 1.4的源码」· Java 代码 · 共 1,376 行 · 第 1/4 页

JAVA
1,376
字号
   * @param jars array of .jar base filenames to look for   *   * @return Vector of Hashtables filled with info about found .jars   * @see #jarNames   * @see #logFoundJars(Vector, String)   * @see #appendFoundJars(Node, Document, Vector, String )   * @see #getApparentVersion(String, long)   */  protected Vector checkPathForJars(String cp, String[] jars)  {    if ((null == cp) || (null == jars) || (0 == cp.length())            || (0 == jars.length))      return null;    Vector v = new Vector();    StringTokenizer st = new StringTokenizer(cp, File.pathSeparator);    while (st.hasMoreTokens())    {      // Look at each classpath entry for each of our requested jarNames      String filename = st.nextToken();      for (int i = 0; i < jars.length; i++)      {        if (filename.indexOf(jars[i]) > -1)        {          File f = new File(filename);          if (f.exists())          {            // If any requested jarName exists, report on             //  the details of that .jar file            try            {              Hashtable h = new Hashtable(2);              // Note "-" char is looked for in appendFoundJars              h.put(jars[i] + "-path", f.getAbsolutePath());              h.put(jars[i] + "-apparent.version",                    getApparentVersion(jars[i], f.length()));              v.addElement(h);            }            catch (Exception e)            {              /* no-op, don't add it  */            }          }          else          {            Hashtable h = new Hashtable(2);            // Note "-" char is looked for in appendFoundJars            h.put(jars[i] + "-path", WARNING + " Classpath entry: "                   + filename + " does not exist");            h.put(jars[i] + "-apparent.version", CLASS_NOTPRESENT);            v.addElement(h);          }        }      }    }    return v;  }  /**   * Cheap-o method to determine the product version of a .jar.      *   * Currently does a lookup into a local table of some recent    * shipped Xalan builds to determine where the .jar probably    * came from.  Note that if you recompile Xalan or Xerces    * yourself this will likely report a potential error, since    * we can't certify builds other than the ones we ship.   * Only reports against selected posted Xalan-J builds.   *   * //@todo actually look up version info in manifests   *   * @param jarName base filename of the .jarfile   * @param jarSize size of the .jarfile   *   * @return String describing where the .jar file probably    * came from   */  protected String getApparentVersion(String jarName, long jarSize)  {    // If we found a matching size and it's for our     //  jar, then return it's description    // Lookup in static jarVersions Hashtable    String foundSize = (String) jarVersions.get(new Long(jarSize));    if ((null != foundSize) && (foundSize.startsWith(jarName)))    {      return foundSize;    }    else    {      if ("xerces.jar".equalsIgnoreCase(jarName)              || "xercesImpl.jar".equalsIgnoreCase(jarName)              || "xalan.jar".equalsIgnoreCase(jarName))      {        // For xalan.jar and xerces.jar/xercesImpl.jar, which we ship together:        // The jar is not from a shipped copy of xalan-j, so         //  it's up to the user to ensure that it's compatible        return jarName + " " + WARNING + CLASS_PRESENT;      }      else      {        // Otherwise, it's just a jar we don't have the version info calculated for        return jarName + " " + CLASS_PRESENT;      }    }  }  /**   * Report version information about JAXP interfaces.   *   * Currently distinguishes between JAXP 1.0.1 and JAXP 1.1,    * and not found; only tests the interfaces, and does not    * check for reference implementation versions.   *   * @param h Hashtable to put information in   */  protected void checkJAXPVersion(Hashtable h)  {    if (null == h)      h = new Hashtable();    final Class noArgs[] = new Class[0];    Class clazz = null;    try    {      final String JAXP1_CLASS = "javax.xml.parsers.DocumentBuilder";      final String JAXP11_METHOD = "getDOMImplementation";      clazz = classForName(JAXP1_CLASS);      Method method = clazz.getMethod(JAXP11_METHOD, noArgs);      // If we succeeded, we at least have JAXP 1.1 available      h.put(VERSION + "JAXP", "1.1");    }    catch (Exception e)    {      if (null != clazz)      {        // We must have found the class itself, just not the         //  method, so we (probably) have JAXP 1.0.1        h.put(ERROR + VERSION + "JAXP", "1.0.1");        h.put(ERROR, ERROR_FOUND);      }      else      {        // We couldn't even find the class, and don't have         //  any JAXP support at all, or only have the         //  transform half of it        h.put(ERROR + VERSION + "JAXP", CLASS_NOTPRESENT);        h.put(ERROR, ERROR_FOUND);      }    }  }  /**   * Report product version information from Xalan-J.   *   * Looks for version info in xalan.jar from Xalan-J products.   *   * @param h Hashtable to put information in   */  protected void checkProcessorVersion(Hashtable h)  {    if (null == h)      h = new Hashtable();    try    {      final String XALAN1_VERSION_CLASS =        "org.apache.xalan.xslt.XSLProcessorVersion";      Class clazz = classForName(XALAN1_VERSION_CLASS);      // Found Xalan-J 1.x, grab it's version fields      StringBuffer buf = new StringBuffer();      Field f = clazz.getField("PRODUCT");      buf.append(f.get(null));      buf.append(';');      f = clazz.getField("LANGUAGE");      buf.append(f.get(null));      buf.append(';');      f = clazz.getField("S_VERSION");      buf.append(f.get(null));      buf.append(';');      h.put(VERSION + "xalan1", buf.toString());    }    catch (Exception e1)    {      h.put(VERSION + "xalan1", CLASS_NOTPRESENT);    }    try    {      // NOTE: This is the old Xalan 2.0, 2.1, 2.2 version class,       //    is being replaced by class below      final String XALAN2_VERSION_CLASS =        "org.apache.xalan.processor.XSLProcessorVersion";      Class clazz = classForName(XALAN2_VERSION_CLASS);      // Found Xalan-J 2.x, grab it's version fields      StringBuffer buf = new StringBuffer();      Field f = clazz.getField("S_VERSION");      buf.append(f.get(null));      h.put(VERSION + "xalan2x", buf.toString());    }    catch (Exception e2)    {      h.put(VERSION + "xalan2x", CLASS_NOTPRESENT);    }    try    {      // NOTE: This is the new Xalan 2.2+ version class      final String XALAN2_2_VERSION_CLASS =        "org.apache.xalan.Version";      final String XALAN2_2_VERSION_METHOD = "getVersion";      final Class noArgs[] = new Class[0];      Class clazz = classForName(XALAN2_2_VERSION_CLASS);      Method method = clazz.getMethod(XALAN2_2_VERSION_METHOD, noArgs);      Object returnValue = method.invoke(null, new Object[0]);      h.put(VERSION + "xalan2_2", (String)returnValue);    }    catch (Exception e2)    {      h.put(VERSION + "xalan2_2", CLASS_NOTPRESENT);    }  }  /**   * Report product version information from common parsers.   *   * Looks for version info in xerces.jar/xercesImpl.jar/crimson.jar.   *   * //@todo actually look up version info in crimson manifest   *   * @param h Hashtable to put information in   */  protected void checkParserVersion(Hashtable h)  {    if (null == h)      h = new Hashtable();    try    {      final String XERCES1_VERSION_CLASS = "org.apache.xerces.framework.Version";      Class clazz = classForName(XERCES1_VERSION_CLASS);      // Found Xerces-J 1.x, grab it's version fields      Field f = clazz.getField("fVersion");      String parserVersion = (String) f.get(null);      h.put(VERSION + "xerces1", parserVersion);    }    catch (Exception e)    {      h.put(VERSION + "xerces1", CLASS_NOTPRESENT);    }    // Look for xerces1 and xerces2 parsers separately    try    {      final String XERCES2_VERSION_CLASS = "org.apache.xerces.impl.Version";      Class clazz = classForName(XERCES2_VERSION_CLASS);      // Found Xerces-J 2.x, grab it's version fields      Field f = clazz.getField("fVersion");      String parserVersion = (String) f.get(null);      h.put(VERSION + "xerces2", parserVersion);    }    catch (Exception e)    {      h.put(VERSION + "xerces2", CLASS_NOTPRESENT);    }    try    {      final String CRIMSON_CLASS = "org.apache.crimson.parser.Parser2";      Class clazz = classForName(CRIMSON_CLASS);      //@todo determine specific crimson version      h.put(VERSION + "crimson", CLASS_PRESENT);    }    catch (Exception e)    {      h.put(VERSION + "crimson", CLASS_NOTPRESENT);    }  }  /**   * Report product version information from Ant.   *   * @param h Hashtable to put information in   */  protected void checkAntVersion(Hashtable h)  {    if (null == h)      h = new Hashtable();    try    {      final String ANT_VERSION_CLASS = "org.apache.tools.ant.Main";      final String ANT_VERSION_METHOD = "getAntVersion"; // noArgs      final Class noArgs[] = new Class[0];      Class clazz = classForName(ANT_VERSION_CLASS);      Method method = clazz.getMethod(ANT_VERSION_METHOD, noArgs);      Object returnValue = method.invoke(null, new Object[0]);      h.put(VERSION + "ant", (String)returnValue);    }    catch (Exception e)    {      h.put(VERSION + "ant", CLASS_NOTPRESENT);    }  }  /**   * Report version info from DOM interfaces.    *   * Currently distinguishes between pre-DOM level 2, the DOM    * level 2 working draft, the DOM level 2 final draft, 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?