diff options
author | acolyer <acolyer> | 2005-04-20 12:35:08 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2005-04-20 12:35:08 +0000 |
commit | 6906800a16da50158ed9f767d36dbf6ff24d5022 (patch) | |
tree | 80a5c8e2b1eac68b43ee62f9105518f1d6df4ecf | |
parent | cf35fc6351b60933460fe44e00e262cb72f43cef (diff) | |
download | aspectj-6906800a16da50158ed9f767d36dbf6ff24d5022.tar.gz aspectj-6906800a16da50158ed9f767d36dbf6ff24d5022.zip |
first half of Andrew Huff's patch for 59636 (-log option not producing output - should it?)
-rw-r--r-- | taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java | 44 | ||||
-rw-r--r-- | taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java | 40 |
2 files changed, 72 insertions, 12 deletions
diff --git a/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java b/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java index ffa97d124..a9d4dde48 100644 --- a/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java +++ b/taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java @@ -25,6 +25,7 @@ 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.*; @@ -291,6 +292,8 @@ 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; @@ -404,6 +407,8 @@ public class AjcTask extends MatchingTask { verbose = false; xweaveDir = null; xdoneSignal = null; + loggingMode = false; + logFile = null; } protected void ignore(String ignored) { @@ -537,7 +542,9 @@ public class AjcTask extends MatchingTask { } public void setLog(File file) { - cmd.addFlagged("-log", file.getAbsolutePath()); + //cmd.addFlagged("-log", file.getAbsolutePath()); + this.loggingMode = true; + this.logFile = file; } public void setProceedOnError(boolean proceedOnError) { @@ -557,10 +564,6 @@ public class AjcTask extends MatchingTask { cmd.addFlag("-referenceInfo", referenceInfo); } - public void setProgress(boolean progress) { - cmd.addFlag("-progress", progress); - } - public void setTime(boolean time) { cmd.addFlag("-time", time); } @@ -1158,6 +1161,7 @@ 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); } @@ -1165,8 +1169,27 @@ public class AjcTask extends MatchingTask { int numPreviousErrors; if (null == holder) { MessageHandler mhandler = new MessageHandler(true); - final IMessageHandler delegate - = verbose ? MessagePrinter.VERBOSE: MessagePrinter.TERSE; + 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); @@ -1194,6 +1217,9 @@ public class AjcTask extends MatchingTask { main.runMain(args, false); } finally { main = null; + if (logStream != null) { + logStream.close(); + } } if (failonerror) { int errs = holder.numMessages(IMessage.ERROR, false); @@ -1782,9 +1808,7 @@ public class AjcTask extends MatchingTask { setPreserveAllLocals(true); } else if ("-proceedOnError".equals(flag)) { setProceedOnError(true); - } else if ("-progress".equals(flag)) { - setProgress(true); - } else if ("-referenceInfo".equals(flag)) { + } else if ("-referenceInfo".equals(flag)) { setReferenceInfo(true); } else if ("-source".equals(flag)) { setSource(in.next()); diff --git a/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java index b8ebf9655..6bc8a4499 100644 --- a/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java +++ b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java @@ -2,6 +2,7 @@ * Copyright (c) 1999-2001 Xerox Corporation, * 2002 Palo Alto Research Center, Incorporated (PARC) * 2003 Contributors. + * 2005 Contributors * All rights reserved. * This program and the accompanying materials are made available * under the terms of the Common Public License v1.0 @@ -9,7 +10,8 @@ * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * Xerox/PARC initial implementation + * Xerox/PARC initial implementation + * IBM ongoing maintenance * ******************************************************************/ package org.aspectj.tools.ant.taskdefs; @@ -155,7 +157,7 @@ public class AjcTaskTest extends TestCase { assertTrue(!"-d".equals(cmd[i])); } } - + public void testOutputRequirement() { AjcTask task = getTask("default.lst"); checkRun(task, null); @@ -286,6 +288,40 @@ public class AjcTaskTest extends TestCase { checkRun(task, "inpathDirCopyFilter"); } + // this test method submitted by patch from Andrew Huff (IBM) + // 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"); + logFile.delete(); + try { + logFile.createNewFile(); + } catch (IOException e) { + fail("unexpected " + e.getMessage()); + } + long initialLength = logFile.length(); + task.setLog(logFile); + checkRun(task, 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 { task.execute(); |