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 | |
parent | bedcb3ea08173f4b4ed837822e917e8dba6837d9 (diff) | |
download | aspectj-27c6150906667e299a6952bc4dda642aad00578d.tar.gz aspectj-27c6150906667e299a6952bc4dda642aad00578d.zip |
Andrew Huff's patch for the -log option
4 files changed, 64 insertions, 68 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java index 9aaf068c3..2de67f693 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java @@ -491,6 +491,9 @@ public class BuildArgParser extends Main { } else { showError("-outjar requires jar path argument"); } + } else if (arg.equals("-log")){ + // remove it as it's already been handled in org.aspectj.tools.ajc.Main + args.remove(args.get(nextArgIndex)); } else if (arg.equals("-incremental")) { buildConfig.setIncrementalMode(true); } else if (arg.equals("-XincrementalFile")) { diff --git a/org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java b/org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java index 5b701334a..3861d18e9 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java @@ -15,9 +15,11 @@ package org.aspectj.tools.ajc; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.List; +import java.util.Date; import org.aspectj.bridge.AbortException; import org.aspectj.bridge.ICommand; @@ -212,12 +214,12 @@ public class Main { IMessageHolder holder = clientHolder; if (null == holder) { holder = ourHandler; - if (verbose) { +// if (verbose) { ourHandler.setInterceptor(MessagePrinter.VERBOSE); - } else { - ourHandler.ignore(IMessage.INFO); - ourHandler.setInterceptor(MessagePrinter.TERSE); - } +// } else { +// ourHandler.ignore(IMessage.INFO); +// ourHandler.setInterceptor(MessagePrinter.TERSE); +// } } // make sure we handle out of memory gracefully... @@ -268,7 +270,34 @@ public class Main { * @param holder the MessageHandler sink for messages. */ public void run(String[] args, IMessageHolder holder) { - if (LangUtil.isEmpty(args)) { + + boolean logMode = (-1 != ("" + LangUtil.arrayAsList(args)).indexOf("-log")); + PrintStream logStream = null; + FileOutputStream fos = null; + if (logMode){ + int logIndex = LangUtil.arrayAsList(args).indexOf("-log"); + String logFileName = args[logIndex + 1]; + File logFile = new File(logFileName); + try{ + logFile.createNewFile(); + fos = new FileOutputStream(logFileName, true); + logStream = new PrintStream(fos,true); + } catch(Exception e){ + fail(holder, "Couldn't open log file: ", e); + } + Date now = new Date(); + logStream.println(now.toString()); + boolean verbose = (-1 != ("" + LangUtil.arrayAsList(args)).indexOf("-verbose")); + if (verbose) { + ourHandler.setInterceptor(new LogModeMessagePrinter(true,logStream)); + } else { + ourHandler.ignore(IMessage.INFO); + ourHandler.setInterceptor(new LogModeMessagePrinter(false,logStream)); + } + holder = ourHandler; + } + + if (LangUtil.isEmpty(args)) { args = new String[] { "-?" }; } else if (controller.running()) { fail(holder, "already running with controller: " + controller, null); @@ -324,6 +353,19 @@ public class Main { } } catch (Throwable t) { fail(holder, "unexpected exception", t); + } finally{ + if (logStream != null){ + logStream.close(); + logStream = null; + } + if (fos != null){ + try { + fos.close(); + } catch (IOException e){ + fail(holder, "unexpected exception", e); + } + fos = null; + } } } 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 { |