>
> Tell us what approaches you have taken,
>
> -Steve
>

I tried a couple of different things, and have sort of settled on this...

I have added an optional attribute to the <java> task called
"systemassertions".  This is a boolean attribute to enable or disable system
assertions.  System assertions are a little simpler than "other" assertions
in that system assertions are either on or off.

Non system assertions have finer grained control.  I can enable or disable
assertions by package or class name.  I have addressed this with nested
<disableassertions> and <enableassertions>.  Each of these can be used with
no attributes or with exactly one of either "package" or "class" attributes.
Here is a sample target...

  <target name="test" depends="compile">
    <java classname="Test"
             classpath="classes"
             systemassertions="on"
             fork="yes">
   <enableassertions package="com.packagetwo"/>
   <enableassertions class="com.packageone.a.Test"/>
   <disableassertions class="com.packagetwo.b.Test"/>
    </java>
  </target>

The disabling and enabling of assertions have a cumulative effect.  The
command line generated by the target above is...

c:\jdk1.4\jre\..\bin\java.exe -ea:com.packagetwo... -ea:com.packageone.a.Tes
t -da:com.packagetwo.b.Test -esa -classpath D:\devel\assertTest\classes Test

This implementation involves three, one line methods added to Java.java (1
for the systemassertions attribute, and one each for the enableassertions
and disableassertions nested elements), and a new class that I have called
AssertionArgument.  This class is a small wrapper around
Commandline.Argument with two public methods (1 each for the optional
package and class attributes).

Attached to this email are three files.

java-assert.diff = the diffs to org.apache.tools.ant.taskdefs.Java
AssertionArgument.java = new class mentioned above
assertTest.zip = a simple test set for exercising the implementation

There is a target in the test set called "test".  Take a look at that to
play with the features.

The AssertionArgument class could have been defined as a public inner class
in org.apache.tools.ant.taskdefs.Java.

I hope some of you will take a look at this and share your thoughts and
suggestions.

btw... I looked around and I couldn't find anything very specific about how
to submit code for discussion.  I hope this is appropriate.  If not, please
offer up any comments.  The combined size of the attached files doesn't seem
to be much to me.  I hope I haven't bounced outside of protocol and
generated any hostility!  :-)

Thanks.



Jeff
--
Jeff Brown
Senior Software Engineer
Object Computing Inc.
http://www.ociweb.com/

Attachment: java-assert.diff
Description: Binary data

Attachment: AssertionArgument.java
Description: Binary data

<<attachment: assertTest.zip>>

Reply via email to