Methods Summary |
---|
public void | addConfigured(org.apache.tools.ant.types.ResourceCollection a)Set the source resource.
if (src != null) {
throw new BuildException("only a single source is supported");
}
if (a.size() != 1) {
throw new BuildException("only single argument resource collections"
+ " are supported");
}
src = (Resource) a.iterator().next();
|
public final void | addFilterChain(org.apache.tools.ant.types.FilterChain filter)Adds a FilterChain.
filterChains.addElement(filter);
|
private void | assertSrcIsJavaResource()
if (src == null) {
src = new JavaResource();
src.setProject(getProject());
} else if (!(src instanceof JavaResource)) {
throw new BuildException("expected a java resource as source");
}
|
public org.apache.tools.ant.types.Path | createClasspath()Add a classpath to use when looking up a resource.
assertSrcIsJavaResource();
return ((JavaResource) src).createClasspath();
|
public final void | execute()load Ant properties from the source file or resource
//validation
if (src == null) {
throw new BuildException("A source resource is required.");
}
if (!src.isExists()) {
if (src instanceof JavaResource) {
// dreaded backwards compatibility
log("Unable to find resource " + src, Project.MSG_WARN);
return;
}
throw new BuildException("Source resource does not exist: " + src);
}
BufferedInputStream bis = null;
Reader instream = null;
ByteArrayInputStream tis = null;
try {
bis = new BufferedInputStream(src.getInputStream());
if (encoding == null) {
instream = new InputStreamReader(bis);
} else {
instream = new InputStreamReader(bis, encoding);
}
ChainReaderHelper crh = new ChainReaderHelper();
crh.setPrimaryReader(instream);
crh.setFilterChains(filterChains);
crh.setProject(getProject());
instream = crh.getAssembledReader();
String text = crh.readFully(instream);
if (text != null) {
if (!text.endsWith("\n")) {
text = text + "\n";
}
if (encoding == null) {
tis = new ByteArrayInputStream(text.getBytes());
} else {
tis = new ByteArrayInputStream(text.getBytes(encoding));
}
final Properties props = new Properties();
props.load(tis);
Property propertyTask = new Property();
propertyTask.bindToOwner(this);
propertyTask.addProperties(props);
}
} catch (final IOException ioe) {
final String message = "Unable to load file: " + ioe.toString();
throw new BuildException(message, ioe, getLocation());
} finally {
FileUtils.close(bis);
FileUtils.close(tis);
}
|
public org.apache.tools.ant.types.Path | getClasspath()get the classpath used by this LoadProperties .
assertSrcIsJavaResource();
return ((JavaResource) src).getClasspath();
|
public void | setClasspath(org.apache.tools.ant.types.Path classpath)Set the classpath to use when looking up a resource.
assertSrcIsJavaResource();
((JavaResource) src).setClasspath(classpath);
|
public void | setClasspathRef(org.apache.tools.ant.types.Reference r)Set the classpath to use when looking up a resource,
given as reference to a <path> defined elsewhere
assertSrcIsJavaResource();
((JavaResource) src).setClasspathRef(r);
|
public final void | setEncoding(java.lang.String encoding)Encoding to use for input, defaults to the platform's default
encoding.
For a list of possible values see
http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html
.
this.encoding = encoding;
|
public void | setResource(java.lang.String resource)Set the resource name of a property file to load.
assertSrcIsJavaResource();
((JavaResource) src).setName(resource);
|
public final void | setSrcFile(java.io.File srcFile)Set the file to load.
addConfigured(new FileResource(srcFile));
|