struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From musa...@apache.org
Subject svn commit: r764310 - in /struts/struts2/trunk/plugins/convention/src: main/java/org/apache/struts2/convention/annotation/ test/java/org/apache/struts2/convention/ test/java/org/apache/struts2/convention/actions/parentpackage/sub/
Date Sun, 12 Apr 2009 18:16:44 GMT
Author: musachy
Date: Sun Apr 12 18:16:43 2009
New Revision: 764310

URL: http://svn.apache.org/viewvc?rev=764310&view=rev
Log:
WW-3083 fix how packages and actions are scanned for annotations

Added:
    struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/actions/parentpackage/sub/
    struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/actions/parentpackage/sub/ClassLevelParentPackageChildAction.java
    struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/actions/parentpackage/sub/PackageLevelParentPackageChildAction.java
Modified:
    struts/struts2/trunk/plugins/convention/src/main/java/org/apache/struts2/convention/annotation/AnnotationTools.java
    struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java

Modified: struts/struts2/trunk/plugins/convention/src/main/java/org/apache/struts2/convention/annotation/AnnotationTools.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/convention/src/main/java/org/apache/struts2/convention/annotation/AnnotationTools.java?rev=764310&r1=764309&r2=764310&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/convention/src/main/java/org/apache/struts2/convention/annotation/AnnotationTools.java
(original)
+++ struts/struts2/trunk/plugins/convention/src/main/java/org/apache/struts2/convention/annotation/AnnotationTools.java
Sun Apr 12 18:16:43 2009
@@ -40,7 +40,9 @@
     public static <T extends Annotation> T findAnnotation(Class<?> klass, Class<T>
annotationClass) {
         T ann = klass.getAnnotation(annotationClass);
         while (ann == null && klass != null) {
-            ann = klass.getPackage().getAnnotation(annotationClass);
+            ann = klass.getAnnotation(annotationClass);
+            if (ann == null)
+                ann = klass.getPackage().getAnnotation(annotationClass);
             if (ann == null) {
                 klass = klass.getSuperclass();
             }

Modified: struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java?rev=764310&r1=764309&r2=764310&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
(original)
+++ struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
Sun Apr 12 18:16:43 2009
@@ -56,6 +56,8 @@
 import org.apache.struts2.convention.actions.params.ActionParamsMethodLevelAction;
 import org.apache.struts2.convention.actions.parentpackage.ClassLevelParentPackageAction;
 import org.apache.struts2.convention.actions.parentpackage.PackageLevelParentPackageAction;
+import org.apache.struts2.convention.actions.parentpackage.sub.ClassLevelParentPackageChildAction;
+import org.apache.struts2.convention.actions.parentpackage.sub.PackageLevelParentPackageChildAction;
 import org.apache.struts2.convention.actions.result.ActionLevelResultAction;
 import org.apache.struts2.convention.actions.result.ActionLevelResultsAction;
 import org.apache.struts2.convention.actions.result.ClassLevelResultAction;
@@ -148,8 +150,12 @@
                 "/interceptor", strutsDefault, null);
         PackageConfig packageLevelPkg = makePackageConfig("org.apache.struts2.convention.actions.parentpackage#package-level#/parentpackage",
             "/parentpackage", packageLevelParentPkg, null);
+        PackageConfig packageLevelSubPkg = makePackageConfig("org.apache.struts2.convention.actions.parentpackage.sub#package-level#/parentpackage/sub",
+            "/parentpackage/sub", packageLevelParentPkg, null);
         PackageConfig differentPkg = makePackageConfig("org.apache.struts2.convention.actions.parentpackage#class-level#/parentpackage",
             "/parentpackage", classLevelParentPkg, null);
+        PackageConfig differentSubPkg = makePackageConfig("org.apache.struts2.convention.actions.parentpackage.sub#class-level#/parentpackage/sub",
+            "/parentpackage/sub", classLevelParentPkg, null);
         PackageConfig pkgLevelNamespacePkg = makePackageConfig("org.apache.struts2.convention.actions.namespace#struts-default#/package-level",
             "/package-level", strutsDefault, null);
         PackageConfig classLevelNamespacePkg = makePackageConfig("org.apache.struts2.convention.actions.namespace#struts-default#/class-level",
@@ -234,7 +240,9 @@
 
         /* org.apache.struts2.convention.actions.parentpackage */
         expect(resultMapBuilder.build(PackageLevelParentPackageAction.class, null, "package-level-parent-package",
packageLevelPkg)).andReturn(results);
+        expect(resultMapBuilder.build(PackageLevelParentPackageChildAction.class, null, "package-level-parent-package-child",
packageLevelSubPkg)).andReturn(results);
         expect(resultMapBuilder.build(ClassLevelParentPackageAction.class, null, "class-level-parent-package",
differentPkg)).andReturn(results);
+        expect(resultMapBuilder.build(ClassLevelParentPackageChildAction.class, null, "class-level-parent-package-child",
differentSubPkg)).andReturn(results);
 
         /* org.apache.struts2.convention.actions.result */
         expect(resultMapBuilder.build(ClassLevelResultAction.class, null, "class-level-result",
resultPkg)).andReturn(results);
@@ -443,12 +451,26 @@
         assertEquals(1, pkgConfig.getActionConfigs().size());
         verifyActionConfig(pkgConfig, "class-level-parent-package", ClassLevelParentPackageAction.class,
"execute", pkgConfig.getName());
 
+        /* org.apache.struts2.convention.actions.parentpackage.sub class level */
+        pkgConfig = configuration.getPackageConfig("org.apache.struts2.convention.actions.parentpackage.sub#class-level#/parentpackage/sub");
+        assertNotNull(pkgConfig);
+        assertEquals(1, pkgConfig.getActionConfigs().size());
+        verifyActionConfig(pkgConfig, "class-level-parent-package-child", ClassLevelParentPackageChildAction.class,
"execute", pkgConfig.getName());
+        assertEquals("class-level", pkgConfig.getParents().get(0).getName());
+
         /* org.apache.struts2.convention.actions.parentpackage package level */
         pkgConfig = configuration.getPackageConfig("org.apache.struts2.convention.actions.parentpackage#package-level#/parentpackage");
         assertNotNull(pkgConfig);
         assertEquals(1, pkgConfig.getActionConfigs().size());
         verifyActionConfig(pkgConfig, "package-level-parent-package", PackageLevelParentPackageAction.class,
"execute", pkgConfig.getName());
 
+        /* org.apache.struts2.convention.actions.parentpackage.sub package level */
+        pkgConfig = configuration.getPackageConfig("org.apache.struts2.convention.actions.parentpackage.sub#package-level#/parentpackage/sub");
+        assertNotNull(pkgConfig);
+        assertEquals(1, pkgConfig.getActionConfigs().size());
+        verifyActionConfig(pkgConfig, "package-level-parent-package-child", PackageLevelParentPackageChildAction.class,
"execute", pkgConfig.getName());
+        assertEquals("package-level", pkgConfig.getParents().get(0).getName());
+
         /* org.apache.struts2.convention.actions.result */
         pkgConfig = configuration.getPackageConfig("org.apache.struts2.convention.actions.result#struts-default#/result");
         assertNotNull(pkgConfig);

Added: struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/actions/parentpackage/sub/ClassLevelParentPackageChildAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/actions/parentpackage/sub/ClassLevelParentPackageChildAction.java?rev=764310&view=auto
==============================================================================
--- struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/actions/parentpackage/sub/ClassLevelParentPackageChildAction.java
(added)
+++ struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/actions/parentpackage/sub/ClassLevelParentPackageChildAction.java
Sun Apr 12 18:16:43 2009
@@ -0,0 +1,29 @@
+/*
+ * $Id: ClassLevelParentPackageAction.java 655902 2008-05-13 15:15:12Z bpontarelli $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.convention.actions.parentpackage.sub;
+
+import org.apache.struts2.convention.actions.parentpackage.ClassLevelParentPackageAction;
+
+/**
+ * Extends an action that hass a @ParentPackage at the class level
+ */
+public class ClassLevelParentPackageChildAction extends ClassLevelParentPackageAction {
+}

Added: struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/actions/parentpackage/sub/PackageLevelParentPackageChildAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/actions/parentpackage/sub/PackageLevelParentPackageChildAction.java?rev=764310&view=auto
==============================================================================
--- struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/actions/parentpackage/sub/PackageLevelParentPackageChildAction.java
(added)
+++ struts/struts2/trunk/plugins/convention/src/test/java/org/apache/struts2/convention/actions/parentpackage/sub/PackageLevelParentPackageChildAction.java
Sun Apr 12 18:16:43 2009
@@ -0,0 +1,29 @@
+/*
+ * $Id: ClassLevelParentPackageAction.java 655902 2008-05-13 15:15:12Z bpontarelli $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.convention.actions.parentpackage.sub;
+
+import org.apache.struts2.convention.actions.parentpackage.PackageLevelParentPackageAction;
+
+/**
+ * Extends a class the has a @ParentPackage at the package level
+ */
+public class PackageLevelParentPackageChildAction extends PackageLevelParentPackageAction
{
+}



Mime
View raw message