You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2013/10/21 12:43:54 UTC

svn commit: r1534087 - in /struts/struts2/trunk/core/src: main/java/org/apache/struts2/config/BeanSelectionProvider.java main/java/org/apache/struts2/dispatcher/ContainerHolder.java test/java/org/apache/struts2/dispatcher/DispatcherTest.java

Author: lukaszlenart
Date: Mon Oct 21 10:43:53 2013
New Revision: 1534087

URL: http://svn.apache.org/r1534087
Log:
WW-4129 Removes checking if configuration changed in ContainerHolder and allows to explicit set reload/cache options  independent from devMode

Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ContainerHolder.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java?rev=1534087&r1=1534086&r2=1534087&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java Mon Oct 21 10:43:53 2013
@@ -409,16 +409,7 @@ public class BeanSelectionProvider imple
 
         alias(SecurityGate.class, StrutsConstants.STRUTS_SECURITY_GATE, builder, props);
 
-        if ("true".equalsIgnoreCase(props.getProperty(StrutsConstants.STRUTS_DEVMODE))) {
-            props.setProperty(StrutsConstants.STRUTS_I18N_RELOAD, "true");
-            props.setProperty(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD, "true");
-            props.setProperty(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE, "false");
-            props.setProperty(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY, "0");
-            // Convert struts properties into ones that xwork expects
-            props.setProperty(XWorkConstants.DEV_MODE, "true");
-        } else {
-            props.setProperty(XWorkConstants.DEV_MODE, "false");
-        }
+        switchDevMode(props);
 
         // Convert Struts properties into XWork properties
         convertIfExist(props, StrutsConstants.STRUTS_LOG_MISSING_PROPERTIES, XWorkConstants.LOG_MISSING_PROPERTIES);
@@ -431,6 +422,32 @@ public class BeanSelectionProvider imple
         loadCustomResourceBundles(props);
     }
 
+    /**
+     * Enables/disables devMode and related settings if they aren't explicit set in struts.xml/struts.properties
+     *
+     * @param props configured properties
+     */
+    private void switchDevMode(LocatableProperties props) {
+        if ("true".equalsIgnoreCase(props.getProperty(StrutsConstants.STRUTS_DEVMODE))) {
+            if (props.getProperty(StrutsConstants.STRUTS_I18N_RELOAD) == null) {
+                props.setProperty(StrutsConstants.STRUTS_I18N_RELOAD, "true");
+            }
+            if (props.getProperty(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD) == null) {
+                props.setProperty(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD, "true");
+            }
+            if (props.getProperty(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE) == null) {
+                props.setProperty(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE, "false");
+            }
+            if (props.getProperty(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY) == null) {
+                props.setProperty(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY, "0");
+            }
+            // Convert struts properties into ones that xwork expects
+            props.setProperty(XWorkConstants.DEV_MODE, "true");
+        } else {
+            props.setProperty(XWorkConstants.DEV_MODE, "false");
+        }
+    }
+
     private void convertIfExist(LocatableProperties props, String fromKey, String toKey) {
         if (props.containsKey(fromKey)) {
             props.setProperty(toKey, props.getProperty(fromKey));

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ContainerHolder.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ContainerHolder.java?rev=1534087&r1=1534086&r2=1534087&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ContainerHolder.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ContainerHolder.java Mon Oct 21 10:43:53 2013
@@ -1,25 +1,21 @@
 package org.apache.struts2.dispatcher;
 
 import com.opensymphony.xwork2.inject.Container;
-import org.apache.struts2.StrutsConstants;
 
 /**
  * Simple class to hold Container instance per thread to minimise number of attempts
  * to read configuration and build each time a new configuration.
  *
- * Thus depends on {@link StrutsConstants#STRUTS_CONFIGURATION_XML_RELOAD} flag,
- * if set to false just use stored container, configuration will do not change.
+ * As ContainerHolder operates just per thread (which means per request) there is no need
+ * to check if configuration changed during the same request. If changed between requests,
+ * first call to store Container in ContainerHolder will be with the new configuration.
  */
 class ContainerHolder {
 
     private static ThreadLocal<Container> instance = new ThreadLocal<Container>();
 
     public static void store(Container instance) {
-        boolean reloadConfigs = Boolean.valueOf(instance.getInstance(String.class, StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD));
-        if (!reloadConfigs) {
-            // reloadConfigs is false, configuration will do not change, just keep it
-            ContainerHolder.instance.set(instance);
-        }
+        ContainerHolder.instance.set(instance);
     }
 
     public static Container get() {

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java?rev=1534087&r1=1534086&r2=1534087&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java (original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java Mon Oct 21 10:43:53 2013
@@ -194,8 +194,6 @@ public class DispatcherTest extends Stru
         
         Mock mockContainer = new Mock(Container.class);
         String reloadConfigs = container.getInstance(String.class, XWorkConstants.RELOAD_XML_CONFIGURATION);
-        mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD)),
-                reloadConfigs);
         mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(XWorkConstants.RELOAD_XML_CONFIGURATION)),
                 reloadConfigs);
         mockContainer.expectAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), destroyedObjectFactory);
@@ -230,8 +228,6 @@ public class DispatcherTest extends Stru
         Mock mockContainer = new Mock(Container.class);
         mockContainer.matchAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), new ObjectFactory());
         String reloadConfigs = container.getInstance(String.class, XWorkConstants.RELOAD_XML_CONFIGURATION);
-        mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD)),
-                reloadConfigs);
         mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(XWorkConstants.RELOAD_XML_CONFIGURATION)),
                 reloadConfigs);