Browse Source

Only print the final stack trace if in verbose or debug mode, otherwise

just print exception message


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269466 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 24 years ago
parent
commit
722f6306c7
2 changed files with 146 additions and 16 deletions
  1. +6
    -1
      src/main/org/apache/tools/ant/DefaultLogger.java
  2. +140
    -15
      src/main/org/apache/tools/ant/taskdefs/FixCRLF.java

+ 6
- 1
src/main/org/apache/tools/ant/DefaultLogger.java View File

@@ -138,7 +138,12 @@ public class DefaultLogger implements BuildLogger {
else {
err.println(lSep + "BUILD FAILED" + lSep);

error.printStackTrace(err);
if (Project.MSG_VERBOSE <= msgOutputLevel) {
error.printStackTrace(err);
}
else {
err.println(error.getMessage());
}
}

out.println(lSep + "Total time: " + formatTime(System.currentTimeMillis() - startTime));


+ 140
- 15
src/main/org/apache/tools/ant/taskdefs/FixCRLF.java View File

@@ -53,16 +53,20 @@
*/

package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.EnumeratedAttribute;

import java.io.*;
import java.util.*;

/**
* FixCRLF.java
*
* Based on FixCR.java
* by Sam Ruby <a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a>.
*
* Task to convert text source files to local OS formatting conventions, as
* well as repair text files damaged by misconfigured or misguided editors or
* file transfer programs.
@@ -133,6 +137,7 @@ public class FixCRLF extends MatchingTask {
private StringBuffer linebuf = new StringBuffer(1024);
private StringBuffer linebuf2 = new StringBuffer(1024);
private int eol;
private int addcr = UNDEF;
private String eolstr;
private int ctrlz;
private int tabs;
@@ -307,13 +312,12 @@ public class FixCRLF extends MatchingTask {
ctrlz = ADD;
}
}

/**
* Executes the task.
*/
public void execute() throws BuildException {
// first off, make sure that we've got a srcdir and destdir
if (srcDir == null) {
throw new BuildException("srcdir attribute must be set!");
}
@@ -332,6 +336,57 @@ public class FixCRLF extends MatchingTask {
}
}

// Set up the correct EOL values
if (eol == UNDEF) {
if (addcr == UNDEF) {
// Neither eol not addcr has been defined
// go for the system defaults
if (System.getProperty("line.separator").equals("\r")) {
eol = CR;
} else if (System.getProperty("line.separator").equals("\n")) {
eol = LF;
} else {
eol = CRLF;
}
} // end of if (addcr == UNDEF)
else {
// addcr has been defined - translate to eol values
switch (addcr) {
case ADD:
eol = CRLF;
break;
case REMOVE:
eol = LF;
break;
case ASIS:
eol = ASIS;
break;

} // end of switch (addcr)
} // end of if (addcr == UNDEF)else
} // end of if (eol == UNDEF)

switch (eol) {
// set eolstr value unless ASIS
case CR:
eolstr = new String("\r");
break;
case LF:
eolstr = new String("\n");
break;
case CRLF:
eolstr = new String("\r\n");
break;
} // end of switch (eol)
// log options used
log("options:" +
" eol=" +
@@ -362,6 +417,49 @@ public class FixCRLF extends MatchingTask {
}
}

/**
* Checks for the inequality of two files
*/
private boolean filesEqual(File file1, File file2) {
BufferedReader reader1;
BufferedReader reader2;
char buf1[] = new char[INBUFLEN];
char buf2[] = new char[INBUFLEN];
int buflen;

if (file1.length() != file2.length()) {
return false;
}
try {
reader1 = new BufferedReader
(new FileReader(file1), INBUFLEN);
reader2 = new BufferedReader
(new FileReader(file2), INBUFLEN);
while ((buflen = reader1.read(buf1, 0, INBUFLEN)) != -1 ) {
reader2.read(buf2, 0, INBUFLEN);
// Compare the contents of the buffers
// There must be an easier way to do this, but I don''t
// know what it is
for (int i = 0; i < buflen; i++) {
if (buf1[i] != buf2[i]) {
reader1.close();
reader2.close();
return false;
} // end of if (buf1[i] != buf2[i])
}
}
reader1.close();
reader2.close();
return true; // equal
} catch (IOException e) {
throw new BuildException("IOException in filesEqual: " +
file1 + " : " + file2);
} // end of try-catch
}


private void processFile(String file) throws BuildException {
File srcFile = new File(srcDir, file);
File tmpFile = null;
@@ -515,20 +613,47 @@ public class FixCRLF extends MatchingTask {
catch (IOException e) {
throw new BuildException("Unable to close source file " + srcFile);
}
if (destFile.exists()) {
if (!destFile.delete()) {
throw new BuildException("Unable to delete " + destFile);
// Compare the destination with the temp file
System.out.println("destFile exists");
if ( ! filesEqual(destFile, tmpFile)) {
System.out.println("destFile exists: files not equal");
log(destFile + " is being written", Project.MSG_VERBOSE);
if (!destFile.delete()) {
throw new BuildException("Unable to delete "
+ destFile);
}
if (!tmpFile.renameTo(destFile)) {
throw new BuildException(
"Failed to transform " + srcFile
+ " to " + destFile
+ ". Couldn't rename temporary file: "
+ tmpFile);
}

} else { // destination is equal to temp file
System.out.println("destFile exists: files equal");
log(destFile +
" is not written, as the contents are identical",
Project.MSG_VERBOSE);
if (!tmpFile.delete()) {
throw new BuildException("Unable to delete "
+ destFile);
}
}
} else { // destFile does not exist - write the temp file
System.out.println("destFile does not exist");
if (!tmpFile.renameTo(destFile)) {
throw new BuildException(
"Failed to transform " + srcFile
+ " to " + destFile
+ ". Couldn't rename temporary file: "
+ tmpFile);
}
}
if (!tmpFile.renameTo(destFile)) {
throw new BuildException("Failed to transform " + srcFile
+ " to " + destFile
+ ". Couldn't rename temporary file: " + tmpFile);
} else {
tmpFile = null;
}

tmpFile = null;

} finally {
try {


Loading…
Cancel
Save