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