samples/differentreturntype/build.xml
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:50:51 +0200
changeset 10 5611653dec2f
child 11 617540e9e582
permissions -rw-r--r--
Example with bytecode patching
     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <project name="differentreturntype" default="run" basedir=".">
     3     <target name="clean">
     4         <delete dir="build"/>
     5     </target>
     6     
     7     <!-- This is the target that does the whole trick - e,g. it compiles
     8         the Java source and then replaces tokens inside of the .class file
     9      -->
    10     <target name="-build-and-rename">
    11         <mkdir dir="build/apimerge/classes"/>
    12         <javac 
    13             srcdir="src-apimerge" 
    14             destdir="build/apimerge/classes" 
    15             source="1.4" target="1.4"
    16             classpath="${cp}"
    17         />
    18         
    19         <!-- this is the replace. As the replace is done textually,
    20             we need to use some reasonable encoding that treats all byte values
    21             as characters. E.g. it is not possible to use UTF-8 as it does not
    22             like the standard Java header 0xCAFEBABE. Western Europe encoding is fine
    23         -->
    24         <replace dir="build/apimerge/classes" casesensitive="true" encoding="iso-8859-1" summary="true">
    25             <include name="**/*.class"/>
    26             <replacetoken>g3tIcon</replacetoken>
    27             <replacevalue>getIcon</replacevalue>
    28         </replace>
    29     </target>
    30     
    31     <target name="build" depends="clean">
    32         <antcall target="-build-one">
    33             <param name="version" value="api1.0"/>
    34         </antcall>
    35         <antcall target="-build-one">
    36             <param name="version" value="api2.0"/>
    37         </antcall>
    38         <antcall target="-build-and-rename"/>
    39         <antcall target="-build-one">
    40             <param name="version" value="impl"/>
    41             <param name="target" value="impl-with-api1.0"/>
    42             <param name="cp" location="build/api1.0/classes"/>
    43         </antcall>
    44         <antcall target="-build-one">
    45             <param name="version" value="impl"/>
    46             <param name="target" value="impl-with-api2.0"/>
    47             <param name="cp" location="build/api2.0/classes"/>
    48         </antcall>
    49     </target>
    50     
    51     <target name="run" depends="build">
    52         <echo level="info" message="Running the Implementation Compiled against Version 1.0 with Version 1.0. This should succeeds."/>
    53         <antcall target="-run-one">
    54             <param name="version" value="api1.0"/>
    55         </antcall>
    56         <echo level="info" message="Running the Implementation Compiled against Version 2.0 with Version 2.0. This should succeeds."/>
    57         <antcall target="-run-one">
    58             <param name="version" value="api2.0"/>
    59         </antcall>
    60         <echo level="info" message="Running the Implementation Compiled against Version 1.0 with Version 2.0. This should fail."/>
    61         <antcall target="-run-one">
    62             <param name="version" value="api2.0"/>
    63             <param name="target" value="api1.0"/>
    64         </antcall>
    65         <echo level="info" message="Running the Implementation Compiled against Version 2.0 with Version 1.0. This should fail."/>
    66         <antcall target="-run-one">
    67             <param name="version" value="api1.0"/>
    68             <param name="target" value="api2.0"/>
    69         </antcall>
    70         <echo level="info" message="Final success1: Running the Implementation Compiled against Version 1.0 with Merged Version."/>
    71         <antcall target="-run-one">
    72             <param name="version" value="apimerge"/>
    73             <param name="target" value="api1.0"/>
    74         </antcall>
    75         <echo level="info" message="Final success2: Running the Implementation Compiled against Version 2.0 with Merged Version."/>
    76         <antcall target="-run-one">
    77             <param name="version" value="apimerge"/>
    78             <param name="target" value="api2.0"/>
    79         </antcall>
    80     </target>
    81 
    82     
    83     <!-- support methods -->
    84     
    85     <target name="-run-one">
    86         <fail message="You need to specify API version number" unless="version"/>
    87         <property name="target" value="${version}"/>
    88         <java classpath="build/${version}/classes:build/impl-with-${target}/classes" classname="impl.Impl"
    89             failonerror="false"
    90         />
    91     </target>
    92     
    93     <target name="-build-one">
    94         <fail message="You need to specify version number" unless="version"/>
    95         
    96         <property name="cp" value=""/>
    97         <property name="target" value="${version}"/>
    98         <mkdir dir="build/${target}/classes"/>
    99         <javac 
   100             srcdir="src-${version}" 
   101             destdir="build/${target}/classes" 
   102             source="1.4" target="1.4"
   103             classpath="${cp}"
   104         />
   105     </target>
   106 </project>