build.xml 11.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
<?xml version="1.0" encoding="UTF-8"?>
<!--
 Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

   - Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.

   - Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.

   - Neither the name of Sun Microsystems nor the names of its
     contributors may be used to endorse or promote products derived
     from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->

<project name="langtools-netbeans" default="build" basedir="../../..">
    
    <property name="langtools.properties" 
        location="make/netbeans/langtools/nbproject/private/langtools.properties"/>
    
    <!-- 
        Instead of importing the main build file, we could call it when needed.
        That would reduce the list of Ant targets that get displayed for this
        file, but it also complicates the interface between the project build 
        file and the main build file. For example, some imported targets
        would have to be reclared, properties would have to be restructured,
        and it would be harder to run results (e.g. in properties) from nested 
        targets.
     -->
    <import file="../../build.xml"/> 
    
    <!-- Build project. (action: build; F11)
        If langtools.tool.name is set, then just build that tool; otherwise
        build all tools.
    -->
    
    <target name="build" depends="-get-tool-if-set,-build-tool,-build-all" 
        description="Build one or all langtools tools"
        />
        
    <target name="-build-tool" if="langtools.tool.name">
        <echo level="info" message="Building ${langtools.tool.name}"/>
        <echo level="verbose" message="(Unset langtools.tool.name to build all tools)"/>
        <antcall target="build-${langtools.tool.name}"/>
    </target>
    
    <target name="-build-all" unless="langtools.tool.name">
        <echo level="info" message="Building all tools"/>
        <echo level="verbose" message="(Set langtools.tool.name to build a single tool)"/>
        <antcall target="build-all-tools"/>
    </target>
    
    <!-- Compile a single file. (action: compile.single; F9) -->
    
    <target name="compile-single" depends="build-bootstrap-javac">
        <fail unless="includes">Must set property 'includes'</fail>
        <javac fork="true" executable="${build.bootstrap.dir}/bin/javac"
               srcdir="${src.classes.dir}"
               destdir="${build.classes.dir}"
               includes="${includes}"
               sourcepath=""
               includeAntRuntime="no"
               target="${javac.target}"
               debug="${javac.debug}" 
               debuglevel="${javac.debuglevel}"/>
    </target>
    
    <!-- Run tool. (action: run; F6) 
        Use langtools.tool.name and langtools.tool.args properties if set; otherwise prompt
        the user.
    -->
    
    <target name="run" depends="-check-target.java.home,build,-def-run,-get-tool-and-args" 
            description="run tool">
        <echo level="info" message="Run ${langtools.tool.name} with args ${langtools.tool.args}"/>
        <run mainclass="com.sun.tools.${langtools.tool.name}.Main" args="${langtools.tool.args}"/>
    </target>
    
    <!-- Run a selected class. (action: run.single;  shift-F6) -->
    
    <target name="run-single" depends="-check-target.java.home,-def-run">
        <fail unless="run.classname">Must set property 'run.classname' </fail>
        <echo level="info" message="run ${run.classname}"/>
        <run mainclass="${run.classname}" args=""/>
    </target>
    
    <!-- Test project, and display results if tests failed. (action: test; Alt-F6)
        If langtools.tool.name is set, then just test that tool; otherwise
        test all tools.
    -->
    
    <target name="jtreg" depends="-get-tool-if-set,-jtreg-tool,-jtreg-all" 
        description="Test one or all langtools tools"
        />
    
    <target name="-jtreg-tool" if="langtools.tool.name">
        <echo level="info" message="Testing ${langtools.tool.name}"/>
        <echo level="verbose" message="(Unset langtools.tool.name to test all tools)"/>
        <antcall>
            <target name="jtreg-${langtools.tool.name}"/>
            <target name="-show-jtreg"/>
        </antcall>
    </target>
    
    <target name="-jtreg-all" unless="langtools.tool.name">
        <echo level="info" message="Testing all tools"/>
        <echo level="verbose" message="(Set langtools.tool.name to test a single tool)"/>
        <antcall>
            <target name="langtools.jtreg"/>
            <target name="-show-jtreg"/>
        </antcall>
    </target>
    
    <target name="-show-jtreg" if="netbeans.home" unless="jtreg.passed">
        <nbbrowse file="${jtreg.report}/report.html"/>
        <fail>Some tests failed; see report for details.</fail>
    </target>
    
    <!-- Debug tool in NetBeans. -->
    
    <target name="debug" depends="-check-target.java.home,-def-run,-def-start-debugger,-get-tool-and-args,build" if="netbeans.home">
        <echo level="info" message="Debug ${langtools.tool.name} with args ${langtools.tool.args}"/>
        <start-debugger/>
        <run mainclass="com.sun.tools.${langtools.tool.name}.Main" args="${langtools.tool.args}" jpda.jvmargs="${jpda.jvmargs}"/>
    </target>
    
    <!-- Debug a selected class . -->
    <target name="debug-single" depends="-check-target.java.home,-def-start-debugger,-def-run">
        <fail unless="debug.classname">Must set property 'debug.classname'</fail>
        <start-debugger/>
        <run mainclass="${debug.classname}" default.args="" jpda.jvmargs="${jpda.jvmargs}"/>
    </target>
    
    <!-- Debug a jtreg test. -->
    <target name="debug-jtreg" depends="-check-target.java.home,-def-start-debugger,-def-jtreg">
        <fail unless="jtreg.tests">Must set property 'jtreg.tests'</fail>
        <start-debugger/>
        <jtreg-tool name="debug" samevm="false" tests="${jtreg.tests}" jpda.jvmargs="${jpda.jvmargs}"/>
    </target>
    
    <!-- Update a class being debugged. -->
    
    <target name="debug-fix" if="langtools.tool.name">
        <fail unless="class">Must set property 'class'
        </fail>
        <antcall target="compile-single">
            <param name="includes" value="${class}.java"/>
        </antcall>
        <nbjpdareload>
            <fileset dir="${build.classes.dir}">
                <include name="${class}.class"/>
            </fileset>
        </nbjpdareload>
    </target>
    
    <!-- Generate javadoc for one or all tools. (action: javadoc; Alt-F6)
        If langtools.tool.name is set, then just test that tool; otherwise
        test all tools.
    -->
    
    <target name="javadoc" depends="-javadoc-tool,-javadoc-all" 
        description="Generate javadoc for one or all langtools tools"
        />
        
    <target name="-javadoc-tool" if="langtools.tool.name">
        <echo level="info" message="Generate javadoc for ${langtools.tool.name}"/>
        <echo level="verbose" message="(Unset langtools.tool.name to generate javadoc for all tools)"/>
        <antcall>
            <target name="javadoc-${langtools.tool.name}"/>
            <target name="-show-javadoc"/>
        </antcall>
    </target>
    
    <target name="-javadoc-all" unless="langtools.tool.name">
        <echo level="info" message="Generate javadoc for all tools"/>
        <echo level="verbose" message="(Set langtools.tool.name to generate javadoc for a single tool)"/>
        <antcall>
            <target name="langtools.javadoc"/>
            <target name="-show-javadoc"/>
        </antcall>
    </target>
    
    <target name="-show-javadoc" if="netbeans.home">
        <!-- what if doing javadoc for all? -->
        <nbbrowse file="${build.javadoc.dir}/${langtools.tool.name}/index.html"/>
    </target>
    
    <!-- Prompt for values. -->
    
    <target name="-get-tool-if-set" depends="-def-select-tool">
        <select-tool 
            toolproperty="langtools.tool.name" 
            propertyfile="${langtools.properties}"
            askIfUnset="false"
            />
    </target>
    
    <target name="-get-tool-and-args" depends="-def-select-tool">
        <select-tool 
            toolproperty="langtools.tool.name" 
            argsproperty="langtools.tool.args" 
            propertyfile="${langtools.properties}"
            askIfUnset="true"
            />
    </target>

    <!-- Macro to run a tool or selected class - used by run* and debug* tasks -->
    <target name="-def-run">
        <macrodef name="run">
            <attribute name="mainclass"/>
            <attribute name="args" default=""/>
            <attribute name="jpda.jvmargs" default=""/>
            <sequential>
                <java fork="true" jvm="${target.java}" classname="@{mainclass}">
                    <jvmarg line="-Xbootclasspath/p:${build.classes.dir}"/>
                    <jvmarg line="@{jpda.jvmargs}"/>
                    <arg line="@{args}"/>
                </java>
            </sequential>
        </macrodef>
    </target>
    
    <!-- Macro to start the debugger and set a property containg the args needed by the run task -->
    <target name="-def-start-debugger" if="netbeans.home">
        <macrodef name="start-debugger">
            <attribute name="jpda.jvmargs.property" default="jpda.jvmargs"/>
            <sequential>
                <nbjpdastart name="${ant.project.name}" addressproperty="jpda.address" transport="dt_socket">
                    <bootclasspath>
                        <pathelement location="${build.classes.dir}"/>
                        <pathelement location="${target.java.home}/jre/lib/rt.jar"/>
                    </bootclasspath>
                    <sourcepath>
                        <pathelement location="${src.classes.dir}"/>
                    </sourcepath>
                </nbjpdastart>
                <property 
                    name="@{jpda.jvmargs.property}" 
                    value="-Xdebug -Xnoagent -Djava.compiler=none -Xrunjdwp:transport=dt_socket,address=${jpda.address}"
                />
            </sequential>
        </macrodef>
    </target>
    
    <target name="-def-select-tool">
        <mkdir dir="${build.toolclasses.dir}"/>
        <javac srcdir="${make.tools.dir}/SelectTool"
               destdir="${build.toolclasses.dir}/"
               classpath="${ant.home}/lib/ant.jar"
               debug="${javac.debug}" 
               debuglevel="${javac.debuglevel}">
                   <compilerarg line="-Xlint"/>
        </javac>
        <taskdef name="select-tool"
                 classname="SelectToolTask" 
                 classpath="${build.toolclasses.dir}/"/>
    </target>
        
    <target name="select-tool" depends="-def-select-tool">
        <select-tool propertyfile="${langtools.properties}"/>
    </target>
</project>