Grokbase Groups Ant user April 2015
FAQ
Hi,


i have a fairly complex build system that recently introduces some additional compexity. To describe my problem, i'll sketch a very simplified Ant build:



<project>

     <target name="clean" depends="-clean" />

     <extension-point name="-clean" />


     <target name="init" depends="-init" />

     <extension-point name="-init" />


     <target name="compile" depends="-compile" />

     <extension-point name="-compile" depends="-init" />


     <target name="install" depends="-install" />

     <extension-point name="-install" depends="-compile" />


     <target name="recompile" depends="-recompile" />

     <extension-point name="-recompile" depends="-clean, -compile" />


</project>


This basic structure of the ANT file is required, because all extension-points are extended by specific implementatiosn for various implementation languages (including PL/I and COBOL).

This way i was able to maintain structured and standardized procedures, to generate the artifacts based on the varous sources.


Recently we tried to include that "recompile" step, that introduces a different "clean" semantic. Therefore i've implemented the "clean semantics as follows:


     <target name="std-clean" extensionOf="-clean">

         <echo>Std. Clean</echo>

     </target>



     <target name="recompile-clean" extensionOf="-clean" if="is.Recompile" >

         <echo>Additional behaviour for recompile</echo>

     </target>


     <target name="-recompile-switch">

         <property name="is.Recompile" value="true" />

     </target>


And the "-recompile" Target was extended this way:


     <target name="recompile" depends="-recompile-switch, -recompile" />


While this solution - in principle - activates "-recompile-switch" just before executing "-clean", this is not guaranteed by ANT. The ANT documentation states, that this dependcy declaration just states, that "-recompile-switch" will be activated BEFORE recompile executes, but it does not guarantee the order of execution for "-recompile-switch" and "-recompile".


