]> source.dussan.org Git - aspectj.git/commitdiff
support for -messageHolder command-line option. This is needed by the forking iajc...
authoracolyer <acolyer>
Mon, 30 Jan 2006 17:34:58 +0000 (17:34 +0000)
committeracolyer <acolyer>
Mon, 30 Jan 2006 17:34:58 +0000 (17:34 +0000)
org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java
org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/MainTest.java
org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/TestMessageHolder.java [new file with mode: 0644]

index e34ec6ce1cc348754cb9ae0608497358ecbca395..99843a3b9408140ec936c683becdfc087fa156e3 100644 (file)
@@ -77,7 +77,9 @@ public class Main {
                  + "should be increased from 64M (default) to 128M or even 256M." + LangUtil.EOL + LangUtil.EOL
                  + "See the AspectJ FAQ available from the documentation link" + LangUtil.EOL
                  + "on the AspectJ home page at http://www.eclipse.org/aspectj";
-    
+
+       private static final String MESSAGE_HOLDER_OPTION = "-messageHolder";
+       
     /** @param args the String[] of command-line arguments */
     public static void main(String[] args) throws IOException {
         new Main().runMain(args, true);
@@ -195,7 +197,7 @@ public class Main {
     
     /** if not null, run this synchronously after each compile completes */
     private Runnable completionRunner;
-    
+
     public Main() {
         controller = new CommandController();
         commandName = ReflectionFactory.ECLIPSE;
@@ -223,16 +225,19 @@ public class Main {
      */
     public void runMain(String[] args, boolean useSystemExit) {
         final boolean verbose = flagInArgs("-verbose", args);
+        if (null == this.clientHolder) {
+               this.clientHolder = checkForCustomMessageHolder(args);
+        }
         IMessageHolder holder = clientHolder;
         if (null == holder) {
-            holder = ourHandler;
+               holder = ourHandler;
             if (verbose) {
                 ourHandler.setInterceptor(MessagePrinter.VERBOSE);
             } else {
                 ourHandler.ignore(IMessage.INFO);
                 ourHandler.setInterceptor(MessagePrinter.TERSE);
             }
-        }
+        } 
         
         // make sure we handle out of memory gracefully...
         try {
@@ -258,6 +263,25 @@ public class Main {
         }
     }
 
+       /**
+        * @param args
+        */
+       private IMessageHolder checkForCustomMessageHolder(String[] args) {
+               IMessageHolder holder = null;
+               final String customMessageHolder = parmInArgs(MESSAGE_HOLDER_OPTION, args);
+               if (customMessageHolder != null) {
+                       try {
+                               holder = (IMessageHolder) Class.forName(customMessageHolder).newInstance();
+                       } 
+                       catch(Exception ex) {
+                               holder = ourHandler;
+                               throw new AbortException("Failed to create custom message holder of class '" +
+                                                          customMessageHolder + "' : " + ex);
+                       }
+               }
+               return holder;
+       }
+
     /**
      * Run without using System.exit(..), putting all messages in holder:
      * <ul>
@@ -391,6 +415,10 @@ public class Main {
         clientHolder = holder;
     }
     
+    public IMessageHolder getHolder() {
+       return clientHolder;
+    }
+    
     /**
      * Install a Runnable to be invoked synchronously
      * after each compile completes.
index dfd1f4783567c6ca783fc9393d8fc26535084ab4..4b079379a348fb041457f9d037cc7b149ea2854c 100644 (file)
@@ -15,6 +15,8 @@ package org.aspectj.tools.ajc;
 import java.util.ArrayList;
 import java.util.ResourceBundle;
 
+import org.aspectj.bridge.AbortException;
+
 /**
  * 
  */
@@ -39,4 +41,19 @@ public class MainTest extends AjcTestCase {
                assertMessages(result,"Expecting xoptions usage message",
                                new MessageSpec(null,null,null,newMessageList(new Message(xoptionText)),null));
     }
+    
+    public void testDashMessageHolder() {
+       try {
+               new Main().runMain(new String[] {"-messageHolder","org.xyz.abc"},false);
+               fail ("Should have thrown abort exception");
+       } catch (AbortException ex) {
+               // good
+       }
+    }
+    
+    public void testDashMessageHolderOk() {
+       Main main = new Main();
+       main.runMain(new String[] {"-messageHolder","org.aspectj.tools.ajc.TestMessageHolder"},false);
+       assertSame("ajc should be using our message handler",TestMessageHolder.class,main.getHolder().getClass());
+    }
 }
diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/TestMessageHolder.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/TestMessageHolder.java
new file mode 100644 (file)
index 0000000..a4a99b0
--- /dev/null
@@ -0,0 +1,92 @@
+/* *******************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Eclipse Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://eclipse.org/legal/epl-v10.html 
+ *  
+ * Contributors: 
+ *   Adrian Colyer                     Initial implementation
+ * ******************************************************************/
+package org.aspectj.tools.ajc;
+
+import java.util.List;
+
+import org.aspectj.bridge.AbortException;
+import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.IMessageHolder;
+import org.aspectj.bridge.IMessage.Kind;
+
+/**
+ * @author Adrian
+ *
+ * Deliberately empty implementation of IMessageHolder
+ */
+public class TestMessageHolder implements IMessageHolder {
+
+       /* (non-Javadoc)
+        * @see org.aspectj.bridge.IMessageHolder#hasAnyMessage(org.aspectj.bridge.IMessage.Kind, boolean)
+        */
+       public boolean hasAnyMessage(Kind kind, boolean orGreater) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       /* (non-Javadoc)
+        * @see org.aspectj.bridge.IMessageHolder#numMessages(org.aspectj.bridge.IMessage.Kind, boolean)
+        */
+       public int numMessages(Kind kind, boolean orGreater) {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       /* (non-Javadoc)
+        * @see org.aspectj.bridge.IMessageHolder#getMessages(org.aspectj.bridge.IMessage.Kind, boolean)
+        */
+       public IMessage[] getMessages(Kind kind, boolean orGreater) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       /* (non-Javadoc)
+        * @see org.aspectj.bridge.IMessageHolder#getUnmodifiableListView()
+        */
+       public List getUnmodifiableListView() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       /* (non-Javadoc)
+        * @see org.aspectj.bridge.IMessageHolder#clearMessages()
+        */
+       public void clearMessages() throws UnsupportedOperationException {
+               // TODO Auto-generated method stub
+
+       }
+
+       /* (non-Javadoc)
+        * @see org.aspectj.bridge.IMessageHandler#handleMessage(org.aspectj.bridge.IMessage)
+        */
+       public boolean handleMessage(IMessage message) throws AbortException {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       /* (non-Javadoc)
+        * @see org.aspectj.bridge.IMessageHandler#isIgnoring(org.aspectj.bridge.IMessage.Kind)
+        */
+       public boolean isIgnoring(Kind kind) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       /* (non-Javadoc)
+        * @see org.aspectj.bridge.IMessageHandler#dontIgnore(org.aspectj.bridge.IMessage.Kind)
+        */
+       public void dontIgnore(Kind kind) {
+               // TODO Auto-generated method stub
+
+       }
+
+}