WW-3083 fix how packages and actions are scanned for annotations

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@764310 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Musachy Barroso
2009-04-12 18:16:43 +00:00
parent 5089d17588
commit bd09bac0b0
4 changed files with 83 additions and 1 deletions
@@ -40,7 +40,9 @@ public class AnnotationTools {
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();
}
@@ -56,6 +56,8 @@ import org.apache.struts2.convention.actions.namespace4.ActionAndPackageLevelNam
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 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
"/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 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
/* 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 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
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);
@@ -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 {
}
@@ -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 {
}