build.xml revision 609:3640b60bd0f6
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3 Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.
4 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
6 This code is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License version 2 only, as
8 published by the Free Software Foundation.  Oracle designates this
9 particular file as subject to the "Classpath" exception as provided
10 by Oracle in the LICENSE file that accompanied this code.
11
12 This code is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 version 2 for more details (a copy is included in the LICENSE file that
16 accompanied this code).
17
18 You should have received a copy of the GNU General Public License version
19 2 along with this work; if not, write to the Free Software Foundation,
20 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21
22 Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23 or visit www.oracle.com if you need additional information or have any
24 questions.
25-->
26
27<!--
28 This is the main build file for the complete langtools repository.
29 It is used when building JDK (in which case it is invoked from the
30 Makefile), and it can be used when working on the tools themselves,
31 in an IDE such as NetBeans.
32
33 External dependencies are specified via properties. These can be given
34 on the command line, or by providing a local build.properties file.
35 (They can also be edited into make/build.properties, although that is not
36 recommended.)  At a minimum, boot.java.home must be set to the installed
37 location of the version of JDK used to build this repository. Additional
38 properties may be required, depending on the targets that are built.
39 For example, to run any of the jtreg tests you must set jtreg.home,
40 to run findbugs on the code you must set findbugs.home, and so on.
41
42 For the most part, javac can be built using the previous version of JDK.
43 However, a small number of javac files require access to the latest JDK,
44 which may not yet have been compiled. To compile these files, you can do
45 one of the following:
46 - Set boot.java.home to a recent build of the latest version of JDK.
47 - Set import.jdk to either a recent build (containing jre/lib/rt.jar)
48   or to jdk source repository.  In the latter case, stub files will
49   automatically be generated and used for the required API, to avoid
50   unnecessary compilation of the source repository.
51 If you do neither, the relevant files will not be built.
52
53 The main build happens in two phases:
54 - First, javac and other tools as needed are built using ${boot.java.home}.
55   (This implies a constraint on the source code that they can be compiled
56   with the previous version of JDK.
57 - Second, all required classes are compiled with the latest javac, created
58   in the previous step.
59 The first phase is called the bootstrap phase. All targets, properties and
60 tasks that are specific to that phase have "bootstrap" in their name.
61
62 For more details on the JDK build, see
63    http://blogs.sun.com/kto/entry/anatomy_of_the_jdk_build
64    http://openjdk.java.net/groups/build/
65 For more details on the stub generator, see
66    http://blogs.sun.com/jjg/entry/building_javac_for_jdk7
67
68 Internal details ...
69
70 Interim build products are created in the build/ directory.
71 Final build products are created in the dist/ directory.
72 When building JDK, the dist/directory will contain:
73 - A bootstrap compiler suitable for running with ${boot.java.home}
74   suitable for compiling downstream parts of JDK
75 - Source files and class files for inclusion in the JDK being built
76 When building standalone, the dist/directory will contain:
77 - Separate jar files for each of the separate langtools components
78 - Simple scripts to invoke the tools by executing the corresponding
79   jar files.
80 These jar files and scripts are "for developer use only".
81
82 This file is organized into sections as follows:
83 - global property definitions
84 - general top level targets
85 - general diagnostic/debugging targets
86 - groups of targets for each tool: javac, javadoc, doclets, javah, javap, apt
87    Within each group, the following targets are provided, where applicable
88      build-bootstrap-TOOL      build the bootstrap version of the tool
89      build-classes-TOOL        build the classes for the tool
90      build-TOOL                build the jar file and script for the tool
91      jtreg-TOOL                build the tool and run the appropriate tests
92      findbugs-TOOL             run findbugs on the tool's source oode
93      TOOL                      build the tool, run the tests, and run findbugs
94 - utility definitions
95 -->
96
97<project name="langtools" default="build" basedir="..">
98    <!--
99    **** Global property definitions.
100    -->
101
102    <!-- Force full debuginfo for javac if the debug.classfiles
103    property is set.  This must be BEFORE the include of
104    build.properties because it sets javac.debuglevel.  -->
105    <condition property="javac.debuglevel" value="source,lines,vars">
106        <equals arg1="${debug.classfiles}" arg2="true"/>
107    </condition>
108
109    <!-- The following locations can be used to override default property values. -->
110
111    <!-- Use this location for customizations specific to this instance of this workspace -->
112    <property file="build.properties"/>
113
114    <!-- Use this location for customizations common to all OpenJDK langtools workspaces -->
115    <property file="${user.home}/.openjdk/${ant.project.name}-build.properties"/>
116
117    <!-- Use this location for customizations common to all OpenJDK workspaces -->
118    <property file="${user.home}/.openjdk/build.properties"/>
119
120    <!-- Convenient shorthands for standard locations within the workspace. -->
121    <property name="build.dir" location="build"/>
122    <property name="build.bootstrap.dir" location="${build.dir}/bootstrap"/>
123    <property name="build.coverage.dir" location="${build.dir}/coverage"/>
124    <property name="build.classes.dir" location="${build.dir}/classes"/>
125    <property name="build.gensrc.dir" location="${build.dir}/gensrc"/>
126    <property name="build.genstubs.dir" location="${build.dir}/genstubs"/>
127    <property name="build.javadoc.dir" location="${build.dir}/javadoc"/>
128    <property name="build.jtreg.dir" location="${build.dir}/jtreg"/>
129    <property name="build.toolclasses.dir" location="${build.dir}/toolclasses"/>
130    <property name="dist.dir" location="dist"/>
131    <property name="dist.bin.dir" location="${dist.dir}/bin"/>
132    <property name="dist.coverage.dir" location="${dist.dir}/coverage"/>
133    <property name="dist.findbugs.dir" location="${dist.dir}/findbugs"/>
134    <property name="dist.lib.dir" location="${dist.dir}/lib"/>
135    <property name="make.dir" location="make"/>
136    <property name="make.tools.dir" location="${make.dir}/tools"/>
137    <property name="src.dir" location="src"/>
138    <property name="src.bin.dir" location="${src.dir}/share/bin"/>
139    <property name="src.classes.dir" location="${src.dir}/share/classes"/>
140    <property name="test.dir" location="test"/>
141
142    <!-- java.marker is set to a marker file to check for within a Java install dir.
143         The best file to check for across Solaris/Linux/Windows/MacOS is one of the
144         executables; regrettably, that is OS-specific. -->
145    <condition property="java.marker" value="bin/java">
146        <os family="unix"/>
147    </condition>
148    <condition property="java.marker" value="bin/java.exe">
149        <os family="windows"/>
150    </condition>
151
152    <!-- Standard property values, if not overriden by earlier settings. -->
153    <property file="${make.dir}/build.properties"/>
154
155    <!-- launcher.java is used in the launcher scripts provided to run
156        the tools' jar files.  If it has not already been set, then
157        default it to use ${target.java.home}, if available, otherwise
158        quietly default to simply use "java". -->
159    <condition property="launcher.java"
160        value="${target.java.home}/bin/java" else="java">
161        <isset property="target.java.home"/>
162    </condition>
163
164    <!-- Logic for handling access import jdk classes, if available.
165        import.jdk should be unset, or set to jdk home (to use rt.jar)
166        or to jdk repo (to use src/share/classes).
167        Based on the value, if any, set up default values for javac's sourcepath,
168        classpath and bootclasspath. Note: the default values are overridden
169        in the build-bootstrap-classes macro. -->
170
171    <available property="import.jdk.src.dir" value="${import.jdk}/src/share/classes"
172        filepath="${import.jdk}/src/share/classes" file="java/nio/file/Path.java"/>
173    <available property="import.jdk.jar" value="${import.jdk}/jre/lib/rt.jar"
174        ignoresystemclasses="true"
175        classpath="${import.jdk}/jre/lib/rt.jar" classname="java.nio.file.Path"/>
176
177    <!-- Set the default bootclasspath option used for javac.
178        Note that different variants of the option are used, meaning we can't just
179        define the value for the option.
180        Note the explicit use of the standard property ${path.separator} in the following.
181        This is because Ant is not clever enough to handle direct use of : or ; -->
182    <condition property="javac.bootclasspath.opt"
183            value="-Xbootclasspath:${build.classes.dir}${path.separator}${import.jdk.jar}"
184            else="-Xbootclasspath/p:${build.classes.dir}">
185        <isset property="import.jdk.jar"/>
186    </condition>
187
188    <condition property="boot.java.provides.latest.jdk">
189        <available
190            ignoresystemclasses="true"
191            classpath="${boot.java.home}/jre/lib/rt.jar" classname="java.nio.file.Path"/>
192    </condition>
193
194    <condition property="bootstrap.exclude.files" value="" else="${require.latest.jdk.files}">
195        <isset property="boot.java.provides.latest.jdk"/>
196    </condition>
197
198    <condition property="exclude.files" value="" else="${require.latest.jdk.files}">
199        <or>
200            <isset property="boot.java.provides.latest.jdk"/>
201            <isset property="import.jdk"/>
202        </or>
203    </condition>
204
205    <condition property="require.import.jdk.stubs">
206        <and>
207            <not>
208                <isset property="boot.java.provides.latest.jdk"/>
209            </not>
210            <isset property="import.jdk.src.dir"/>
211        </and>
212    </condition>
213
214    <!-- Set the default value of the sourcepath used for javac. -->
215    <condition property="javac.sourcepath" value="${build.genstubs.dir}" else="">
216        <isset property="require.import.jdk.stubs"/>
217    </condition>
218
219    <!-- Set the default value of the classpath used for javac. -->
220    <property name="javac.classpath" value=""/>
221
222
223    <!--
224    **** General top level targets.
225    -->
226
227    <!-- Standard target to build deliverables for JDK build. -->
228
229    <target name="build" depends="build-bootstrap-tools,build-all-classes">
230        <copy todir="${dist.dir}/bootstrap">
231            <fileset dir="${build.bootstrap.dir}" includes="bin/,lib/"/>
232        </copy>
233        <chmod dir="${dist.dir}/bootstrap/bin" perm="ugo+rx">
234            <include name="*"/>
235        </chmod>
236        <mkdir dir="${dist.lib.dir}"/>
237        <jar file="${dist.lib.dir}/classes.jar" basedir="${build.classes.dir}"/>
238        <zip file="${dist.lib.dir}/src.zip" basedir="${src.classes.dir}"/>
239    </target>
240
241    <target name="build-bootstrap-tools"
242        depends="build-bootstrap-javac,build-bootstrap-javadoc,build-bootstrap-doclets,build-bootstrap-javah"
243    />
244
245    <target name="build-all-tools"
246        depends="build-javac,build-javadoc,build-doclets,build-javah,build-javap,build-apt"
247    />
248
249    <target name="build-all-classes" depends="build-bootstrap-javac,-create-import-jdk-stubs">
250        <build-classes includes="${javac.includes} ${javadoc.includes} ${doclets.includes} ${javah.includes} ${javap.includes} ${apt.includes}"/>
251    </target>
252
253    <!-- clean -->
254
255    <target name="clean" description="Delete all generated files">
256        <delete dir="${build.dir}"/>
257        <delete dir="${dist.dir}"/>
258    </target>
259
260    <!-- Additional targets for running tools on the build -->
261
262    <target name="jtreg" depends="build-all-tools,-def-jtreg">
263        <jtreg-tool name="all" tests="${jtreg.tests}"/>
264    </target>
265
266    <target name="findbugs" depends="-def-findbugs,build-all-tools">
267        <property name="findbugs.reportLevel" value="medium"/>
268        <mkdir dir="${dist.findbugs.dir}"/>
269        <findbugs
270            home="${findbugs.home}"
271            projectName="JDK langtools ${full.version}"
272            output="xml"
273            outputFile="${dist.findbugs.dir}/findbugs.xml"
274            reportLevel="${findbugs.reportLevel}"
275            failOnError="false"
276            errorProperty="findbugs.all.errors"
277            warningsProperty="findbugs.all.warnings"
278            jvmargs="-Xmx512M">
279            <class location="${build.classes.dir}"/>
280            <sourcePath>
281                <pathelement location="${src.classes.dir}"/>
282            </sourcePath>
283        </findbugs>
284        <exec executable="sh">
285            <arg value="${findbugs.home}/bin/convertXmlToText"/>
286            <arg value="-longBugCodes"/>
287            <arg value="-html:${findbugs.home}/src/xsl/fancy.xsl"/>
288            <arg value="${dist.findbugs.dir}/findbugs.xml"/>
289            <redirector output="${dist.findbugs.dir}/findbugs.html"/>
290        </exec>
291    </target>
292
293    <target name="coverage" depends="-def-cobertura,build-all-classes,instrument-classes,jtreg,coverage-report"/>
294
295    <target name="instrument-classes" depends="-def-cobertura">
296        <!-- only define the following property when we want coverage info -->
297        <path id="coverage.classpath">
298            <pathelement location="${build.coverage.dir}/classes"/>
299            <path refid="cobertura.classpath"/>
300        </path>
301        <property name="coverage.options" value="-Dnet.sourceforge.cobertura.datafile=${build.coverage.dir}/cobertura.ser"/>
302        <property name="coverage.classpath" refid="coverage.classpath"/>
303        <mkdir dir="${build.coverage.dir}/classes"/>
304        <delete file="${build.coverage.dir}/cobertura.ser"/>
305        <cobertura-instrument todir="${build.coverage.dir}/classes"
306            datafile="${build.coverage.dir}/cobertura.ser">
307            <fileset dir="${build.classes.dir}"
308               includes="**/*.class" excludes="**/resources/*.class"/>
309        </cobertura-instrument>
310    </target>
311
312    <target name="coverage-report" depends="-def-cobertura">
313        <mkdir dir="${dist.coverage.dir}"/>
314        <cobertura-report
315            srcdir="${src.classes.dir}"
316            destdir="${dist.coverage.dir}"
317            datafile="${build.coverage.dir}/cobertura.ser"/>
318        <cobertura-report
319            format="xml"
320            srcdir="${src.classes.dir}"
321            destdir="${dist.coverage.dir}"
322            datafile="${build.coverage.dir}/cobertura.ser"/>
323    </target>
324
325    <target name="diags-examples" depends="build-javac">
326        <!-- can override the following on the command line if desired. -->
327        <property name="diags.examples.out" location="${build.dir}/diag-examples/diags-examples.html"/>
328        <mkdir dir="${build.dir}/diag-examples/classes"/>
329        <javac fork="true"
330            executable="${dist.bin.dir}/javac"
331            srcdir="test/tools/javac/diags"
332            destdir="${build.dir}/diag-examples/classes"
333            includes="Example.java,FileManager.java,HTMLWriter.java,RunExamples.java"
334            sourcepath=""
335            classpath="${dist.lib.dir}/javac.jar"
336            includeAntRuntime="no"
337            debug="${javac.debug}"
338            debuglevel="${javac.debuglevel}"/>
339        <java fork="true"
340            jvm="${target.java.home}/bin/java"
341            dir="test/tools/javac/diags"
342            classpath="${build.dir}/diag-examples/classes;${dist.lib.dir}/javac.jar"
343            classname="RunExamples">
344            <arg value="-examples"/>
345            <arg value="examples"/>
346            <arg value="-o"/>
347            <arg file="${diags.examples.out}"/>
348            <arg value="-showFiles"/>
349            <arg value="-title"/>
350            <arg value="Examples of javac diagnostics"/>
351        </java>
352    </target>
353
354
355    <!--
356    **** Debugging/diagnostic targets.
357    -->
358
359    <!-- standard JDK target -->
360    <target name="sanity"
361        description="display settings of configuration values">
362        <echo level="info">ant.home = ${ant.home}</echo>
363        <echo level="info">boot.java.home = ${boot.java.home}</echo>
364        <echo level="info">target.java.home = ${target.java.home}</echo>
365        <echo level="info">jtreg.home = ${jtreg.home}</echo>
366        <echo level="info">findbugs.home = ${findbugs.home}</echo>
367    </target>
368
369    <target name="post-sanity" depends="-def-jtreg,sanity,build"
370        description="perform basic validation after a standard build">
371        <jtreg
372            dir="make/test"
373            workDir="${build.jtreg.dir}/post-sanity/work"
374            reportDir="${build.jtreg.dir}/post-sanity/report"
375            jdk="${target.java.home}"
376            verbose="summary"
377            failonerror="false" resultproperty="jtreg.post-sanity.result">
378        </jtreg>
379    </target>
380
381    <!-- use vizant tool to generate graphical image of this Ant file.-->
382    <target name="vizant" depends="-def-vizant">
383        <mkdir dir="${build.dir}"/>
384        <echo message="Generating ${build.dir}/build.dot"/>
385        <vizant antfile="${make.dir}/build.xml" outfile="${build.dir}/build.dot"/>
386        <echo message="Generating ${build.dir}/build.png"/>
387        <exec executable="${dot}" >
388            <arg value="-Tpng"/>
389            <arg value="-o"/>
390            <arg file="${build.dir}/build.png"/>
391            <arg file="${build.dir}/build.dot"/>
392        </exec>
393    </target>
394
395    <target name="check-import.jdk">
396        <echo message="import.jdk: ${import.jdk}"/>
397        <echo message="import.jdk.jar: ${import.jdk.jar}"/>
398        <echo message="import.jdk.src.dir: ${import.jdk.src.dir}"/>
399    </target>
400
401    <target name="diagnostics">
402        <diagnostics/>
403    </target>
404
405
406    <!--
407    **** javac targets.
408    -->
409
410    <target name="build-bootstrap-javac"
411            depends="-def-build-bootstrap-classes,-def-build-bootstrap-jar,-def-build-bootstrap-tool">
412        <build-bootstrap-classes includes="${javac.includes}"/>
413        <build-bootstrap-jar     name="javac" includes="${javac.includes}"/>
414        <build-bootstrap-tool    name="javac"/>
415    </target>
416
417    <target name="build-classes-javac" depends="build-bootstrap-javac,-create-import-jdk-stubs">
418        <build-classes includes="${javac.includes}"/>
419    </target>
420
421    <target name="build-javac" depends="build-classes-javac">
422        <build-jar  name="javac" includes="${javac.includes}"/>
423        <build-tool name="javac"/>
424    </target>
425
426    <target name="javadoc-javac" depends="build-javac,-def-javadoc-tool">
427        <javadoc-tool name="javac" includes="${javac.includes}" options="${javadoc.jls3.option}"/>
428    </target>
429
430    <target name="jtreg-javac" depends="build-javac,build-javap,-def-jtreg">
431        <jtreg-tool name="javac" tests="${javac.tests}"/>
432    </target>
433
434    <target name="findbugs-javac" depends="build-javac,-def-findbugs">
435        <findbugs-tool name="javac"/>
436    </target>
437
438    <target name="javac" depends="build-javac,jtreg-javac,findbugs-javac"/>
439
440
441    <!--
442    **** javadoc targets.
443    -->
444
445    <target name="build-bootstrap-javadoc" depends="build-bootstrap-javac">
446        <build-bootstrap-classes includes="${javadoc.includes}"/>
447        <build-bootstrap-jar     name="javadoc" includes="${javadoc.includes}"
448                                 jarclasspath="javac.jar doclets.jar"/>
449        <build-bootstrap-tool    name="javadoc"/>
450    </target>
451
452    <target name="build-classes-javadoc" depends="build-classes-javac">
453        <build-classes includes="${javadoc.includes}"/>
454    </target>
455
456    <target name="build-javadoc" depends="build-javac,build-classes-javadoc">
457        <build-jar  name="javadoc" includes="${javadoc.includes}"
458                    jarclasspath="javac.jar doclets.jar"/>
459        <build-tool name="javadoc"/>
460    </target>
461
462    <target name="javadoc-javadoc" depends="build-javadoc,-def-javadoc-tool">
463        <javadoc-tool name="javadoc" includes="${javadoc.includes}"/>
464    </target>
465
466    <target name="jtreg-javadoc" depends="build-javadoc,-def-jtreg">
467        <jtreg-tool name="javadoc" tests="${javadoc.tests}"/>
468    </target>
469
470    <target name="findbugs-javadoc" depends="build-javadoc,-def-findbugs">
471        <findbugs-tool name="javadoc"/>
472    </target>
473
474    <target name="javadoc" depends="build-javadoc,jtreg-javadoc,findbugs-javadoc"/>
475
476
477    <!--
478    **** doclets targets.
479    -->
480
481    <target name="build-bootstrap-doclets" depends="build-bootstrap-javadoc,-def-build-bootstrap-jar">
482        <build-bootstrap-classes includes="${doclets.includes}"/>
483        <build-bootstrap-jar     name="doclets" includes="${doclets.includes}"
484                                 jarmainclass="com.sun.tools.javadoc.Main"
485                                 jarclasspath="javadoc.jar"/>
486    </target>
487
488    <target name="build-classes-doclets" depends="build-classes-javadoc">
489        <build-classes includes="${doclets.includes}"/>
490    </target>
491
492    <target name="build-doclets" depends="build-javadoc,build-classes-doclets">
493        <!-- just jar, no bin for doclets -->
494        <build-jar name="doclets" includes="${doclets.includes}" jarclasspath="javadoc.jar"/>
495    </target>
496
497    <!-- (no javadoc for doclets) -->
498
499    <target name="jtreg-doclets" depends="build-doclets,-def-jtreg">
500        <jtreg-tool name="doclets" tests="${doclets.tests}"/>
501    </target>
502
503    <target name="findbugs-doclets" depends="build-doclets,-def-findbugs">
504        <findbugs-tool name="doclets"/>
505    </target>
506
507    <target name="doclets" depends="build-doclets,jtreg-doclets,findbugs-doclets"/>
508
509
510    <!--
511    **** javah targets.
512    -->
513
514    <target name="build-bootstrap-javah" depends="build-bootstrap-javadoc">
515        <build-bootstrap-classes includes="${javah.includes}"/>
516        <build-bootstrap-jar     name="javah" includes="${javah.includes}"
517                                 jarclasspath="javadoc.jar doclets.jar javac.jar"/>
518        <build-bootstrap-tool    name="javah"/>
519    </target>
520
521    <target name="build-javah" depends="build-javac,build-classes-javah">
522        <build-jar  name="javah" includes="${javah.includes}" jarclasspath="javac.jar"/>
523        <build-tool name="javah"/>
524    </target>
525
526    <target name="build-classes-javah" depends="build-classes-javadoc">
527        <build-classes includes="${javah.includes}"/>
528    </target>
529
530    <!-- (no javadoc for javah) -->
531
532    <target name="jtreg-javah" depends="build-javah,-def-jtreg">
533        <jtreg-tool name="javah" tests="${javah.tests}"/>
534    </target>
535
536    <target name="findbugs-javah" depends="build-javah,-def-findbugs">
537        <findbugs-tool name="javah"/>
538    </target>
539
540    <target name="javah" depends="build-javah,jtreg-javah,findbugs-javah"/>
541
542
543    <!--
544    **** javap targets.
545    -->
546
547    <target name="build-bootstrap-javap"
548            depends="-def-build-bootstrap-classes,-def-build-bootstrap-jar,-def-build-bootstrap-tool">
549        <build-bootstrap-classes includes="${javap.includes}"/>
550        <build-bootstrap-jar     name="javap" includes="${javap.includes}"
551                                 jarmainclass="sun.tools.javap.Main"/>
552        <build-bootstrap-tool    name="javap"/>
553    </target>
554
555    <target name="build-classes-javap" depends="build-classes-javac">
556        <build-classes includes="${javap.includes}"/>
557    </target>
558
559    <target name="build-javap" depends="build-javac,build-classes-javap">
560        <build-jar  name="javap" includes="${javap.includes}"
561                    jarmainclass="com.sun.tools.javap.Main"
562                    jarclasspath="javac.jar"/>
563        <build-tool name="javap"/>
564    </target>
565
566    <!-- (no javadoc for javap) -->
567
568    <target name="jtreg-javap" depends="build-javap,-def-jtreg">
569        <jtreg-tool name="javap" tests="${javap.tests}"/>
570    </target>
571
572    <target name="findbugs-javap" depends="build-javap,-def-findbugs">
573        <findbugs-tool name="javap"/>
574    </target>
575
576    <target name="javap" depends="build-javap,jtreg-javap,findbugs-javap"/>
577
578
579    <!--
580    **** apt targets.
581    -->
582
583    <target name="build-bootstrap-apt" depends="build-bootstrap-javac">
584        <build-bootstrap-classes includes="${apt.includes}"/>
585        <build-bootstrap-jar     name="apt" includes="${apt.includes}"
586                                 jarclasspath="javac.jar"/>
587        <build-bootstrap-tool    name="apt"/>
588    </target>
589
590    <target name="build-apt" depends="build-javac,build-classes-apt">
591        <build-jar  name="apt" includes="${apt.includes}" jarclasspath="javac.jar"/>
592        <build-tool name="apt"/>
593    </target>
594
595    <target name="build-classes-apt" depends="build-classes-javac">
596        <build-classes includes="${apt.includes}"/>
597    </target>
598
599    <target name="javadoc-apt" depends="build-apt,-def-javadoc-tool">
600        <javadoc-tool name="apt" includes="${apt.includes}"/>
601    </target>
602
603
604    <target name="jtreg-apt" depends="build-apt,-def-jtreg">
605        <jtreg-tool name="apt" tests="${apt.tests}"/>
606    </target>
607
608    <target name="findbugs-apt" depends="build-apt,-def-findbugs">
609        <findbugs-tool name="apt"/>
610    </target>
611
612    <target name="apt" depends="build-apt,jtreg-apt,findbugs-apt"/>
613
614
615    <!--
616    **** Create import JDK stubs.
617    -->
618
619    <target name="-create-import-jdk-stubs" depends="-def-genstubs" if="require.import.jdk.stubs">
620        <mkdir dir="${build.genstubs.dir}"/>
621        <genstubs
622            srcdir="${import.jdk.src.dir}" destdir="${build.genstubs.dir}"
623            includes="${import.jdk.stub.files}"
624            fork="true" classpath="${build.toolclasses.dir}:${build.bootstrap.dir}/classes:${ant.home}/lib/ant.jar"
625        />
626    </target>
627
628
629    <!--
630    **** Check targets.
631    **** "-check-*" targets check that a required property is set, and set to a reasonable value.
632    **** A user friendly message is generated if not, and the build exits.
633    -->
634
635    <target name="-check-boot.java.home" depends="-def-check">
636        <check name="bootstrap java" property="boot.java.home" marker="${java.marker}"/>
637    </target>
638
639    <target name="-check-target.java.home" depends="-def-check">
640        <check name="target java" property="target.java.home" marker="${java.marker}"/>
641    </target>
642
643    <target name="-check-cobertura.home" depends="-def-check">
644        <check name="cobertura" property="cobertura.home" marker="cobertura.jar"/>
645    </target>
646
647    <target name="-check-findbugs.home" depends="-def-check">
648        <check name="findbugs" property="findbugs.home" marker="lib/findbugs.jar"/>
649    </target>
650
651    <target name="-check-jtreg.home" depends="-def-check">
652        <check name="jtreg" property="jtreg.home" marker="lib/jtreg.jar"/>
653    </target>
654
655    <target name="-check-vizant" depends="-def-check">
656        <check name="vizant" property="vizant.jar"/>
657        <check name="dot" property="dot"/>
658    </target>
659
660
661    <!--
662    **** Targets for Ant macro and task definitions.
663    -->
664
665    <target name="-def-build-tool">
666        <macrodef name="build-tool">
667            <attribute name="name"/>
668            <attribute name="bin.dir" default="${dist.bin.dir}"/>
669            <attribute name="java" default="${launcher.java}"/>
670            <sequential>
671                <mkdir dir="@{bin.dir}"/>
672                <copy file="${src.bin.dir}/launcher.sh-template" tofile="@{bin.dir}/@{name}">
673                    <filterset begintoken="#" endtoken="#">
674                        <filter token="PROGRAM" value="@{name}"/>
675                        <filter token="TARGET_JAVA" value="@{java}"/>
676                    </filterset>
677                </copy>
678                <chmod file="@{bin.dir}/@{name}" perm="ugo+rx"/>
679            </sequential>
680        </macrodef>
681    </target>
682
683    <target name="-def-build-jar">
684        <macrodef name="build-jar">
685            <attribute name="name"/>
686            <attribute name="includes"/>
687            <attribute name="classes.dir" default="${build.classes.dir}"/>
688            <attribute name="lib.dir" default="${dist.lib.dir}"/>
689            <attribute name="jarmainclass" default="com.sun.tools.@{name}.Main"/>
690            <attribute name="jarclasspath" default=""/>
691            <sequential>
692                <mkdir dir="@{lib.dir}"/>
693                <jar destfile="@{lib.dir}/@{name}.jar"
694                     basedir="@{classes.dir}"
695                     includes="@{includes}">
696                    <manifest>
697                        <attribute name="Main-Class" value="@{jarmainclass}"/>
698                        <attribute name="Class-Path" value="@{jarclasspath}"/>
699                    </manifest>
700                </jar>
701            </sequential>
702        </macrodef>
703    </target>
704
705    <target name="-def-build-classes" depends="-def-pcompile">
706        <macrodef name="build-classes">
707            <attribute name="includes"/>
708            <attribute name="excludes" default="${exclude.files} **/package-info.java"/>
709            <attribute name="classes.dir" default="${build.classes.dir}"/>
710            <attribute name="gensrc.dir" default="${build.gensrc.dir}"/>
711            <attribute name="javac.bootclasspath" default="${build.bootstrap.dir}/classes"/>
712            <attribute name="bootclasspath.opt" default="${javac.bootclasspath.opt}"/>
713            <attribute name="classpath" default="${javac.classpath}"/>
714            <attribute name="sourcepath" default="${javac.sourcepath}"/>
715            <attribute name="java.home" default="${boot.java.home}"/>
716            <attribute name="source" default="${javac.source}"/>
717            <attribute name="target" default="${javac.target}"/>
718            <attribute name="release" default="${release}"/>
719            <attribute name="full.version" default="${full.version}"/>
720            <sequential>
721                <echo level="verbose" message="build-classes: excludes=@{excludes}"/>
722                <echo level="verbose" message="build-classes: bootclasspath.opt=@{bootclasspath.opt}"/>
723                <echo level="verbose" message="build-classes: classpath=@{classpath}"/>
724                <echo level="verbose" message="build-classes: sourcepath=@{sourcepath}"/>
725                <mkdir dir="@{gensrc.dir}"/>
726                <mkdir dir="@{classes.dir}"/>
727                <pcompile srcdir="${src.classes.dir}"
728                          destdir="@{gensrc.dir}"
729                          includes="@{includes}"/>
730                <copy todir="@{gensrc.dir}">
731                    <fileset dir="${src.classes.dir}" includes="@{includes}"/>
732                    <globmapper from="*.properties-template" to="*.properties"/>
733                    <filterset begintoken="$(" endtoken=")">
734                        <filter token="JDK_VERSION" value="${jdk.version}"/>
735                        <filter token="RELEASE" value="@{release}"/>
736                        <filter token="FULL_VERSION" value="@{full.version}"/>
737                    </filterset>
738                </copy>
739                <pcompile srcdir="@{gensrc.dir}"
740                          destdir="@{gensrc.dir}"
741                          includes="**/*.properties"/>
742                <javac fork="true"
743                       executable="@{java.home}/bin/javac"
744                       srcdir="${src.classes.dir}:@{gensrc.dir}"
745                       destdir="@{classes.dir}"
746                       includes="@{includes}"
747                       excludes="@{excludes}"
748                       sourcepath="@{sourcepath}"
749                       classpath="@{classpath}"
750                       includeAntRuntime="no"
751                       source="@{source}"
752                       target="@{target}"
753                       debug="${javac.debug}"
754                       debuglevel="${javac.debuglevel}">
755                    <compilerarg value="-implicit:none"/>
756                    <compilerarg value="-Xprefer:source"/>
757                    <compilerarg value="-J-Xbootclasspath/p:@{javac.bootclasspath}"/>
758                    <compilerarg line="@{bootclasspath.opt}"/>
759                    <compilerarg line="${javac.no.jdk.warnings}"/>
760                    <compilerarg line="${javac.version.opt}"/>
761                    <compilerarg line="${javac.lint.opts}"/>
762                </javac>
763                <copy todir="@{classes.dir}" includeemptydirs="false">
764                    <fileset dir="${src.classes.dir}" includes="@{includes}" excludes="@{excludes}">
765                        <exclude name="**/*.java"/>
766                        <exclude name="**/*.properties"/>
767                        <exclude name="**/*-template"/>
768                        <exclude name="**/package.html"/>
769                    </fileset>
770                </copy>
771            </sequential>
772        </macrodef>
773    </target>
774
775    <target name="-def-build-bootstrap-tool" depends="-check-boot.java.home,-def-build-tool">
776        <presetdef name="build-bootstrap-tool">
777            <build-tool
778                bin.dir="${build.bootstrap.dir}/bin"
779                java="${boot.java}"/>
780        </presetdef>
781    </target>
782
783    <target name="-def-build-bootstrap-jar" depends="-def-build-jar">
784        <presetdef name="build-bootstrap-jar">
785            <build-jar
786                classes.dir="${build.bootstrap.dir}/classes"
787                lib.dir="${build.bootstrap.dir}/lib"/>
788        </presetdef>
789    </target>
790
791    <target name="-def-build-bootstrap-classes" depends="-def-build-classes">
792        <presetdef name="build-bootstrap-classes">
793            <build-classes
794                source="${boot.javac.source}"
795                target="${boot.javac.target}"
796                gensrc.dir="${build.bootstrap.dir}/gensrc"
797                classes.dir="${build.bootstrap.dir}/classes"
798                javac.bootclasspath=""
799                bootclasspath.opt="-Xbootclasspath/p:${build.bootstrap.dir}/classes"
800                sourcepath=""
801                release="${bootstrap.release}"
802                full.version="${bootstrap.full.version}"
803                excludes="${bootstrap.exclude.files} **/package-info.java"/>
804        </presetdef>
805    </target>
806
807    <target name="-def-pcompile">
808        <mkdir dir="${build.toolclasses.dir}"/>
809        <javac fork="true"
810               source="${boot.javac.source}"
811               target="${boot.javac.target}"
812               executable="${boot.java.home}/bin/javac"
813               srcdir="${make.tools.dir}/CompileProperties"
814               destdir="${build.toolclasses.dir}/"
815               classpath="${ant.home}/lib/ant.jar"/>
816        <taskdef name="pcompile"
817                 classname="CompilePropertiesTask"
818                 classpath="${build.toolclasses.dir}/"/>
819    </target>
820
821    <target name="-def-genstubs" depends="build-bootstrap-javac" if="require.import.jdk.stubs">
822        <mkdir dir="${build.toolclasses.dir}"/>
823        <javac fork="true"
824               source="${boot.javac.source}"
825               target="${boot.javac.target}"
826               executable="${boot.java.home}/bin/javac"
827               srcdir="${make.tools.dir}/GenStubs"
828               destdir="${build.toolclasses.dir}/"
829               classpath="${build.bootstrap.dir}/classes:${ant.home}/lib/ant.jar"/>
830        <taskdef name="genstubs"
831                 classname="GenStubs$$Ant"
832                 classpath="${build.toolclasses.dir}/"/>
833    </target>
834
835    <target name="-def-javadoc-tool" depends="-check-target.java.home">
836        <macrodef name="javadoc-tool">
837            <attribute name="name"/>
838            <attribute name="includes"/>
839            <attribute name="options" default=""/>
840            <attribute name="source" default="1.5"/> <!-- FIXME -->
841            <sequential>
842                <property name="javadoc.options" value=""/> <!-- default, can be overridden per user or per project -->
843                <!-- Note: even with this default value, includes
844                from src.classes.dir get javadoc'd; see packageset below -->
845                <property name="javadoc.packagenames" value="none"/> <!-- default, can be overridden per user or per project -->
846                <javadoc
847                    executable="${target.java.home}/bin/javadoc"
848                    destdir="${build.javadoc.dir}/@{name}"
849                    source="@{source}"
850                    windowtitle="UNOFFICIAL"
851                    failonerror="true"
852                    use="true"
853                    author="false"
854                    version="false"
855                    packagenames="${javadoc.packagenames}" >
856                    <header><![CDATA[<strong>Unofficial Javadoc</strong> generated from developer sources for preview purposes only]]></header>
857                    <arg line="@{options}"/>
858                    <bootclasspath>
859                        <path location="${build.classes.dir}"/>
860                        <path location="${target.java.home}/jre/lib/rt.jar"/>
861                    </bootclasspath>
862                    <sourcepath>
863                        <pathelement location="${src.classes.dir}"/>
864                    </sourcepath>
865                    <!-- XXX just <fileset> (restricted further to **/*.java) and no <packageset> -->
866                    <!-- means that {@link some.package} will not work, which is no good. -->
867                    <!-- (It correctly skips excluded single classes, but not if packageset is also included, -->
868                    <!-- which also causes duplicates in the class index for included files.) -->
869                    <packageset dir="${src.classes.dir}" includes="@{includes}">
870                        <or>
871                            <filename name="java/"/>
872                            <filename name="javax/"/>
873                            <filename name="com/sun/javadoc/"/>
874                            <filename name="com/sun/mirror/"/>
875                            <filename name="com/sun/source/"/>
876                        </or>
877                    </packageset>
878                </javadoc>
879            </sequential>
880        </macrodef>
881    </target>
882
883    <target name="-def-jtreg" unless="jtreg.defined" depends="-check-jtreg.home,-check-target.java.home">
884        <taskdef name="jtreg" classname="com.sun.javatest.regtest.Main$$Ant">
885            <classpath>
886                <pathelement location="${jtreg.home}/lib/jtreg.jar"/>
887                <pathelement location="${jtreg.home}/lib/javatest.jar"/>
888            </classpath>
889        </taskdef>
890        <macrodef name="jtreg-tool">
891            <attribute name="name"/>
892            <attribute name="tests"/>
893            <attribute name="jdk" default="${target.java.home}"/>
894            <attribute name="samevm" default="true"/>
895            <attribute name="verbose" default="${default.jtreg.verbose}"/>
896            <attribute name="options" default="${other.jtreg.options}"/>
897            <attribute name="keywords" default="-keywords:!ignore"/>
898            <attribute name="jpda.jvmargs" default=""/>
899            <sequential>
900                <property name="coverage.options" value=""/>              <!-- default -->
901                <property name="coverage.classpath" value=""/>            <!-- default -->
902                <property name="default.jtreg.verbose" value="summary"/>  <!-- default -->
903                <property name="other.jtreg.options" value=""/>           <!-- default -->
904                <jtreg
905                    dir="${test.dir}"
906                    workDir="${build.jtreg.dir}/@{name}/work"
907                    reportDir="${build.jtreg.dir}/@{name}/report"
908                    jdk="@{jdk}"
909                    samevm="@{samevm}" verbose="@{verbose}"
910                    failonerror="false" resultproperty="jtreg.@{name}.result"
911                    javacoptions="-g"
912                    vmoptions="${coverage.options} -Xbootclasspath/p:${coverage.classpath}:${build.classes.dir} @{jpda.jvmargs}">
913                    <arg line="@{keywords}"/>
914                    <arg line="@{options}"/>
915                    <arg line="@{tests}"/>
916                </jtreg>
917                <!-- the next two properties are for convenience, when only
918                     a single instance of jtreg will be invoked. -->
919                <condition property="jtreg.passed">
920                    <equals arg1="${jtreg.@{name}.result}" arg2="0"/>
921                </condition>
922                <property name="jtreg.report" value="${build.jtreg.dir}/@{name}/report"/>
923            </sequential>
924        </macrodef>
925        <property name="jtreg.defined" value="true"/>
926    </target>
927
928    <target name="-def-cobertura" depends="-check-cobertura.home">
929        <path id="cobertura.classpath">
930            <fileset dir="${cobertura.home}">
931                <include name="cobertura.jar"/>
932                <include name="lib/**/*.jar"/>
933            </fileset>
934        </path>
935        <taskdef classpathref="cobertura.classpath" resource="tasks.properties"/>
936    </target>
937
938    <target name="-def-findbugs" unless="findbugs.defined" depends="-check-findbugs.home">
939        <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
940            <classpath>
941                <pathelement location="${findbugs.home}/lib/findbugs.jar"/>
942            </classpath>
943        </taskdef>
944        <macrodef name="findbugs-tool">
945            <attribute name="name"/>
946            <attribute name="output" default="emacs"/>
947            <attribute name="outputFile" default=""/>
948            <attribute name="reportLevel" default="high"/>
949            <sequential>
950                <findbugs
951                    home="${findbugs.home}"
952                    output="@{output}"
953                    outputFile="@{outputFile}"
954                    reportLevel="@{reportLevel}"
955                    failOnError="false"
956                    errorProperty="findbugs.@{name}.errors"
957                    warningsProperty="findbugs.@{name}.warnings"
958                    jvmargs="-Xmx512M" >
959                    <class location="${dist.dir}/lib/@{name}.jar"/>
960                    <auxClasspath>
961                        <pathelement location="${build.classes.dir}"/>
962                    </auxClasspath>
963                    <sourcePath>
964                        <pathelement location="${src.classes.dir}"/>
965                    </sourcePath>
966                </findbugs>
967            </sequential>
968        </macrodef>
969        <property name="findbugs.defined" value="true"/>
970    </target>
971
972    <target name="-def-vizant" unless="vizant.defined" depends="-check-vizant">
973        <taskdef name="vizant" classname="net.sourceforge.vizant.Vizant" classpath="${vizant.jar}"/>
974        <property name="vizant.defined" value="true"/>
975    </target>
976
977    <target name="-def-check">
978        <macrodef name="check">
979            <attribute name="name"/>
980            <attribute name="property"/>
981            <attribute name="marker" default=""/>
982            <sequential>
983                <fail message="Cannot locate @{name}: please set @{property} to its location">
984                    <condition>
985                        <not>
986                            <isset property="@{property}"/>
987                        </not>
988                    </condition>
989                </fail>
990                <fail message="@{name} is not installed in ${@{property}}">
991                    <condition>
992                        <and>
993                            <not>
994                                <equals arg1="@{marker}" arg2=""/>
995                            </not>
996                            <not>
997                                <available file="${@{property}}/@{marker}"/>
998                            </not>
999                        </and>
1000                    </condition>
1001                </fail>
1002            </sequential>
1003        </macrodef>
1004    </target>
1005
1006</project>
1007
1008