java/ant/build.xml
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 03 Apr 2020 16:32:36 +0200
changeset 416 9ed8788a1a4e
parent 328 9e7c0ac38233
permissions -rw-r--r--
Using HTTPS to download the libraries
jtulach@268
     1
<?xml version="1.0" encoding="UTF-8"?>
jtulach@268
     2
<!-- You may freely edit this file. See commented blocks below for -->
jtulach@268
     3
<!-- some examples of how to customize the build. -->
jtulach@268
     4
<!-- (If you delete it and reopen the project it will be recreated.) -->
jtulach@328
     5
<!-- By default, only the Clean and Build commands use this build script. -->
jtulach@328
     6
<!-- Commands such as Run, Debug, and Test only use this build script if -->
jtulach@328
     7
<!-- the Compile on Save feature is turned off for the project. -->
jtulach@328
     8
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
jtulach@328
     9
<!-- in the project's Project Properties dialog box.-->
jtulach@268
    10
<project name="ant" default="default" basedir=".">
jtulach@268
    11
    <description>Builds, tests, and runs the project ant.</description>
jtulach@268
    12
    <import file="nbproject/build-impl.xml"/>
jtulach@268
    13
    <!--
jtulach@268
    14
jtulach@268
    15
    There exist several targets which are by default empty and which can be 
jtulach@268
    16
    used for execution of your tasks. These targets are usually executed 
jtulach@268
    17
    before and after some main targets. They are: 
jtulach@268
    18
jtulach@268
    19
      -pre-init:                 called before initialization of project properties
jtulach@268
    20
      -post-init:                called after initialization of project properties
jtulach@268
    21
      -pre-compile:              called before javac compilation
jtulach@268
    22
      -post-compile:             called after javac compilation
jtulach@268
    23
      -pre-compile-single:       called before javac compilation of single file
jtulach@268
    24
      -post-compile-single:      called after javac compilation of single file
jtulach@268
    25
      -pre-compile-test:         called before javac compilation of JUnit tests
jtulach@268
    26
      -post-compile-test:        called after javac compilation of JUnit tests
jtulach@268
    27
      -pre-compile-test-single:  called before javac compilation of single JUnit test
jtulach@268
    28
      -post-compile-test-single: called after javac compilation of single JUunit test
jtulach@268
    29
      -pre-jar:                  called before JAR building
jtulach@268
    30
      -post-jar:                 called after JAR building
jtulach@268
    31
      -post-clean:               called after cleaning build products
jtulach@268
    32
jtulach@268
    33
    (Targets beginning with '-' are not intended to be called on their own.)
jtulach@268
    34
jtulach@268
    35
    Example of inserting an obfuscator after compilation could look like this:
jtulach@268
    36
jtulach@268
    37
        <target name="-post-compile">
jtulach@268
    38
            <obfuscate>
jtulach@268
    39
                <fileset dir="${build.classes.dir}"/>
jtulach@268
    40
            </obfuscate>
jtulach@268
    41
        </target>
jtulach@268
    42
jtulach@268
    43
    For list of available properties check the imported 
jtulach@268
    44
    nbproject/build-impl.xml file. 
jtulach@268
    45
jtulach@268
    46
jtulach@268
    47
    Another way to customize the build is by overriding existing main targets.
jtulach@268
    48
    The targets of interest are: 
jtulach@268
    49
jtulach@268
    50
      -init-macrodef-javac:     defines macro for javac compilation
jtulach@268
    51
      -init-macrodef-junit:     defines macro for junit execution
jtulach@268
    52
      -init-macrodef-debug:     defines macro for class debugging
jtulach@268
    53
      -init-macrodef-java:      defines macro for class execution
jtulach@268
    54
      -do-jar-with-manifest:    JAR building (if you are using a manifest)
jtulach@268
    55
      -do-jar-without-manifest: JAR building (if you are not using a manifest)
jtulach@268
    56
      run:                      execution of project 
jtulach@268
    57
      -javadoc-build:           Javadoc generation
jtulach@268
    58
      test-report:              JUnit report generation
jtulach@268
    59
jtulach@268
    60
    An example of overriding the target for project execution could look like this:
jtulach@268
    61
jtulach@268
    62
        <target name="run" depends="ant-impl.jar">
jtulach@268
    63
            <exec dir="bin" executable="launcher.exe">
jtulach@268
    64
                <arg file="${dist.jar}"/>
jtulach@268
    65
            </exec>
jtulach@268
    66
        </target>
jtulach@268
    67
jtulach@268
    68
    Notice that the overridden target depends on the jar target and not only on 
jtulach@268
    69
    the compile target as the regular run target does. Again, for a list of available 
jtulach@268
    70
    properties which you can use, check the target you are overriding in the
jtulach@268
    71
    nbproject/build-impl.xml file. 
jtulach@268
    72
jtulach@268
    73
    -->
jtulach@328
    74
    <target name="-revision" unless="revision">
jtulach@328
    75
        <fail unless="snippets.code.dir"/>
jtulach@328
    76
        <exec dir="${snippets.code.dir}" outputproperty="revision" executable="/bin/sh">
jtulach@328
    77
            <arg file="${ant.file}/../tip.sh"/>
jtulach@328
    78
        </exec>
jtulach@328
    79
    </target>
jtulach@328
    80
jtulach@328
    81
    <target name="snippets" depends="jar,-revision" description="Extracts code snippets">
jtulach@328
    82
        <fail unless="revision"/>
jtulach@328
    83
        <fail unless="snippets.dir"/>
jtulach@328
    84
        <fail unless="snippets.repo"/>
jtulach@328
    85
        <fail unless="snippets.path"/>
jtulach@328
    86
        <fail unless="snippets.code.dir"/>
jtulach@328
    87
jtulach@328
    88
        <taskdef name="grepcopy" classname="org.apidesign.infra.ant.GrepCopy" classpath="dist/apidesign-ant-tasks.jar"/>
jtulach@328
    89
        <grepcopy target="${snippets.dir}" baseurl="${snippets.repo}/file/${revision}/${snippets.path}">
jtulach@328
    90
            <fileset dir="${snippets.code.dir}">
jtulach@328
    91
                <include name="**/*"/>
jtulach@328
    92
                <exclude name="**/build/**/*"/>
jtulach@329
    93
                <exclude name="**/target/**/*"/>
jtulach@328
    94
            </fileset>
jtulach@328
    95
        </grepcopy>
jtulach@328
    96
    </target>
jtulach@328
    97
jtulach@268
    98
</project>