build.xml revision 2384:176a2e871eb9
1183878Sraj<?xml version="1.0" encoding="UTF-8"?>
2183878Sraj<!--
3183878Sraj Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
4183878Sraj
5183878Sraj Redistribution and use in source and binary forms, with or without
6235537Sgber modification, are permitted provided that the following conditions
7208538Sraj are met:
8185099Sraj
9183878Sraj   - 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        If langtools.tool.name is set, then just build that tool; otherwise
51        build all tools.
52    -->
53
54    <target name="build" depends="-get-tool-if-set,-build-tool,-build-all"
55        description="Build one or all langtools tools"
56        />
57
58    <condition property="use_bootstrap" value="bootstrap-" else="">
59        <isset property="langtools.tool.bootstrap"/>
60    </condition>
61    <condition property="with_bootclasspath" value="${build.bootstrap.dir}/classes" else="${build.classes.dir}">
62        <isset property="langtools.tool.bootstrap"/>
63    </condition>
64
65    <target name="-build-tool" if="langtools.tool.name">
66        <echo level="info" message="Building ${use_bootstrap}${langtools.tool.name}"/>
67        <echo level="verbose" message="(Unset langtools.tool.name to build all tools)"/>
68        <antcall target="build-${use_bootstrap}${langtools.tool.name}"/>
69    </target>
70
71    <target name="-build-all" unless="langtools.tool.name">
72        <echo level="info" message="Building all tools"/>
73        <echo level="verbose" message="(Set langtools.tool.name to build a single tool)"/>
74        <antcall target="build-all-tools"/>
75    </target>
76
77    <!-- Compile a single file. (action: compile.single; F9) -->
78
79    <target name="compile-single" depends="build-bootstrap-javac">
80        <fail unless="includes">Must set property 'includes'</fail>
81        <javac fork="true" executable="${build.bootstrap.dir}/bin/javac"
82               srcdir="${src.classes.dir}"
83               destdir="${build.classes.dir}"
84               includes="${includes}"
85               sourcepath=""
86               includeAntRuntime="no"
87               target="${javac.target}"
88               debug="${javac.debug}"
89               debuglevel="${javac.debuglevel}"/>
90    </target>
91
92    <!-- Run tool. (action: run; F6)
93        Use langtools.tool.name and langtools.tool.args properties if set; otherwise prompt
94        the user.
95    -->
96
97    <target name="run" depends="-check-target.java.home,build,-def-run,-get-tool-and-args"
98            description="run tool">
99        <echo level="info" message="${with_bootclasspath}"/>
100        <echo level="info" message="Run ${use_bootstrap}${langtools.tool.name} with args ${langtools.tool.args}"/>
101        <run bcp="${with_bootclasspath}" mainclass="com.sun.tools.${langtools.tool.name}.Main" args="${langtools.tool.args}"/>
102    </target>
103
104    <!-- Run a selected class. (action: run.single;  shift-F6) -->
105
106    <target name="run-single" depends="-check-target.java.home,-def-run">
107        <fail unless="run.classname">Must set property 'run.classname' </fail>
108        <echo level="info" message="run ${run.classname}"/>
109        <run mainclass="${run.classname}" args=""/>
110    </target>
111
112    <!-- Test project, and display results if tests failed. (action: test; Alt-F6)
113        If langtools.tool.name is set, then just test that tool; otherwise
114        test all tools.
115    -->
116
117    <target name="jtreg" depends="-get-tool-if-set,-jtreg-tool,-jtreg-all"
118        description="Test one or all langtools tools"
119        />
120
121    <target name="-jtreg-tool" if="langtools.tool.name">
122        <echo level="info" message="Testing ${langtools.tool.name}"/>
123        <echo level="verbose" message="(Unset langtools.tool.name to test all tools)"/>
124        <antcall>
125            <target name="jtreg-${langtools.tool.name}"/>
126            <target name="-show-jtreg"/>
127        </antcall>
128    </target>
129
130    <target name="-jtreg-all" unless="langtools.tool.name">
131        <echo level="info" message="Testing all tools"/>
132        <echo level="verbose" message="(Set langtools.tool.name to test a single tool)"/>
133        <antcall>
134            <target name="langtools.jtreg"/>
135            <target name="-show-jtreg"/>
136        </antcall>
137    </target>
138
139    <target name="-show-jtreg-single-detect" if="netbeans.home" unless="jtreg.passed">
140        <dirname property="netbeans.jtreg.tests.dir.temp" file="${jtreg.report}/../work/${jtreg.tests}"/>
141        <basename property="netbeans.jtreg.tests.basename.temp" file="${jtreg.tests}" suffix=".java"/>
142        <property name="netbeans.jtreg.single.jtr" value="${netbeans.jtreg.tests.dir.temp}/${netbeans.jtreg.tests.basename.temp}.jtr"/>
143        <condition property="netbeans.jtreg.single">
144            <available file="${netbeans.jtreg.single.jtr}" />
145        </condition>
146        <condition property="netbeans.jtreg.multiple">
147            <not>
148                <available file="${netbeans.jtreg.single.jtr}" />
149            </not>
150        </condition>
151    </target>
152
153    <target name="-show-jtreg-single" if="netbeans.jtreg.single" depends="-show-jtreg-single-detect">
154        <nbbrowse file="${netbeans.jtreg.single.jtr}"/>
155        <fail>Some tests failed; see report for details.</fail>
156    </target>
157
158    <target name="-show-jtreg-multiple" if="netbeans.jtreg.multiple" depends="-show-jtreg-single-detect">
159        <nbbrowse url="file://${jtreg.report}/html/report.html#Results"/>
160        <fail>Some tests failed; see report for details.</fail>
161    </target>
162
163    <target name="-show-jtreg" depends="-show-jtreg-single-detect,-show-jtreg-single,-show-jtreg-multiple" />
164
165    <!-- Debug tool in NetBeans. -->
166
167    <target name="debug" depends="-check-target.java.home,-def-run,-def-start-debugger,-get-tool-and-args,build" if="netbeans.home">
168        <echo level="info" message="Debug ${use_bootstrap}${langtools.tool.name} with args ${langtools.tool.args}"/>
169        <start-debugger/>
170        <run bcp="${with_bootclasspath}" mainclass="com.sun.tools.${langtools.tool.name}.Main" args="${langtools.tool.args}" jpda.jvmargs="${jpda.jvmargs}"/>
171    </target>
172
173    <!-- Debug a selected class . -->
174    <target name="debug-single" depends="-check-target.java.home,-def-start-debugger,-def-run">
175        <fail unless="debug.classname">Must set property 'debug.classname'</fail>
176        <start-debugger/>
177        <run mainclass="${debug.classname}" default.args="" jpda.jvmargs="${jpda.jvmargs}"/>
178    </target>
179
180    <!-- Debug a jtreg test. -->
181    <target name="debug-jtreg" depends="-check-target.java.home,-def-start-debugger,-def-jtreg">
182        <fail unless="jtreg.tests">Must set property 'jtreg.tests'</fail>
183        <start-debugger/>
184        <jtreg-tool name="debug" samevm="false" tests="${jtreg.tests}" jpda.jvmargs="${jpda.jvmargs}"/>
185    </target>
186
187    <!-- Update a class being debugged. -->
188
189    <target name="debug-fix" if="langtools.tool.name">
190        <fail unless="class">Must set property 'class'
191        </fail>
192        <antcall target="compile-single">
193            <param name="includes" value="${class}.java"/>
194        </antcall>
195        <nbjpdareload>
196            <fileset dir="${build.classes.dir}">
197                <include name="${class}.class"/>
198            </fileset>
199        </nbjpdareload>
200    </target>
201
202    <!-- Generate javadoc for one or all tools. (action: javadoc; Alt-F6)
203        If langtools.tool.name is set, then just test that tool; otherwise
204        test all tools.
205    -->
206
207    <target name="javadoc" depends="-javadoc-tool,-javadoc-all"
208        description="Generate javadoc for one or all langtools tools"
209        />
210
211    <target name="-javadoc-tool" if="langtools.tool.name">
212        <echo level="info" message="Generate javadoc for ${langtools.tool.name}"/>
213        <echo level="verbose" message="(Unset langtools.tool.name to generate javadoc for all tools)"/>
214        <antcall>
215            <target name="javadoc-${langtools.tool.name}"/>
216            <target name="-show-javadoc"/>
217        </antcall>
218    </target>
219
220    <target name="-javadoc-all" unless="langtools.tool.name">
221        <echo level="info" message="Generate javadoc for all tools"/>
222        <echo level="verbose" message="(Set langtools.tool.name to generate javadoc for a single tool)"/>
223        <antcall>
224            <target name="langtools.javadoc"/>
225            <target name="-show-javadoc"/>
226        </antcall>
227    </target>
228
229    <target name="-show-javadoc" if="netbeans.home">
230        <!-- what if doing javadoc for all? -->
231        <nbbrowse file="${build.javadoc.dir}/${langtools.tool.name}/index.html"/>
232    </target>
233
234    <!-- Prompt for values. -->
235
236    <target name="-get-tool-if-set" depends="-def-select-tool">
237        <select-tool
238            toolproperty="langtools.tool.name"
239            bootstrapproperty="langtools.tool.bootstrap"
240            propertyfile="${langtools.properties}"
241            askIfUnset="false"
242            />
243    </target>
244
245    <target name="-get-tool-and-args" depends="-def-select-tool">
246        <select-tool
247            toolproperty="langtools.tool.name"
248            argsproperty="langtools.tool.args"
249            bootstrapproperty="langtools.tool.bootstrap"
250            propertyfile="${langtools.properties}"
251            askIfUnset="true"
252            />
253    </target>
254
255    <!-- Macro to run a tool or selected class - used by run* and debug* tasks -->
256    <target name="-def-run">
257        <macrodef name="run">
258            <attribute name="mainclass"/>
259            <attribute name="args" default=""/>
260            <attribute name="bcp" default="${with_bootclasspath}"/>
261            <attribute name="jpda.jvmargs" default=""/>
262
263            <sequential>
264                <java fork="true" jvm="${target.java}" classname="@{mainclass}">
265                    <jvmarg line="-Xbootclasspath/p:@{bcp}"/>
266                    <jvmarg line="@{jpda.jvmargs}"/>
267                    <arg line="@{args}"/>
268                </java>
269            </sequential>
270        </macrodef>
271    </target>
272
273    <!-- Macro to start the debugger and set a property containg the args needed by the run task -->
274    <target name="-def-start-debugger" if="netbeans.home">
275        <macrodef name="start-debugger">
276            <attribute name="jpda.jvmargs.property" default="jpda.jvmargs"/>
277            <sequential>
278                <nbjpdastart name="${ant.project.name}" addressproperty="jpda.address" transport="dt_socket">
279                    <bootclasspath>
280                        <pathelement location="${build.classes.dir}"/>
281                        <pathelement location="${target.java.home}/jre/lib/rt.jar"/>
282                    </bootclasspath>
283                    <sourcepath>
284                        <pathelement location="${src.classes.dir}"/>
285                    </sourcepath>
286                </nbjpdastart>
287                <property
288                    name="@{jpda.jvmargs.property}"
289                    value="-Xdebug -Xnoagent -Djava.compiler=none -Xrunjdwp:transport=dt_socket,address=${jpda.address}"
290                />
291            </sequential>
292        </macrodef>
293    </target>
294
295    <target name="-def-select-tool">
296        <mkdir dir="${build.toolclasses.dir}"/>
297        <javac srcdir="${make.tools.dir}"
298               includes="anttasks/SelectTool*"
299               destdir="${build.toolclasses.dir}/"
300               classpath="${ant.core.lib}"
301               includeantruntime="false"
302               debug="${javac.debug}"
303               debuglevel="${javac.debuglevel}">
304                   <compilerarg line="-Xlint"/>
305        </javac>
306        <taskdef name="select-tool"
307                 classname="anttasks.SelectToolTask"
308                 classpath="${build.toolclasses.dir}/"/>
309    </target>
310
311    <target name="select-tool" depends="-def-select-tool">
312        <select-tool propertyfile="${langtools.properties}"/>
313    </target>
314</project>
315