Methods Summary |
---|
public static void | doReport(java.io.PrintStream out)Print a report to the given stream.
out.println("------- Ant diagnostics report -------");
out.println(Main.getAntVersion());
header(out, "Implementation Version");
out.println("core tasks : " + getImplementationVersion(Main.class));
Class optional = null;
try {
optional = Class.forName(TEST_CLASS);
out.println("optional tasks : "
+ getImplementationVersion(optional));
} catch (ClassNotFoundException e) {
ignoreThrowable(e);
out.println("optional tasks : not available");
}
header(out, "ANT PROPERTIES");
doReportAntProperties(out);
header(out, "ANT_HOME/lib jar listing");
doReportAntHomeLibraries(out);
header(out, "USER_HOME/.ant/lib jar listing");
doReportUserHomeLibraries(out);
header(out, "Tasks availability");
doReportTasksAvailability(out);
header(out, "org.apache.env.Which diagnostics");
doReportWhich(out);
header(out, "XML Parser information");
doReportParserInfo(out);
header(out, "System properties");
doReportSystemProperties(out);
header(out, "Temp dir");
doReportTempDir(out);
header(out, "Locale information");
doReportLocale(out);
header(out, "Proxy information");
doReportProxy(out);
out.println();
|
private static void | doReportAntHomeLibraries(java.io.PrintStream out)Report the content of ANT_HOME/lib directory
out.println(MagicNames.ANT_HOME + ": " + System.getProperty(MagicNames.ANT_HOME));
File[] libs = listLibraries();
printLibraries(libs, out);
|
private static void | doReportAntProperties(java.io.PrintStream out)Report the content of ANT_HOME/lib directory
Project p = new Project();
p.initProperties();
out.println(MagicNames.ANT_VERSION + ": " + p.getProperty(MagicNames.ANT_VERSION));
out.println(MagicNames.ANT_JAVA_VERSION + ": "
+ p.getProperty(MagicNames.ANT_JAVA_VERSION));
out.println(MagicNames.ANT_LIB + ": " + p.getProperty(MagicNames.ANT_LIB));
out.println(MagicNames.ANT_HOME + ": " + p.getProperty(MagicNames.ANT_HOME));
|
private static void | doReportLocale(java.io.PrintStream out)Report locale information
//calendar stuff.
Calendar cal = Calendar.getInstance();
TimeZone tz = cal.getTimeZone();
out.println("Timezone " + tz.getDisplayName()
+ " offset=" + tz.getOffset(cal.get(Calendar.ERA),
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH),
cal.get(Calendar.DAY_OF_WEEK),
((cal.get(Calendar.HOUR_OF_DAY) * MINUTES_PER_HOUR
+ cal.get(Calendar.MINUTE)) * SECONDS_PER_MINUTE
+ cal.get(Calendar.SECOND)) * SECONDS_PER_MILLISECOND
+ cal.get(Calendar.MILLISECOND)));
|
private static void | doReportParserInfo(java.io.PrintStream out)tell the user about the XML parser
String parserName = getXmlParserName();
String parserLocation = getXMLParserLocation();
printParserInfo(out, "XML Parser", parserName, parserLocation);
printParserInfo(out, "Namespace-aware parser",
getNamespaceParserName(),
getNamespaceParserLocation());
|
private static void | doReportProxy(java.io.PrintStream out)Report proxy information
printProperty(out, ProxySetup.HTTP_PROXY_HOST);
printProperty(out, ProxySetup.HTTP_PROXY_PORT);
printProperty(out, ProxySetup.HTTP_PROXY_USERNAME);
printProperty(out, ProxySetup.HTTP_PROXY_PASSWORD);
printProperty(out, ProxySetup.HTTP_NON_PROXY_HOSTS);
printProperty(out, ProxySetup.HTTPS_PROXY_HOST);
printProperty(out, ProxySetup.HTTPS_PROXY_PORT);
printProperty(out, ProxySetup.HTTPS_NON_PROXY_HOSTS);
printProperty(out, ProxySetup.FTP_PROXY_HOST);
printProperty(out, ProxySetup.FTP_PROXY_PORT);
printProperty(out, ProxySetup.FTP_NON_PROXY_HOSTS);
printProperty(out, ProxySetup.SOCKS_PROXY_HOST);
printProperty(out, ProxySetup.SOCKS_PROXY_PORT);
printProperty(out, ProxySetup.SOCKS_PROXY_USERNAME);
printProperty(out, ProxySetup.SOCKS_PROXY_PASSWORD);
if (JavaEnvUtils.getJavaVersionNumber() < 15) {
return;
}
printProperty(out, ProxySetup.USE_SYSTEM_PROXIES);
final String proxyDiagClassname
= "org.apache.tools.ant.util.java15.ProxyDiagnostics";
try {
Class proxyDiagClass = Class.forName(proxyDiagClassname);
Object instance = proxyDiagClass.newInstance();
out.println("Java1.5+ proxy settings:");
out.println(instance.toString());
} catch (ClassNotFoundException e) {
//not included, do nothing
} catch (IllegalAccessException e) {
//not included, do nothing
} catch (InstantiationException e) {
//not included, do nothing
} catch (NoClassDefFoundError e) {
// not included, to nothing
}
|
private static void | doReportSystemProperties(java.io.PrintStream out)Report a listing of system properties existing in the current vm.
Properties sysprops = null;
try {
sysprops = System.getProperties();
} catch (SecurityException e) {
ignoreThrowable(e);
out.println("Access to System.getProperties() blocked "
+ "by a security manager");
}
for (Enumeration keys = sysprops.propertyNames();
keys.hasMoreElements();) {
String key = (String) keys.nextElement();
String value = getProperty(key);
out.println(key + " : " + value);
}
|
private static void | doReportTasksAvailability(java.io.PrintStream out)Create a report about non-available tasks that are defined in the
mapping but could not be found via lookup. It might generally happen
because Ant requires multiple libraries to compile and one of them
was missing when compiling Ant.
InputStream is = Main.class.getResourceAsStream(
MagicNames.TASKDEF_PROPERTIES_RESOURCE);
if (is == null) {
out.println("None available");
} else {
Properties props = new Properties();
try {
props.load(is);
for (Enumeration keys = props.keys(); keys.hasMoreElements();) {
String key = (String) keys.nextElement();
String classname = props.getProperty(key);
try {
Class.forName(classname);
props.remove(key);
} catch (ClassNotFoundException e) {
out.println(key + " : Not Available "
+ "(the implementation class is not present)");
} catch (NoClassDefFoundError e) {
String pkg = e.getMessage().replace('/", '.");
out.println(key + " : Missing dependency " + pkg);
} catch (LinkageError e) {
out.println(key + " : Initialization error");
}
}
if (props.size() == 0) {
out.println("All defined tasks are available");
} else {
out.println("A task being missing/unavailable should only "
+ "matter if you are trying to use it");
}
} catch (IOException e) {
out.println(e.getMessage());
}
}
|
private static void | doReportTempDir(java.io.PrintStream out)try and create a temp file in our temp dir; this
checks that it has space and access.
We also do some clock reporting.
String tempdir = System.getProperty("java.io.tmpdir");
if (tempdir == null) {
out.println("Warning: java.io.tmpdir is undefined");
return;
}
out.println("Temp dir is " + tempdir);
File tempDirectory = new File(tempdir);
if (!tempDirectory.exists()) {
out.println("Warning, java.io.tmpdir directory does not exist: "
+ tempdir);
return;
}
//create the file
long now = System.currentTimeMillis();
File tempFile = null;
FileOutputStream fileout = null;
try {
tempFile = File.createTempFile("diag", "txt", tempDirectory);
//do some writing to it
fileout = new FileOutputStream(tempFile);
byte[] buffer = new byte[KILOBYTE];
for (int i = 0; i < TEST_FILE_SIZE; i++) {
fileout.write(buffer);
}
fileout.close();
fileout = null;
long filetime = tempFile.lastModified();
tempFile.delete();
out.println("Temp dir is writeable");
long drift = filetime - now;
out.println("Temp dir alignment with system clock is " + drift + " ms");
if (Math.abs(drift) > BIG_DRIFT_LIMIT) {
out.println("Warning: big clock drift -maybe a network filesystem");
}
} catch (IOException e) {
ignoreThrowable(e);
out.println("Failed to create a temporary file in the temp dir "
+ tempdir);
out.println("File " + tempFile + " could not be created/written to");
} finally {
FileUtils.close(fileout);
if (tempFile != null && tempFile.exists()) {
tempFile.delete();
}
}
|
private static void | doReportUserHomeLibraries(java.io.PrintStream out)Report the content of ~/.ant/lib directory
String home = System.getProperty(Launcher.USER_HOMEDIR);
out.println("user.home: " + home);
File libDir = new File(home, Launcher.USER_LIBDIR);
File[] libs = listJarFiles(libDir);
printLibraries(libs, out);
|
private static void | doReportWhich(java.io.PrintStream out)Call org.apache.env.Which if available
Throwable error = null;
try {
Class which = Class.forName("org.apache.env.Which");
Method method
= which.getMethod("main", new Class[]{String[].class});
method.invoke(null, new Object[]{new String[]{}});
} catch (ClassNotFoundException e) {
out.println("Not available.");
out.println("Download it at http://xml.apache.org/commons/");
} catch (InvocationTargetException e) {
error = e.getTargetException() == null ? e : e.getTargetException();
} catch (Throwable e) {
error = e;
}
// report error if something weird happens...this is diagnostic.
if (error != null) {
out.println("Error while running org.apache.env.Which");
error.printStackTrace();
}
|
private static java.lang.String | getClassLocation(java.lang.Class clazz)get the location of a class. Stolen from axis/webapps/happyaxis.jsp
File f = LoaderUtils.getClassSource(clazz);
return f == null ? null : f.getAbsolutePath();
|
private static java.lang.String | getImplementationVersion(java.lang.Class clazz)Helper method to get the implementation version.
Package pkg = clazz.getPackage();
return pkg.getImplementationVersion();
|
private static java.lang.String | getNamespaceParserLocation()
try {
XMLReader reader = JAXPUtils.getNamespaceXMLReader();
return getClassLocation(reader.getClass());
} catch (BuildException e) {
//ignore
ignoreThrowable(e);
return null;
}
|
private static java.lang.String | getNamespaceParserName()
try {
XMLReader reader = JAXPUtils.getNamespaceXMLReader();
return reader.getClass().getName();
} catch (BuildException e) {
//ignore
ignoreThrowable(e);
return null;
}
|
private static java.lang.String | getProperty(java.lang.String key)Get the value of a system property. If a security manager
blocks access to a property it fills the result in with an error
String value;
try {
value = System.getProperty(key);
} catch (SecurityException e) {
value = ERROR_PROPERTY_ACCESS_BLOCKED;
}
return value;
|
private static javax.xml.parsers.SAXParser | getSAXParser()Create a JAXP SAXParser
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
if (saxParserFactory == null) {
return null;
}
SAXParser saxParser = null;
try {
saxParser = saxParserFactory.newSAXParser();
} catch (Exception e) {
// ignore
ignoreThrowable(e);
}
return saxParser;
|
private static java.lang.String | getXMLParserLocation()get the location of the parser
SAXParser saxParser = getSAXParser();
if (saxParser == null) {
return null;
}
String location = getClassLocation(saxParser.getClass());
return location;
|
private static java.lang.String | getXmlParserName()what parser are we using.
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;
|
private static void | header(java.io.PrintStream out, java.lang.String section)
out.println();
out.println("-------------------------------------------");
out.print(" ");
out.println(section);
out.println("-------------------------------------------");
|
private static void | ignoreThrowable(java.lang.Throwable thrown)ignore exceptions. This is to allow future
implementations to log at a verbose level
|
public static boolean | isOptionalAvailable()Check if optional tasks are available. Not that it does not check
for implementation version. Use validateVersion() for this.
try {
Class.forName(TEST_CLASS);
} catch (ClassNotFoundException e) {
return false;
}
return true;
|
private static java.io.File[] | listJarFiles(java.io.File libDir)get a list of all JAR files in a directory
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
};
File[] files = libDir.listFiles(filter);
return files;
|
public static java.io.File[] | listLibraries()return the list of jar files existing in ANT_HOME/lib
and that must have been picked up by Ant script.
String home = System.getProperty(MagicNames.ANT_HOME);
if (home == null) {
return null;
}
File libDir = new File(home, "lib");
return listJarFiles(libDir);
|
public static void | main(java.lang.String[] args)main entry point for command line
doReport(System.out);
|
private static void | printLibraries(java.io.File[] libs, java.io.PrintStream out)list the libraries
if (libs == null) {
out.println("No such directory.");
return;
}
for (int i = 0; i < libs.length; i++) {
out.println(libs[i].getName()
+ " (" + libs[i].length() + " bytes)");
}
|
private static void | printParserInfo(java.io.PrintStream out, java.lang.String parserType, java.lang.String parserName, java.lang.String parserLocation)
if (parserName == null) {
parserName = "unknown";
}
if (parserLocation == null) {
parserLocation = "unknown";
}
out.println(parserType + " : " + parserName);
out.println(parserType + " Location: " + parserLocation);
|
private static void | printProperty(java.io.PrintStream out, java.lang.String key)print a property name="value" pair if the property is set;
print nothing if it is null
String value = getProperty(key);
if (value != null) {
out.print(key);
out.print(" = ");
out.print('"");
out.print(value);
out.println('"");
}
|
public static void | validateVersion()Check if core and optional implementation version do match.
try {
Class optional
= Class.forName(TEST_CLASS);
String coreVersion = getImplementationVersion(Main.class);
String optionalVersion = getImplementationVersion(optional);
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);
}
} catch (ClassNotFoundException e) {
// ignore
ignoreThrowable(e);
}
|