struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r1311931 - in /struts/struts2/trunk/plugins/convention/src: main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
Date Tue, 10 Apr 2012 19:04:58 GMT
Author: lukaszlenart
Date: Tue Apr 10 19:04:57 2012
New Revision: 1311931

URL: http://svn.apache.org/viewvc?rev=1311931&view=rev
Log:
WW-3418 solves problem with excludePackages

Modified:
    struts/struts2/trunk/plugins/convention/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.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/PackageBasedActionConfigBuilder.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/convention/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java?rev=1311931&r1=1311930&r2=1311931&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/convention/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java
(original)
+++ struts/struts2/trunk/plugins/convention/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java
Tue Apr 10 19:04:57 2012
@@ -33,6 +33,7 @@ import com.opensymphony.xwork2.inject.Co
 import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.util.FileManager;
 import com.opensymphony.xwork2.util.TextParseUtil;
+import com.opensymphony.xwork2.util.WildcardHelper;
 import com.opensymphony.xwork2.util.classloader.ReloadingClassLoader;
 import com.opensymphony.xwork2.util.finder.ClassFinder;
 import com.opensymphony.xwork2.util.finder.ClassFinder.ClassInfo;
@@ -486,6 +487,20 @@ public class PackageBasedActionConfigBui
 
         String classPackageName = StringUtils.substringBeforeLast(className, ".");
 
+        if(excludePackages != null && excludePackages.length > 0) {
+            WildcardHelper wildcardHelper = new WildcardHelper();
+
+            //we really don't care about the results, just the boolean
+            Map<String, String> matchMap = new HashMap<String, String>();
+
+            for(String packageExclude : excludePackages) {
+                int[] packagePattern = wildcardHelper.compilePattern(packageExclude);
+                if(wildcardHelper.match(matchMap, classPackageName, packagePattern)) {
+                    return false;
+                }
+            }
+        }
+
         if (actionPackages != null) {
             for (String packageName : actionPackages) {
                 String strictPackageName = packageName + ".";

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=1311931&r1=1311930&r2=1311931&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
Tue Apr 10 19:04:57 2012
@@ -82,6 +82,7 @@ import org.apache.struts2.convention.act
 import org.apache.struts2.convention.actions.skip.Index;
 import org.apache.struts2.convention.annotation.Action;
 import org.apache.struts2.convention.annotation.Actions;
+import org.apache.struts2.convention.dontfind.DontFindMeAction;
 import org.apache.struts2.dispatcher.ServletDispatcherResult;
 import org.easymock.EasyMock;
 
@@ -115,6 +116,10 @@ public class PackageBasedActionConfigBui
         run(null, "actions,dontfind", null);
     }
 
+    public void testExcludedPackages() throws MalformedURLException {
+        run(null, "actions", "dontfind");
+    }
+
     private void run(String actionPackages, String packageLocators, String excludePackages)
throws MalformedURLException {
         //setup interceptors
         List<InterceptorConfig> defaultInterceptors = new ArrayList<InterceptorConfig>();
@@ -337,6 +342,7 @@ public class PackageBasedActionConfigBui
         assertEquals(14, pkgConfig.getActionConfigs().size());
         verifyActionConfig(pkgConfig, "action1", ActionNameAction.class, "run1", pkgConfig.getName());
         verifyActionConfig(pkgConfig, "action2", ActionNameAction.class, "run2", pkgConfig.getName());
+        verifyMissingActionConfig(pkgConfig, "foo", DontFindMeAction.class, "foo", pkgConfig.getName());
         verifyActionConfig(pkgConfig, "action3", "someClassName", "run1", pkgConfig.getName());
         verifyActionConfig(pkgConfig, "actions1", ActionNamesAction.class, "run", pkgConfig.getName());
         verifyActionConfig(pkgConfig, "actions2", ActionNamesAction.class, "run", pkgConfig.getName());
@@ -350,6 +356,7 @@ public class PackageBasedActionConfigBui
         verifyActionConfig(pkgConfig, "class4", ClassLevelAnnotationsDefaultMethodAction.class,
"execute", pkgConfig.getName());
         verifyActionConfig(pkgConfig, "class5", ClassLevelAnnotationAction.class, null, pkgConfig.getName());
         verifyActionConfig(pkgConfig, "class6", ClassLevelAnnotationDefaultMethodAction.class,
"execute", pkgConfig.getName());
+        verifyActionConfig(pkgConfig, "class6", ClassLevelAnnotationDefaultMethodAction.class,
"execute", pkgConfig.getName());
 
         /* org.apache.struts2.convention.actions.namespace3 */
         //action on namespace1 (action level)
@@ -571,6 +578,12 @@ public class PackageBasedActionConfigBui
         assertEquals(packageName, ac.getPackageName());
     }
 
+    private void verifyMissingActionConfig(PackageConfig pkgConfig, String actionName, Class<?>
actionClass,
+            String methodName, String packageName) {
+        ActionConfig ac = pkgConfig.getAllActionConfigs().get(actionName);
+        assertNull(ac);
+    }
+
     private void verifyActionConfig(PackageConfig pkgConfig, String actionName, String actionClass,
String methodName, String packageName) {
         ActionConfig ac = pkgConfig.getAllActionConfigs().get(actionName);
         assertNotNull(ac);



Mime
View raw message