You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2006/03/28 20:05:03 UTC

svn commit: r389560 - in /beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler: CompilerUtils.java JpfLanguageConstants.java processor/TwoPhaseCoreAnnotationProcessor.java

Author: ekoneil
Date: Tue Mar 28 10:05:01 2006
New Revision: 389560

URL: http://svn.apache.org/viewcvs?rev=389560&view=rev
Log:
Add support for running the Page Flow annotation processor in two phases -- the "reconcile" and "build" phases -- as per the implementation of JDT/APT for hosting annotation processors inside of Eclipse.  In such an environment, a flag is provided by the AP hosting infrastructure that tells APs whether Eclipse is running a reconcile or build phase.  These map to the "build" and "generate" phases of Beehive's TwoPhaseAnnotationProcessor.

This change allows Eclipse to run the AP to reconcile without going through the expesne of writing out all of the generated files (generally, struts-config-*.xml files).  This improves performance when using Ecilpse + JDT/APT or using Eclipse 3.2 which supports this natively.

BB: self
Test: NetUI and distribution tests pass


Modified:
    beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/CompilerUtils.java
    beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/JpfLanguageConstants.java
    beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/processor/TwoPhaseCoreAnnotationProcessor.java

Modified: beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/CompilerUtils.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/CompilerUtils.java?rev=389560&r1=389559&r2=389560&view=diff
==============================================================================
--- beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/CompilerUtils.java (original)
+++ beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/CompilerUtils.java Tue Mar 28 10:05:01 2006
@@ -1275,6 +1275,18 @@
         return getOption( "-Aweb.content.root", true, env );
     }
 
+    /**
+     * Utility method to get the value of the "phase" option from the annotation processing environment.
+     * @param env the annotation processing environment
+     * @return the value of the "phase" option, or <code>null</code> if the option is unspecified
+     * @throws FatalCompileTimeException if an error occurs getting the value of the option 
+     */
+    public static String isReconcilePhase(CoreAnnotationProcessorEnv env)
+        throws FatalCompileTimeException {
+        String[] phase = getOption("-A" + JpfLanguageConstants.ANNOTATION_PROCESSOR_OPTION_PHASE, false, env);
+        return phase != null && phase.length > 0 ? phase[0] : null;
+    }
+
     private static String[] getOption( String optionName, boolean required, CoreAnnotationProcessorEnv env )
         throws MissingOptionException
     {

Modified: beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/JpfLanguageConstants.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/JpfLanguageConstants.java?rev=389560&r1=389559&r2=389560&view=diff
==============================================================================
--- beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/JpfLanguageConstants.java (original)
+++ beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/JpfLanguageConstants.java Tue Mar 28 10:05:01 2006
@@ -24,7 +24,9 @@
     public static final String PAGEFLOW_PACKAGE = NETUI_PACKAGE + ".pageflow";
     public static final String PAGEFLOW_INTERNAL_PACKAGE = PAGEFLOW_PACKAGE + ".internal";
     public static final String ANNOTATIONS_CLASSNAME = PAGEFLOW_PACKAGE + ".annotations.Jpf";
-    
+
+    public static final String ANNOTATION_PROCESSOR_OPTION_PHASE = "phase";
+
     public static final String ACTION_TAG_NAME = "Action";
     public static final String SIMPLE_ACTION_TAG_NAME = "SimpleAction";
     public static final String EXCEPTION_HANDLER_TAG_NAME = "ExceptionHandler";
@@ -226,7 +228,7 @@
     public static final String GETTER_PREFIX = "get";
     public static final String BOOLEAN_GETTER_PREFIX = "is";
     
-    public static final String PAGEFLOW_RUNTIME_JAR = '/' + WEBINF_DIR_NAME + "/lib/beehive-netui-pageflow.jar";    
+    public static final String PAGEFLOW_RUNTIME_JAR = '/' + WEBINF_DIR_NAME + "/lib/beehive-netui-core.jar";
     public static final String RUNTIME_VERSION_ATTRIBUTE = "PageFlow-Runtime-Version";
     
     public static final String VERSION_8_SP2_STRING = "2";

Modified: beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/processor/TwoPhaseCoreAnnotationProcessor.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/processor/TwoPhaseCoreAnnotationProcessor.java?rev=389560&r1=389559&r2=389560&view=diff
==============================================================================
--- beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/processor/TwoPhaseCoreAnnotationProcessor.java (original)
+++ beehive/trunk/netui/src/compiler-core/org/apache/beehive/netui/compiler/processor/TwoPhaseCoreAnnotationProcessor.java Tue Mar 28 10:05:01 2006
@@ -26,6 +26,7 @@
 import org.apache.beehive.netui.compiler.typesystem.declaration.Declaration;
 import org.apache.beehive.netui.compiler.Diagnostics;
 import org.apache.beehive.netui.compiler.FatalCompileTimeException;
+import org.apache.beehive.netui.compiler.CompilerUtils;
 
 /**
  * The TwoPhaseCoreAnnotationProcessor class is an abstract class that implements the APT
@@ -84,9 +85,29 @@
         try
         {
             check();
-    
-            // Do not call generate if check resulted in errors.
-            if ( ! hasErrors() ) generate();
+
+            boolean isReconcilePhase = false;
+
+            // In the Eclipse IDE's integration between JDT and APT, annotation processors
+            // run in two phases -- reconcile and build.  These translate into the
+            // check and generate phases for a TwoPhaseAnnotationProcessor.  In order to
+            // optimize for hosting in this environment (and other IDE-centric AP environments)
+            // the generate phase can be cut out when performing only the check phase.
+            // Custom AP environments that wish to control this shoudl set the "phase" flag of the
+            // annotation processor to "RECONCILE".
+            try {
+                String phase = (String)CompilerUtils.isReconcilePhase(getAnnotationProcessorEnvironment());
+                isReconcilePhase = "RECONCILE".equals(phase);
+            }
+            catch(FatalCompileTimeException e) {
+                e.printDiagnostic(this);
+            }
+
+            // Do not call generate if check resulted in errors of if the AP is running in
+            // a phase called "reconcile"
+            if (!isReconcilePhase && !hasErrors()) {
+                generate();
+            }
         }
         catch ( FatalCompileTimeException e )
         {
@@ -102,7 +123,7 @@
         throws FatalCompileTimeException
     {
         HashSet declsToCheck = new HashSet();
-        
+
         //
         // First, build up the Set of declarations to check.  We don't want any duplicates.
         //
@@ -115,7 +136,7 @@
                 declsToCheck.add( decls[j] );
             }
         }
-        
+
         //
         // Now, check the declarations.
         //
@@ -135,12 +156,12 @@
         try
         {
             HashSet alreadyProcessed = new HashSet();
-            
+
             for ( int i = 0; i < _atds.length; i++ )
             {
                 AnnotationTypeDeclaration atd = _atds[i];
                 Declaration[] decls = getAnnotationProcessorEnvironment().getDeclarationsAnnotatedWith( atd );
-                
+
                 for ( int j = 0; j < decls.length; j++ )
                 {
                     Declaration decl = decls[j];