} 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")) {
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;
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...
* @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);
}
} 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;
+ }
}
}
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.*;
// ---------------------------- 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;
verbose = false;
xweaveDir = null;
xdoneSignal = null;
- loggingMode = false;
- logFile = null;
}
protected void ignore(String ignored) {
}
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) {
*
*/
protected void executeInSameVM(String[] args) {
- PrintStream logStream = null;
if (null != maxMem) {
log("maxMem ignored unless forked: " + maxMem, Project.MSG_WARN);
}
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);
}
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;
* @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) {
// super.stop();
// }
// };
- Execute exe = new Execute(handler);
+
+ Execute exe = new Execute(handler);
exe.setAntRun(project);
exe.setWorkingDirectory(project.getBaseDir());
exe.setCommandline(args);
// 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 {