mirror of
https://github.com/apache/struts.git
synced 2026-08-31 19:35:40 +00:00
Improving check for action impls and action class names by combining into one test (much faster),
added unit test WW-1491 git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@474882 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -32,8 +32,8 @@ import java.util.Set;
|
||||
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.inject.ContainerBuilder;
|
||||
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 @@ public class ClasspathConfigurationProvider implements ConfigurationProvider {
|
||||
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 @@ public class ClasspathConfigurationProvider implements ConfigurationProvider {
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,13 @@ public class ClasspathConfigurationProviderTest extends TestCase {
|
||||
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");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user