Browse Source

Layout, extracted methods / named constants

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@291012 13f79535-47bb-0310-9956-ffa450edef68
master
Jacobus Martinus Kruithof 20 years ago
parent
commit
954f6058d7
2 changed files with 53 additions and 43 deletions
  1. +22
    -18
      src/main/org/apache/tools/ant/ComponentHelper.java
  2. +31
    -25
      src/main/org/apache/tools/ant/Diagnostics.java

+ 22
- 18
src/main/org/apache/tools/ant/ComponentHelper.java View File

@@ -705,10 +705,7 @@ public class ComponentHelper {
*/ */
private void initTasks() { private void initTasks() {
ClassLoader classLoader = null; 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; String dataDefs = MagicNames.TASKDEF_PROPERTIES_RESOURCE;


InputStream in = null; InputStream in = null;
@@ -745,15 +742,21 @@ public class ComponentHelper {
} }
} }


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. * Load ant's datatypes.
*/ */
private void initTypes() { private void initTypes() {
ClassLoader classLoader = null; 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; String dataDefs = MagicNames.TYPEDEFS_PROPERTIES_RESOURCE;


InputStream in = null; InputStream in = null;
@@ -890,7 +893,7 @@ public class ComponentHelper {
} }
out.println("Action: Determine what extra JAR files are needed, and place them"); out.println("Action: Determine what extra JAR files are needed, and place them");
out.println(" in ANT_HOME/lib or"); out.println(" in ANT_HOME/lib or");
out.println(" in " + libDir );
out.println(" in " + libDir);
} }
//here we successfully loaded the class or failed. //here we successfully loaded the class or failed.
if (clazz != null) { if (clazz != null) {
@@ -931,27 +934,28 @@ public class ComponentHelper {
out.println(); out.println();
out.println("Do not panic, this is a common problem."); out.println("Do not panic, this is a common problem.");
if (definitions) { 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) { if (jars) {
out.println("The commonest cause is a missing JAR."); out.println("The commonest cause is a missing JAR.");
} }
if (lowlevel) { 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) { 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 { } else {
out.println("This does not appear to be a task bundled with Ant."); 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."); out.println("If you have written it yourself, you probably have a bug to fix.");
} }
} else { } else {
out.println(); 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(); out.flush();


+ 31
- 25
src/main/org/apache/tools/ant/Diagnostics.java View File

@@ -44,6 +44,12 @@ import java.lang.reflect.InvocationTargetException;
*/ */
public final class Diagnostics { 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 private static final String TEST_CLASS
= "org.apache.tools.ant.taskdefs.optional.Test"; = "org.apache.tools.ant.taskdefs.optional.Test";


@@ -263,8 +269,8 @@ public final class Diagnostics {
try { try {
sysprops = System.getProperties(); sysprops = System.getProperties();
} catch (SecurityException e) { } 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(); for (Enumeration keys = sysprops.propertyNames();
keys.hasMoreElements();) { keys.hasMoreElements();) {
@@ -411,47 +417,47 @@ public final class Diagnostics {
* @param out * @param out
*/ */
private static void doReportTempDir(PrintStream 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"); out.println("Warning: java.io.tmpdir is undefined");
return; 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; return;
} }
//create the file //create the file
long now=System.currentTimeMillis();
File tempFile=null;
long now = System.currentTimeMillis();
File tempFile = null;
FileOutputStream fileout = null; FileOutputStream fileout = null;
try { try {
tempFile = File.createTempFile("diag","txt",tempDirectory);
tempFile = File.createTempFile("diag", "txt", tempDirectory);
//do some writing to it //do some writing to it
fileout = new FileOutputStream(tempFile); 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.write(buffer);
} }
fileout.close(); fileout.close();
fileout=null;
long filetime=tempFile.lastModified();
fileout = null;
long filetime = tempFile.lastModified();
tempFile.delete(); tempFile.delete();
out.println("Temp dir is writeable"); 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"); out.println("Warning: big clock drift -maybe a network filesystem");
} }
} catch (IOException e) { } catch (IOException e) {
out.println("Failed to create a temporary file in the temp dir " out.println("Failed to create a temporary file in the temp dir "
+ tempdir); + tempdir);
out.println("File "+ tempFile + " could not be created/written to");
out.println("File " + tempFile + " could not be created/written to");
} finally { } finally {
FileUtils.close(fileout); FileUtils.close(fileout);
if(tempFile!=null && tempFile.exists()) {
if (tempFile != null && tempFile.exists()) {
tempFile.delete(); tempFile.delete();
} }
} }
@@ -466,14 +472,14 @@ public final class Diagnostics {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
TimeZone tz = cal.getTimeZone(); TimeZone tz = cal.getTimeZone();
out.println("Timezone " + tz.getDisplayName() 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.YEAR),
cal.get(Calendar.MONTH), cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH),
cal.get(Calendar.DAY_OF_WEEK), 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))); + cal.get(Calendar.MILLISECOND)));
} }
} }

Loading…
Cancel
Save