Author: kentam
Date: Tue Mar  1 15:04:55 2005
New Revision: 155837

URL: http://svn.apache.org/viewcvs?view=rev&rev=155837
Log:
BEEHIVE-230: Controls versioning: VersionRequired not enforced on control 
extension and declaration

There was actually an error in the original test (@VersionRequired is only 
supported on extensions,
not on plain control interfaces), but we should have had build-time diagnostics 
to make this clear.
Added those, fixed the test.


Removed:
    
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/versioning/SubHelloImpl.jcs
Modified:
    
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java
    
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
    
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/strings.properties
    
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/versioning/SubHello.java
    
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/versioning/VersionRequiredTest.java

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java?view=diff&r1=155836&r2=155837
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java
 (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java
 Tue Mar  1 15:04:55 2005
@@ -93,17 +93,17 @@
         _bean = new ControlBean(this);
 
         //
+        // Enforce VersionRequired semantics
+        //
+        enforceVersionRequired();
+
+        //
         // Do work specific to control extensions
         //
 
         if (isExtension())
         {
             //
-            // Enforce VersionRequired semantics
-            //
-            enforceVersionRequired();
-
-            //
             // If this is an control extension, run the 
control-author-specified
             // checker class to perform additional validation.
             //
@@ -810,6 +810,13 @@
     {
         if ( _versionRequired != null )
         {
+            if ( !isExtension() )
+            {
+                _env.getMessager().printError( _intfDecl.getPosition(),
+                        "Illegal usage of @VersionRequired: not permitted on 
interfaces annotated with @ControlInterface" );
+                return;
+            }
+
             int majorRequired = _versionRequired.major();
             int minorRequired = _versionRequired.minor();
 

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java?view=diff&r1=155836&r2=155837
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
 (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
 Tue Mar  1 15:04:55 2005
@@ -29,17 +29,16 @@
 
 import java.util.*;
 
-import org.apache.beehive.controls.runtime.generator.AptControlClient;
-import org.apache.beehive.controls.runtime.generator.CodeGenerationException;
-import org.apache.beehive.controls.runtime.generator.Generator;
-import org.apache.beehive.controls.runtime.generator.GeneratorOutput;
-import org.apache.beehive.controls.runtime.generator.CodeGenerator;
+import org.apache.beehive.controls.runtime.generator.*;
 import org.apache.beehive.controls.runtime.bean.ControlBeanContext;
 import org.apache.beehive.controls.api.bean.*;
+import org.apache.beehive.controls.api.versioning.Version;
+import org.apache.beehive.controls.api.versioning.VersionRequired;
 
 import java.util.Set;
 import java.io.File;
 import java.io.IOException;
+import java.lang.annotation.Annotation;
 
 public class ControlClientAnnotationProcessor extends 
TwoPhaseAnnotationProcessor
 {
@@ -256,15 +255,24 @@
              printError( f, "control.field.bad.type" );
          }
 
+         // Enforce any versioning requirements this control field has.
+         //
          // Since our generate() does some detailed grovelling of control 
types, make sure that
          // will not result in an error by doing that grovelling now.  Control 
types may be
-         // malformed if the source for those types has errors (yet the apt 
type map still exist!).
+         // malformed if the source for those types has errors (yet the apt 
type may still exist!).
          try
          {
              InterfaceType controlIntfOrExt = 
getControlInterfaceOrExtension(fieldType);
              InterfaceType controlIntf = getMostDerivedControlInterface( 
controlIntfOrExt );
-             if ( controlIntf == null )
+
+             if ( controlIntf != null )
+             {
+                 enforceVersionRequired( f, controlIntf );
+             }
+             else
+             {
                  printError( f, "control.field.type.malformed" );
+             }
          }
          catch ( CodeGenerationException cge )
          {
@@ -284,6 +292,7 @@
 
          if ( mods.contains( Modifier.STATIC ))
              printError( f, "static.control.field" );
+
     }
 
     private void checkControlClientType( TypeDeclaration t )
@@ -349,6 +358,45 @@
         }
 
         return ci;
+    }
+
+    /**
+     * Enforces the VersionRequired annotation for control fields.
+     */
+    private void enforceVersionRequired( FieldDeclaration f, InterfaceType 
controlIntf )
+    {
+        VersionRequired versionRequired = 
f.getAnnotation(VersionRequired.class);
+        Version versionPresent = 
controlIntf.getDeclaration().getAnnotation(Version.class);
+
+        if ( versionRequired != null )
+        {
+            int majorRequired = versionRequired.major();
+            int minorRequired = versionRequired.minor();
+
+            if ( majorRequired < 0 )    // no real version requirement
+                return;
+
+            int majorPresent = -1;
+            int minorPresent = -1;
+            if ( versionPresent != null )
+            {
+                majorPresent = versionPresent.major();
+                minorPresent = versionPresent.minor();
+
+                if ( majorRequired <= majorPresent &&
+                     (minorRequired < 0 || minorRequired <= minorPresent) )
+                {
+                    // Version requirement is satisfied
+                    return;
+                }
+            }
+
+            //
+            // Version requirement failed
+            //
+            printError( f, "control.field.bad.version", f.getSimpleName(), 
majorRequired, minorRequired,
+                        majorPresent, minorPresent  );
+        }
     }
 
     /**

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/strings.properties
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/strings.properties?view=diff&r1=155836&r2=155837
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/strings.properties
 (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/strings.properties
 Tue Mar  1 15:04:55 2005
@@ -17,6 +17,9 @@
 control.field.type.malformed=\
 The type of the control field is malformed.  Verify that the source of the 
type has no errors.
 
+control.field.bad.version=\
+Control field {0} fails version requirement: requires interface version 
{1}.{2}, found interface version {3}.{4}
+
 control.field.in.inner.class=\
 A control field can exist only within the top-level class. \
 Move fields marked with the Control annotation to just inside the top-level 
class.

Modified: 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/versioning/SubHello.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/versioning/SubHello.java?view=diff&r1=155836&r2=155837
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/versioning/SubHello.java
 (original)
+++ 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/versioning/SubHello.java
 Tue Mar  1 15:04:55 2005
@@ -5,16 +5,15 @@
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
-import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.controls.api.bean.ControlExtension;
 import org.apache.beehive.controls.api.properties.PropertySet;
 import org.apache.beehive.controls.api.versioning.VersionRequired;
 
 /**
  * A control extension with VersionRequired annotation
  */
[EMAIL PROTECTED]
[EMAIL PROTECTED]( major=3, minor=5 )
[EMAIL PROTECTED]
[EMAIL PROTECTED]( major=1, minor=1 )
 public interface SubHello extends Hello
 {
-       int getVersion();
 }

Modified: 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/versioning/VersionRequiredTest.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/versioning/VersionRequiredTest.java?view=diff&r1=155836&r2=155837
==============================================================================
--- 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/versioning/VersionRequiredTest.java
 (original)
+++ 
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/versioning/VersionRequiredTest.java
 Tue Mar  1 15:04:55 2005
@@ -14,7 +14,7 @@
 
 
 
[EMAIL PROTECTED]("detailed")
[EMAIL PROTECTED]("checkin")
 public class VersionRequiredTest extends TestCase
 {
     public VersionRequiredTest( String s ) { super( s ); }
@@ -22,17 +22,15 @@
     public void setUp() { }
 
     /**
-     * A control that contains a nested control
+     * A control that declares a version requirement
      */
     @Control
-    @VersionRequired(major =3)
+    @VersionRequired(major=2)
     public HelloBean helloBean;
 
 
-    @Freq("detailed")
+    @Freq("checkin")
     public void testRequiredVersion() throws Exception
     {
-               fail("VersionRequired is not enforced.");
     }
-
 }


Reply via email to