Author: stevel Date: Thu Oct 26 16:11:25 2006 New Revision: 468181 URL: http://svn.apache.org/viewvc?view=rev&rev=468181 Log: handle security checks on property get gracefully
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?view=diff&rev=468181&r1=468180&r2=468181 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/Diagnostics.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/Diagnostics.java Thu Oct 26 16:11:25 2006 @@ -49,7 +49,16 @@ */ public final class Diagnostics { + /** + * value for which a difference between clock and temp file time triggers + * a warning. + * [EMAIL PROTECTED] + */ private static final int BIG_DRIFT_LIMIT = 10000; + /** + * How big a test file to write. + * [EMAIL PROTECTED] + */ private static final int TEST_FILE_SIZE = 32; private static final int KILOBYTE = 1024; private static final int SECONDS_PER_MILLISECOND = 1000; @@ -58,6 +67,12 @@ private static final String TEST_CLASS = "org.apache.tools.ant.taskdefs.optional.Test"; + /** + * The error text when a security manager blocks access to a property. + * [EMAIL PROTECTED] + */ + protected static final String ERROR_PROPERTY_ACCESS_BLOCKED = "Access to this property blocked by a security manager"; + /** utility class */ private Diagnostics() { // hidden constructor @@ -322,17 +337,29 @@ for (Enumeration keys = sysprops.propertyNames(); keys.hasMoreElements();) { String key = (String) keys.nextElement(); - String value; - try { - value = System.getProperty(key); - } catch (SecurityException e) { - value = "Access to this property blocked by a security manager"; - } + String value = getProperty(key); out.println(key + " : " + value); } } /** + * Get the value of a system property. If a security manager + * blocks access to a property it fills the result in with an error + * @param key + * @return the system property's value or error text + * @see #ERROR_PROPERTY_ACCESS_BLOCKED + */ + private static String getProperty(String key) { + String value; + try { + value = System.getProperty(key); + } catch (SecurityException e) { + value = ERROR_PROPERTY_ACCESS_BLOCKED; + } + return value; + } + + /** * Report the content of ANT_HOME/lib directory * @param out the stream to print the content to */ @@ -558,28 +585,27 @@ } /** - * print a property name="value" pair, or name=[undefined] if there is none - * @param out - * @param name + * print a property name="value" pair if the property is set; + * print nothing if it is null + * @param out stream to print on + * @param key property name */ - private static void printProperty(PrintStream out,String name) { - out.print(name); - out.print(" = "); - String value=System.getProperty(name); + private static void printProperty(PrintStream out,String key) { + String value= getProperty(key); if(value!=null) { + out.print(key); + out.print(" = "); out.print('"'); out.print(value); out.println('"'); - } else { - out.println("[undefined]"); } - } /** * Report proxy information - * + * * @param out stream to print to + * @since Ant1.7 */ private static void doReportProxy(PrintStream out) { printProperty(out,ProxySetup.HTTP_PROXY_HOST); @@ -607,7 +633,7 @@ try { Class proxyDiagClass = Class.forName(proxyDiagClassname); Object instance =proxyDiagClass.newInstance(); - out.println("Java1.5+ proxy settings"); + out.println("Java1.5+ proxy settings:"); out.println(instance.toString()); } catch (ClassNotFoundException e) { //not included, do nothing --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]