build.xml revision 1223:7245999a0075
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3 Copyright (c) 2007, 2011, 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
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.checkstyle.dir" location="${dist.dir}/checkstyle"/>
135    <property name="dist.lib.dir" location="${dist.dir}/lib"/>
136    <property name="make.dir" location="make"/>
137    <property name="make.conf.dir" location="${make.dir}/conf"/>
138    <property name="make.tools.dir" location="${make.dir}/tools"/>
139    <property name="src.dir" location="src"/>
140    <property name="src.bin.dir" location="${src.dir}/share/bin"/>
141    <property name="src.classes.dir" location="${src.dir}/share/classes"/>
142    <property name="test.dir" location="test"/>
143
144    <!-- java.marker is set to a marker file to check for within a Java install dir.
145         The best file to check for across Solaris/Linux/Windows/MacOS is one of the
146         executables; regrettably, that is OS-specific. -->
147    <condition property="java.marker" value="bin/java">
148        <os family="unix"/>
149    </condition>
150    <condition property="java.marker" value="bin/java.exe">
151        <os family="windows"/>
152    </condition>
153
154    <!-- Standard property values, if not overriden by earlier settings. -->
155    <property file="${make.dir}/build.properties"/>
156
157    <!-- launcher.java is used in the launcher scripts provided to run
158        the tools' jar files.  If it has not already been set, then
159        default it to use ${target.java.home}, if available, otherwise
160        quietly default to simply use "java". -->
161    <condition property="launcher.java"
162        value="${target.java.home}/bin/java" else="java">
163        <isset property="target.java.home"/>
164    </condition>
165
166    <!-- Logic for handling access import jdk classes, if available.
167        import.jdk should be unset, or set to jdk home (to use rt.jar)
168        or to jdk repo (to use src/share/classes).
169        Based on the value, if any, set up default values for javac's sourcepath,
170        classpath and bootclasspath. Note: the default values are overridden
171        in the build-bootstrap-classes macro. -->
172
173    <available property="import.jdk.src.dir" value="${import.jdk}/src/share/classes"
174        filepath="${import.jdk}/src/share/classes" file="java/nio/file/Path.java"/>
175    <available property="import.jdk.jar" value="${import.jdk}/jre/lib/rt.jar"
176        ignoresystemclasses="true"
177        classpath="${import.jdk}/jre/lib/rt.jar" classname="java.nio.file.Path"/>
178
179    <!-- Set the default bootclasspath option used for javac.
180        Note that different variants of the option are used, meaning we can't just
181        define the value for the option.
182        Note the explicit use of the standard property ${path.separator} in the following.
183        This is because Ant is not clever enough to handle direct use of : or ; -->
184    <condition property="javac.bootclasspath.opt"
185            value="-Xbootclasspath:${build.classes.dir}${path.separator}${import.jdk.jar}"
186            else="-Xbootclasspath/p:${build.classes.dir}">
187        <isset property="import.jdk.jar"/>
188    </condition>
189
190    <condition property="boot.java.provides.latest.jdk">
191        <available
192            ignoresystemclasses="true"
193            classpath="${boot.java.home}/jre/lib/rt.jar" classname="java.nio.file.Path"/>
194    </condition>
195
196    <condition property="bootstrap.exclude.files" value="" else="${require.latest.jdk.files}">
197        <isset property="boot.java.provides.latest.jdk"/>
198    </condition>
199
200    <condition property="exclude.files" value="" else="${require.latest.jdk.files}">
201        <or>
202            <isset property="boot.java.provides.latest.jdk"/>
203            <isset property="import.jdk"/>
204        </or>
205    </condition>
206
207    <condition property="require.import.jdk.stubs">
208        <and>
209            <not>
210                <isset property="boot.java.provides.latest.jdk"/>
211            </not>
212            <isset property="import.jdk.src.dir"/>
213        </and>
214    </condition>
215
216    <!-- Set the default value of the sourcepath used for javac. -->
217    <condition property="javac.sourcepath" value="${build.genstubs.dir}" else="">
218        <isset property="require.import.jdk.stubs"/>
219    </condition>
220
221    <!-- Set the default value of the classpath used for javac. -->
222    <property name="javac.classpath" value=""/>
223
224
225    <!--
226    **** General top level targets.
227    -->
228
229    <!-- Standard target to build deliverables for JDK build. -->
230
231    <target name="build" depends="build-bootstrap-tools,build-all-classes">
232        <copy todir="${dist.dir}/bootstrap">
233            <fileset dir="${build.bootstrap.dir}" includes="bin/,lib/"/>
234        </copy>
235        <chmod dir="${dist.dir}/bootstrap/bin" perm="ugo+rx">
236            <include name="*"/>
237        </chmod>
238        <mkdir dir="${dist.lib.dir}"/>
239        <jar file="${dist.lib.dir}/classes.jar" basedir="${build.classes.dir}"/>
240        <zip file="${dist.lib.dir}/src.zip" basedir="${src.classes.dir}"/>
241    </target>
242
243    <target name="build-bootstrap-tools"
244        depends="build-bootstrap-javac,build-bootstrap-javadoc,build-bootstrap-doclets,build-bootstrap-javah"
245    />
246
247    <target name="build-all-tools"
248        depends="build-javac,build-javadoc,build-doclets,build-javah,build-javap"
249    />
250
251    <target name="build-all-classes" depends="build-bootstrap-javac,-create-import-jdk-stubs">
252        <build-classes includes="${javac.includes} ${javadoc.includes} ${doclets.includes} ${javah.includes} ${javap.includes}"/>
253    </target>
254
255    <!-- clean -->
256
257    <target name="clean" description="Delete all generated files">
258        <delete dir="${build.dir}"/>
259        <delete dir="${dist.dir}"/>
260    </target>
261
262    <!-- Additional targets for running tools on the build -->
263
264    <target name="jtreg" depends="build-all-tools,-def-jtreg">
265        <jtreg-tool name="all" tests="${jtreg.tests}"/>
266    </target>
267
268    <target name="checkstyle" depends="-def-checkstyle"
269        description="Generates reports for code convention violations.">
270        <mkdir dir="${dist.checkstyle.dir}"/>
271        <checkstyle config="${make.conf.dir}/checkstyle-langtools.xml"
272              failureProperty="checkstyle.failure"
273              failOnViolation="false">
274            <formatter type="xml" tofile="${dist.checkstyle.dir}/checkstyle_report.xml"/>
275            <fileset dir="src" includes="**/*.java, **/*.properties"/>
276        </checkstyle>
277        <!-- transform the output to a simple html -->
278        <xslt  in="${dist.checkstyle.dir}/checkstyle_report.xml"
279               out="${dist.checkstyle.dir}/checkstyle_report.html"
280               style="${checkstyle.home}/contrib/checkstyle-simple.xsl"/>            
281        <!-- transform the output to a very simple emacs friendly text file -->
282        <xslt  in="${dist.checkstyle.dir}/checkstyle_report.xml"
283               out="${dist.checkstyle.dir}/checkstyle_report.tmp"
284               style="${make.conf.dir}/checkstyle-emacs.xsl"/>
285        <!-- beautify remove extra lines -->
286        <move file="${dist.checkstyle.dir}/checkstyle_report.tmp"
287             toFile="${dist.checkstyle.dir}/checkstyle_report.emacs.txt">
288            <filterchain>
289                <ignoreblank/>
290                <replaceregex byline="true" pattern="^File:" replace="${line.separator}File:"/>
291            </filterchain>
292        </move>
293    </target>
294    <!-- target can be invoked from an ide, the output of which can be used
295         to access and fix the errors directly.
296     -->
297    <target name="checkstyle-ide" depends="checkstyle">
298        <concat>
299            <fileset file="${dist.checkstyle.dir}/checkstyle_report.emacs.txt"/>
300        </concat>  
301    </target>
302    
303    <target name="findbugs" depends="-def-findbugs,build-all-tools">
304        <property name="findbugs.reportLevel" value="medium"/>
305        <mkdir dir="${dist.findbugs.dir}"/>
306        <findbugs
307            home="${findbugs.home}"
308            projectName="JDK langtools ${full.version}"
309            output="xml"
310            outputFile="${dist.findbugs.dir}/findbugs.xml"
311            reportLevel="${findbugs.reportLevel}"
312            failOnError="false"
313            errorProperty="findbugs.all.errors"
314            warningsProperty="findbugs.all.warnings"
315            jvm="${target.java.home}/bin/java"
316            jvmargs="-Xmx512M">
317            <class location="${build.classes.dir}"/>
318            <sourcePath>
319                <pathelement location="${src.classes.dir}"/>
320            </sourcePath>
321        </findbugs>
322        <exec executable="sh">
323            <arg value="${findbugs.home}/bin/convertXmlToText"/>
324            <arg value="-longBugCodes"/>
325            <arg value="-html:${findbugs.home}/src/xsl/fancy.xsl"/>
326            <arg value="${dist.findbugs.dir}/findbugs.xml"/>
327            <redirector output="${dist.findbugs.dir}/findbugs.html"/>
328        </exec>
329    </target>
330
331    <target name="coverage" depends="-def-cobertura,build-all-classes,instrument-classes,jtreg,coverage-report"/>
332
333    <target name="instrument-classes" depends="-def-cobertura">
334        <!-- only define the following property when we want coverage info -->
335        <path id="coverage.classpath">
336            <pathelement location="${build.coverage.dir}/classes"/>
337            <path refid="cobertura.classpath"/>
338        </path>
339        <property name="coverage.options" value="-Dnet.sourceforge.cobertura.datafile=${build.coverage.dir}/cobertura.ser"/>
340        <property name="coverage.classpath" refid="coverage.classpath"/>
341        <mkdir dir="${build.coverage.dir}/classes"/>
342        <delete file="${build.coverage.dir}/cobertura.ser"/>
343        <cobertura-instrument todir="${build.coverage.dir}/classes"
344            datafile="${build.coverage.dir}/cobertura.ser">
345            <fileset dir="${build.classes.dir}"
346               includes="**/*.class" excludes="**/resources/*.class"/>
347        </cobertura-instrument>
348    </target>
349
350    <target name="coverage-report" depends="-def-cobertura">
351        <mkdir dir="${dist.coverage.dir}"/>
352        <cobertura-report
353            srcdir="${src.classes.dir}"
354            destdir="${dist.coverage.dir}"
355            datafile="${build.coverage.dir}/cobertura.ser"/>
356        <cobertura-report
357            format="xml"
358            srcdir="${src.classes.dir}"
359            destdir="${dist.coverage.dir}"
360            datafile="${build.coverage.dir}/cobertura.ser"/>
361    </target>
362
363    <target name="diags-examples" depends="build-javac">
364        <!-- can override the following on the command line if desired. -->
365        <property name="diags.examples.out" location="${build.dir}/diag-examples/diags-examples.html"/>
366        <mkdir dir="${build.dir}/diag-examples/classes"/>
367        <javac fork="true"
368            executable="${dist.bin.dir}/javac"
369            srcdir="test/tools/javac/diags"
370            destdir="${build.dir}/diag-examples/classes"
371            includes="ArgTypeCompilerFactory.java,Example.java,FileManager.java,HTMLWriter.java,RunExamples.java"
372            sourcepath=""
373            classpath="${dist.lib.dir}/javac.jar"
374            includeAntRuntime="no"
375            debug="${javac.debug}"
376            debuglevel="${javac.debuglevel}">
377            <compilerarg line="${javac.lint.opts}"/>
378        </javac>
379        <java fork="true"
380            jvm="${target.java.home}/bin/java"
381            dir="test/tools/javac/diags"
382            classpath="${build.dir}/diag-examples/classes;${dist.lib.dir}/javac.jar"
383            classname="RunExamples">
384            <arg value="-examples"/>
385            <arg value="examples"/>
386            <arg value="-o"/>
387            <arg file="${diags.examples.out}"/>
388            <arg value="-showFiles"/>
389            <arg value="-title"/>
390            <arg value="Examples of javac diagnostics"/>
391        </java>
392    </target>
393
394    <!-- a patching facility to speed up incorporating the langtools' classfiles
395         into a jdk of your choice. Either target.java.home or patch.jdk can be
396         set on the command line; setting target.java.home has the advantage of
397         patching the jdk used for jtreg and other tests.
398    -->
399    <target name="patch" depends="build-all-classes">
400        <condition property="patch.jdk" value="${target.java.home}">
401            <available file="${target.java.home}" type="dir"/>
402        </condition>
403        <fail message="patch.jdk or target.java.home is not set, please set target.java.home, or patch.jdk for an alternate jdk image to patch">
404            <condition>
405                <not>
406                    <isset property="patch.jdk"/>
407                </not>
408            </condition>
409        </fail>
410        <property name="patch.tools.jar" location="${patch.jdk}/lib/tools.jar"/>
411        <property name="patch.rt.jar" location="${patch.jdk}/jre/lib/rt.jar"/>
412        <fail message="patch.jdk or target.java.home must point to a valid jdk image: missing tools.jar">
413            <condition>
414                <not>
415                    <available file="${patch.tools.jar}" type="file"/>
416                </not>
417            </condition>
418        </fail>
419        <fail message="patch.jdk or target.java.home must point to a valid jdk image: missing rt.jar">
420            <condition>
421                <not>
422                    <available file="${patch.rt.jar}" type="file"/>
423                </not>
424            </condition>
425        </fail>
426        <zip zipfile="${patch.tools.jar}" update="true">
427            <zipfileset dir="${build.classes.dir}" includes="com/**"/>
428        </zip>
429        <zip zipfile="${patch.rt.jar}" update="true">
430            <zipfileset dir="${build.classes.dir}" includes="javax/**"/>
431        </zip>
432    </target>
433
434    <!--
435    **** Debugging/diagnostic targets.
436    -->
437
438    <!-- standard JDK target -->
439    <target name="sanity"
440        description="display settings of configuration values">
441        <echo level="info">ant.home = ${ant.home}</echo>
442        <echo level="info">boot.java.home = ${boot.java.home}</echo>
443        <echo level="info">target.java.home = ${target.java.home}</echo>
444        <echo level="info">jtreg.home = ${jtreg.home}</echo>
445        <echo level="info">findbugs.home = ${findbugs.home}</echo>
446        <echo level="info">checkstyle.home = ${checkstyle.home}</echo>
447    </target>
448
449    <target name="post-sanity" depends="-def-jtreg,sanity,build"
450        description="perform basic validation after a standard build">
451        <jtreg
452            dir="make/test"
453            workDir="${build.jtreg.dir}/post-sanity/work"
454            reportDir="${build.jtreg.dir}/post-sanity/report"
455            jdk="${target.java.home}"
456            verbose="summary"
457            failonerror="false" resultproperty="jtreg.post-sanity.result">
458        </jtreg>
459    </target>
460
461    <!-- use vizant tool to generate graphical image of this Ant file.-->
462    <target name="vizant" depends="-def-vizant">
463        <mkdir dir="${build.dir}"/>
464        <echo message="Generating ${build.dir}/build.dot"/>
465        <vizant antfile="${make.dir}/build.xml" outfile="${build.dir}/build.dot"/>
466        <echo message="Generating ${build.dir}/build.png"/>
467        <exec executable="${dot}" >
468            <arg value="-Tpng"/>
469            <arg value="-o"/>
470            <arg file="${build.dir}/build.png"/>
471            <arg file="${build.dir}/build.dot"/>
472        </exec>
473    </target>
474
475    <target name="check-import.jdk">
476        <echo message="import.jdk: ${import.jdk}"/>
477        <echo message="import.jdk.jar: ${import.jdk.jar}"/>
478        <echo message="import.jdk.src.dir: ${import.jdk.src.dir}"/>
479    </target>
480
481    <target name="diagnostics">
482        <diagnostics/>
483    </target>
484
485
486    <!--
487    **** javac targets.
488    -->
489
490    <target name="build-bootstrap-javac"
491            depends="-def-build-bootstrap-classes,-def-build-bootstrap-jar,-def-build-bootstrap-tool">
492        <build-bootstrap-classes includes="${javac.includes}"/>
493        <build-bootstrap-jar     name="javac" includes="${javac.includes}"/>
494        <build-bootstrap-tool    name="javac"/>
495    </target>
496
497    <target name="build-classes-javac" depends="build-bootstrap-javac,-create-import-jdk-stubs">
498        <build-classes includes="${javac.includes}"/>
499    </target>
500
501    <target name="build-javac" depends="build-classes-javac">
502        <build-jar  name="javac" includes="${javac.includes}"/>
503        <build-tool name="javac"/>
504    </target>
505
506    <target name="javadoc-javac" depends="build-javac,-def-javadoc-tool">
507        <javadoc-tool name="javac" includes="${javac.includes}" options="${javadoc.jls.option}"/>
508    </target>
509
510    <target name="jtreg-javac" depends="build-javac,build-javap,-def-jtreg">
511        <jtreg-tool name="javac" tests="${javac.tests}"/>
512    </target>
513
514    <target name="findbugs-javac" depends="build-javac,-def-findbugs">
515        <findbugs-tool name="javac"/>
516    </target>
517
518    <target name="javac" depends="build-javac,jtreg-javac,findbugs-javac"/>
519
520
521    <!--
522    **** javadoc targets.
523    -->
524
525    <target name="build-bootstrap-javadoc" depends="build-bootstrap-javac">
526        <build-bootstrap-classes includes="${javadoc.includes}"/>
527        <build-bootstrap-jar     name="javadoc" includes="${javadoc.includes}"
528                                 jarclasspath="javac.jar doclets.jar"/>
529        <build-bootstrap-tool    name="javadoc"/>
530    </target>
531
532    <target name="build-classes-javadoc" depends="build-classes-javac">
533        <build-classes includes="${javadoc.includes}"/>
534    </target>
535
536    <target name="build-javadoc" depends="build-javac,build-classes-javadoc">
537        <build-jar  name="javadoc" includes="${javadoc.includes}"
538                    jarclasspath="javac.jar doclets.jar"/>
539        <build-tool name="javadoc"/>
540    </target>
541
542    <target name="javadoc-javadoc" depends="build-javadoc,-def-javadoc-tool">
543        <javadoc-tool name="javadoc" includes="${javadoc.includes}"/>
544    </target>
545
546    <target name="jtreg-javadoc" depends="build-javadoc,-def-jtreg">
547        <jtreg-tool name="javadoc" tests="${javadoc.tests}"/>
548    </target>
549
550    <target name="findbugs-javadoc" depends="build-javadoc,-def-findbugs">
551        <findbugs-tool name="javadoc"/>
552    </target>
553
554    <target name="javadoc" depends="build-javadoc,jtreg-javadoc,findbugs-javadoc"/>
555
556
557    <!--
558    **** doclets targets.
559    -->
560
561    <target name="build-bootstrap-doclets" depends="build-bootstrap-javadoc,-def-build-bootstrap-jar">
562        <build-bootstrap-classes includes="${doclets.includes}"/>
563        <build-bootstrap-jar     name="doclets" includes="${doclets.includes}"
564                                 jarmainclass="com.sun.tools.javadoc.Main"
565                                 jarclasspath="javadoc.jar"/>
566    </target>
567
568    <target name="build-classes-doclets" depends="build-classes-javadoc">
569        <build-classes includes="${doclets.includes}"/>
570    </target>
571
572    <target name="build-doclets" depends="build-javadoc,build-classes-doclets">
573        <!-- just jar, no bin for doclets -->
574        <build-jar name="doclets" includes="${doclets.includes}" jarclasspath="javadoc.jar"/>
575    </target>
576
577    <!-- (no javadoc for doclets) -->
578
579    <target name="jtreg-doclets" depends="build-doclets,-def-jtreg">
580        <jtreg-tool name="doclets" tests="${doclets.tests}"/>
581    </target>
582
583    <target name="findbugs-doclets" depends="build-doclets,-def-findbugs">
584        <findbugs-tool name="doclets"/>
585    </target>
586
587    <target name="doclets" depends="build-doclets,jtreg-doclets,findbugs-doclets"/>
588
589
590    <!--
591    **** javah targets.
592    -->
593
594    <target name="build-bootstrap-javah" depends="build-bootstrap-javadoc">
595        <build-bootstrap-classes includes="${javah.includes}"/>
596        <build-bootstrap-jar     name="javah" includes="${javah.includes}"
597                                 jarclasspath="javadoc.jar doclets.jar javac.jar"/>
598        <build-bootstrap-tool    name="javah"/>
599    </target>
600
601    <target name="build-javah" depends="build-javac,build-classes-javah">
602        <build-jar  name="javah" includes="${javah.includes}" jarclasspath="javac.jar"/>
603        <build-tool name="javah"/>
604    </target>
605
606    <target name="build-classes-javah" depends="build-classes-javadoc">
607        <build-classes includes="${javah.includes}"/>
608    </target>
609
610    <!-- (no javadoc for javah) -->
611
612    <target name="jtreg-javah" depends="build-javah,-def-jtreg">
613        <jtreg-tool name="javah" tests="${javah.tests}"/>
614    </target>
615
616    <target name="findbugs-javah" depends="build-javah,-def-findbugs">
617        <findbugs-tool name="javah"/>
618    </target>
619
620    <target name="javah" depends="build-javah,jtreg-javah,findbugs-javah"/>
621
622
623    <!--
624    **** javap targets.
625    -->
626
627    <target name="build-bootstrap-javap"
628            depends="-def-build-bootstrap-classes,-def-build-bootstrap-jar,-def-build-bootstrap-tool">
629        <build-bootstrap-classes includes="${javap.includes}"/>
630        <build-bootstrap-jar     name="javap" includes="${javap.includes}"
631                                 jarmainclass="sun.tools.javap.Main"/>
632        <build-bootstrap-tool    name="javap"/>
633    </target>
634
635    <target name="build-classes-javap" depends="build-classes-javac">
636        <build-classes includes="${javap.includes}"/>
637    </target>
638
639    <target name="build-javap" depends="build-javac,build-classes-javap">
640        <build-jar  name="javap" includes="${javap.includes}"
641                    jarmainclass="com.sun.tools.javap.Main"
642                    jarclasspath="javac.jar"/>
643        <build-tool name="javap"/>
644    </target>
645
646    <!-- (no javadoc for javap) -->
647
648    <target name="jtreg-javap" depends="build-javap,-def-jtreg">
649        <jtreg-tool name="javap" tests="${javap.tests}"/>
650    </target>
651
652    <target name="findbugs-javap" depends="build-javap,-def-findbugs">
653        <findbugs-tool name="javap"/>
654    </target>
655
656    <target name="javap" depends="build-javap,jtreg-javap,findbugs-javap"/>
657
658
659    <!--
660    **** Create import JDK stubs.
661    -->
662
663    <target name="-create-import-jdk-stubs" depends="-def-genstubs" if="require.import.jdk.stubs">
664        <mkdir dir="${build.genstubs.dir}"/>
665        <genstubs
666            srcdir="${import.jdk.src.dir}" destdir="${build.genstubs.dir}"
667            includes="${import.jdk.stub.files}"
668            fork="true" classpath="${build.toolclasses.dir}:${build.bootstrap.dir}/classes:${ant.core.lib}"
669        />
670    </target>
671
672
673    <!--
674    **** Check targets.
675    **** "-check-*" targets check that a required property is set, and set to a reasonable value.
676    **** A user friendly message is generated if not, and the build exits.
677    -->
678
679    <target name="-check-boot.java.home" depends="-def-check">
680        <check name="bootstrap java" property="boot.java.home" marker="${java.marker}"/>
681    </target>
682
683    <target name="-check-target.java.home" depends="-def-check">
684        <check name="target java" property="target.java.home" marker="${java.marker}"/>
685    </target>
686
687    <target name="-check-cobertura.home" depends="-def-check">
688        <check name="cobertura" property="cobertura.home" marker="cobertura.jar"/>
689    </target>
690
691    <target name="-check-findbugs.home" depends="-def-check">
692        <check name="findbugs" property="findbugs.home" marker="lib/findbugs.jar"/>
693    </target>
694
695    <target name="-check-checkstyle.home" depends="-def-check">
696        <check name="checkstyle" property="checkstyle.home" marker="${checkstyle.name.version}.jar"/>
697    </target>
698    
699    <target name="-check-jtreg.home" depends="-def-check">
700        <check name="jtreg" property="jtreg.home" marker="lib/jtreg.jar"/>
701    </target>
702
703    <target name="-check-vizant" depends="-def-check">
704        <check name="vizant" property="vizant.jar"/>
705        <check name="dot" property="dot"/>
706    </target>
707
708
709    <!--
710    **** Targets for Ant macro and task definitions.
711    -->
712
713    <target name="-def-build-tool">
714        <macrodef name="build-tool">
715            <attribute name="name"/>
716            <attribute name="bin.dir" default="${dist.bin.dir}"/>
717            <attribute name="java" default="${launcher.java}"/>
718            <sequential>
719                <mkdir dir="@{bin.dir}"/>
720                <copy file="${src.bin.dir}/launcher.sh-template" tofile="@{bin.dir}/@{name}">
721                    <filterset begintoken="#" endtoken="#">
722                        <filter token="PROGRAM" value="@{name}"/>
723                        <filter token="TARGET_JAVA" value="@{java}"/>
724                        <filter token="PS" value="${path.separator}"/>
725                    </filterset>
726                </copy>
727                <chmod file="@{bin.dir}/@{name}" perm="ugo+rx"/>
728            </sequential>
729        </macrodef>
730    </target>
731
732    <target name="-def-build-jar">
733        <macrodef name="build-jar">
734            <attribute name="name"/>
735            <attribute name="includes"/>
736            <attribute name="classes.dir" default="${build.classes.dir}"/>
737            <attribute name="lib.dir" default="${dist.lib.dir}"/>
738            <attribute name="jarmainclass" default="com.sun.tools.@{name}.Main"/>
739            <attribute name="jarclasspath" default=""/>
740            <sequential>
741                <mkdir dir="@{lib.dir}"/>
742                <jar destfile="@{lib.dir}/@{name}.jar"
743                     basedir="@{classes.dir}"
744                     includes="@{includes}">
745                    <manifest>
746                        <attribute name="Main-Class" value="@{jarmainclass}"/>
747                        <attribute name="Class-Path" value="@{jarclasspath}"/>
748                    </manifest>
749                </jar>
750            </sequential>
751        </macrodef>
752    </target>
753
754    <target name="-def-build-classes" depends="-def-pcompile">
755        <macrodef name="build-classes">
756            <attribute name="includes"/>
757            <attribute name="excludes" default="${exclude.files} **/package-info.java"/>
758            <attribute name="classes.dir" default="${build.classes.dir}"/>
759            <attribute name="gensrc.dir" default="${build.gensrc.dir}"/>
760            <attribute name="javac.bootclasspath" default="${build.bootstrap.dir}/classes"/>
761            <attribute name="bootclasspath.opt" default="${javac.bootclasspath.opt}"/>
762            <attribute name="classpath" default="${javac.classpath}"/>
763            <attribute name="sourcepath" default="${javac.sourcepath}"/>
764            <attribute name="java.home" default="${boot.java.home}"/>
765            <attribute name="source" default="${javac.source}"/>
766            <attribute name="target" default="${javac.target}"/>
767            <attribute name="release" default="${release}"/>
768            <attribute name="full.version" default="${full.version}"/>
769            <sequential>
770                <echo level="verbose" message="build-classes: excludes=@{excludes}"/>
771                <echo level="verbose" message="build-classes: bootclasspath.opt=@{bootclasspath.opt}"/>
772                <echo level="verbose" message="build-classes: classpath=@{classpath}"/>
773                <echo level="verbose" message="build-classes: sourcepath=@{sourcepath}"/>
774                <mkdir dir="@{gensrc.dir}"/>
775                <mkdir dir="@{classes.dir}"/>
776                <pcompile srcdir="${src.classes.dir}"
777                          destdir="@{gensrc.dir}"
778                          includes="@{includes}"/>
779                <copy todir="@{gensrc.dir}">
780                    <fileset dir="${src.classes.dir}" includes="@{includes}"/>
781                    <globmapper from="*.properties-template" to="*.properties"/>
782                    <filterset begintoken="$(" endtoken=")">
783                        <filter token="JDK_VERSION" value="${jdk.version}"/>
784                        <filter token="RELEASE" value="@{release}"/>
785                        <filter token="FULL_VERSION" value="@{full.version}"/>
786                    </filterset>
787                </copy>
788                <pcompile srcdir="@{gensrc.dir}"
789                          destdir="@{gensrc.dir}"
790                          includes="**/*.properties"/>
791                <javac fork="true"
792                       executable="@{java.home}/bin/javac"
793                       srcdir="${src.classes.dir}:@{gensrc.dir}"
794                       destdir="@{classes.dir}"
795                       includes="@{includes}"
796                       excludes="@{excludes}"
797                       sourcepath="@{sourcepath}"
798                       classpath="@{classpath}"
799                       includeAntRuntime="no"
800                       source="@{source}"
801                       target="@{target}"
802                       debug="${javac.debug}"
803                       debuglevel="${javac.debuglevel}">
804                    <compilerarg value="-implicit:none"/>
805                    <compilerarg value="-Xprefer:source"/>
806                    <compilerarg value="-J-Xbootclasspath/p:@{javac.bootclasspath}"/>
807                    <compilerarg line="@{bootclasspath.opt}"/>
808                    <compilerarg line="${javac.no.jdk.warnings}"/>
809                    <compilerarg line="${javac.version.opt}"/>
810                    <compilerarg line="${javac.lint.opts}"/>
811                </javac>
812                <copy todir="@{classes.dir}" includeemptydirs="false">
813                    <fileset dir="${src.classes.dir}" includes="@{includes}" excludes="@{excludes}">
814                        <exclude name="**/*.java"/>
815                        <exclude name="**/*.properties"/>
816                        <exclude name="**/*-template"/>
817                        <exclude name="**/*.rej"/>
818                        <exclude name="**/*.orig"/>
819                        <exclude name="**/overview.html"/>
820                        <exclude name="**/package.html"/>
821                    </fileset>
822                </copy>
823            </sequential>
824        </macrodef>
825    </target>
826
827    <target name="-def-build-bootstrap-tool" depends="-check-boot.java.home,-def-build-tool">
828        <presetdef name="build-bootstrap-tool">
829            <build-tool
830                bin.dir="${build.bootstrap.dir}/bin"
831                java="${boot.java}"/>
832        </presetdef>
833    </target>
834
835    <target name="-def-build-bootstrap-jar" depends="-def-build-jar">
836        <presetdef name="build-bootstrap-jar">
837            <build-jar
838                classes.dir="${build.bootstrap.dir}/classes"
839                lib.dir="${build.bootstrap.dir}/lib"/>
840        </presetdef>
841    </target>
842
843    <target name="-def-build-bootstrap-classes" depends="-def-build-classes">
844        <presetdef name="build-bootstrap-classes">
845            <build-classes
846                source="${boot.javac.source}"
847                target="${boot.javac.target}"
848                gensrc.dir="${build.bootstrap.dir}/gensrc"
849                classes.dir="${build.bootstrap.dir}/classes"
850                javac.bootclasspath=""
851                bootclasspath.opt="-Xbootclasspath/p:${build.bootstrap.dir}/classes"
852                sourcepath=""
853                release="${bootstrap.release}"
854                full.version="${bootstrap.full.version}"
855                excludes="${bootstrap.exclude.files} **/package-info.java"/>
856        </presetdef>
857    </target>
858
859    <target name="-def-pcompile">
860        <mkdir dir="${build.toolclasses.dir}"/>
861        <javac fork="true"
862               source="${boot.javac.source}"
863               target="${boot.javac.target}"
864               executable="${boot.java.home}/bin/javac"
865               srcdir="${make.tools.dir}"
866               includes="compileproperties/* anttasks/CompileProperties*"
867               destdir="${build.toolclasses.dir}/"
868               classpath="${ant.core.lib}"
869               bootclasspath="${boot.java.home}/jre/lib/rt.jar"
870               includeantruntime="false">
871            <compilerarg line="${javac.lint.opts}"/>
872        </javac>
873        <taskdef name="pcompile"
874                 classname="anttasks.CompilePropertiesTask"
875                 classpath="${build.toolclasses.dir}/"/>
876    </target>
877
878    <target name="-def-genstubs" depends="build-bootstrap-javac" if="require.import.jdk.stubs">
879        <mkdir dir="${build.toolclasses.dir}"/>
880        <javac fork="true"
881               source="${boot.javac.source}"
882               target="${boot.javac.target}"
883               executable="${boot.java.home}/bin/javac"
884               srcdir="${make.tools.dir}"
885               includes="genstubs/* anttasks/GenStubs*"
886               destdir="${build.toolclasses.dir}/"
887               classpath="${ant.core.lib}"
888               includeantruntime="false">
889            <compilerarg value="-Xbootclasspath/p:${build.bootstrap.dir}/classes"/>
890            <compilerarg line="${javac.lint.opts}"/>
891        </javac>
892        <taskdef name="genstubs"
893                 classname="anttasks.GenStubsTask"
894                 classpath="${build.toolclasses.dir}/"/>
895    </target>
896
897    <target name="-def-javadoc-tool" depends="-check-target.java.home">
898        <macrodef name="javadoc-tool">
899            <attribute name="name"/>
900            <attribute name="includes"/>
901            <attribute name="options" default=""/>
902            <attribute name="source" default="1.5"/> <!-- FIXME -->
903            <sequential>
904                <property name="javadoc.options" value=""/> <!-- default, can be overridden per user or per project -->
905                <!-- Note: even with this default value, includes
906                from src.classes.dir get javadoc'd; see packageset below -->
907                <property name="javadoc.packagenames" value="none"/> <!-- default, can be overridden per user or per project -->
908                <javadoc
909                    executable="${target.java.home}/bin/javadoc"
910                    destdir="${build.javadoc.dir}/@{name}"
911                    source="@{source}"
912                    windowtitle="UNOFFICIAL"
913                    failonerror="true"
914                    use="true"
915                    author="false"
916                    version="false"
917                    packagenames="${javadoc.packagenames}" >
918                    <header><![CDATA[<strong>Unofficial Javadoc</strong> generated from developer sources for preview purposes only]]></header>
919                    <arg line="@{options}"/>
920                    <bootclasspath>
921                        <path location="${build.classes.dir}"/>
922                        <path location="${target.java.home}/jre/lib/rt.jar"/>
923                    </bootclasspath>
924                    <sourcepath>
925                        <pathelement location="${src.classes.dir}"/>
926                    </sourcepath>
927                    <!-- XXX just <fileset> (restricted further to **/*.java) and no <packageset> -->
928                    <!-- means that {@link some.package} will not work, which is no good. -->
929                    <!-- (It correctly skips excluded single classes, but not if packageset is also included, -->
930                    <!-- which also causes duplicates in the class index for included files.) -->
931                    <packageset dir="${src.classes.dir}" includes="@{includes}">
932                        <or>
933                            <filename name="java/"/>
934                            <filename name="javax/"/>
935                            <filename name="com/sun/javadoc/"/>
936                            <filename name="com/sun/source/"/>
937                        </or>
938                    </packageset>
939                </javadoc>
940            </sequential>
941        </macrodef>
942    </target>
943
944    <target name="-def-jtreg" unless="jtreg.defined" depends="-check-jtreg.home,-check-target.java.home">
945        <taskdef name="jtreg" classname="com.sun.javatest.regtest.Main$$Ant">
946            <classpath>
947                <pathelement location="${jtreg.home}/lib/jtreg.jar"/>
948                <pathelement location="${jtreg.home}/lib/javatest.jar"/>
949            </classpath>
950        </taskdef>
951        <macrodef name="jtreg-tool">
952            <attribute name="name"/>
953            <attribute name="tests"/>
954            <attribute name="jdk" default="${target.java.home}"/>
955            <attribute name="samevm" default="true"/>
956            <attribute name="verbose" default="${default.jtreg.verbose}"/>
957            <attribute name="options" default="${other.jtreg.options}"/>
958            <attribute name="keywords" default="-keywords:!ignore"/>
959            <attribute name="jpda.jvmargs" default=""/>
960            <sequential>
961                <property name="coverage.options" value=""/>              <!-- default -->
962                <property name="coverage.classpath" value=""/>            <!-- default -->
963                <property name="default.jtreg.verbose" value="summary"/>  <!-- default -->
964                <property name="other.jtreg.options" value=""/>           <!-- default -->
965                <jtreg
966                    dir="${test.dir}"
967                    workDir="${build.jtreg.dir}/@{name}/work"
968                    reportDir="${build.jtreg.dir}/@{name}/report"
969                    jdk="@{jdk}"
970                    samevm="@{samevm}" verbose="@{verbose}"
971                    failonerror="false" resultproperty="jtreg.@{name}.result"
972                    javacoptions="-g"
973                    vmoptions="${coverage.options} -Xbootclasspath/p:${coverage.classpath}${path.separator}${build.classes.dir} @{jpda.jvmargs}">
974                    <arg line="@{keywords}"/>
975                    <arg line="@{options}"/>
976                    <arg line="@{tests}"/>
977                </jtreg>
978                <!-- the next two properties are for convenience, when only
979                     a single instance of jtreg will be invoked. -->
980                <condition property="jtreg.passed">
981                    <equals arg1="${jtreg.@{name}.result}" arg2="0"/>
982                </condition>
983                <property name="jtreg.report" value="${build.jtreg.dir}/@{name}/report"/>
984            </sequential>
985        </macrodef>
986        <property name="jtreg.defined" value="true"/>
987    </target>
988
989    <target name="-def-cobertura" depends="-check-cobertura.home">
990        <path id="cobertura.classpath">
991            <fileset dir="${cobertura.home}">
992                <include name="cobertura.jar"/>
993                <include name="lib/**/*.jar"/>
994            </fileset>
995        </path>
996        <taskdef classpathref="cobertura.classpath" resource="tasks.properties"/>
997    </target>
998
999    <target name="-def-checkstyle" unless="checkstyle.defined"
1000        depends="-check-checkstyle.home">
1001        <taskdef resource="checkstyletask.properties">
1002            <classpath>
1003                <pathelement location="${checkstyle.home}/${checkstyle.name.version}-all.jar"/>
1004            </classpath>
1005        </taskdef>
1006        <property name="checkstyle.defined" value="true"/>
1007    </target>
1008    
1009    <target name="-def-findbugs" unless="findbugs.defined"
1010        depends="-check-findbugs.home,-check-target.java.home">
1011        <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
1012            <classpath>
1013                <pathelement location="${findbugs.home}/lib/findbugs.jar"/>
1014            </classpath>
1015        </taskdef>
1016        <macrodef name="findbugs-tool">
1017            <attribute name="name"/>
1018            <attribute name="output" default="emacs"/>
1019            <attribute name="outputFile" default=""/>
1020            <attribute name="reportLevel" default="high"/>
1021            <sequential>
1022                <findbugs
1023                    home="${findbugs.home}"
1024                    output="@{output}"
1025                    outputFile="@{outputFile}"
1026                    reportLevel="@{reportLevel}"
1027                    failOnError="false"
1028                    errorProperty="findbugs.@{name}.errors"
1029                    warningsProperty="findbugs.@{name}.warnings"
1030                    jvm="${target.java.home}/bin/java"
1031                    jvmargs="-Xmx512M" >
1032                    <class location="${dist.dir}/lib/@{name}.jar"/>
1033                    <auxClasspath>
1034                        <pathelement location="${build.classes.dir}"/>
1035                    </auxClasspath>
1036                    <sourcePath>
1037                        <pathelement location="${src.classes.dir}"/>
1038                    </sourcePath>
1039                </findbugs>
1040            </sequential>
1041        </macrodef>
1042        <property name="findbugs.defined" value="true"/>
1043    </target>
1044
1045    <target name="-def-vizant" unless="vizant.defined" depends="-check-vizant">
1046        <taskdef name="vizant" classname="net.sourceforge.vizant.Vizant" classpath="${vizant.jar}"/>
1047        <property name="vizant.defined" value="true"/>
1048    </target>
1049
1050    <target name="-def-check">
1051        <macrodef name="check">
1052            <attribute name="name"/>
1053            <attribute name="property"/>
1054            <attribute name="marker" default=""/>
1055            <sequential>
1056                <fail message="Cannot locate @{name}: please set @{property} to its location">
1057                    <condition>
1058                        <not>
1059                            <isset property="@{property}"/>
1060                        </not>
1061                    </condition>
1062                </fail>
1063                <fail message="@{name} is not installed in ${@{property}}">
1064                    <condition>
1065                        <and>
1066                            <not>
1067                                <equals arg1="@{marker}" arg2=""/>
1068                            </not>
1069                            <not>
1070                                <available file="${@{property}}/@{marker}"/>
1071                            </not>
1072                        </and>
1073                    </condition>
1074                </fail>
1075            </sequential>
1076        </macrodef>
1077    </target>
1078
1079</project>
1080
1081