Browse Source

fmt/refac

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@557062 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 18 years ago
parent
commit
c6753edecb
1 changed files with 11 additions and 20 deletions
  1. +11
    -20
      src/main/org/apache/tools/ant/taskdefs/LoadProperties.java

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

@@ -76,8 +76,7 @@ public class LoadProperties extends Task {
* @param resource resource on classpath * @param resource resource on classpath
*/ */
public void setResource(String resource) { public void setResource(String resource) {
assertSrcIsJavaResource();
((JavaResource) src).setName(resource);
getRequiredJavaResource().setName(resource);
} }


/** /**
@@ -100,8 +99,7 @@ public class LoadProperties extends Task {
* @param classpath to add to any existing classpath * @param classpath to add to any existing classpath
*/ */
public void setClasspath(Path classpath) { public void setClasspath(Path classpath) {
assertSrcIsJavaResource();
((JavaResource) src).setClasspath(classpath);
getRequiredJavaResource().setClasspath(classpath);
} }


/** /**
@@ -109,8 +107,7 @@ public class LoadProperties extends Task {
* @return The classpath to be configured * @return The classpath to be configured
*/ */
public Path createClasspath() { public Path createClasspath() {
assertSrcIsJavaResource();
return ((JavaResource) src).createClasspath();
return getRequiredJavaResource().createClasspath();
} }


/** /**
@@ -119,8 +116,7 @@ public class LoadProperties extends Task {
* @param r The reference value * @param r The reference value
*/ */
public void setClasspathRef(Reference r) { public void setClasspathRef(Reference r) {
assertSrcIsJavaResource();
((JavaResource) src).setClasspathRef(r);
getRequiredJavaResource().setClasspathRef(r);
} }


/** /**
@@ -128,8 +124,7 @@ public class LoadProperties extends Task {
* @return The classpath * @return The classpath
*/ */
public Path getClasspath() { public Path getClasspath() {
assertSrcIsJavaResource();
return ((JavaResource) src).getClasspath();
return getRequiredJavaResource().getClasspath();
} }


/** /**
@@ -150,7 +145,6 @@ public class LoadProperties extends Task {
} }
throw new BuildException("Source resource does not exist: " + src); throw new BuildException("Source resource does not exist: " + src);
} }

BufferedInputStream bis = null; BufferedInputStream bis = null;
Reader instream = null; Reader instream = null;
ByteArrayInputStream tis = null; ByteArrayInputStream tis = null;
@@ -162,7 +156,6 @@ public class LoadProperties extends Task {
} else { } else {
instream = new InputStreamReader(bis, encoding); instream = new InputStreamReader(bis, encoding);
} }

ChainReaderHelper crh = new ChainReaderHelper(); ChainReaderHelper crh = new ChainReaderHelper();
crh.setPrimaryReader(instream); crh.setPrimaryReader(instream);
crh.setFilterChains(filterChains); crh.setFilterChains(filterChains);
@@ -175,7 +168,6 @@ public class LoadProperties extends Task {
if (!text.endsWith("\n")) { if (!text.endsWith("\n")) {
text = text + "\n"; text = text + "\n";
} }

if (encoding == null) { if (encoding == null) {
tis = new ByteArrayInputStream(text.getBytes()); tis = new ByteArrayInputStream(text.getBytes());
} else { } else {
@@ -188,10 +180,8 @@ public class LoadProperties extends Task {
propertyTask.bindToOwner(this); propertyTask.bindToOwner(this);
propertyTask.addProperties(props); propertyTask.addProperties(props);
} }

} catch (final IOException ioe) { } catch (final IOException ioe) {
final String message = "Unable to load file: " + ioe.toString();
throw new BuildException(message, ioe, getLocation());
throw new BuildException("Unable to load file: " + ioe, ioe, getLocation());
} finally { } finally {
FileUtils.close(bis); FileUtils.close(bis);
FileUtils.close(tis); FileUtils.close(tis);
@@ -211,23 +201,24 @@ public class LoadProperties extends Task {
* @param a the resource to load as a single element Resource collection. * @param a the resource to load as a single element Resource collection.
* @since Ant 1.7 * @since Ant 1.7
*/ */
public void addConfigured(ResourceCollection a) {
public synchronized void addConfigured(ResourceCollection a) {
if (src != null) { if (src != null) {
throw new BuildException("only a single source is supported"); throw new BuildException("only a single source is supported");
} }
if (a.size() != 1) { if (a.size() != 1) {
throw new BuildException("only single argument resource collections"
+ " are supported");
throw new BuildException(
"only single-element resource collections are supported");
} }
src = (Resource) a.iterator().next(); src = (Resource) a.iterator().next();
} }


private void assertSrcIsJavaResource() {
private synchronized JavaResource getRequiredJavaResource() {
if (src == null) { if (src == null) {
src = new JavaResource(); src = new JavaResource();
src.setProject(getProject()); src.setProject(getProject());
} else if (!(src instanceof JavaResource)) { } else if (!(src instanceof JavaResource)) {
throw new BuildException("expected a java resource as source"); throw new BuildException("expected a java resource as source");
} }
return (JavaResource) src;
} }
} }

Loading…
Cancel
Save