@@ -59,6 +59,7 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.types.DestFile;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.types.Reference;
import java.io.File;
import java.io.File;
@@ -88,15 +89,15 @@ public class Property extends Task {
protected Reference ref;
protected Reference ref;
protected boolean userProperty; // set read-only properties
protected boolean userProperty; // set read-only properties
public Property() {
public Property() {
super();
super();
}
}
protected Property(boolean userProperty) {
protected Property(boolean userProperty) {
this.userProperty = userProperty;
this.userProperty = userProperty;
}
}
public void setName(String name) {
public void setName(String name) {
this.name = name;
this.name = name;
}
}
@@ -117,8 +118,20 @@ public class Property extends Task {
return value;
return value;
}
}
/**
* @deprecated setFile(File) is deprecated and is replaced with
* setFile(DestFile) to let Ant's core perform validation
*/
public void setFile(File file) {
public void setFile(File file) {
this.file = file;
log("DEPRECATED - The setFile(File) method has been deprecated."
+ " Use setFile(DestFile) instead.");
DestFile destFile = new DestFile();
destFile.setFile(file);
setFile(destFile);
}
public void setFile(DestFile file) {
this.file = file.getFile();
}
}
public File getFile() {
public File getFile() {
@@ -156,14 +169,14 @@ public class Property extends Task {
this.classpath.append(classpath);
this.classpath.append(classpath);
}
}
}
}
public Path createClasspath() {
public Path createClasspath() {
if (this.classpath == null) {
if (this.classpath == null) {
this.classpath = new Path(project);
this.classpath = new Path(project);
}
}
return this.classpath.createPath();
return this.classpath.createPath();
}
}
public void setClasspathRef(Reference r) {
public void setClasspathRef(Reference r) {
createClasspath().setRefid(r);
createClasspath().setRefid(r);
}
}
@@ -172,7 +185,7 @@ public class Property extends Task {
* @deprecated This was never a supported feature and has been deprecated without replacement
* @deprecated This was never a supported feature and has been deprecated without replacement
*/
*/
public void setUserProperty(boolean userProperty) {
public void setUserProperty(boolean userProperty) {
log("DEPRECATED: Ignoring request to set user property in Property task.",
log("DEPRECATED: Ignoring request to set user property in Property task.",
Project.MSG_WARN);
Project.MSG_WARN);
}
}
@@ -196,13 +209,13 @@ public class Property extends Task {
if ((name != null) && (value != null)) {
if ((name != null) && (value != null)) {
addProperty(name, value);
addProperty(name, value);
}
}
if (file != null) loadFile(file);
if (file != null) loadFile(file);
if (resource != null) loadResource(resource);
if (resource != null) loadResource(resource);
if (env != null) loadEnvironment(env);
if (env != null) loadEnvironment(env);
if ((name != null) && (ref != null)) {
if ((name != null) && (ref != null)) {
Object obj = ref.getReferencedObject(getProject());
Object obj = ref.getReferencedObject(getProject());
if (obj != null) {
if (obj != null) {
@@ -215,18 +228,18 @@ public class Property extends Task {
Properties props = new Properties();
Properties props = new Properties();
log("Loading " + file.getAbsolutePath(), Project.MSG_VERBOSE);
log("Loading " + file.getAbsolutePath(), Project.MSG_VERBOSE);
try {
try {
if (file.exists()) {
if (file.exists()) {
FileInputStream fis = new FileInputStream(file);
FileInputStream fis = new FileInputStream(file);
try {
try {
props.load(fis);
props.load(fis);
} finally {
} finally {
if (fis != null) {
if (fis != null) {
fis.close();
fis.close();
}
}
}
}
addProperties(props);
addProperties(props);
} else {
} else {
log("Unable to find property file: " + file.getAbsolutePath(),
log("Unable to find property file: " + file.getAbsolutePath(),
Project.MSG_VERBOSE);
Project.MSG_VERBOSE);
}
}
} catch(IOException ex) {
} catch(IOException ex) {
@@ -238,21 +251,21 @@ public class Property extends Task {
Properties props = new Properties();
Properties props = new Properties();
log("Resource Loading " + name, Project.MSG_VERBOSE);
log("Resource Loading " + name, Project.MSG_VERBOSE);
try {
try {
ClassLoader cL = null;
ClassLoader cL = null;
InputStream is = null;
InputStream is = null;
if (classpath != null) {
cL = new AntClassLoader(project, classpath);
} else {
cL = this.getClass().getClassLoader();
}
if (classpath != null) {
cL = new AntClassLoader(project, classpath);
} else {
cL = this.getClass().getClassLoader();
}
if (cL == null) {
if (cL == null) {
is = ClassLoader.getSystemResourceAsStream(name);
is = ClassLoader.getSystemResourceAsStream(name);
} else {
} else {
is = cL.getResourceAsStream(name);
is = cL.getResourceAsStream(name);
}
}
if (is != null) {
if (is != null) {
props.load(is);
props.load(is);
addProperties(props);
addProperties(props);
@@ -275,7 +288,7 @@ public class Property extends Task {
if (pos == -1) {
if (pos == -1) {
log("Ignoring: " + entry, Project.MSG_WARN);
log("Ignoring: " + entry, Project.MSG_WARN);
} else {
} else {
props.put(prefix + entry.substring(0, pos),
props.put(prefix + entry.substring(0, pos),
entry.substring(pos + 1));
entry.substring(pos + 1));
}
}
}
}
@@ -316,7 +329,7 @@ public class Property extends Task {
Vector fragments = new Vector();
Vector fragments = new Vector();
Vector propertyRefs = new Vector();
Vector propertyRefs = new Vector();
ProjectHelper.parsePropertyString(value, fragments, propertyRefs);
ProjectHelper.parsePropertyString(value, fragments, propertyRefs);
resolved = true;
resolved = true;
if (propertyRefs.size() != 0) {
if (propertyRefs.size() != 0) {
StringBuffer sb = new StringBuffer();
StringBuffer sb = new StringBuffer();
@@ -347,5 +360,5 @@ public class Property extends Task {
}
}
}
}
}
}
}
}
}
}