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             <property name="langtools.main.class" value="${tool.@{tool.name}.main.class}"/>
  97           </sequential>
  98         </macrodef>
  99     </target>
 100 
 101     <target name="-build-classes" depends="-get-tool-if-set,-build-classes-bootstrap-javac,-build-classes-all" />
 102     <target name="-build-classes-bootstrap-javac" if="langtools.tool.bootstrap">
 103         <antcall target="build-bootstrap-javac-classes"/>
 104     </target>
 105     <target name="-build-classes-all" unless="langtools.tool.bootstrap">
 106         <antcall target="build-all-classes"/>
 107     </target>
 108 
 109     <!-- Run a selected class. (action: run.single;  shift-F6) -->
 110 
 111     <target name="run-single" depends="-check-target.java.home,-setup-bootclasspath,-def-run">
 112         <fail unless="run.classname">Must set property 'run.classname' </fail>
 113         <echo level="info" message="run ${run.classname}"/>
 114         <run mainclass="${run.classname}" args=""/>
 115     </target>
 116 
 117     <!-- Test project, and display results if tests failed. (action: test; Alt-F6)
 118         If langtools.tool.name is set, then just test that tool; otherwise
 119         test all tools.
 120     -->
 121 
 122     <target name="jtreg" depends="-get-tool-if-set,-jtreg-bootstrap-javac,-jtreg-all"
 123         description="Test langtools tools or bootstrap javac"
 124         />
 125 
 126     <target name="-jtreg-bootstrap-javac" if="langtools.tool.bootstrap">
 127         <echo level="info" message="Testing bootstrap javac"/>
 128         <echo level="verbose" message="(Unset langtools.tool.bootstrap to test all tools)"/>
 129         <antcall>
 130             <target name="jtreg-bootstrap-javac"/>
 131             <target name="-show-jtreg"/>
 132         </antcall>
 133     </target>
 134 
 135     <target name="-jtreg-all" unless="langtools.tool.bootstrap">
 136         <echo level="info" message="Testing all tools"/>
 137         <echo level="verbose" message="(Set langtools.tool.bootstrap to test bootstrap javac)"/>
 138         <antcall>
 139             <target name="langtools.jtreg"/>
 140             <target name="-show-jtreg"/>
 141         </antcall>
 142     </target>
 143 
 144     <target name="-show-jtreg-single-detect" if="netbeans.home" unless="jtreg.passed">
 145         <dirname property="netbeans.jtreg.tests.dir.temp" file="${jtreg.report}/../work/${jtreg.tests}"/>
 146         <basename property="netbeans.jtreg.tests.basename.temp" file="${jtreg.tests}" suffix=".java"/>
 147         <property name="netbeans.jtreg.single.jtr" value="${netbeans.jtreg.tests.dir.temp}/${netbeans.jtreg.tests.basename.temp}.jtr"/>
 148         <condition property="netbeans.jtreg.single">
 149             <available file="${netbeans.jtreg.single.jtr}" />
 150         </condition>
 151         <condition property="netbeans.jtreg.multiple">
 152             <not>
 153                 <available file="${netbeans.jtreg.single.jtr}" />
 154             </not>
 155         </condition>
 156     </target>
 157 
 158     <target name="-show-jtreg-single" if="netbeans.jtreg.single" depends="-show-jtreg-single-detect">
 159         <nbbrowse file="${netbeans.jtreg.single.jtr}"/>
 160         <fail>Some tests failed; see report for details.</fail>
 161     </target>
 162 
 163     <target name="-show-jtreg-multiple" if="netbeans.jtreg.multiple" depends="-show-jtreg-single-detect">
 164         <nbbrowse url="file://${jtreg.report}/html/report.html#Results"/>
 165         <fail>Some tests failed; see report for details.</fail>
 166     </target>
 167 
 168     <target name="-show-jtreg" depends="-show-jtreg-single-detect,-show-jtreg-single,-show-jtreg-multiple" />
 169 
 170     <!-- Debug tool in NetBeans. -->
 171 
 172     <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">
 173         <echo level="info" message="Debug ${use_bootstrap}${langtools.tool.name} with args ${langtools.tool.args}"/>
 174         <start-debugger/>
 175         <resolve-main-class tool.name="${langtools.tool.name}" />
 176         <run bcp="${with_bootclasspath}" mainclass="${langtools.main.class}" args="${langtools.tool.args}" jpda.jvmargs="${jpda.jvmargs}"/>
 177     </target>
 178 
 179     <!-- Debug a selected class . -->
 180     <target name="debug-single" depends="-check-target.java.home,-def-start-debugger,-def-run">
 181         <fail unless="debug.classname">Must set property 'debug.classname'</fail>
 182         <start-debugger/>
 183         <run mainclass="${debug.classname}" args="" jpda.jvmargs="${jpda.jvmargs}"/>
 184     </target>
 185 
 186     <!-- Debug a jtreg test. -->
 187     <target name="debug-jtreg" depends="-check-target.java.home,-def-start-debugger,-def-jtreg,-get-tool-if-set,-setup-bootclasspath">
 188         <fail unless="jtreg.tests">Must set property 'jtreg.tests'</fail>
 189         <start-debugger/>
 190         <jtreg-tool name="debug"
 191                     samevm="false"
 192                     tests="${jtreg.tests}"
 193                     jpda.jvmargs="${jpda.jvmargs}"
 194                     langtools.classes="${with_bootclasspath}"/>
 195     </target>
 196 
 197     <!-- Update a class being debugged. -->
 198 
 199     <target name="debug-fix" depends="-get-tool-if-set">
 200         <fail unless="class">Must set property 'class'
 201         </fail>
 202         <antcall target="compile-single">
 203             <param name="includes" value="${class}.java"/>
 204         </antcall>
 205         <condition property="build.classes.dir"
 206                    value="${build.dir}/${module.name}/classes"
 207                    else="${boot.build.dir}/${module.name}/classes">
 208             <isset property="use_bootstrap"/>
 209         </condition>
 210         <nbjpdareload>
 211             <fileset dir="${build.classes.dir}">
 212                 <include name="${class}.class"/>
 213             </fileset>
 214         </nbjpdareload>
 215     </target>
 216 
 217     <!-- Generate javadoc for one or all tools. (action: javadoc; Alt-F6)
 218         If langtools.tool.name is set, then just test that tool; otherwise
 219         test all tools.
 220     -->
 221 
 222     <target name="javadoc" depends="langtools.javadoc,-show-javadoc" />
 223 
 224     <target name="-show-javadoc" if="netbeans.home">
 225         <nbbrowse file="${build.javadoc.dir}/index.html"/>
 226     </target>
 227 
 228     <!-- Prompt for values. -->
 229 
 230     <target name="-get-tool-if-set" depends="-def-select-tool">
 231         <select-tool
 232             toolproperty="langtools.tool.name"
 233             bootstrapproperty="langtools.tool.bootstrap"
 234             propertyfile="${langtools.properties}"
 235             askIfUnset="false"
 236             />
 237     </target>
 238 
 239     <target name="-get-tool-and-args" depends="-def-select-tool">
 240         <select-tool
 241             toolproperty="langtools.tool.name"
 242             argsproperty="langtools.tool.args"
 243             bootstrapproperty="langtools.tool.bootstrap"
 244             propertyfile="${langtools.properties}"
 245             askIfUnset="true"
 246             />
 247     </target>
 248 
 249     <target name="-setup-bootclasspath">
 250         <condition property="use_bootstrap" value="bootstrap-" else="">
 251             <isset property="langtools.tool.bootstrap"/>
 252         </condition>
 253         <condition property="with_bootclasspath" value="${langtools.boot.classes}" else="${langtools.classes}">
 254             <isset property="langtools.tool.bootstrap"/>
 255         </condition>
 256     </target>
 257 
 258     <!-- Macro to run a tool or selected class - used by run* and debug* tasks -->
 259     <target name="-def-run">
 260         <macrodef name="run">
 261             <attribute name="mainclass"/>
 262             <attribute name="args" default=""/>
 263             <attribute name="bcp" default="${with_bootclasspath}"/>
 264             <attribute name="jpda.jvmargs" default=""/>
 265 
 266             <sequential>
 267                 <java fork="true" jvm="${target.java.home}/bin/java" classname="@{mainclass}">
 268                     <jvmarg line="-Xbootclasspath/p:@{bcp}"/>
 269                     <jvmarg line="@{jpda.jvmargs}"/>
 270                     <arg line="@{args}"/>
 271                 </java>
 272             </sequential>
 273         </macrodef>
 274     </target>
 275 
 276     <!-- Macro to start the debugger and set a property containg the args needed by the run task -->
 277     <target name="-def-start-debugger" if="netbeans.home">
 278         <macrodef name="start-debugger">
 279             <attribute name="jpda.jvmargs.property" default="jpda.jvmargs"/>
 280             <sequential>
 281                 <nbjpdastart name="${ant.project.name}" addressproperty="jpda.address" transport="dt_socket">
 282                     <bootclasspath>
 283                         <pathelement path="${langtools.classes}"/>
 284                         <pathelement location="${target.java.home}/jre/lib/rt.jar"/>
 285                     </bootclasspath>
 286                     <sourcepath>
 287                         <pathelement path="${langtools.sources}"/>
 288                     </sourcepath>
 289                 </nbjpdastart>
 290                 <property
 291                     name="@{jpda.jvmargs.property}"
 292                     value="-Xdebug -Xnoagent -Djava.compiler=none -Xrunjdwp:transport=dt_socket,address=${jpda.address}"
 293                 />
 294             </sequential>
 295         </macrodef>
 296     </target>
 297 
 298     <target name="-def-select-tool">
 299         <mkdir dir="${build.toolclasses.dir}"/>
 300         <javac srcdir="${make.tools.dir}"
 301                includes="anttasks/SelectTool*"
 302                destdir="${build.toolclasses.dir}/"
 303                classpath="${ant.core.lib}"
 304                includeantruntime="false"
 305                debug="${javac.debug}"
 306                debuglevel="${javac.debuglevel}">
 307                    <compilerarg line="-Xlint"/>
 308         </javac>
 309         <taskdef name="select-tool"
 310                  classname="anttasks.SelectToolTask"
 311                  classpath="${build.toolclasses.dir}/"/>
 312     </target>
 313 
 314     <target name="select-tool" depends="-def-select-tool">
 315         <select-tool propertyfile="${langtools.properties}"/>
 316     </target>
 317 </project>