You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2015/06/24 22:25:03 UTC
[1/3] [lang] [LANG-1141] StrLookup for system properties now sees
updated values.
Repository: commons-lang
Updated Branches:
refs/heads/master 04b55bc7c -> 80644cdab
[LANG-1141] StrLookup for system properties now sees updated values.
The lookup implementation now directly accesses system properties without
caching the Properties object in any way.
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/54e63005
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/54e63005
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/54e63005
Branch: refs/heads/master
Commit: 54e63005446a2b0a4255ba16838122c5808ef886
Parents: 0343b4f
Author: oheger <ol...@oliver-heger.de>
Authored: Wed Jun 24 22:14:13 2015 +0200
Committer: oheger <ol...@oliver-heger.de>
Committed: Wed Jun 24 22:14:13 2015 +0200
----------------------------------------------------------------------
.../apache/commons/lang3/text/StrLookup.java | 65 ++++++++------------
.../commons/lang3/text/StrLookupTest.java | 48 +++++++++++----
2 files changed, 64 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/54e63005/src/main/java/org/apache/commons/lang3/text/StrLookup.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/text/StrLookup.java b/src/main/java/org/apache/commons/lang3/text/StrLookup.java
index c4d42b3..446ee4c 100644
--- a/src/main/java/org/apache/commons/lang3/text/StrLookup.java
+++ b/src/main/java/org/apache/commons/lang3/text/StrLookup.java
@@ -16,9 +16,7 @@
*/
package org.apache.commons.lang3.text;
-import java.util.Enumeration;
import java.util.Map;
-import java.util.Properties;
/**
* Lookup a String key to a String value.
@@ -42,6 +40,11 @@ public abstract class StrLookup<V> {
*/
private static final StrLookup<String> NONE_LOOKUP = new MapStrLookup<String>(null);
+ /**
+ * Lookup based on system properties.
+ */
+ private static final StrLookup<String> SYSTEM_PROPERTIES_LOOKUP = new SystemPropertiesStrLookup();
+
//-----------------------------------------------------------------------
/**
* Returns a lookup which always returns null.
@@ -53,29 +56,6 @@ public abstract class StrLookup<V> {
}
/**
- * Creates a copy of the given properties instance.
- *
- * @param input the Properties instance to copy.
- * @return a copy of {@code input}.
- */
- private static Properties copyProperties(Properties input) {
- if (input == null) {
- return null;
- }
-
- Properties output = new Properties();
- @SuppressWarnings("unchecked") // Property names are Strings.
- Enumeration<String> propertyNames = (Enumeration<String>) input.propertyNames();
-
- while (propertyNames.hasMoreElements()) {
- String propertyName = propertyNames.nextElement();
- output.setProperty(propertyName, input.getProperty(propertyName));
- }
-
- return output;
- }
-
- /**
* Returns a new lookup which uses a copy of the current
* {@link System#getProperties() System properties}.
* <p>
@@ -87,19 +67,7 @@ public abstract class StrLookup<V> {
* @return a lookup using system properties, not null
*/
public static StrLookup<String> systemPropertiesLookup() {
- Properties systemProperties = null;
-
- try {
- systemProperties = System.getProperties();
- } catch (final SecurityException ex) {
- // Squelched. All lookup(String) will return null.
- }
-
- Properties properties = copyProperties(systemProperties);
- @SuppressWarnings("unchecked") // System property keys and values are always Strings
- final Map<String, String> propertiesMap = (Map) properties;
-
- return new MapStrLookup<String>(propertiesMap);
+ return SYSTEM_PROPERTIES_LOOKUP;
}
/**
@@ -188,4 +156,25 @@ public abstract class StrLookup<V> {
return obj.toString();
}
}
+
+ //-----------------------------------------------------------------------
+ /**
+ * Lookup implementation based on system properties.
+ */
+ private static class SystemPropertiesStrLookup extends StrLookup<String> {
+ /**
+ * {@inheritDoc} This implementation directly accesses system properties.
+ */
+ @Override
+ public String lookup(String key) {
+ if (key.length() > 0) {
+ try {
+ return System.getProperty(key);
+ } catch (SecurityException scex) {
+ // Squelched. All lookup(String) will return null.
+ }
+ }
+ return null;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/54e63005/src/test/java/org/apache/commons/lang3/text/StrLookupTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/text/StrLookupTest.java b/src/test/java/org/apache/commons/lang3/text/StrLookupTest.java
index 121dbff..9190185 100644
--- a/src/test/java/org/apache/commons/lang3/text/StrLookupTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/StrLookupTest.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,6 +22,7 @@ import static org.junit.Assert.fail;
import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
import org.junit.Test;
@@ -51,20 +52,45 @@ public class StrLookupTest {
}
}
+ /**
+ * Tests that a lookup object for system properties can deal with a full
+ * replacement of the system properties object. This test is related to
+ * LANG-1055.
+ */
@Test
- public void testSystemPropertiesLookupNotSingleton() {
+ public void testSystemPropertiesLookupReplacedProperties() {
+ Properties oldProperties = System.getProperties();
final String osName = "os.name";
- final String originalOsName = System.getProperty(osName);
+ final String newOsName = oldProperties.getProperty(osName) + "_changed";
- StrLookup<String> properties1 = StrLookup.systemPropertiesLookup();
- assertEquals(originalOsName, properties1.lookup(osName));
+ StrLookup<String> sysLookup = StrLookup.systemPropertiesLookup();
+ Properties newProps = new Properties();
+ newProps.setProperty(osName, newOsName);
+ System.setProperties(newProps);
+ try {
+ assertEquals("Changed properties not detected", newOsName, sysLookup.lookup(osName));
+ } finally {
+ System.setProperties(oldProperties);
+ }
+ }
- final String differentOsName = "HAL-9000";
- System.setProperty(osName, differentOsName);
- StrLookup<String> properties2 = StrLookup.systemPropertiesLookup();
+ /**
+ * Tests that a lookup object for system properties sees changes on system
+ * properties. This test is related to LANG-1141.
+ */
+ @Test
+ public void testSystemPropertiesLookupUpdatedProperty() {
+ final String osName = "os.name";
+ String oldOs = System.getProperty(osName);
+ final String newOsName = oldOs + "_changed";
- assertEquals(originalOsName, properties1.lookup(osName));
- assertEquals(differentOsName, properties2.lookup(osName));
+ StrLookup<String> sysLookup = StrLookup.systemPropertiesLookup();
+ System.setProperty(osName, newOsName);
+ try {
+ assertEquals("Changed properties not detected", newOsName, sysLookup.lookup(osName));
+ } finally {
+ System.setProperty(osName, oldOs);
+ }
}
@Test
[2/3] [lang] [LANG-1141] Updated changes.xml.
Posted by oh...@apache.org.
[LANG-1141] Updated changes.xml.
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/305d5eb8
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/305d5eb8
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/305d5eb8
Branch: refs/heads/master
Commit: 305d5eb8969285dbec10d888186c6f2ee447c142
Parents: 54e6300
Author: oheger <ol...@oliver-heger.de>
Authored: Wed Jun 24 22:17:35 2015 +0200
Committer: oheger <ol...@oliver-heger.de>
Committed: Wed Jun 24 22:17:35 2015 +0200
----------------------------------------------------------------------
src/changes/changes.xml | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/305d5eb8/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c848755..d6b89bb 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -22,6 +22,7 @@
<body>
<release version="3.5" date="tba" description="tba">
+ <action issue="LANG-1141" type="fix" dev="oheger">StrLookup.systemPropertiesLookup() no longer reacts on changes on system properties</action>
<action issue="LANG-1137" type="add" dev="britter" due-to="Matthew Aguirre">Add check for duplicate event listener in EventListenerSupport</action>
<action issue="LANG-1133" type="bug" dev="chas" due-to="Pascal Schumacher">FastDateParser_TimeZoneStrategyTest#testTimeZoneStrategyPattern fails on Windows with German Locale</action>
<action issue="LANG-1135" type="add" dev="britter" due-to="Eduardo Martins">Add method containsAllWords to WordUtils</action>
[3/3] [lang] Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/commons-lang
Posted by oh...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/commons-lang
Conflicts:
src/changes/changes.xml
src/main/java/org/apache/commons/lang3/text/StrLookup.java
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/80644cda
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/80644cda
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/80644cda
Branch: refs/heads/master
Commit: 80644cdab9a77db0a52d09d9ebb1f406912997d1
Parents: 305d5eb 04b55bc
Author: oheger <ol...@oliver-heger.de>
Authored: Wed Jun 24 22:23:17 2015 +0200
Committer: oheger <ol...@oliver-heger.de>
Committed: Wed Jun 24 22:23:17 2015 +0200
----------------------------------------------------------------------
src/changes/changes.xml | 2 +
.../org/apache/commons/lang3/EnumUtils.java | 8 +--
.../org/apache/commons/lang3/StringUtils.java | 9 +--
.../apache/commons/lang3/text/WordUtils.java | 20 +++---
.../org/apache/commons/lang3/EnumUtilsTest.java | 51 ++++++++++++++
.../apache/commons/lang3/StringUtilsTest.java | 71 +++++++++++++-------
.../commons/lang3/text/WordUtilsTest.java | 9 ++-
.../FastDateParser_TimeZoneStrategyTest.java | 9 ++-
8 files changed, 129 insertions(+), 50 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/80644cda/src/changes/changes.xml
----------------------------------------------------------------------
diff --cc src/changes/changes.xml
index d6b89bb,5f54262..9d961cc
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@@ -22,7 -22,8 +22,9 @@@
<body>
<release version="3.5" date="tba" description="tba">
+ <action issue="LANG-1141" type="fix" dev="oheger">StrLookup.systemPropertiesLookup() no longer reacts on changes on system properties</action>
+ <action issue="LANG-1147" type="fix" dev="sebb" due-to="Loic Guibert">EnumUtils *BitVector issue with more than 32 values Enum</action>
+ <action issue="LANG-1059" type="fix" dev="sebb" due-to="Colin Casey">Capitalize javadoc is incorrect</action>
<action issue="LANG-1137" type="add" dev="britter" due-to="Matthew Aguirre">Add check for duplicate event listener in EventListenerSupport</action>
<action issue="LANG-1133" type="bug" dev="chas" due-to="Pascal Schumacher">FastDateParser_TimeZoneStrategyTest#testTimeZoneStrategyPattern fails on Windows with German Locale</action>
<action issue="LANG-1135" type="add" dev="britter" due-to="Eduardo Martins">Add method containsAllWords to WordUtils</action>