ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Jackson" <>
Subject Java6 possible condition HasFreeSpace
Date Tue, 12 Dec 2006 07:17:47 GMT
Hi all,

I've coded up a new condition to take advantage of (one of) the new
features of the the api

Currently this works and I have an antunit test and everything!

public class HasFreeSpace implements Condition {

	private String partition;
	private String needed;
	public boolean eval() throws BuildException {
		try {
			if (JavaEnvUtils.isAtLeastJavaVersion("1.6")) {
				long free = Java6FileUtils.freeSpace(partition);
				return free >= StringUtils.parseHumanSizes(needed);
			} else {
				throw new BuildException("HasFreeSpace condition not supported on
Java5 or less.");
		} catch (Exception e) {
			throw new BuildException(e);

<?xml version="1.0"?>
<project name="hasfreespace-test" default="all" basedir="."

  <target name="test-not-enough-space-human">
      <hasfreespace partition="c:" needed="1P"/>			

  <target name="test-enough-space-human">
      <hasfreespace partition="c:" needed="1K"/>			

  <target name="test-not-enough-space">
  	<property name="long.max-value" value="9223372036854775807"/>
   	  <hasfreespace partition="c:" needed="${long.max-value}"/>
  <target name="test-enough-space">
      <hasfreespace partition="c:" needed="1"/>			

  <target name="all">
      <fileset file="${ant.file}"/>


Now the problem is that I currently use a Java6FileUtils to allow me
to keep the special Java6 methods out of the base FileUtils, but none
of this code will compile on <jdk6 (well ok the StringUtils code is
fine).  I'd like to separate out the java6 specific stuff in a way
that allows me to bootstrap/build correctly on jdk5, but right now it
fails as the bootstrap script expects everything in the conditions
package to be bwc with jdk1.2.

I want to check in the StringUtils changes as they will build fine on
pre-jdk6, but they'd be unused unless I checked in my new condition.
So any helpful suggestions as to how to structure everything to work
in a bwc way and ignore my new condition when on jdk5 & lower?

(I've added a o.a.t.a.u.java6 package which my Java6FileUtils resides
in, so I can conditionally compile that, it's just that the
HasFreeSpace condition is in with the rest of the conditions and this
is failing on Java5)


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message