In my case, the "-clean" targets activates, before "-recompile-switch" has any chance to execute. (Sometime it works, sometime it fails. But it's backed by ANTs definition.)



Now my question(s):

================


     Are there any ways to define the order of execution to guarantee an optional task just like "-recompile-switch" to execute at the right moment?


     Is there any way using the Java API to the ANT core to inspect the execution graph?
     Instead of injecting a target setting switch into the execution graph, it might by suitable to look up the chain of target execution to get an idea wich main target is active.



Unfortunately it is impossible to manipulate the execution graph at runtime, conditionally <import>ing different extesions.


A interim solution using <antcall> is in place.


     <target name="recompile">

         <antcall target="-recompile" inheritAll="true">

             <param name="is.Recompile" value="true" />

         </antcall>

     </target>


But ths solution requires a complete re-evaluation of the complete set of ANT build filles which takes a long time and is not applicable in any case.



Mit freundlichen Grüßen,

Ralf Edmund Stranzenbach
Manager, FS-Technology

BearingPoint
Management & Technology Consultants

Karl-Arnold-Platz 1
Düsseldorf 40474
Germany

T + 49 211 17143 6038
C + 49 174 3075 211
F + 49 211 17143 6060

www.bearingpoint.com
<../../owa/redir.aspx?C=4fef6935f97e45feb117b401747f61f1&URL=http%3a%2f%2fwww.bearingpoint.com%2f>
________________________________
BearingPoint GmbH
Geschäftsführer: Marcel Nickler (Vorsitzender), Hans-Werner Wurzel (stellv. Vorsitzender), Kiumars Hamidian, Matthias Loebich, Kai Wächter, Dr. Robert Wagner
Vorsitzender des Aufsichtsrats: Beat Leimbacher
Sitz: Frankfurt am Main
Registergericht: Amtsgericht Frankfurt am Main HRB 55490

The information in this email is confidential and may be legally privileged. If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful. If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachments, and any copies thereof from your system.

Search Discussions

  • Chris Barlock at Apr 14, 2015 at 6:36 pm
    I have the following Ant script:

    <project name="build" default="all" basedir=".">
         <target name="all">
             <property name="srcDir" value="/root/CCM/src"/>
             <property name="srcProtobufJavaDir"
    value="/root/CCM/srcProtobufJava"/>
             <property name="prereqToolsDir" value="/root/protoc"/>
             <mkdir dir="${srcProtobufJavaDir}"/>
             <chmod file="${prereqToolsDir}/bin/protoc" perm="755"/>
             <exec executable="${prereqToolsDir}/bin/protoc">
                 <!-- <arg value="${prereqToolsDir}/bin/protoc"/> -->
                 <arg value="--java_out=${srcProtobufJavaDir}"/>
                 <arg value="--proto_path=${srcDir}/protobuf/asf"/>
                 <arg value="${srcDir}/protobuf/asf/*.proto"/>
                 <env key="LD_LIBRARY_PATH" value="${prereqToolsDir}/lib"/>
            </exec>
         </target>
    </project>

    When I run this, I get:

    [root@nc9042036240 ~]# /usr/apache-ant-1.9.4/bin/ant -v -f build.xml
    Apache Ant(TM) version 1.9.4 compiled on April 29 2014
    Buildfile: /root/build.xml
    Detected Java version: 1.7 in:
    /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64/jre
    Detected OS: Linux
    parsing buildfile /root/build.xml with URI = file:/root/build.xml
    Project base dir set to: /root
    Build sequence for target(s) `all' is [all]
    Complete build sequence is [all, ]

    all:
    parsing buildfile
    jar:file:/usr/apache-ant-1.9.4/lib/ant.jar!/org/apache/tools/ant/antlib.xml
    with URI =
    jar:file:/usr/apache-ant-1.9.4/lib/ant.jar!/org/apache/tools/ant/antlib.xml
    from a zip file
         [mkdir] Skipping /root/CCM/srcProtobufJava because it already exists.
         [chmod] Executing 'chmod' with arguments:
         [chmod] '755'
         [chmod] '/root/protoc/bin/protoc'
         [chmod]
         [chmod] The ' characters around the executable and arguments are
         [chmod] not part of the command.
         [chmod] Applied chmod to 1 file and 0 directories.
          [exec] Current OS is Linux
          [exec] Setting environment variable: LD_LIBRARY_PATH=/root/protoc/lib
          [exec] Executing '/root/protoc/bin/protoc' with arguments:
          [exec] '--java_out=/root/CCM/srcProtobufJava'
          [exec] '--proto_path=/root/CCM/src/protobuf/asf'
          [exec] '/root/CCM/src/protobuf/asf/*.proto'
          [exec]
          [exec] The ' characters around the executable and arguments are
          [exec] not part of the command.
          [exec] /root/CCM/src/protobuf/asf/*.proto: No such file or directory
          [exec] Result: 1

    Running the equivalent command manually works just fine:

    /root/protoc/bin/protoc --java_out=/root/CCM/srcProtobufJava/
    --proto_path=/root/CCM/src/protobuf/asf /root/CCM/src/protobuf/asf/*.proto

    (It silently compiles a set of Google Protobuf files.) I originally set
    the executable to "/bin/sh" and the protoc command was the first arg,
    which you can see commented out above. With this arrangement, the exec
    task failed saying "cannot execute binary file" for protoc. Where have I
    gone wrong here?

    Thanks!

    Chris
  • Steve Schlaifer at Apr 14, 2015 at 7:14 pm

    On Tue, Apr 14, 2015 at 02:35:03PM -0400, Chris Barlock wrote:
    I have the following Ant script:

    <project name="build" default="all" basedir=".">
    <target name="all">
    <property name="srcDir" value="/root/CCM/src"/>
    <property name="srcProtobufJavaDir"
    value="/root/CCM/srcProtobufJava"/>
    <property name="prereqToolsDir" value="/root/protoc"/>
    <mkdir dir="${srcProtobufJavaDir}"/>
    <chmod file="${prereqToolsDir}/bin/protoc" perm="755"/>
    <exec executable="${prereqToolsDir}/bin/protoc">
    <!-- <arg value="${prereqToolsDir}/bin/protoc"/> -->
    <arg value="--java_out=${srcProtobufJavaDir}"/>
    <arg value="--proto_path=${srcDir}/protobuf/asf"/>
    <arg value="${srcDir}/protobuf/asf/*.proto"/>
    <env key="LD_LIBRARY_PATH" value="${prereqToolsDir}/lib"/>
    </exec>
    </target>
    </project>

    When I run this, I get:

    [root@nc9042036240 ~]# /usr/apache-ant-1.9.4/bin/ant -v -f build.xml
    Apache Ant(TM) version 1.9.4 compiled on April 29 2014
    Buildfile: /root/build.xml
    Detected Java version: 1.7 in:
    /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64/jre
    Detected OS: Linux
    parsing buildfile /root/build.xml with URI = file:/root/build.xml
    Project base dir set to: /root
    Build sequence for target(s) `all' is [all]
    Complete build sequence is [all, ]

    all:
    parsing buildfile
    jar:file:/usr/apache-ant-1.9.4/lib/ant.jar!/org/apache/tools/ant/antlib.xml
    with URI =
    jar:file:/usr/apache-ant-1.9.4/lib/ant.jar!/org/apache/tools/ant/antlib.xml
    from a zip file
    [mkdir] Skipping /root/CCM/srcProtobufJava because it already exists.
    [chmod] Executing 'chmod' with arguments:
    [chmod] '755'
    [chmod] '/root/protoc/bin/protoc'
    [chmod]
    [chmod] The ' characters around the executable and arguments are
    [chmod] not part of the command.
    [chmod] Applied chmod to 1 file and 0 directories.
    [exec] Current OS is Linux
    [exec] Setting environment variable: LD_LIBRARY_PATH=/root/protoc/lib
    [exec] Executing '/root/protoc/bin/protoc' with arguments:
    [exec] '--java_out=/root/CCM/srcProtobufJava'
    [exec] '--proto_path=/root/CCM/src/protobuf/asf'
    [exec] '/root/CCM/src/protobuf/asf/*.proto'
    [exec]
    [exec] The ' characters around the executable and arguments are
    [exec] not part of the command.
    [exec] /root/CCM/src/protobuf/asf/*.proto: No such file or directory
    [exec] Result: 1

    Running the equivalent command manually works just fine:
    /root/CCM/src/protobuf/asf/*.proto
    /root/protoc/bin/protoc --java_out=/root/CCM/srcProtobufJava/
    --proto_path=/root/CCM/src/protobuf/asf /root/CCM/src/protobuf/asf/*.proto

    (It silently compiles a set of Google Protobuf files.) I originally set
    the executable to "/bin/sh" and the protoc command was the first arg,
    which you can see commented out above. With this arrangement, the exec
    task failed saying "cannot execute binary file" for protoc. Where have I
    gone wrong here?
    Wild cards like /root/CCM/src/protobuf/asf/*.proto are expanded by the
    shell in unix type o/s's. When you took out the /bin/sh you no longer
    get this expanded. It works when you run it from the command line
    because you are giving the command to the shell and it expands the
    wildcard for you.

    --

                     --Steve

    "The world is a dangerous place to live; not because of the people who are
    evil, but because of the people who don't do anything about it. "
                     --Albert Einstein.

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Chris Barlock at Apr 14, 2015 at 7:22 pm
    Thank you, Steve. If I make the executable="/bin/sh" and uncomment the
    protoc command, I get:

    parsing buildfile
    jar:file:/usr/apache-ant-1.9.4/lib/ant.jar!/org/apache/tools/ant/antlib.xml
    with URI =
    jar:file:/usr/apache-ant-1.9.4/lib/ant.jar!/org/apache/tools/ant/antlib.xml
    from a zip file
         [mkdir] Skipping /root/CCM/srcProtobufJava because it already exists.
         [chmod] Executing 'chmod' with arguments:
         [chmod] '755'
         [chmod] '/root/protoc/bin/protoc'
         [chmod]
         [chmod] The ' characters around the executable and arguments are
         [chmod] not part of the command.
         [chmod] Applied chmod to 1 file and 0 directories.
          [exec] Current OS is Linux
          [exec] Setting environment variable: LD_LIBRARY_PATH=/root/protoc/lib
          [exec] Executing '/bin/sh' with arguments:
          [exec] '/root/protoc/bin/protoc'
          [exec] '--java_out=/root/CCM/srcProtobufJava'
          [exec] '--proto_path=/root/CCM/src/protobuf/asf'
          [exec] '/root/CCM/src/protobuf/asf/*.proto'
          [exec]
          [exec] The ' characters around the executable and arguments are
          [exec] not part of the command.
          [exec] /root/protoc/bin/protoc: /root/protoc/bin/protoc: cannot
    execute binary file
          [exec] Result: 126

    Thoughts?

    Chris

    From: Steve Schlaifer <steve@jetcafe.org>
    To: Ant Users List <user@ant.apache.org>
    Date: 04/14/2015 03:15 PM
    Subject: Re: Exec Task Problem on Linux


    On Tue, Apr 14, 2015 at 02:35:03PM -0400, Chris Barlock wrote:
    I have the following Ant script:

    <project name="build" default="all" basedir=".">
    <target name="all">
    <property name="srcDir" value="/root/CCM/src"/>
    <property name="srcProtobufJavaDir"
    value="/root/CCM/srcProtobufJava"/>
    <property name="prereqToolsDir" value="/root/protoc"/>
    <mkdir dir="${srcProtobufJavaDir}"/>
    <chmod file="${prereqToolsDir}/bin/protoc" perm="755"/>
    <exec executable="${prereqToolsDir}/bin/protoc">
    <!-- <arg value="${prereqToolsDir}/bin/protoc"/> -->
    <arg value="--java_out=${srcProtobufJavaDir}"/>
    <arg value="--proto_path=${srcDir}/protobuf/asf"/>
    <arg value="${srcDir}/protobuf/asf/*.proto"/>
    <env key="LD_LIBRARY_PATH" value="${prereqToolsDir}/lib"/>
    </exec>
    </target>
    </project>

    When I run this, I get:

    [root@nc9042036240 ~]# /usr/apache-ant-1.9.4/bin/ant -v -f build.xml
    Apache Ant(TM) version 1.9.4 compiled on April 29 2014
    Buildfile: /root/build.xml
    Detected Java version: 1.7 in:
    /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64/jre
    Detected OS: Linux
    parsing buildfile /root/build.xml with URI = file:/root/build.xml
    Project base dir set to: /root
    Build sequence for target(s) `all' is [all]
    Complete build sequence is [all, ]

    all:
    parsing buildfile
    jar:file:/usr/apache-ant-1.9.4/lib/ant.jar!/org/apache/tools/ant/antlib.xml
    with URI =
    jar:file:/usr/apache-ant-1.9.4/lib/ant.jar!/org/apache/tools/ant/antlib.xml
    from a zip file
    [mkdir] Skipping /root/CCM/srcProtobufJava because it already exists.
    [chmod] Executing 'chmod' with arguments:
    [chmod] '755'
    [chmod] '/root/protoc/bin/protoc'
    [chmod]
    [chmod] The ' characters around the executable and arguments are
    [chmod] not part of the command.
    [chmod] Applied chmod to 1 file and 0 directories.
    [exec] Current OS is Linux
    [exec] Setting environment variable:
    LD_LIBRARY_PATH=/root/protoc/lib
    [exec] Executing '/root/protoc/bin/protoc' with arguments:
    [exec] '--java_out=/root/CCM/srcProtobufJava'
    [exec] '--proto_path=/root/CCM/src/protobuf/asf'
    [exec] '/root/CCM/src/protobuf/asf/*.proto'
    [exec]
    [exec] The ' characters around the executable and arguments are
    [exec] not part of the command.
    [exec] /root/CCM/src/protobuf/asf/*.proto: No such file or directory
    [exec] Result: 1

    Running the equivalent command manually works just fine:
    /root/CCM/src/protobuf/asf/*.proto
    /root/protoc/bin/protoc --java_out=/root/CCM/srcProtobufJava/
    --proto_path=/root/CCM/src/protobuf/asf
    /root/CCM/src/protobuf/asf/*.proto
    (It silently compiles a set of Google Protobuf files.) I originally set
    the executable to "/bin/sh" and the protoc command was the first arg,
    which you can see commented out above. With this arrangement, the exec
    task failed saying "cannot execute binary file" for protoc. Where have I
    gone wrong here?
    Wild cards like /root/CCM/src/protobuf/asf/*.proto are expanded by the
    shell in unix type o/s's. When you took out the /bin/sh you no longer
    get this expanded. It works when you run it from the command line
    because you are giving the command to the shell and it expands the
    wildcard for you.

    --

                     --Steve

    "The world is a dangerous place to live; not because of the people who are
    evil, but because of the people who don't do anything about it. "
                     --Albert Einstein.

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Earl Hood at Apr 14, 2015 at 8:05 pm

    On Tue, Apr 14, 2015 at 2:21 PM, Chris Barlock wrote:
    Thank you, Steve. If I make the executable="/bin/sh" and uncomment the
    protoc command, I get:
    You need the -c option to /bin/sh to indicate it should execute the command
    that follows on the argument list.

    --ewh

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Chris Barlock at Apr 14, 2015 at 8:29 pm
    Earl, thank you again! Should have remembered that...

    This gets me closer, but protoc doesn't think I specified any input files.
      Perhaps this is now a question for the Google Protobuf forums!

    Chris




    From: Earl Hood <earlhood@gmail.com>
    To: Ant Users List <user@ant.apache.org>
    Date: 04/14/2015 04:06 PM
    Subject: Re: Exec Task Problem on Linux


    On Tue, Apr 14, 2015 at 2:21 PM, Chris Barlock wrote:
    Thank you, Steve. If I make the executable="/bin/sh" and uncomment the
    protoc command, I get:
    You need the -c option to /bin/sh to indicate it should execute the
    command
    that follows on the argument list.

    --ewh

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Steve Schlaifer at Apr 14, 2015 at 8:39 pm

    On Tue, Apr 14, 2015 at 03:04:28PM -0500, Earl Hood wrote:
    On Tue, Apr 14, 2015 at 2:21 PM, Chris Barlock wrote:
    Thank you, Steve. If I make the executable="/bin/sh" and uncomment the
    protoc command, I get:
    You need the -c option to /bin/sh to indicate it should execute the command
    that follows on the argument list.
    To expand on that a little,

        /bin/sh <something>

    expects that <something> is a text file with a set of shell commands in
    it to be interpreted and executed by sh. This is somewhat simplified
    since the first line could tell sh to use some other program to
    interpret and execute the rest of the file but for our purposes, the
    simplification is OK. If <something> is a binary executable then you
    get various interesting error messages that essentially mean it wasn't
    what sh was looking for. sh then fails and ant reports the error you
    got. By putting -c before <something> you tell /bin/sh that <something>
    is an executable file that should be executed directly. That's what you
    would want for the original problem but apply is much cleaner.

    --

                  --Steve

          "It must not be forgotten that it is especially dangerous
          to enslave men in the minor details of life." Alexis de Tocqueville

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Earl Hood at Apr 14, 2015 at 7:19 pm

    On Tue, Apr 14, 2015 at 1:35 PM, Chris Barlock wrote:

    I have the following Ant script: ...
    <arg value="${srcDir}/protobuf/asf/*.proto"/>
    Glob expansion is a shell function, hence the error you are getting
    since the file "*.proto" does not exist.

    Have a look at <apply>. It supports filesets.

    --ewh

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Chris Barlock at Apr 14, 2015 at 7:44 pm
    Thank you, Earl. Was not aware of apply. That worked nicely! I would
    love to understand why exec does not work, though, when the executable is
    "/bin/sh" and the protoc command is the first arg.

    Chris




    From: Earl Hood <earlhood@gmail.com>
    To: Ant Users List <user@ant.apache.org>
    Date: 04/14/2015 03:20 PM
    Subject: Re: Exec Task Problem on Linux


    On Tue, Apr 14, 2015 at 1:35 PM, Chris Barlock wrote:

    I have the following Ant script: ...
    <arg value="${srcDir}/protobuf/asf/*.proto"/>
    Glob expansion is a shell function, hence the error you are getting
    since the file "*.proto" does not exist.

    Have a look at <apply>. It supports filesets.

    --ewh

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Stefan Bodewig at Apr 18, 2015 at 8:34 pm
    [pretty impressive build setup, kudos]
    On 2015-04-14, Stranzenbach, Ralf wrote:

    <target name="clean" depends="-clean" />
    <extension-point name="-clean" />
    <target name="recompile" depends="-recompile" />
    <extension-point name="-recompile" depends="-clean, -compile" /> ...
    <target name="recompile-clean" extensionOf="-clean" if="is.Recompile" >
    <echo>Additional behaviour for recompile</echo>
    </target>
    <target name="-recompile-switch">
    <property name="is.Recompile" value="true" />
    </target>

    Before I go into Java options, none of them nice, couldn't you add a
    dependency to "-clean" that was an (empty) extensionPoint itself and
    make "-recompile-switch" and extension of that extensionPoint?

    Now my question(s):
    ================
    Are there any ways to define the order of execution to guarantee an
    optional task just like "-recompile-switch" to execute at the right
    moment?
    Maybe, but not in a nice way.

    After figuring out the dependency graph Ant prepares an array of target
    names and passes them to the registered Executor instance - by default
    org.apache.ant.helpers.DefaultExecutor. You could replace it with an
    executor of your own (by setting the property ant.executor.class when
    starting Ant), inject your switch target and delegate to
    DefaultExecutor. Of course this would be a one-off solutions, but at
    least you don't need the overhead of antcall.

    The actual graph building happens in Project's topoSort method

    \begin{digression}
    This actually answers your second question
    Is there any way using the Java API to the ANT core to inspect the
    execution graph?
    project.topoSort(targetsInvokedOnCommandLine, project.getTargets(), false)

    should work.
    \end{digression}

    Unfortunately we are making it pretty difficult to inject a Project
    implementation of your own, it is hard coded in Ant's Main. This means
    if you simply wanted to override topoSort you'd not only need subclass
    of Project but your own implementation of AntMain as well.
    Unfortunately it is impossible to manipulate the execution graph at
    runtime, conditionally <import>ing different extesions.
    I don't think this is completely true. <import> is a task itself, it
    uses some support in Ant's ProjectHelper but you can write a task of
    your own that performs the same actions. Whether you could
    conditionally imprt different extensions depends on what you'd want
    to base your decision on. It would work for anything that is fixed at the
    point in time when Ant parses the build file. This includes properties,
    but unfortunately it does not include the targets specified at the
    command line (they are fixed, but there is no way to know them in a top
    level task).

    If the aditional dependency extensionPoint doesn't work, the most clean
    solution would be a custom Project and AntMain - but it would also imply
    quite a bit of work.

    Stefan

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Parag Doke at May 22, 2015 at 7:51 am
    If you download
    https://github.com/downloads/ggtools/GrandUI/grand-ui-0.7.2.tar.gz, unzip,
    replace ant.jar and ant-launcher.jar with updated jars ... and then launch
    the bat file on Windows with a 32 bit JRE, it will render a visual for you
    (including extension points).

    I was also working on something similar a short while back ... and simply
    decided to use the depends attribute.
    For example:
    <extension-point name="-jar" depends="compile"/>

    <target name="module.specific.jar" extensionOf="-jar"
    depends="another.jar.target">
    ...
    </target>


    Parag Doke
    Save paper, save trees. Do not print emails/documents unless absolutely
    necessary.
    On Sun, Apr 19, 2015 at 1:21 AM, Stefan Bodewig wrote:

    [pretty impressive build setup, kudos]
    On 2015-04-14, Stranzenbach, Ralf wrote:

    <target name="clean" depends="-clean" />
    <extension-point name="-clean" />
    <target name="recompile" depends="-recompile" />
    <extension-point name="-recompile" depends="-clean, -compile" /> ...
    <target name="recompile-clean" extensionOf="-clean"
    if="is.Recompile" >
    <echo>Additional behaviour for recompile</echo>
    </target>
    <target name="-recompile-switch">
    <property name="is.Recompile" value="true" />
    </target>

    Before I go into Java options, none of them nice, couldn't you add a
    dependency to "-clean" that was an (empty) extensionPoint itself and
    make "-recompile-switch" and extension of that extensionPoint?

    Now my question(s):
    ================
    Are there any ways to define the order of execution to guarantee an
    optional task just like "-recompile-switch" to execute at the right
    moment?
    Maybe, but not in a nice way.

    After figuring out the dependency graph Ant prepares an array of target
    names and passes them to the registered Executor instance - by default
    org.apache.ant.helpers.DefaultExecutor. You could replace it with an
    executor of your own (by setting the property ant.executor.class when
    starting Ant), inject your switch target and delegate to
    DefaultExecutor. Of course this would be a one-off solutions, but at
    least you don't need the overhead of antcall.

    The actual graph building happens in Project's topoSort method

    \begin{digression}
    This actually answers your second question
    Is there any way using the Java API to the ANT core to inspect the
    execution graph?
    project.topoSort(targetsInvokedOnCommandLine, project.getTargets(), false)

    should work.
    \end{digression}

    Unfortunately we are making it pretty difficult to inject a Project
    implementation of your own, it is hard coded in Ant's Main. This means
    if you simply wanted to override topoSort you'd not only need subclass
    of Project but your own implementation of AntMain as well.
    Unfortunately it is impossible to manipulate the execution graph at
    runtime, conditionally <import>ing different extesions.
    I don't think this is completely true. <import> is a task itself, it
    uses some support in Ant's ProjectHelper but you can write a task of
    your own that performs the same actions. Whether you could
    conditionally imprt different extensions depends on what you'd want
    to base your decision on. It would work for anything that is fixed at the
    point in time when Ant parses the build file. This includes properties,
    but unfortunately it does not include the targets specified at the
    command line (they are fixed, but there is no way to know them in a top
    level task).

    If the aditional dependency extensionPoint doesn't work, the most clean
    solution would be a custom Project and AntMain - but it would also imply
    quite a bit of work.

    Stefan

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriesant
postedApr 14, '15 at 8:51a
activeMay 22, '15 at 7:51a
posts11
users6
websiteant.apache.org

People

Translate

site design / logo © 2018 Grokbase