Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 54455 invoked from network); 1 Dec 2002 04:38:53 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 1 Dec 2002 04:38:53 -0000 Received: (qmail 26751 invoked by uid 97); 1 Dec 2002 04:40:03 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 26735 invoked by uid 97); 1 Dec 2002 04:40:02 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 26714 invoked by uid 97); 1 Dec 2002 04:40:02 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Date: 1 Dec 2002 04:38:44 -0000 Message-ID: <20021201043844.3045.qmail@icarus.apache.org> From: stevel@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/src/main/org/apache/tools/ant Diagnostics.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N stevel 2002/11/30 20:38:44 Modified: src/main/org/apache/tools/ant Diagnostics.java Log: because I had a pressing need to be find out which parser I was using on java1.4, and new all the code was a cut and paste away Revision Changes Path 1.6 +99 -0 jakarta-ant/src/main/org/apache/tools/ant/Diagnostics.java Index: Diagnostics.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Diagnostics.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Diagnostics.java 4 Nov 2002 17:37:05 -0000 1.5 +++ Diagnostics.java 1 Dec 2002 04:38:44 -0000 1.6 @@ -53,6 +53,9 @@ */ package org.apache.tools.ant; + +import javax.xml.parsers.SAXParserFactory; +import javax.xml.parsers.SAXParser; import java.io.File; import java.io.FilenameFilter; import java.io.PrintStream; @@ -175,6 +178,79 @@ } /** + * what parser are we using. + * @return the classname of the parser + */ + private static String getXmlParserName() { + SAXParser saxParser= getSAXParser(); + if (saxParser == null) { + return "Could not create an XML Parser"; + } + + // check to what is in the classname + String saxParserName = saxParser.getClass().getName(); + return saxParserName; + } + + /** + * Create a JAXP SAXParser + * @return parser or null for trouble + */ + private static SAXParser getSAXParser() { + SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); + if (saxParserFactory == null) { + return null; + } + SAXParser saxParser=null; + try { + saxParser = saxParserFactory.newSAXParser(); + } catch (Exception e) { + } + return saxParser; + } + + /** + * get the location of the parser + * @return path or null for trouble in tracking it down + */ + + private static String getXMLParserLocation() { + SAXParser saxParser = getSAXParser(); + if (saxParser == null) { + return null; + } + String location=getClassLocation(saxParser.getClass()); + return location; + } + + /** + * get the location of a class. Stolen from axis/webapps/happyaxis.jsp + * @param clazz + * @return the jar file or path where a class was found, or null + */ + + private static String getClassLocation( Class clazz) { + try { + java.net.URL url = clazz.getProtectionDomain().getCodeSource().getLocation(); + String location = url.toString(); + if (location.startsWith("jar")) { + url = ((java.net.JarURLConnection) url.openConnection()).getJarFileURL(); + location = url.toString(); + } + + if (location.startsWith("file")) { + java.io.File file = new java.io.File(url.getFile()); + return file.getAbsolutePath(); + } else { + return url.toString(); + } + } catch (Throwable t) { + } + return null; + } + + + /** * Print a report to the given stream. * @param out the stream to print the report to. */ @@ -214,6 +290,13 @@ out.println("-------------------------------------------"); doReportWhich(out); + + out.println(); + out.println("-------------------------------------------"); + out.println(" XML Parser information"); + out.println("-------------------------------------------"); + doReportParserInfo(out); + out.println(); out.println("-------------------------------------------"); out.println(" System properties"); @@ -320,4 +403,20 @@ } } + /** + * tell the user about the XML parser + * @param out + */ + private static void doReportParserInfo(PrintStream out) { + String parserName=getXmlParserName(); + String parserLocation=getXMLParserLocation(); + if(parserName==null) { + parserName="unknown"; + } + if(parserLocation==null) { + parserLocation="unknown"; + } + out.println("XML Parser : " + parserName); + out.println("XML Parser Location: " + parserLocation); + } } -- To unsubscribe, e-mail: For additional commands, e-mail: