FileDocCategorySizeDatePackage
Assertions.javaAPI DocApache Ant 1.7011940Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.types

Assertions

public class Assertions extends DataType implements Cloneable
The assertion datatype. This type describes assertion settings for the <java> task and others. One can set the system assertions, and enable/disable those in packages and classes. Assertions can only be enabled or disabled when forking Java. Example: set system assertions and all org.apache packages except for ant, and the class org.apache.tools.ant.Main.
<assertions enableSystemAssertions="true" >
<enable package="org.apache" />
<disable package="org.apache.ant" />
<enable class="org.apache.tools.ant.Main"/>
</assertions>
Disable system assertions; enable those in the anonymous package
<assertions enableSystemAssertions="false" >
<enable package="..." />
</assertions>
enable assertions in a class called Test
<assertions >
<enable class="Test" />
</assertions>
This type is a datatype, so you can declare assertions and use them later
<assertions id="project.assertions" >
<enable project="org.apache.test" />
</assertions>

<assertions refid="project.assertions" />

since
Ant 1.6

Fields Summary
private Boolean
enableSystemAssertions
enable/disable sys assertions; null means undefined
private ArrayList
assertionList
list of type BaseAssertion
Constructors Summary
Methods Summary
public voidaddDisable(org.apache.tools.ant.types.Assertions$DisabledAssertion assertion)
disable assertions

param
assertion a disable assertion nested element

        checkChildrenAllowed();
        assertionList.add(assertion);
    
public voidaddEnable(org.apache.tools.ant.types.Assertions$EnabledAssertion assertion)
enable assertions

param
assertion an enable assertion nested element



                  
        
        checkChildrenAllowed();
        assertionList.add(assertion);
    
private static voidaddVmArgument(CommandlineJava command, java.lang.String arg)
helper method to add a string JVM argument to a command

param
command
param
arg

        Commandline.Argument argument;
        argument = command.createVmArgument();
        argument.setValue(arg);
    
public voidapplyAssertions(java.util.ListIterator commandIterator)
add the assertions to a list in a format suitable for adding to a command line

param
commandIterator list of commands

        getProject().log("Applying assertions", Project.MSG_DEBUG);
        Assertions clause = getFinalReference();
        //do the system assertions
        if (Boolean.TRUE.equals(clause.enableSystemAssertions)) {
            getProject().log("Enabling system assertions", Project.MSG_DEBUG);
            commandIterator.add("-enablesystemassertions");
        } else if (Boolean.FALSE.equals(clause.enableSystemAssertions)) {
            getProject().log("disabling system assertions", Project.MSG_DEBUG);
            commandIterator.add("-disablesystemassertions");
        }

        //now any inner assertions
        Iterator it = clause.assertionList.iterator();
        while (it.hasNext()) {
            BaseAssertion assertion = (BaseAssertion) it.next();
            String arg = assertion.toCommand();
            getProject().log("adding assertion " + arg, Project.MSG_DEBUG);
            commandIterator.add(arg);
        }
    
public voidapplyAssertions(java.util.List commandList)
add the assertions to a list in a format suitable for adding to a command line

param
commandList the command line to format

        getProject().log("Applying assertions", Project.MSG_DEBUG);
        Assertions clause = getFinalReference();
        //do the system assertions
        if (Boolean.TRUE.equals(clause.enableSystemAssertions)) {
            getProject().log("Enabling system assertions", Project.MSG_DEBUG);
            commandList.add("-enablesystemassertions");
        } else if (Boolean.FALSE.equals(clause.enableSystemAssertions)) {
            getProject().log("disabling system assertions", Project.MSG_DEBUG);
            commandList.add("-disablesystemassertions");
        }

        //now any inner assertions
        Iterator it = clause.assertionList.iterator();
        while (it.hasNext()) {
            BaseAssertion assertion = (BaseAssertion) it.next();
            String arg = assertion.toCommand();
            getProject().log("adding assertion " + arg, Project.MSG_DEBUG);
            commandList.add(arg);
        }
    
public voidapplyAssertions(CommandlineJava command)
apply all the assertions to the command.

param
command the command line to format

        Assertions clause = getFinalReference();
        //do the system assertions
        if (Boolean.TRUE.equals(clause.enableSystemAssertions)) {
            addVmArgument(command, "-enablesystemassertions");
        } else if (Boolean.FALSE.equals(clause.enableSystemAssertions)) {
            addVmArgument(command, "-disablesystemassertions");
        }

        //now any inner assertions
        Iterator it = clause.assertionList.iterator();
        while (it.hasNext()) {
            BaseAssertion assertion = (BaseAssertion) it.next();
            String arg = assertion.toCommand();
            addVmArgument(command, arg);
        }
    
public java.lang.Objectclone()
clone the objects. This is not a full depth clone; the list of assertions is cloned, but it does not clone the underlying assertions.

return
a cli
throws
CloneNotSupportedException if the super class does not support cloning

        Assertions that = (Assertions) super.clone();
        that.assertionList = (ArrayList) assertionList.clone();
        return that;
    
private org.apache.tools.ant.types.AssertionsgetFinalReference()
get whatever we are referencing to. This could be ourself.

return
the object that contains the assertion info

        if (getRefid() == null) {
            return this;
        } else {
            Object o = getRefid().getReferencedObject(getProject());
            if (!(o instanceof Assertions)) {
                throw new BuildException("reference is of wrong type");
            }
            return (Assertions) o;
        }
    
private intgetFinalSize()
what is the final size of this object

return

        return assertionList.size() + (enableSystemAssertions != null ? 1 : 0);
    
public voidsetEnableSystemAssertions(java.lang.Boolean enableSystemAssertions)
enable or disable system assertions. Default is not set (neither -enablesystemassersions or -disablesytemassertions are used on the command line).

param
enableSystemAssertions if true enable system assertions

        checkAttributesAllowed();
        this.enableSystemAssertions = enableSystemAssertions;
    
public voidsetRefid(Reference ref)
Set the value of the refid attribute.

Subclasses may need to check whether any other attributes have been set as well or child elements have been created and thus override this method. if they do the must call super.setRefid.

param
ref the reference to use

        if (assertionList.size() > 0 || enableSystemAssertions != null) {
            throw tooManyAttributes();
        }
        super.setRefid(ref);
    
public intsize()
how many assertions are made...will resolve references before returning

return
total # of commands to make

        Assertions clause = getFinalReference();
        return clause.getFinalSize();