On 12/12/06, Kevin Jackson <[EMAIL PROTECTED]> wrote:
Hi all,

I've coded up a new condition to take advantage of (one of) the new
features of the the java.io.File 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="."
xmlns:au="antlib:org.apache.ant.antunit">

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

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

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

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

  <target name="all">
    <au:antunit>
      <fileset file="${ant.file}"/>
      <au:plainlistener/>
    </au:antunit>
  </target>

</project>
<<<<

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 just use reflection for the javax.scripting stuff.
It is not too bad - see o.a.t.a.util.ReflectUtil and ReflectWrapper.

Peter


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)

Thanks,
Kev

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to