mirror of
https://github.com/apache/struts.git
synced 2026-08-07 15:46:57 +00:00
WW-3418 solves problem with excludePackages
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1311931 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+15
@@ -33,6 +33,7 @@ import com.opensymphony.xwork2.inject.Container;
|
||||
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 PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
|
||||
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 + ".";
|
||||
|
||||
+13
@@ -82,6 +82,7 @@ import org.apache.struts2.convention.actions.resultpath.PackageLevelResultPathAc
|
||||
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 PackageBasedActionConfigBuilderTest extends TestCase {
|
||||
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 PackageBasedActionConfigBuilderTest extends TestCase {
|
||||
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 PackageBasedActionConfigBuilderTest extends TestCase {
|
||||
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 PackageBasedActionConfigBuilderTest extends TestCase {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user