Browse Source

-fix tabs, add validate method

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@486161 13f79535-47bb-0310-9956-ffa450edef68
master
Kevin Jackson 18 years ago
parent
commit
cc32e094ec
1 changed files with 48 additions and 38 deletions
  1. +48
    -38
      src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java

+ 48
- 38
src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java View File

@@ -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;
}
}

Loading…
Cancel
Save