This is an automated email from the ASF dual-hosted git repository.

bodewig pushed a commit to branch property-enumerator
in repository https://gitbox.apache.org/repos/asf/ant.git

commit 2c5194ed03840a33d41c87fbab3e2f4f2d6b6429
Author: Stefan Bodewig <bode...@apache.org>
AuthorDate: Sun Aug 2 15:24:46 2020 +0200

    make local properties visible to propertyset
    
    fixes https://bz.apache.org/bugzilla/show_bug.cgi?id=50179
    
    test by Sai Kiran
---
 WHATSNEW                                                    |  3 +++
 src/etc/testcases/taskdefs/optional/echoproperties.xml      | 10 ++++++++++
 src/main/org/apache/tools/ant/types/PropertySet.java        | 13 ++++++++++++-
 .../tools/ant/taskdefs/optional/EchoPropertiesTest.java     |  6 ++++++
 4 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/WHATSNEW b/WHATSNEW
index b085be7..96920b7 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -7,6 +7,9 @@ Fixed bugs:
  * the ftp task could throw a NullPointerException if an error occured
    Bugzilla Report 64438
 
+ * propertyset now also sees in-scope local properties
+   Bugzilla Report 50179
+
 Changes from Ant 1.10.7 TO Ant 1.10.8
 =====================================
 
diff --git a/src/etc/testcases/taskdefs/optional/echoproperties.xml 
b/src/etc/testcases/taskdefs/optional/echoproperties.xml
index 449f171..661df13 100644
--- a/src/etc/testcases/taskdefs/optional/echoproperties.xml
+++ b/src/etc/testcases/taskdefs/optional/echoproperties.xml
@@ -123,6 +123,16 @@
     <echoproperties regex=".*ant.*"/>
   </target>
 
+  <target name="testEchoLocalPropertyset">
+    <local name="loc"/>
+    <property name="loc" value="foo"/>
+    <echoproperties>
+      <propertyset>
+        <propertyref name="loc"/>
+      </propertyset>
+    </echoproperties>
+  </target>
+
   <target name="cleanup">
     <delete file="test.properties" failonerror="no" />
     <delete file="test-prefix.properties" failonerror="no" />
diff --git a/src/main/org/apache/tools/ant/types/PropertySet.java 
b/src/main/org/apache/tools/ant/types/PropertySet.java
index 21d59fe..b1b7d79 100644
--- a/src/main/org/apache/tools/ant/types/PropertySet.java
+++ b/src/main/org/apache/tools/ant/types/PropertySet.java
@@ -18,6 +18,7 @@
 
 package org.apache.tools.ant.types;
 
+import java.util.AbstractMap;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -34,6 +35,7 @@ import java.util.stream.Stream;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.PropertyHelper;
 import org.apache.tools.ant.types.resources.MappedResource;
 import org.apache.tools.ant.types.resources.PropertyResource;
 import org.apache.tools.ant.util.FileNameMapper;
@@ -334,7 +336,16 @@ public class PropertySet extends DataType implements 
ResourceCollection {
 
     private Map<String, Object> getEffectiveProperties() {
         final Project prj = getProject();
-        final Map<String, Object> result = prj == null ? 
getAllSystemProperties() : prj.getProperties();
+        final Map<String, Object> result;
+        if (prj == null) {
+            result = getAllSystemProperties();
+        } else {
+            final PropertyHelper ph = PropertyHelper.getPropertyHelper(prj);
+            result = prj.getPropertyNames().stream()
+                .map(n -> new AbstractMap.SimpleImmutableEntry<>(n, 
ph.getProperty(n)))
+                .filter(kv -> kv.getValue() != null)
+                .collect(Collectors.toMap(Map.Entry::getKey, 
Map.Entry::getValue));
+        }
         //quick & dirty, to make nested mapped p-sets work:
         for (PropertySet set : setRefs) {
             result.putAll(set.getPropertyMap());
diff --git 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java
 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java
index 0c561a4..b2c3054 100644
--- 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java
+++ 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java
@@ -186,6 +186,12 @@ public class EchoPropertiesTest {
         assertThat(buildRule.getFullLog(), 
containsString(MagicNames.ANT_VERSION + "="));
     }
 
+    @Test
+    public void testLocalPropertyset() {
+        buildRule.executeTarget("testEchoLocalPropertyset");
+        assertThat(buildRule.getLog(), containsString("loc=foo"));
+    }
+
     private void testEchoPrefixVarious(String target) throws Exception {
         buildRule.executeTarget(target);
         Properties props = loadPropFile(PREFIX_OUTFILE);

Reply via email to