1 <?xml version="1.0" encoding="UTF-8"?>
   2 <!--
   3  Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
   4 
   5  Redistribution and use in source and binary forms, with or without
   6  modification, are permitted provided that the following conditions
   7  are met:
   8 
   9    - Redistributions of source code must retain the above copyright
  10      notice, this list of conditions and the following disclaimer.
  11 
  12    - Redistributions in binary form must reproduce the above copyright
  13      notice, this list of conditions and the following disclaimer in the
  14      documentation and/or other materials provided with the distribution.
  15 
  16    - Neither the name of Oracle nor the names of its
  17      contributors may be used to endorse or promote products derived
  18      from this software without specific prior written permission.
  19 
  20  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31 -->
  32 
  33 <project name="langtools-netbeans" default="build" basedir="../../..">
  34 
  35     <property name="langtools.properties"
  36         location="make/netbeans/langtools/nbproject/private/langtools.properties"/>
  37 
  38     <!--
  39         Instead of importing the main build file, we could call it when needed.
  40         That would reduce the list of Ant targets that get displayed for this
  41         file, but it also complicates the interface between the project build
  42         file and the main build file. For example, some imported targets
  43         would have to be reclared, properties would have to be restructured,
  44         and it would be harder to run results (e.g. in properties) from nested
  45         targets.
  46      -->
  47     <import file="../../build.xml"/>
  48 
  49     <!-- Build project. (action: build; F11) -->
  50 
  51     <target name="build" depends="-get-tool-if-set,-build-bootstrap-javac,-build-all" />
  52     <target name="-build-bootstrap-javac" if="langtools.tool.bootstrap">
  53         <antcall target="build-bootstrap-javac"/>
  54     </target>
  55     <target name="-build-all" unless="langtools.tool.bootstrap">
  56         <antcall target="build-all-tools"/>
  57     </target>
  58 
  59     <!-- Compile a single file. (action: compile.single; F9) -->
  60 
  61     <target name="compile-single" depends="-get-tool-if-set,build-bootstrap-javac-classes" unless="langtools.tool.bootstrap">
  62         <fail unless="includes">Must set property 'includes'</fail>
  63         <mkdir dir="${build.dir}/${module.name}/classes" />
  64         <javac fork="true" executable="${boot.java.home}/bin/javac"
  65                srcdir="${basedir}/src/${module.name}/share/classes"
  66                destdir="${build.dir}/${module.name}/classes"
  67                includes="${includes}"
  68                sourcepath=""
  69                classpath="${langtools.classes}"
  70                includeAntRuntime="no"
  71                source="${javac.source}"
  72                target="${javac.target}"
  73                debug="${javac.debug}"
  74                debuglevel="${javac.debuglevel}">
  75             <compilerarg value="-J-Xbootclasspath/p:${build.bootstrap.dir}/classes"/>
  76         </javac>
  77     </target>
  78 
  79     <!-- Run tool. (action: run; F6)
  80         Use langtools.tool.name and langtools.tool.args properties if set; otherwise prompt
  81         the user.
  82     -->
  83 
  84     <target name="run" depends="-check-target.java.home,-build-classes,-def-run,-get-tool-and-args,-setup-bootclasspath,-def-resolve-main-class"
  85             description="run tool">
  86         <echo level="info" message="${with_bootclasspath}"/>
  87         <echo level="info" message="Run ${use_bootstrap}${langtools.tool.name} with args ${langtools.tool.args}"/>
  88         <resolve-main-class tool.name="${langtools.tool.name}" />
  89         <run bcp="${with_bootclasspath}" mainclass="${langtools.main.class}" args="${langtools.tool.args}"/>
  90     </target>
  91 
  92     <target name="-def-resolve-main-class">
  93         <macrodef name="resolve-main-class">
  94           <attribute name="tool.name"/>
  95           <sequential>
  96             <condition property="langtools.main.class"
  97                     value="jdk.javadoc.internal.tool.Main"
  98                     else="${tool.@{tool.name}.main.class}">
  99                 <equals arg1="${langtools.tool.name}" arg2="javadoc"/>
 100             </condition>
 101           </sequential>
 102         </macrodef>
 103     </target>
 104 
 105     <target name="-build-classes" depends="-get-tool-if-set,-build-classes-bootstrap-javac,-build-classes-all" />
 106     <target name="-build-classes-bootstrap-javac" if="langtools.tool.bootstrap">
 107         <antcall target="build-bootstrap-javac-classes"/>
 108     </target>
 109     <target name="-build-classes-all" unless="langtools.tool.bootstrap">
 110         <antcall target="build-all-classes"/>
 111     </target>
 112 
 113     <!-- Run a selected class. (action: run.single;  shift-F6) -->
 114 
 115     <target name="run-single" depends="-check-target.java.home,-setup-bootclasspath,-def-run">
 116         <fail unless="run.classname">Must set property 'run.classname' </fail>
 117         <echo level="info" message="run ${run.classname}"/>
 118         <run mainclass="${run.classname}" args=""/>
 119     </target>
 120 
 121     <!-- Test project, and display results if tests failed. (action: test; Alt-F6)
 122         If langtools.tool.name is set, then just test that tool; otherwise
 123         test all tools.
 124     -->
 125 
 126     <target name="jtreg" depends="-get-tool-if-set,-jtreg-bootstrap-javac,-jtreg-all"
 127         description="Test langtools tools or bootstrap javac"
 128         />
 129 
 130     <target name="-jtreg-bootstrap-javac" if="langtools.tool.bootstrap">
 131         <echo level="info" message="Testing bootstrap javac"/>
 132         <echo level="verbose" message="(Unset langtools.tool.bootstrap to test all tools)"/>
 133         <antcall>
 134             <target name="jtreg-bootstrap-javac"/>
 135             <target name="-show-jtreg"/>
 136         </antcall>
 137     </target>
 138 
 139     <target name="-jtreg-all" unless="langtools.tool.bootstrap">
 140         <echo level="info" message="Testing all tools"/>
 141         <echo level="verbose" message="(Set langtools.tool.bootstrap to test bootstrap javac)"/>
 142         <antcall>
 143             <target name="langtools.jtreg"/>
 144             <target name="-show-jtreg"/>
 145         </antcall>
 146     </target>
 147 
 148     <target name="-show-jtreg-single-detect" if="netbeans.home" unless="jtreg.passed">
 149         <dirname property="netbeans.jtreg.tests.dir.temp" file="${jtreg.report}/../work/${jtreg.tests}"/>
 150         <basename property="netbeans.jtreg.tests.basename.temp" file="${jtreg.tests}" suffix=".java"/>
 151         <property name="netbeans.jtreg.single.jtr" value="${netbeans.jtreg.tests.dir.temp}/${netbeans.jtreg.tests.basename.temp}.jtr"/>
 152         <condition property="netbeans.jtreg.single">
 153             <available file="${netbeans.jtreg.single.jtr}" />
 154         </condition>
 155         <condition property="netbeans.jtreg.multiple">
 156             <not>
 157                 <available file="${netbeans.jtreg.single.jtr}" />
 158             </not>
 159         </condition>
 160     </target>
 161 
 162     <target name="-show-jtreg-single" if="netbeans.jtreg.single" depends="-show-jtreg-single-detect">
 163         <nbbrowse file="${netbeans.jtreg.single.jtr}"/>
 164         <fail>Some tests failed; see report for details.</fail>
 165     </target>
 166 
 167     <target name="-show-jtreg-multiple" if="netbeans.jtreg.multiple" depends="-show-jtreg-single-detect">
 168         <nbbrowse url="file://${jtreg.report}/html/report.html#Results"/>
 169         <fail>Some tests failed; see report for details.</fail>
 170     </target>
 171 
 172     <target name="-show-jtreg" depends="-show-jtreg-single-detect,-show-jtreg-single,-show-jtreg-multiple" />
 173 
 174     <!-- Debug tool in NetBeans. -->
 175 
 176     <target name="debug" depends="-check-target.java.home,-def-run,-def-start-debugger,-get-tool-and-args,-setup-bootclasspath,-build-classes,-def-resolve-main-class" if="netbeans.home">
 177         <echo level="info" message="Debug ${use_bootstrap}${langtools.tool.name} with args ${langtools.tool.args}"/>
 178         <start-debugger/>
 179         <resolve-main-class tool.name="${langtools.tool.name}" />
 180         <run bcp="${with_bootclasspath}" mainclass="${langtools.main.class}" args="${langtools.tool.args}" jpda.jvmargs="${jpda.jvmargs}"/>
 181     </target>
 182 
 183     <!-- Debug a selected class . -->
 184     <target name="debug-single" depends="-check-target.java.home,-def-start-debugger,-def-run">
 185         <fail unless="debug.classname">Must set property 'debug.classname'</fail>
 186         <start-debugger/>
 187         <run mainclass="${debug.classname}" args="" jpda.jvmargs="${jpda.jvmargs}"/>
 188     </target>
 189 
 190     <!-- Debug a jtreg test. -->
 191     <target name="debug-jtreg" depends="-check-target.java.home,-def-start-debugger,-def-jtreg,-get-tool-if-set,-setup-bootclasspath">
 192         <fail unless="jtreg.tests">Must set property 'jtreg.tests'</fail>
 193         <start-debugger/>
 194         <jtreg-tool name="debug"
 195                     samevm="false"
 196                     tests="${jtreg.tests}"
 197                     jpda.jvmargs="${jpda.jvmargs}"
 198                     langtools.classes="${with_bootclasspath}"/>
 199     </target>
 200 
 201     <!-- Update a class being debugged. -->
 202 
 203     <target name="debug-fix" depends="-get-tool-if-set">
 204         <fail unless="class">Must set property 'class'
 205         </fail>
 206         <antcall target="compile-single">
 207             <param name="includes" value="${class}.java"/>
 208         </antcall>
 209         <condition property="build.classes.dir"
 210                    value="${build.dir}/${module.name}/classes"
 211                    else="${boot.build.dir}/${module.name}/classes">
 212             <isset property="use_bootstrap"/>
 213         </condition>
 214         <nbjpdareload>
 215             <fileset dir="${build.classes.dir}">
 216                 <include name="${class}.class"/>
 217             </fileset>
 218         </nbjpdareload>
 219     </target>
 220 
 221     <!-- Generate javadoc for one or all tools. (action: javadoc; Alt-F6)
 222         If langtools.tool.name is set, then just test that tool; otherwise
 223         test all tools.
 224     -->
 225 
 226     <target name="javadoc" depends="langtools.javadoc,-show-javadoc" />
 227 
 228     <target name="-show-javadoc" if="netbeans.home">
 229         <nbbrowse file="${build.javadoc.dir}/index.html"/>
 230     </target>
 231 
 232     <!-- Prompt for values. -->
 233 
 234     <target name="-get-tool-if-set" depends="-def-select-tool">
 235         <select-tool
 236             toolproperty="langtools.tool.name"
 237             bootstrapproperty="langtools.tool.bootstrap"
 238             propertyfile="${langtools.properties}"
 239             askIfUnset="false"
 240             />
 241     </target>
 242 
 243     <target name="-get-tool-and-args" depends="-def-select-tool">
 244         <select-tool
 245             toolproperty="langtools.tool.name"
 246             argsproperty="langtools.tool.args"
 247             bootstrapproperty="langtools.tool.bootstrap"
 248             propertyfile="${langtools.properties}"
 249             askIfUnset="true"
 250             />
 251     </target>
 252 
 253     <target name="-setup-bootclasspath">
 254         <condition property="use_bootstrap" value="bootstrap-" else="">
 255             <isset property="langtools.tool.bootstrap"/>
 256         </condition>
 257         <condition property="with_bootclasspath" value="${langtools.boot.classes}" else="${langtools.classes}">
 258             <isset property="langtools.tool.bootstrap"/>
 259         </condition>
 260     </target>
 261 
 262     <!-- Macro to run a tool or selected class - used by run* and debug* tasks -->
 263     <target name="-def-run">
 264         <macrodef name="run">
 265             <attribute name="mainclass"/>
 266             <attribute name="args" default=""/>
 267             <attribute name="bcp" default="${with_bootclasspath}"/>
 268             <attribute name="jpda.jvmargs" default=""/>
 269 
 270             <sequential>
 271                 <java fork="true" jvm="${target.java.home}/bin/java" classname="@{mainclass}">
 272                     <jvmarg line="-Xbootclasspath/p:@{bcp}"/>
 273                     <jvmarg line="@{jpda.jvmargs}"/>
 274                     <arg line="@{args}"/>
 275                 </java>
 276             </sequential>
 277         </macrodef>
 278     </target>
 279 
 280     <!-- Macro to start the debugger and set a property containg the args needed by the run task -->
 281     <target name="-def-start-debugger" if="netbeans.home">
 282         <macrodef name="start-debugger">
 283             <attribute name="jpda.jvmargs.property" default="jpda.jvmargs"/>
 284             <sequential>
 285                 <nbjpdastart name="${ant.project.name}" addressproperty="jpda.address" transport="dt_socket">
 286                     <bootclasspath>
 287                         <pathelement path="${langtools.classes}"/>
 288                         <pathelement location="${target.java.home}/jre/lib/rt.jar"/>
 289                     </bootclasspath>
 290                     <sourcepath>
 291                         <pathelement path="${langtools.sources}"/>
 292                     </sourcepath>
 293                 </nbjpdastart>
 294                 <property
 295                     name="@{jpda.jvmargs.property}"
 296                     value="-Xdebug -Xnoagent -Djava.compiler=none -Xrunjdwp:transport=dt_socket,address=${jpda.address}"
 297                 />
 298             </sequential>
 299         </macrodef>
 300     </target>
 301 
 302     <target name="-def-select-tool">
 303         <mkdir dir="${build.toolclasses.dir}"/>
 304         <javac srcdir="${make.tools.dir}"
 305                includes="anttasks/SelectTool*"
 306                destdir="${build.toolclasses.dir}/"
 307                classpath="${ant.core.lib}"
 308                includeantruntime="false"
 309                debug="${javac.debug}"
 310                debuglevel="${javac.debuglevel}">
 311                    <compilerarg line="-Xlint"/>
 312         </javac>
 313         <taskdef name="select-tool"
 314                  classname="anttasks.SelectToolTask"
 315                  classpath="${build.toolclasses.dir}/"/>
 316     </target>
 317 
 318     <target name="select-tool" depends="-def-select-tool">
 319         <select-tool propertyfile="${langtools.properties}"/>
 320     </target>
 321 </project>