|
|
@@ -36,6 +36,7 @@ import java.io.InputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.FileInputStream; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.net.URL; |
|
|
|
import java.util.Enumeration; |
|
|
|
import java.util.Properties; |
|
|
|
import java.util.Calendar; |
|
|
@@ -71,7 +72,7 @@ public final class Diagnostics { |
|
|
|
private static final int SECONDS_PER_MILLISECOND = 1000; |
|
|
|
private static final int SECONDS_PER_MINUTE = 60; |
|
|
|
private static final int MINUTES_PER_HOUR = 60; |
|
|
|
private static final String TEST_CLASS = "org.apache.tools.ant.taskdefs.optional.Test"; |
|
|
|
private static final String TEST_CLASS = "org.apache.tools.ant.taskdefs.optional.EchoProperties"; |
|
|
|
|
|
|
|
/** |
|
|
|
* The error text when a security manager blocks access to a property. |
|
|
@@ -112,8 +113,11 @@ public final class Diagnostics { |
|
|
|
|
|
|
|
if (coreVersion != null && !coreVersion.equals(optionalVersion)) { |
|
|
|
throw new BuildException("Invalid implementation version " |
|
|
|
+ "between Ant core and Ant optional tasks.\n" + " core : " |
|
|
|
+ coreVersion + "\n" + " optional: " + optionalVersion); |
|
|
|
+ "between Ant core and Ant optional tasks.\n" |
|
|
|
+ " core : " + coreVersion + " in " |
|
|
|
+ getClassLocation(Main.class) |
|
|
|
+ "\n" + " optional: " + optionalVersion + " in " |
|
|
|
+ getClassLocation(optional)); |
|
|
|
} |
|
|
|
} catch (ClassNotFoundException e) { |
|
|
|
// ignore |
|
|
@@ -170,6 +174,15 @@ public final class Diagnostics { |
|
|
|
return clazz.getPackage().getImplementationVersion(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Helper method to get the location. |
|
|
|
* @param clazz the class to get the information from. |
|
|
|
* @since Ant 1.8.0 |
|
|
|
*/ |
|
|
|
private static URL getClassLocation(Class clazz) { |
|
|
|
return clazz.getProtectionDomain().getCodeSource().getLocation(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* what parser are we using. |
|
|
|
* @return the classname of the parser |
|
|
@@ -245,8 +258,8 @@ public final class Diagnostics { |
|
|
|
if (saxParser == null) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
String location = getClassLocation(saxParser.getClass()); |
|
|
|
return location; |
|
|
|
URL location = getClassLocation(saxParser.getClass()); |
|
|
|
return location != null ? location.toString() : null; |
|
|
|
} |
|
|
|
|
|
|
|
private static String getNamespaceParserName() { |
|
|
@@ -263,7 +276,8 @@ public final class Diagnostics { |
|
|
|
private static String getNamespaceParserLocation() { |
|
|
|
try { |
|
|
|
XMLReader reader = JAXPUtils.getNamespaceXMLReader(); |
|
|
|
return getClassLocation(reader.getClass()); |
|
|
|
URL location = getClassLocation(reader.getClass()); |
|
|
|
return location != null ? location.toString() : null; |
|
|
|
} catch (BuildException e) { |
|
|
|
//ignore |
|
|
|
ignoreThrowable(e); |
|
|
@@ -280,8 +294,8 @@ public final class Diagnostics { |
|
|
|
if (transformer == null) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
String location = getClassLocation(transformer.getClass()); |
|
|
|
return location; |
|
|
|
URL location = getClassLocation(transformer.getClass()); |
|
|
|
return location != null ? location.toString() : null; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -292,17 +306,6 @@ public final class Diagnostics { |
|
|
|
private static void ignoreThrowable(Throwable thrown) { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 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) { |
|
|
|
File f = LoaderUtils.getClassSource(clazz); |
|
|
|
return f == null ? null : f.getAbsolutePath(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Print a report to the given stream. |
|
|
@@ -323,12 +326,14 @@ public final class Diagnostics { |
|
|
|
out.println(Main.getAntVersion()); |
|
|
|
header(out, "Implementation Version"); |
|
|
|
|
|
|
|
out.println("core tasks : " + getImplementationVersion(Main.class)); |
|
|
|
out.println("core tasks : " + getImplementationVersion(Main.class) |
|
|
|
+ " in " + getClassLocation(Main.class)); |
|
|
|
|
|
|
|
Class optional = null; |
|
|
|
try { |
|
|
|
optional = Class.forName(TEST_CLASS); |
|
|
|
out.println("optional tasks : " + getImplementationVersion(optional)); |
|
|
|
out.println("optional tasks : " + getImplementationVersion(optional) |
|
|
|
+ " in " + getClassLocation(optional)); |
|
|
|
} catch (ClassNotFoundException e) { |
|
|
|
ignoreThrowable(e); |
|
|
|
out.println("optional tasks : not available"); |
|
|
|