]> source.dussan.org Git - aspectj.git/commitdiff
Fix 136707 new logCommand option emits command line to INFO
authorwisberg <wisberg>
Tue, 13 Jun 2006 19:45:44 +0000 (19:45 +0000)
committerwisberg <wisberg>
Tue, 13 Jun 2006 19:45:44 +0000 (19:45 +0000)
docs/devGuideDB/antsupport.xml
taskdefs/src/org/aspectj/tools/ant/taskdefs/AjcTask.java
taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java

index cba940e1a3994c91dd84a2c1a55c861efc8b74d6..445c37e48419d8611eb42f3895974126dc78dfb1 100644 (file)
                                <entry><para>verbose
                                </para></entry>
                                <entry><para>
-                               If true, emit compiler status messages during the compile.                              
+                               If true, log compiler verbose messages as Project.INFO during the compile.
+                               </para></entry>
+                       </row>
+                       <row>
+                               <entry><para>logCommand
+                               </para></entry>
+                               <entry><para>
+                               If true, log compiler command elements as Project.INFO
+                               (rather than the usual Project.VERBOSE level).                          
                                </para></entry>
                        </row>
                        <row>
index 19c4e61274d11389585b69d5f651f2b5d4f6891a..62034beb8fd4fdd46f0adb53185a7823b0b13738 100644 (file)
@@ -402,6 +402,9 @@ public class AjcTask extends MatchingTask {
     /** true if -XincrementalFile (i.e, setTagFile)*/
     private boolean inIncrementalFileMode; 
 
+    /** log command in non-verbose mode */
+    private boolean logCommand; 
+
     /** used when forking */
     private CommandlineJava javaCmd = new CommandlineJava();
 
@@ -447,6 +450,7 @@ public class AjcTask extends MatchingTask {
         verbose = false;
         xweaveDir = null;
         xdoneSignal = null;
+        logCommand = false;
         javaCmd = new CommandlineJava();
     }
 
@@ -495,6 +499,10 @@ public class AjcTask extends MatchingTask {
         inIncrementalMode = incremental;
     }
 
+    public void setLogCommand(boolean logCommand) {
+        this.logCommand = logCommand;
+    }
+    
     public void setHelp(boolean help) {  
         cmd.addFlag("-help", help);
     }
@@ -1063,7 +1071,11 @@ public class AjcTask extends MatchingTask {
         verifyOptions();
         try {
             String[] args = makeCommand();
-            logVerbose("ajc " + Arrays.asList(args));
+            if (logCommand) {
+                log("ajc " + Arrays.asList(args));                
+            } else {
+                logVerbose("ajc " + Arrays.asList(args));
+            }
             if (!fork) {
                 executeInSameVM(args);
             } else { // when forking, Adapter handles failonerror
index da24f8e033b8a1e1527580d080deb96d8db69d36..c0667abb347379aea5a9e08e0114a3ae0a435b96 100644 (file)
@@ -22,13 +22,16 @@ import java.io.FileFilter;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 
 import junit.framework.TestCase;
 
+import org.apache.tools.ant.BuildEvent;
 import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildListener;
 import org.apache.tools.ant.Location;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.types.Path;
@@ -715,25 +718,48 @@ public class AjcTaskTest extends TestCase {
                runTest(task, NO_EXCEPTION, MessageHolderChecker.ONE_ERROR_ONE_ABORT);
        }
 
-       public void testDefaultFileComplete() {
-               AjcTask task = getTask("default.lst");
-               task.setDebugLevel("none");
-               task.setDeprecation(true);
-               task.setFailonerror(false);
-               task.setNoExit(true); // ok to override Ant?
-               task.setNoImportError(true);
-               task.setNowarn(true);
-               task.setXTerminateAfterCompilation(true);
-               task.setPreserveAllLocals(true);
-               task.setProceedOnError(true);
-               task.setReferenceInfo(true);
-               task.setSource("1.3");
-               task.setTarget("1.1");
-               task.setTime(true);
-               task.setVerbose(true);
-               task.setXlint("info");
-               runTest(task, NO_EXCEPTION, MessageHolderChecker.INFOS);
-       }
+    public void testDefaultFileComplete() {
+        AjcTask task = getTask("default.lst");
+        defaultSettings(task);
+        runTest(task, NO_EXCEPTION, MessageHolderChecker.INFOS);
+    }
+    private void defaultSettings(AjcTask task) {
+        task.setDebugLevel("none");
+        task.setDeprecation(true);
+        task.setFailonerror(false);
+        task.setNoExit(true); // ok to override Ant?
+        task.setNoImportError(true);
+        task.setNowarn(true);
+        task.setXTerminateAfterCompilation(true);
+        task.setPreserveAllLocals(true);
+        task.setProceedOnError(true);
+        task.setReferenceInfo(true);
+        task.setSource("1.3");
+        task.setTarget("1.1");
+        task.setTime(true);
+        task.setVerbose(true);
+        task.setXlint("info");        
+    }
+    
+    public void testLogCommand() {
+        final String DEFAULT = "default.lst";
+        AjcTask task = getTask(DEFAULT);
+        defaultSettings(task);
+        task.setVerbose(false);
+        task.setLogCommand(true);
+        LogListener listener = new LogListener(Project.MSG_INFO);
+        task.getProject().addBuildListener(listener);
+        runTest(task, NO_EXCEPTION, MessageHolderChecker.INFOS);
+        String[] results = listener.getResults();
+        boolean matched = false;
+        for (int i = 0; !matched && (i < results.length); i++) {
+            String s = results[i];
+            matched = (null != s) && (-1 != s.indexOf(DEFAULT));
+        }
+        if (!matched) {
+            fail(DEFAULT + " not found in " + Arrays.asList(results));
+        }
+    }
 
        public void testXOptions() {
                String[] xopts = new String[] {
@@ -937,6 +963,27 @@ public class AjcTaskTest extends TestCase {
                        }
                }
        }
+    private static class LogListener implements BuildListener {
+        private final ArrayList results = new ArrayList();
+        private final int priority;
+        private LogListener(int priority) {
+            this.priority = priority;
+        }
+        public void buildFinished(BuildEvent event) {}
+        public void buildStarted(BuildEvent event) {}
+        public void messageLogged(BuildEvent event) {
+            if (priority == event.getPriority()) {
+                results.add(event.getMessage());
+            }
+        }
+        public void targetFinished(BuildEvent event) {}
+        public void targetStarted(BuildEvent event) {}
+        public void taskFinished(BuildEvent event) {}
+        public void taskStarted(BuildEvent event) {}
+        String[] getResults() {
+            return (String[]) results.toArray(new String[0]);
+        }
+    }
 }
 class SnoopingCommandEditor implements ICommandEditor {
        private static final String[] NONE = new String[0];