Author: bodewig
Date: Tue Jul 28 04:42:28 2009
New Revision: 798399
URL: http://svn.apache.org/viewvc?rev=798399&view=rev
Log:
print where core and optional classes have been found. PR 47574. Make check
for optional classes work again after the test task has been removed.
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/Diagnostics.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/Diagnostics.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Diagnostics.java?rev=798399&r1=798398&r2=798399&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Diagnostics.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Diagnostics.java Tue Jul 28
04:42:28 2009
@@ -36,6 +36,7 @@
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 @@
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 @@
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
@@ -171,6 +175,15 @@
}
/**
+ * 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 @@
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 @@
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 @@
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 @@
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 @@
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");