You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mr...@apache.org on 2008/04/20 05:09:24 UTC

svn commit: r649873 - in /struts/struts2/trunk/plugins: codebehind/src/main/java/org/apache/struts2/config/ codebehind/src/test/java/org/apache/struts2/config/ rest/src/main/java/org/apache/struts2/rest/ rest/src/main/resources/

Author: mrdon
Date: Sat Apr 19 20:09:23 2008
New Revision: 649873

URL: http://svn.apache.org/viewvc?rev=649873&view=rev
Log:
Adding new settings to disable classpath action scanning for the codebehind and rest plugins
WW-2506

Modified:
    struts/struts2/trunk/plugins/codebehind/src/main/java/org/apache/struts2/config/ClasspathPackageProvider.java
    struts/struts2/trunk/plugins/codebehind/src/test/java/org/apache/struts2/config/ClasspathPackageProviderTest.java
    struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/ControllerClasspathPackageProvider.java
    struts/struts2/trunk/plugins/rest/src/main/resources/struts-plugin.xml

Modified: struts/struts2/trunk/plugins/codebehind/src/main/java/org/apache/struts2/config/ClasspathPackageProvider.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/codebehind/src/main/java/org/apache/struts2/config/ClasspathPackageProvider.java?rev=649873&r1=649872&r2=649873&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/codebehind/src/main/java/org/apache/struts2/config/ClasspathPackageProvider.java (original)
+++ struts/struts2/trunk/plugins/codebehind/src/main/java/org/apache/struts2/config/ClasspathPackageProvider.java Sat Apr 19 20:09:23 2008
@@ -61,7 +61,7 @@
      * The default page prefix (or "path").
      * Some applications may place pages under "/WEB-INF" as an extreme security precaution.
      */
-    private static final String DEFAULT_PAGE_PREFIX = "struts.configuration.classpath.defaultPagePrefix";
+    protected static final String DEFAULT_PAGE_PREFIX = "struts.configuration.classpath.defaultPagePrefix";
 
     /**
      * The default page prefix (none).
@@ -71,7 +71,7 @@
     /**
      * The default page extension,  to use in place of ".jsp".
      */
-    private static final String DEFAULT_PAGE_EXTENSION = "struts.configuration.classpath.defaultPageExtension";
+    protected static final String DEFAULT_PAGE_EXTENSION = "struts.configuration.classpath.defaultPageExtension";
 
     /**
      * The defacto default page extension, usually associated with JavaServer Pages.
@@ -82,7 +82,12 @@
      * A setting to indicate a custom default parent package,
      * to use in place of "struts-default".
      */
-    private static final String DEFAULT_PARENT_PACKAGE = "struts.configuration.classpath.defaultParentPackage";
+    protected static final String DEFAULT_PARENT_PACKAGE = "struts.configuration.classpath.defaultParentPackage";
+    
+    /**
+     * A setting to disable action scanning.
+     */
+    protected static final String DISABLE_ACTION_SCANNING = "struts.configuration.classpath.disableActionScanning";
 
     /**
      * Name of the framework's default configuration package,
@@ -94,7 +99,7 @@
      * The default page prefix (or "path").
      * Some applications may place pages under "/WEB-INF" as an extreme security precaution.
      */
-    private static final String FORCE_LOWER_CASE = "struts.configuration.classpath.forceLowerCase";
+    protected static final String FORCE_LOWER_CASE = "struts.configuration.classpath.forceLowerCase";
 
     /**
      * Whether to use a lowercase letter as the initial letter of an action.
@@ -120,6 +125,8 @@
      * @see #needsReload
      */
     private boolean initialized = false;
+    
+    private boolean disableActionScanning = false;
 
     private PackageLoader packageLoader;
 
