alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Ant example source code file (scriptdef.xml)

This example Ant source code file (scriptdef.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Ant tags/keywords

attribute, attribute, cdata, cdata, fileset, fileset, task1, task2, task2

The scriptdef.xml source code

<project name="testproject" default="def" basedir=".">

  <target name="def">
    <fail>This build-file is intended to be run from the test cases
  </target>

  <target name="simple">
    <scriptdef name="scripttest" language="javascript">
      <attribute name="attr1"/>
      <element name="fileset" type="fileset"/>
      <![CDATA[
        
        project.log("Attribute attr1 = " + attributes.get("attr1"));
        project.log("Fileset basedir = "
          + elements.get("fileset").get(0).getDir(project));
        
      ]]>
    </scriptdef>
    
    <fileset id="testfileset" dir="."/>
    <scripttest attr1="test">
      <fileset refid="testfileset"/>
    </scripttest>
  </target>

  <target name="nolang">
    <scriptdef name="nolang">
      <![CDATA[
        java.lang.System.out.println("Hello");
      ]]>
    </scriptdef>
  </target>

  <target name="noname">
    <scriptdef language="javascript">
      <![CDATA[
        java.lang.System.out.println("Hello");
      ]]>
    </scriptdef>
  </target>

  <target name="nestedbyclassname">
    <scriptdef name="scripttest" language="javascript">
      <attribute name="attr1"/>
      <element name="fileset" classname="org.apache.tools.ant.types.FileSet"/>
      <![CDATA[
        
        project.log("Attribute attr1 = " + attributes.get("attr1"));
        project.log("Fileset basedir = "
          + elements.get("fileset").get(0).getDir(project));
        
      ]]>
    </scriptdef>
    
    <fileset id="testfileset" dir="."/>
    <scripttest attr1="test">
      <fileset refid="testfileset"/>
    </scripttest>
  </target>
  
  <target name="noelement">
    <scriptdef name="scripttest" language="javascript">
      <attribute name="attr1"/>
      <element name="fileset" type="fileset"/>
      <![CDATA[
        java.lang.System.out.println("Attribute attr1 = " + attributes.get("attr1"));
      ]]>
    </scriptdef>
    
    <scripttest attr1="test">
    </scripttest>
  </target>

  <target name="exception">
    <scriptdef name="scripttest" language="javascript">
      <attribute name="attr1"/>
      <element name="fileset" classname="org.apache.tools.ant.types.FileSet"/>
      <![CDATA[
        
        java.lang.System.out.println("Attribute attr1 = " + attributes.get("attr1"));
        java.lang.System.out.println("Fileset basedir = "
          + elements.get("fileset").get(0).getDir(project));
        
      ]]>
    </scriptdef>
    
    <scripttest attr1="test">
    </scripttest>
  </target>
  
  <target name="doubledef">
    <scriptdef name="task1" language="javascript">
      <![CDATA[
        project.log("Task1");
      ]]>
    </scriptdef>
    <scriptdef name="task2" language="javascript">
      <![CDATA[
        project.log("Task2");
      ]]>
    </scriptdef>
    <task1/>
    <task2/>
  </target>
  
  <target name="doubleAttributeDef">
    <scriptdef name="scripttest" language="javascript">
      <attribute name="attr1"/>
      <attribute name="attr1"/>
    </scriptdef>
  </target>
  
  <target name="property">
    <scriptdef name="scripttest" language="javascript">
      <attribute name="attr1"/>
      <![CDATA[
        
        project.log("Attribute value = " + attributes.get("attr1"));
      ]]>
    </scriptdef>

    <property name="testproperty" value="test"/>    
    <scripttest attr1="${testproperty}">
    </scripttest>
  </target>


</project>

Other Ant examples (source code examples)

Here is a short list of links related to this Ant scriptdef.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.