Author: mrdon
Date: Tue Nov 14 09:29:33 2006
New Revision: 474882

URL: http://svn.apache.org/viewvc?view=rev&rev=474882
Log:
Improving check for action impls and action class names by combining into one 
test (much faster),
added unit test
WW-1491

Added:
    
struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/cltest/ActionImpl.java
Modified:
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java
    
struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/ClasspathConfigurationProviderTest.java

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java?view=diff&rev=474882&r1=474881&r2=474882
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java
 (original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java
 Tue Nov 14 09:29:33 2006
@@ -32,8 +32,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.struts2.StrutsConstants;
-import org.apache.struts2.Action;
 
+import com.opensymphony.xwork2.Action;
 import com.opensymphony.xwork2.ObjectFactory;
 import com.opensymphony.xwork2.config.Configuration;
 import com.opensymphony.xwork2.config.ConfigurationException;
@@ -46,6 +46,7 @@
 import com.opensymphony.xwork2.util.ClassLoaderUtil;
 import com.opensymphony.xwork2.util.ResolverUtil;
 import com.opensymphony.xwork2.util.TextUtils;
+import com.opensymphony.xwork2.util.ResolverUtil.Test;
 
 /**
  * Loads the configuration by scanning the classpath looking for classes that 
end in
@@ -128,9 +129,15 @@
     protected void loadPackages(String[] pkgs) {
 
         ResolverUtil<Class> resolver = new ResolverUtil<Class>();
-        resolver.findImplementations(Action.class,pkgs);
-        // TODO: resolver.findAnnotated( ,pkgs);
-        resolver.findSuffix(ACTION, pkgs);
+        resolver.find(new Test() {
+            // Match Action implementations and classes ending with "Action"
+            public boolean matches(Class type) {
+                // TODO: should also find annotated classes
+                return (Action.class.isAssignableFrom(type) || 
+                        type.getSimpleName().endsWith("Action"));
+            }
+            
+        }, pkgs);
         Set actionClasses = resolver.getClasses();
         for (Object obj : actionClasses) {
            Class cls = (Class) obj;
@@ -183,8 +190,8 @@
             }
         }
 
-        boolean trimSuffix = (actionName.lastIndexOf(ACTION) > 0);
-        if (trimSuffix) {
+        // Cut off the Action suffix if found
+        if (actionName.endsWith(ACTION)) {
             actionName = actionName.substring(0, actionName.length() - 
ACTION.length());
         }
 

Modified: 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/ClasspathConfigurationProviderTest.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/ClasspathConfigurationProviderTest.java?view=diff&rev=474882&r1=474881&r2=474882
==============================================================================
--- 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/ClasspathConfigurationProviderTest.java
 (original)
+++ 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/ClasspathConfigurationProviderTest.java
 Tue Nov 14 09:29:33 2006
@@ -88,6 +88,13 @@
         assertNotNull(acfg);
         assertEquals(3, acfg.getResults().size());
     }
+    
+    public void testActionImplementation() {
+        PackageConfig pkg = 
config.getPackageConfig("org.apache.struts2.config.cltest");
+        assertEquals("/cltest", pkg.getNamespace());
+        ActionConfig acfg = pkg.getActionConfigs().get("actionImpl");
+        assertNotNull(acfg);
+    }
 
     public void testDynamicResults() {
         PackageConfig pkg = 
config.getPackageConfig("org.apache.struts2.config.cltest");

Added: 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/cltest/ActionImpl.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/cltest/ActionImpl.java?view=auto&rev=474882
==============================================================================
--- 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/cltest/ActionImpl.java
 (added)
+++ 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/cltest/ActionImpl.java
 Tue Nov 14 09:29:33 2006
@@ -0,0 +1,31 @@
+/*
+ * $Id: $
+ *
+ * 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.config.cltest;
+
+import com.opensymphony.xwork2.Action;
+
+public class ActionImpl implements Action {
+
+    public String execute() throws Exception {
+        return null;
+    }
+
+}


Reply via email to