@@ -168,6 +175,16 @@
     }
 
     /**
+     * Disables action scanning.
+     *
+     * @param disableActionScanning True to disable
+     */
+    @Inject(value=DISABLE_ACTION_SCANNING, required=false)
+    public void setDisableActionScanning(String disableActionScanning) {
+        this.disableActionScanning = "true".equals(disableActionScanning);
+    }
+    
+    /**
      * Register a default parent package for the actions.
      *
      * @param defaultParentPackage the new defaultParentPackage
@@ -437,7 +454,7 @@
      * @throws ConfigurationException
      */
     public void loadPackages() throws ConfigurationException {
-        if (actionPackages != null) {
+        if (actionPackages != null && !disableActionScanning) {
             String[] names = actionPackages.split("\\s*[,]\\s*");
             // Initialize the classloader scanner with the configured packages
             if (names.length > 0) {

Modified: struts/struts2/trunk/plugins/codebehind/src/test/java/org/apache/struts2/config/ClasspathPackageProviderTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/codebehind/src/test/java/org/apache/struts2/config/ClasspathPackageProviderTest.java?rev=649873&r1=649872&r2=649873&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/codebehind/src/test/java/org/apache/struts2/config/ClasspathPackageProviderTest.java (original)
+++ struts/struts2/trunk/plugins/codebehind/src/test/java/org/apache/struts2/config/ClasspathPackageProviderTest.java Sat Apr 19 20:09:23 2008
@@ -74,6 +74,17 @@
         ActionConfig actionConfig = (ActionConfig) configs.get("customParentPackage");
         assertNotNull(actionConfig);
     }
+    
+    public void testDisableScanning() {
+        provider = new ClasspathPackageProvider();
+        provider.setActionPackages("org.apache.struts2.config");
+        provider.setDisableActionScanning("true");
+        config = new DefaultConfiguration();
+        provider.init(config);
+        provider.loadPackages();
+        
+        assertEquals(0, config.getPackageConfigs().size());
+    }
 
     public void testParentPackage() {
         PackageConfig pkg = config.getPackageConfig("org.apache.struts2.config");

Modified: struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/ControllerClasspathPackageProvider.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/ControllerClasspathPackageProvider.java?rev=649873&r1=649872&r2=649873&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/ControllerClasspathPackageProvider.java (original)
+++ struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/ControllerClasspathPackageProvider.java Sat Apr 19 20:09:23 2008
@@ -22,6 +22,7 @@
 
 import org.apache.struts2.config.ClasspathPackageProvider;
 
+import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.util.ResolverUtil.ClassTest;
 
 /**
@@ -29,6 +30,11 @@
  */
 public class ControllerClasspathPackageProvider extends ClasspathPackageProvider {
     
+    /**
+     * A setting to disable action scanning.
+     */
+    protected static final String DISABLE_REST_CONTROLLER_SCANNING = "struts.configuration.rest.disableControllerScanning";
+    
     @Override
     protected ClassTest createActionClassTest() {
         return new ClassTest() {
@@ -42,6 +48,27 @@
     @Override
     protected String getClassSuffix() {
         return "Controller";
+    }
+    
+    /**
+     * Ignore setting to disable action scanning from the codebehind plugin.
+     *
+     * @param disableActionScanning True to disable
+     */
+    @Override
+    @Inject(value=DISABLE_ACTION_SCANNING, required=false)
+    public void setDisableActionScanning(String disableActionScanning) {
+        // do nothing
+    }
+    
+    /**
+     * Disables controller scanning.
+     *
+     * @param disableActionScanning True to disable
+     */
+    @Inject(value=DISABLE_REST_CONTROLLER_SCANNING, required=false)
+    public void setDisableRestControllerScanning(String disableActionScanning) {
+        super.setDisableActionScanning(disableActionScanning);
     }
 
 }

Modified: struts/struts2/trunk/plugins/rest/src/main/resources/struts-plugin.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/rest/src/main/resources/struts-plugin.xml?rev=649873&r1=649872&r2=649873&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/rest/src/main/resources/struts-plugin.xml (original)
+++ struts/struts2/trunk/plugins/rest/src/main/resources/struts-plugin.xml Sat Apr 19 20:09:23 2008
@@ -22,6 +22,11 @@
     <constant name="struts.mapper.class" value="rest" />
     <constant name="struts.mapper.idParameterName" value="id" />
     <constant name="struts.action.extension" value="xhtml,,xml,json" />
+    
+    <!--  Disable the scanning by the codebehind plugin to prevent duplicates -->
+    <constant name="struts.configuration.classpath.disableActionScanning" value="true" />
+    
+    <constant name="struts.configuration.rest.disableControllerScanning" value="false" />
     <constant name="struts.configuration.classpath.defaultParentPackage" value="rest-default" />
     
     <package name="rest-default" extends="struts-default">