Browse Source

Reuse the resolution logic of <property> inside <loadproperties>.

PR: 17782
Submitted by:	Peter Reilly


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275488 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 21 years ago
parent
commit
3742656f6d
2 changed files with 20 additions and 13 deletions
  1. +7
    -2
      WHATSNEW
  2. +13
    -11
      src/main/org/apache/tools/ant/taskdefs/LoadProperties.java

+ 7
- 2
WHATSNEW View File

@@ -14,8 +14,8 @@ Other changes:
* Translate task logs a debug message specifying the number of files * Translate task logs a debug message specifying the number of files
that it processed. Bugzilla Report 13938. that it processed. Bugzilla Report 13938.


Changes from Ant 1.5.4 to Ant 1.6Beta1
======================================
Changes from Ant 1.5.4 to Ant 1.6
=================================


Changes that could break older environments: Changes that could break older environments:
-------------------------------------------- --------------------------------------------
@@ -79,6 +79,11 @@ Changes that could break older environments:
is now Hashtable<String, String[]>). This will affect third party code is now Hashtable<String, String[]>). This will affect third party code
that extend Copy and override Copy#doFileOperations. that extend Copy and override Copy#doFileOperations.


* <loadproperties> didn't expand properties while <property file="..."/>
does, so they were not equivalent. This has been fixed, which means
that propetries may get expanded twice if you use an
<expandproperties> filterreader. Bugzilla Report 17782.

Fixed bugs: Fixed bugs:
----------- -----------
* Filter readers were not handling line endings properly. Bugzilla * Filter readers were not handling line endings properly. Bugzilla


+ 13
- 11
src/main/org/apache/tools/ant/taskdefs/LoadProperties.java View File

@@ -140,6 +140,7 @@ public final class LoadProperties extends Task {
FileInputStream fis = null; FileInputStream fis = null;
BufferedInputStream bis = null; BufferedInputStream bis = null;
Reader instream = null; Reader instream = null;
ByteArrayInputStream tis = null;


try { try {
final long len = srcFile.length(); final long len = srcFile.length();
@@ -166,7 +167,6 @@ public final class LoadProperties extends Task {
text = text + "\n"; text = text + "\n";
} }


ByteArrayInputStream tis = null;
if (encoding == null) { if (encoding == null) {
tis = new ByteArrayInputStream(text.getBytes()); tis = new ByteArrayInputStream(text.getBytes());
} else { } else {
@@ -174,16 +174,11 @@ public final class LoadProperties extends Task {
} }
final Properties props = new Properties(); final Properties props = new Properties();
props.load(tis); props.load(tis);
final Enumeration e = props.keys();
while (e.hasMoreElements()) {
final String key = (String) e.nextElement();
final String value = props.getProperty(key);
if (key != null && value != null
&& value.trim().length() > 0) {
getProject().setNewProperty(key, value);
}
}
tis.close();

Property propertyTask =
(Property) getProject().createTask("property");
propertyTask.setTaskName(getTaskName());
propertyTask.addProperties(props);
} }


} catch (final IOException ioe) { } catch (final IOException ioe) {
@@ -199,6 +194,13 @@ public final class LoadProperties extends Task {
} catch (IOException ioex) { } catch (IOException ioex) {
//ignore //ignore
} }
try {
if (tis != null) {
tis.close();
}
} catch (IOException ioex) {
//ignore
}
} }
} }




Loading…
Cancel
Save