You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by ke...@apache.org on 2006/12/12 15:24:51 UTC
svn commit: r486161 -
/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java
Author: kevj
Date: Tue Dec 12 06:24:51 2006
New Revision: 486161
URL: http://svn.apache.org/viewvc?view=rev&rev=486161
Log:
-fix tabs, add validate method
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java?view=diff&rev=486161&r1=486160&r2=486161
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java Tue Dec 12 06:24:51 2006
@@ -31,46 +31,56 @@
*/
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;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: svn commit: r486161 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java
Posted by Kevin Jackson <fo...@gmail.com>.
> Kev, I'd have expected the reflection to be on the new File method in
> jdk6, not on an Ant class that depends on jdk6+. Because this means
> this new Ant class must be compiled with jdk6+, or cross-compiled
> against a jdk6+ rt.jar.
True, I hadn't considered that, my focus was entirely on maintaining a
clean build on pre java6 vms, without considering if the code was
actually compiled.
>
> So more something like (assuming a File#freeSpace method):
>
> > + ReflectWrapper w = new ReflectWrapper(..., "java.io.File");
> > + long free = ((Long)w.invoke("freeSpace", String.class, partition)).longValue();
> > + return free >= StringUtils.parseHumanSizes(needed);
I'll try some variations of this to see if I can get it to work as suggested.
Thanks
Kev
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: svn commit: r486161 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java
Posted by Dominique Devienne <dd...@gmail.com>.
> + if (JavaEnvUtils.isAtLeastJavaVersion("1.6")) {
> + //reflection to avoid bootstrap/build problems
> + String j6FileUtils = "org.apache.tools.ant.util.java16.Java6FileUtils";
> + ReflectWrapper w = new ReflectWrapper(..., j6FileUtils);
> + long free = ((Long)w.invoke("freeSpace", String.class, partition)).longValue();
> + return free >= StringUtils.parseHumanSizes(needed);
Kev, I'd have expected the reflection to be on the new File method in
jdk6, not on an Ant class that depends on jdk6+. Because this means
this new Ant class must be compiled with jdk6+, or cross-compiled
against a jdk6+ rt.jar.
So more something like (assuming a File#freeSpace method):
> + ReflectWrapper w = new ReflectWrapper(..., "java.io.File");
> + long free = ((Long)w.invoke("freeSpace", String.class, partition)).longValue();
> + return free >= StringUtils.parseHumanSizes(needed);
Am I missing something? AFAIK, Ant 1.7 will not be built with jdk6. --DD
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org