diff options
author | acolyer <acolyer> | 2005-06-02 11:46:31 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2005-06-02 11:46:31 +0000 |
commit | 27c6150906667e299a6952bc4dda642aad00578d (patch) | |
tree | 4ccbc1e238ba018c51d1fa45d3bcceb2ebac9c90 /taskdefs | |
parent | bedcb3ea08173f4b4ed837822e917e8dba6837d9 (diff) | |
download | aspectj-27c6150906667e299a6952bc4dda642aad00578d.tar.gz aspectj-27c6150906667e299a6952bc4dda642aad00578d.zip |
Andrew Huff's patch for the -log option
Diffstat (limited to 'taskdefs')
-rw-r--r-- | taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java | 49 | ||||
-rw-r--r-- | taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java | 26 |
2 files changed, 13 insertions, 62 deletions
diff --git a/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java b/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java index 60fba4b89..0427f9c1f 100644 --- a/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java +++ b/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java @@ -25,7 +25,6 @@ import org.apache.tools.ant.types.*; import org.aspectj.bridge.*; import org.aspectj.tools.ajc.Main; import org.aspectj.tools.ajc.Main.MessagePrinter; -import org.aspectj.tools.ajc.Main.LogModeMessagePrinter; import org.aspectj.util.*; @@ -292,8 +291,6 @@ public class AjcTask extends MatchingTask { // ---------------------------- state and Ant interface thereto private boolean verbose; private boolean listFileArgs; - private boolean loggingMode; - private File logFile; private boolean failonerror; private boolean fork; private String maxMem; @@ -407,8 +404,6 @@ public class AjcTask extends MatchingTask { verbose = false; xweaveDir = null; xdoneSignal = null; - loggingMode = false; - logFile = null; } protected void ignore(String ignored) { @@ -546,9 +541,7 @@ public class AjcTask extends MatchingTask { } public void setLog(File file) { - //cmd.addFlagged("-log", file.getAbsolutePath()); - this.loggingMode = true; - this.logFile = file; + cmd.addFlagged("-log", file.getAbsolutePath()); } public void setProceedOnError(boolean proceedOnError) { @@ -1166,7 +1159,6 @@ public class AjcTask extends MatchingTask { * */ protected void executeInSameVM(String[] args) { - PrintStream logStream = null; if (null != maxMem) { log("maxMem ignored unless forked: " + maxMem, Project.MSG_WARN); } @@ -1175,26 +1167,7 @@ public class AjcTask extends MatchingTask { if (null == holder) { MessageHandler mhandler = new MessageHandler(true); final IMessageHandler delegate; - if (!loggingMode){ delegate = verbose ? MessagePrinter.VERBOSE: MessagePrinter.TERSE; - } - else{ - String logFileName = logFile.toString(); - try { - logFile.createNewFile(); - FileOutputStream fos = new FileOutputStream(logFileName, true); - logStream = new PrintStream(fos,true); - delegate = new LogModeMessagePrinter(verbose, logStream); - Date now = new Date(); - logStream.println("Log started: " + now.toString()); - } catch (IOException e){ - if (logStream != null) { - logStream.close(); - logStream = null; - } - throw new BuildException("Logfile couldn't be written to: ",e); - } - } mhandler.setInterceptor(delegate); if (!verbose) { mhandler.ignore(IMessage.INFO); @@ -1218,14 +1191,7 @@ public class AjcTask extends MatchingTask { } main = newmain; } - try { - main.runMain(args, false); - } finally { - main = null; - if (logStream != null) { - logStream.close(); - } - } + main.runMain(args, false); if (failonerror) { int errs = holder.numMessages(IMessage.ERROR, false); errs -= numPreviousErrors; @@ -1376,10 +1342,12 @@ public class AjcTask extends MatchingTask { * @return */ protected int execInOtherVM(String[] args) { - try { + try { + Project project = getProject(); - LogStreamHandler handler = new LogStreamHandler(this, - Project.MSG_INFO, Project.MSG_WARN); + PumpStreamHandler handler = new LogStreamHandler(this, + Project.MSG_INFO, Project.MSG_WARN); + // replace above two lines with what follows as an aid to debugging when running the unit tests.... // LogStreamHandler handler = new LogStreamHandler(this, // Project.MSG_INFO, Project.MSG_WARN) { @@ -1402,7 +1370,8 @@ public class AjcTask extends MatchingTask { // super.stop(); // } // }; - Execute exe = new Execute(handler); + + Execute exe = new Execute(handler); exe.setAntRun(project); exe.setWorkingDirectory(project.getBaseDir()); exe.setCommandline(args); diff --git a/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java index d7019d061..fcc27eef1 100644 --- a/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java +++ b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java @@ -301,35 +301,17 @@ public class AjcTaskTest extends TestCase { // verifies that the log attribute of AjcTask writes output to the given log file public void testLoggingMode() { AjcTask task = getTask("default.lst"); - File logFile = new File("testLogFile.txt"); + task.setFailonerror(false); + File logFile = new File("testLogFile1.txt"); + String s = logFile.getAbsolutePath(); logFile.delete(); - try { - logFile.createNewFile(); - } catch (IOException e) { - fail("unexpected " + e.getMessage()); - } long initialLength = logFile.length(); task.setLog(logFile); - checkRun(task, null); + runTest(task,null,null); long newLength = logFile.length(); assertTrue(newLength > initialLength); logFile.delete(); } - - // this test method submitted by patch from Andrew Huff (IBM) - // verifies that the log attribute of AjcTask appends output to the given log file - public void testLoggingIsAppending(){ - AjcTask task = getTask("compileError.lst"); - task.setFailonerror(false); - File logFile = new File("testLogFile.txt"); - task.setLog(logFile); - checkRun(task,null); - long oldLength = logFile.length(); - checkRun(task,null); - long newLength = logFile.length(); - assertTrue(newLength > oldLength); - logFile.delete(); - } private void checkRun(AjcTask task, String exceptionString) { try { |