glennm 00/10/02 06:52:09
Modified: src/main/org/apache/tools/ant/taskdefs Property.java
Log:
Patch to ensure a properties file is always closed after its read. Contributed
by Nico Seessle.
Some cleanup of field access levels, etc. by me.
Revision Changes Path
1.18 +25 -18
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java
Index: Property.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Property.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Property.java 2000/09/27 15:08:53 1.17
+++ Property.java 2000/10/02 13:52:08 1.18
@@ -69,20 +69,20 @@
*/
public class Property extends Task {
- String name;
- String value;
- File file;
- String resource;
- private Reference ref = null;
+ protected String name;
+ protected String value;
+ protected File file;
+ protected String resource;
+ protected Reference ref = null;
- boolean userProperty=false; // set read-only properties
+ protected boolean userProperty=false; // set read-only properties
public void setName(String name) {
this.name = name;
}
public String getName() {
- return name;
+ return name;
}
public void setValue(String value) {
@@ -90,7 +90,7 @@
}
public String getValue() {
- return value;
+ return value;
}
public void setFile(File file) {
@@ -117,6 +117,10 @@
return resource;
}
+ public void setUserProperty(boolean userProperty) {
+ this.userProperty = userProperty;
+ }
+
public String toString() {
return value == null ? "" : value;
}
@@ -143,12 +147,19 @@
}
}
- private void loadFile (File file) throws BuildException {
+ protected void loadFile (File file) throws BuildException {
Properties props = new Properties();
log("Loading " + file.getAbsolutePath(), Project.MSG_VERBOSE);
try {
- if (file.exists()) {
- props.load(new FileInputStream(file));
+ if (file.exists()) {
+ FileInputStream fis = new FileInputStream(file);
+ try {
+ props.load(fis);
+ } finally {
+ if (fis != null) {
+ fis.close();
+ }
+ }
addProperties(props);
} else {
log("Unable to find " + file.getAbsolutePath(),
@@ -159,7 +170,7 @@
}
}
- private void loadResource( String name ) {
+ protected void loadResource( String name ) {
Properties props = new Properties();
log("Resource Loading " + name, Project.MSG_VERBOSE);
try {
@@ -173,7 +184,7 @@
}
}
- private void addProperties(Properties props) {
+ protected void addProperties(Properties props) {
resolveAllProperties(props);
Enumeration e = props.keys();
while (e.hasMoreElements()) {
@@ -183,12 +194,8 @@
addProperty(name, value);
}
}
-
- public void setUserProperty( boolean userP ) {
- userProperty=userP;
- }
- private void addProperty(String n, String v) {
+ protected void addProperty(String n, String v) {
if( userProperty ) {
if (project.getUserProperty(n) == null) {
project.setUserProperty(n, v);