Author: jkf Date: Thu Sep 22 13:03:53 2005 New Revision: 291012 URL: http://svn.apache.org/viewcvs?rev=291012&view=rev Log: Layout, extracted methods / named constants Modified: ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java ant/core/trunk/src/main/org/apache/tools/ant/Diagnostics.java Modified: ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java?rev=291012&r1=291011&r2=291012&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java Thu Sep 22 13:03:53 2005 @@ -705,10 +705,7 @@ */ private void initTasks() { ClassLoader classLoader = null; - if (project.getCoreLoader() != null - && !(BUILD_SYSCLASSPATH_ONLY.equals(project.getProperty(MagicNames.BUILD_SYSCLASSPATH)))) { - classLoader = project.getCoreLoader(); - } + classLoader = getClassLoader(classLoader); String dataDefs = MagicNames.TASKDEF_PROPERTIES_RESOURCE; InputStream in = null; @@ -745,15 +742,21 @@ } } + private ClassLoader getClassLoader(ClassLoader classLoader) { + String buildSysclasspath = project.getProperty(MagicNames.BUILD_SYSCLASSPATH); + if (project.getCoreLoader() != null + && !(BUILD_SYSCLASSPATH_ONLY.equals(buildSysclasspath))) { + classLoader = project.getCoreLoader(); + } + return classLoader; + } + /** * Load ant's datatypes. */ private void initTypes() { ClassLoader classLoader = null; - if (project.getCoreLoader() != null - && !(BUILD_SYSCLASSPATH_ONLY.equals(project.getProperty(MagicNames.BUILD_SYSCLASSPATH)))) { - classLoader = project.getCoreLoader(); - } + classLoader = getClassLoader(classLoader); String dataDefs = MagicNames.TYPEDEFS_PROPERTIES_RESOURCE; InputStream in = null; @@ -890,7 +893,7 @@ } out.println("Action: Determine what extra JAR files are needed, and place them"); out.println(" in ANT_HOME/lib or"); - out.println(" in " + libDir ); + out.println(" in " + libDir); } //here we successfully loaded the class or failed. if (clazz != null) { @@ -931,27 +934,28 @@ out.println(); out.println("Do not panic, this is a common problem."); if (definitions) { - out.println("It may just be a typographical error in the build file " + - "or the task/type declaration."); + out.println("It may just be a typographical error in the build file " + + "or the task/type declaration."); } if (jars) { out.println("The commonest cause is a missing JAR."); } if (lowlevel) { - out.println("This is quite a low level problem, which may need " + - "consultation with the author of the task."); + out.println("This is quite a low level problem, which may need " + + "consultation with the author of the task."); if (antTask) { - out.println("This may be the Ant team. Please file a " + - "defect or contact the developer team."); + out.println("This may be the Ant team. Please file a " + + "defect or contact the developer team."); } else { out.println("This does not appear to be a task bundled with Ant."); - out.println("Please take it up with the supplier of the third-party " + type + "."); + out.println("Please take it up with the supplier of the third-party " + + type + "."); out.println("If you have written it yourself, you probably have a bug to fix."); } } else { out.println(); - out.println("It is not an Ant bug; there is no need to file a bug" + - " report or contact the developers."); + out.println("It is not an Ant bug; there is no need to file a bug" + + " report or contact the developers."); } } out.flush(); Modified: ant/core/trunk/src/main/org/apache/tools/ant/Diagnostics.java URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/Diagnostics.java?rev=291012&r1=291011&r2=291012&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 Thu Sep 22 13:03:53 2005 @@ -44,6 +44,12 @@ */ public final class Diagnostics { + private static final int BIG_DRIFT_LIMIT = 10000; + private static final int TEST_FILE_SIZE = 32; + private static final int KILOBYTE = 1024; + 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"; @@ -263,8 +269,8 @@ try { sysprops = System.getProperties(); } catch (SecurityException e) { - out.println("Access to System.getProperties() blocked " + - "by a security manager"); + out.println("Access to System.getProperties() blocked " + + "by a security manager"); } for (Enumeration keys = sysprops.propertyNames(); keys.hasMoreElements();) { @@ -411,47 +417,47 @@ * @param out */ private static void doReportTempDir(PrintStream out) { - String tempdir=System.getProperty("java.io.tmpdir"); - if( tempdir == null ) { + 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); + 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; + long now = System.currentTimeMillis(); + File tempFile = null; FileOutputStream fileout = null; try { - tempFile = File.createTempFile("diag","txt",tempDirectory); + tempFile = File.createTempFile("diag", "txt", tempDirectory); //do some writing to it fileout = new FileOutputStream(tempFile); - byte buffer[]=new byte[1024]; - for(int i=0;i<32;i++) { + 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(); + 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)>10000) { + 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) { out.println("Failed to create a temporary file in the temp dir " + tempdir); - out.println("File "+ tempFile + " could not be created/written to"); + out.println("File " + tempFile + " could not be created/written to"); } finally { FileUtils.close(fileout); - if(tempFile!=null && tempFile.exists()) { + if (tempFile != null && tempFile.exists()) { tempFile.delete(); } } @@ -466,14 +472,14 @@ Calendar cal = Calendar.getInstance(); TimeZone tz = cal.getTimeZone(); out.println("Timezone " + tz.getDisplayName() - + " offset=" + tz.getOffset(cal.get(Calendar.ERA), + + " 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) * 60 - + cal.get(Calendar.MINUTE)) * 60 - + cal.get(Calendar.SECOND)) * 1000 + ((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))); } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org