From cc32e094ecf8f0ac6334ad7a1c33ecd7c9523629 Mon Sep 17 00:00:00 2001 From: Kevin Jackson Date: Tue, 12 Dec 2006 14:24:51 +0000 Subject: [PATCH] -fix tabs, add validate method git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@486161 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/taskdefs/condition/HasFreeSpace.java | 86 +++++++++++-------- 1 file changed, 48 insertions(+), 38 deletions(-) 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