struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WW-4928) Setting struts.devMode from system property not working as described
Date Fri, 23 Mar 2018 06:45:00 GMT

    [ https://issues.apache.org/jira/browse/WW-4928?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16410886#comment-16410886
] 

ASF GitHub Bot commented on WW-4928:
------------------------------------

lukaszlenart closed pull request #217: WW-4928 Using the same default value delimiter
URL: https://github.com/apache/struts/pull/217
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core/src/main/java/com/opensymphony/xwork2/config/providers/EnvsValueSubstitutor.java
b/core/src/main/java/com/opensymphony/xwork2/config/providers/EnvsValueSubstitutor.java
index 6aff302a1..f6cafefc4 100644
--- a/core/src/main/java/com/opensymphony/xwork2/config/providers/EnvsValueSubstitutor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/config/providers/EnvsValueSubstitutor.java
@@ -18,6 +18,7 @@
  */
 package com.opensymphony.xwork2.config.providers;
 
+import org.apache.commons.text.StrLookup;
 import org.apache.commons.text.StrSubstitutor;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -26,20 +27,26 @@
 
     private static final Logger LOG = LogManager.getLogger(EnvsValueSubstitutor.class);
 
-    protected StrSubstitutor strSubstitutor;
+    protected StrSubstitutor envStrSubstitutor;
+    protected StrSubstitutor sysStrSubstitutor;
 
     public EnvsValueSubstitutor() {
-        strSubstitutor = new StrSubstitutor(System.getenv());
-        strSubstitutor.setVariablePrefix("${env.");
-        strSubstitutor.setVariableSuffix('}');
-        strSubstitutor.setValueDelimiter(":");
+        envStrSubstitutor = new StrSubstitutor(System.getenv());
+        envStrSubstitutor.setVariablePrefix("${env.");
+        envStrSubstitutor.setVariableSuffix('}');
+        envStrSubstitutor.setValueDelimiter(':');
+
+        sysStrSubstitutor = new StrSubstitutor(StrLookup.systemPropertiesLookup());
+        sysStrSubstitutor.setVariablePrefix("${");
+        sysStrSubstitutor.setVariableSuffix('}');
+        sysStrSubstitutor.setValueDelimiter(':');
     }
 
     @Override
     public String substitute(String value) {
         LOG.debug("Substituting value {} with proper System variable or environment variable",
value);
 
-        String substituted = StrSubstitutor.replaceSystemProperties(value);
-        return strSubstitutor.replace(substituted);
+        String substituted = sysStrSubstitutor.replace(value);
+        return envStrSubstitutor.replace(substituted);
     }
 }
diff --git a/core/src/test/java/com/opensymphony/xwork2/config/providers/EnvsValueSubstitutorTest.java
b/core/src/test/java/com/opensymphony/xwork2/config/providers/EnvsValueSubstitutorTest.java
index da25e6524..0ecbd43d9 100644
--- a/core/src/test/java/com/opensymphony/xwork2/config/providers/EnvsValueSubstitutorTest.java
+++ b/core/src/test/java/com/opensymphony/xwork2/config/providers/EnvsValueSubstitutorTest.java
@@ -20,10 +20,9 @@
 
 import org.apache.struts2.StrutsInternalTestCase;
 
-
 public class EnvsValueSubstitutorTest extends StrutsInternalTestCase {
 
-    public void testSimpleValue() throws Exception {
+    public void testEnvSimpleValue() throws Exception {
         // given
         String expected = System.getenv("USER");
         ValueSubstitutor substitutor = new EnvsValueSubstitutor();
@@ -35,6 +34,45 @@ public void testSimpleValue() throws Exception {
         assertEquals(expected, actual);
     }
 
+    public void testEnvSimpleDefaultValue() throws Exception {
+        // given
+        String expected = "defaultValue";
+        ValueSubstitutor substitutor = new EnvsValueSubstitutor();
+
+        // when
+        String actual = substitutor.substitute("${env.UNKNOWN:" + expected + "}");
+
+        // then
+        assertEquals(expected, actual);
+    }
+
+    public void testSystemSimpleValue() throws Exception {
+        // given
+        String key = "sysPropKey";
+        String expected = "sysPropValue";
+        System.setProperty(key, expected);
+       
+        ValueSubstitutor substitutor = new EnvsValueSubstitutor();
+
+        // when
+        String actual = substitutor.substitute("${" + key + "}");
+
+        // then
+        assertEquals(expected, actual);
+    }
+
+    public void testSystemSimpleDefaultValue() throws Exception {
+        // given
+        String expected = "defaultValue";
+        ValueSubstitutor substitutor = new EnvsValueSubstitutor();
+
+        // when
+        String actual = substitutor.substitute("${UNKNOWN:" + expected + "}");
+
+        // then
+        assertEquals(expected, actual);
+    }
+
     public void testNoSubstitution() throws Exception {
         // given
         ValueSubstitutor substitutor = new EnvsValueSubstitutor();
@@ -45,4 +83,4 @@ public void testNoSubstitution() throws Exception {
         // then
         assertEquals("val1", actual);
     }
-}
\ No newline at end of file
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Setting struts.devMode from system property not working as described
> --------------------------------------------------------------------
>
>                 Key: WW-4928
>                 URL: https://issues.apache.org/jira/browse/WW-4928
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.5.14.1
>         Environment: **Windows, Linux, Solaris
>            Reporter: Peter J Ford
>            Priority: Minor
>              Labels: documentation, easyfix
>             Fix For: 2.6
>
>
> According to [http://struts.apache.org/core-developers/constant-configuration.html] the
struts.devMode setting can be read from environment strings or system properties. This works
correctly when setting from an environment string - for example:
> {{<constant name="struts.devMode" value="${env.STRUTS_DEV_MODE:false}"/>}}
> However it does not work for system properties, such as setting "-DstrutsDevMode=true"
as a system property and this in struts.xml:
> {{<constant name="struts.devMode" value="${strutsDevMode:false}"/>}}
> Having dug through the source I found that this is to do with the way the value substitutor
is configured, and that using ":-" instead of ":" as the separator string when using system
properties will work:
> {{<constant name="struts.devMode" value="${strutsDevMode:-false}"/>}}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message