Browse Source

make local properties visible to propertyset

fixes https://bz.apache.org/bugzilla/show_bug.cgi?id=50179

test by Sai Kiran
master
Stefan Bodewig 4 years ago
parent
commit
2c5194ed03
4 changed files with 31 additions and 1 deletions
  1. +3
    -0
      WHATSNEW
  2. +10
    -0
      src/etc/testcases/taskdefs/optional/echoproperties.xml
  3. +12
    -1
      src/main/org/apache/tools/ant/types/PropertySet.java
  4. +6
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java

+ 3
- 0
WHATSNEW View File

@@ -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
=====================================



+ 10
- 0
src/etc/testcases/taskdefs/optional/echoproperties.xml View File

@@ -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" />


+ 12
- 1
src/main/org/apache/tools/ant/types/PropertySet.java View File

@@ -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());


+ 6
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java View File

@@ -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);


Loading…
Cancel
Save