struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From musa...@apache.org
Subject svn commit: r722219 - in /struts/sandbox/trunk/struts2-convention-plugin/src: main/java/org/apache/struts2/convention/ main/resources/ test/java/org/apache/struts2/convention/
Date Mon, 01 Dec 2008 20:41:27 GMT
Author: musachy
Date: Mon Dec  1 12:41:26 2008
New Revision: 722219

URL: http://svn.apache.org/viewvc?rev=722219&view=rev
Log:
WW-2576 Add config setting packageLocatorBase, so only packages that start with that name
will be scanned.

Thanks to Piero Sartini for patch

Modified:
    struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java
    struts/sandbox/trunk/struts2-convention-plugin/src/main/resources/struts-plugin.xml
    struts/sandbox/trunk/struts2-convention-plugin/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java

Modified: struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java?rev=722219&r1=722218&r2=722219&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java
(original)
+++ struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java
Mon Dec  1 12:41:26 2008
@@ -75,6 +75,7 @@
     private String[] excludePackages;
     private String[] packageLocators;
     private String[] excludeJars;
+    private String packageLocatorsBasePackage;
     private boolean disableJarScanning = true;
     private boolean disableActionScanning = false;
     private boolean disablePackageLocatorsScanning = false;
@@ -205,7 +206,16 @@
     }
 
     /**
-     * @param   packageLocators (Optional) Map actions that match the "*${Suffix}" pattern
+     * @param   packageLocatorsBasePackage (Optional) If set, only packages that start with
this
+     * name will be scanned for actions.
+     */
+    @Inject(value = "struts.convention.package.locators.basePackage", required = false)
+    public void setPackageLocatorsBase(String packageLocatorsBasePackage) {
+        this.packageLocatorsBasePackage = packageLocatorsBasePackage;
+    }        
+
+    /**
+     * @param   mapAllMatches (Optional) Map actions that match the "*${Suffix}" pattern
      *                          even if they don't have a default method. The mapping from
      *                          the url to the action will be delegated the action mapper.
      */
@@ -330,7 +340,7 @@
         return new Test<ClassFinder.ClassInfo>() {
             public boolean test(ClassFinder.ClassInfo classInfo) {
                 String packageName = classInfo.getPackageName();
-                if (packageName.length() > 0) {
+                if (packageName.length() > 0 && (packageLocatorsBasePackage ==
null || packageName.startsWith(packageLocatorsBasePackage))) {
                     String[] splitted = packageName.split("\\.");
 
                     boolean packageMatches = StringTools.contains(splitted, packageLocator,
false);
@@ -775,4 +785,4 @@
             }
         }
     }
-}
\ No newline at end of file
+}

Modified: struts/sandbox/trunk/struts2-convention-plugin/src/main/resources/struts-plugin.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-convention-plugin/src/main/resources/struts-plugin.xml?rev=722219&r1=722218&r2=722219&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-convention-plugin/src/main/resources/struts-plugin.xml (original)
+++ struts/sandbox/trunk/struts2-convention-plugin/src/main/resources/struts-plugin.xml Mon
Dec  1 12:41:26 2008
@@ -31,28 +31,29 @@
 
   <bean type="org.apache.struts2.convention.ActionConfigBuilder" class="org.apache.struts2.convention.PackageBasedActionConfigBuilder"/>
   <bean type="org.apache.struts2.convention.ActionNameBuilder" class="org.apache.struts2.convention.SEOActionNameBuilder"/>
-  <bean type="org.apache.struts2.convention.ResultMapBuilder" class="org.apache.struts2.convention.DefaultResultMapBuilder"/>
+  <bean type="org.apache.struts2.convention.ResultMapBuilder" class="org.apache.struts2.convention.DefaultResultMapBuilder"/>
   <bean type="org.apache.struts2.convention.InterceptorMapBuilder" class="org.apache.struts2.convention.DefaultInterceptorMapBuilder"/>
   <bean type="org.apache.struts2.convention.ConventionsService" class="org.apache.struts2.convention.ConventionsServiceImpl"/>
 
   <bean type="com.opensymphony.xwork2.config.PackageProvider" class="org.apache.struts2.convention.ClasspathConfigurationProvider"/>
 
-  <constant name="struts.convention.result.path" value="/WEB-INF/content/"/>
-  <constant name="struts.convention.result.flatLayout" value="true"/>
-  <constant name="struts.convention.action.suffix" value="Action"/>
-  <constant name="struts.convention.action.disableScanning" value="false"/>
-  <constant name="struts.convention.action.disableJarScanning" value="true"/>
-  <constant name="struts.convention.action.mapAllMatches" value="false"/>
+  <constant name="struts.convention.result.path" value="/WEB-INF/content/"/>
+  <constant name="struts.convention.result.flatLayout" value="true"/>
+  <constant name="struts.convention.action.suffix" value="Action"/>
+  <constant name="struts.convention.action.disableScanning" value="false"/>
+  <constant name="struts.convention.action.disableJarScanning" value="true"/>
+  <constant name="struts.convention.action.mapAllMatches" value="false"/>
   <constant name="struts.convention.action.checkImplementsAction" value="true"/>
   <constant name="struts.convention.default.parent.package" value="convention-default"/>
   <constant name="struts.convention.action.name.lowercase" value="true"/>
   <constant name="struts.convention.action.name.separator" value="-"/>
-  <constant name="struts.convention.package.locators" value="action,actions,struts,struts2"/>
+  <constant name="struts.convention.package.locators" value="action,actions,struts,struts2"/>
   <constant name="struts.convention.package.locators.disable" value="false"/>
+  <constant name="struts.convention.package.locators.basePackage" value=""/>
   <constant name="struts.convention.exclude.packages" value="org.apache.struts.*,org.apache.struts2.*,org.springframework.web.struts.*,org.springframework.web.struts2.*,org.hibernate.*"/>
   <constant name="struts.convention.relative.result.types" value="dispatcher,velocity,freemarker"/>
   <constant name="struts.convention.redirect.to.slash" value="true"/>
-  <constant name="struts.mapper.alwaysSelectFullNamespace" value="true"/>
+  <constant name="struts.mapper.alwaysSelectFullNamespace" value="true"/>
 
   <package name="convention-default" extends="struts-default">
   </package>

Modified: struts/sandbox/trunk/struts2-convention-plugin/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-convention-plugin/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java?rev=722219&r1=722218&r2=722219&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-convention-plugin/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
(original)
+++ struts/sandbox/trunk/struts2-convention-plugin/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
Mon Dec  1 12:41:26 2008
@@ -102,7 +102,7 @@
     }
 
     public void testPackageLocators() throws MalformedURLException {
-        run(null, "actions", null);
+        run(null, "actions,dontfind", null);
     }
 
     private void run(String actionPackages, String packageLocators, String excludePackages)
throws MalformedURLException {
@@ -289,6 +289,7 @@
         if (excludePackages != null) {
             builder.setExcludePackages(excludePackages);
         }
+        builder.setPackageLocatorsBase("org.apache.struts2.convention.actions");
         builder.buildActionConfigs();
         verify(resultMapBuilder);
 



Mime
View raw message