diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java b/src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java index ed63d8b2c..0d0244b7d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java @@ -31,46 +31,56 @@ import org.apache.tools.ant.util.StringUtils; */ public class HasFreeSpace implements Condition { - private String partition; - private String needed; - - public boolean eval() throws BuildException { - try { - if (JavaEnvUtils.isAtLeastJavaVersion("1.6")) { - //reflection to avoid bootstrap/build problems - String j6FileUtils = "org.apache.tools.ant.util.java16.Java6FileUtils"; - ReflectWrapper w = new ReflectWrapper(getClass().getClassLoader(), j6FileUtils); - long free = ((Long)w.invoke("freeSpace", String.class, partition)).longValue(); - return free >= StringUtils.parseHumanSizes(needed); - } else { - throw new BuildException("HasFreeSpace condition not supported on Java5 or less."); - } - } catch (Exception e) { - throw new BuildException(e); - } - } + private String partition; + private String needed; - /** - * The partition/device to check - * @return - */ - public String getPartition() { - return partition; - } + public boolean eval() throws BuildException { + validate(); + try { + if (JavaEnvUtils.isAtLeastJavaVersion("1.6")) { + //reflection to avoid bootstrap/build problems + String j6FileUtils = "org.apache.tools.ant.util.java16.Java6FileUtils"; + ReflectWrapper w = new ReflectWrapper(getClass().getClassLoader(), j6FileUtils); + long free = ((Long)w.invoke("freeSpace", String.class, partition)).longValue(); + return free >= StringUtils.parseHumanSizes(needed); + } else { + throw new BuildException("HasFreeSpace condition not supported on Java5 or less."); + } + } catch (Exception e) { + throw new BuildException(e); + } + } - public void setPartition(String partition) { - this.partition = partition; - } + private void validate() throws BuildException { + if(null == partition) { + throw new BuildException("Please set the partition attribute."); + } + if(null == needed) { + throw new BuildException("Please set the needed attribute."); + } + } + + /** + * The partition/device to check + * @return + */ + public String getPartition() { + return partition; + } - /** - * The amount of free space required - * @return the amount required - */ - public String getNeeded() { - return needed; - } + public void setPartition(String partition) { + this.partition = partition; + } - public void setNeeded(String needed) { - this.needed = needed; - } + /** + * The amount of free space required + * @return the amount required + */ + public String getNeeded() { + return needed; + } + + public void setNeeded(String needed) { + this.needed = needed; + } } \ No newline at end of file