groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Add `importProperties` to `GProperties`
Date Sun, 04 Nov 2018 18:27:56 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 257f764dc -> 44b7cdc4e


Add `importProperties` to `GProperties`


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/44b7cdc4
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/44b7cdc4
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/44b7cdc4

Branch: refs/heads/master
Commit: 44b7cdc4e59f6e370725f317709fd58c4c040395
Parents: 257f764
Author: Daniel Sun <sunlan@apache.org>
Authored: Mon Nov 5 02:26:01 2018 +0800
Committer: Daniel Sun <sunlan@apache.org>
Committed: Mon Nov 5 02:27:35 2018 +0800

----------------------------------------------------------------------
 src/main/groovy/groovy/util/GProperties.groovy | 18 +++++++++++++-----
 src/test/groovy/util/GPropertiesTest.groovy    |  8 ++++++++
 2 files changed, 21 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/44b7cdc4/src/main/groovy/groovy/util/GProperties.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/util/GProperties.groovy b/src/main/groovy/groovy/util/GProperties.groovy
index e9565f0..efcdca1 100644
--- a/src/main/groovy/groovy/util/GProperties.groovy
+++ b/src/main/groovy/groovy/util/GProperties.groovy
@@ -90,7 +90,7 @@ class GProperties extends Properties {
     private static final String LEFT_CURLY_BRACE = '{'
     private static final String RIGHT_CURLY_BRACE = '}'
     private static final String COMMA = ','
-    private final List<GProperties> importPropertiesList = new LinkedList<>()
+    private final List<Properties> importPropertiesList = new LinkedList<>()
 
     GProperties() {
         this((Properties) null)
@@ -135,7 +135,7 @@ class GProperties extends Properties {
         String value = super.getProperty(key)
 
         if (null == value) {
-            for (GProperties importProperties : importPropertiesList) {
+            for (Properties importProperties : importPropertiesList) {
                 value = importProperties.getProperty(key)
 
                 if (null != value) {
@@ -290,7 +290,7 @@ class GProperties extends Properties {
     synchronized void load(Reader reader) throws IOException {
         reader.withReader {
             super.load(it)
-            importProperties()
+            _importProperties()
         }
     }
 
@@ -298,11 +298,19 @@ class GProperties extends Properties {
     synchronized void load(InputStream inStream) throws IOException {
         inStream.withStream {
             super.load(it)
-            importProperties()
+            _importProperties()
         }
     }
 
-    private void importProperties() {
+    synchronized void importProperties(Properties properties) {
+        if (importPropertiesList.contains(properties)) {
+            return
+        }
+
+        importPropertiesList << properties
+    }
+
+    private void _importProperties() {
         String importPropertiesPaths = super.getProperty(IMPORT_PROPERTIES_KEY)
 
         if (!importPropertiesPaths?.trim()) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/44b7cdc4/src/test/groovy/util/GPropertiesTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/util/GPropertiesTest.groovy b/src/test/groovy/util/GPropertiesTest.groovy
index e7fb691..5e84d54 100644
--- a/src/test/groovy/util/GPropertiesTest.groovy
+++ b/src/test/groovy/util/GPropertiesTest.groovy
@@ -29,6 +29,14 @@ class GPropertiesTest extends GroovyTestCase {
         assert 'Hi' == gp.getProperty('greeting.word2')
     }
 
+    void testImportProperties2() {
+        def gp = new GProperties()
+        gp.importProperties(System.getProperties())
+
+        // JAVA 8'S CLASS VERSION IS 52.0
+        assert new BigDecimal('52.0').compareTo(gp.getBigDecimal('java.class.version')) <=
0
+    }
+
     void testInterpolate() {
         def gp = new GProperties()
         gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))


Mime
View raw message