Ant - Run the target at the end of each assembly

Is there a way to always run the target at the end of each build?

I know I can do something like this ...

<target name="runJob" depends="actuallyRunJob, teardown"/>

... but this is messy, because I need a shell for every goal that needs a break.

Any ideas?

Thanks Roy

+5
source share
4 answers

buildlistener, .. exec-listener, taskcontainer
(BUILD SUCCESSFUL | BUILD FAILED),
. exec Ant
, . =
http://ant.apache.org/manual/develop.html
api docs ant=
$ ANT_HOME///API//Apache// ant/BuildListener.html

+4

, Rebse, BuildListener Javascript ( Ant - makefile):

<project name="test-ant" default="build">                                                           

<target name="init">                                                                            
    <script language="javascript"> <![CDATA[                                                    
        function noop () {}                                                                     
        var listener = new org.apache.tools.ant.BuildListener() {                               
            buildFinished: function(e) {                                                        
                project.executeTarget("_finally");                                              
            },                                                                                  
            buildStarted: noop,                                                                 
            messageLogged: noop,                                                                
            targetStarted: noop,                                                                
            targetFinished: noop,                                                               
            taskStarted: noop,                                                                  
            taskFinished: noop                                                                  
        }                                                                                       
        project.addBuildListener(listener)                                                      
    ]]></script>                                                                                
</target>                                                                                       

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

<target name="fail" depends="init">                                                             
    <fail message="expected failure"/>                                                          
</target>                                                                                       

<target name="_finally">                                                                        
    <echo message="executing _finally target..."/>                                              
</target>                                                                                       

</project>

, .

+1

, :

<!-- a task that executes the embedded sequential element at the end of the build,
    but only if the nested condition is true; in this case, we're dumping out the
    properties to a file but only if the target directory exists (otherwise, the clean
    target would also generate the file and we'd never really be clean!) -->
<build:whendone>
    <condition>
        <available file="${project_target-dir}" />
    </condition>
    <sequential>
        <mkdir dir="${project_final-build-properties-file}/.." />
        <echoproperties destfile="${project_final-build-properties-file}" />
    </sequential>
</build:whendone>

Ant, , ( , ).

, , , Ant Task, SubBuildListener, buildFinished(BuildEvent). , , true, sequential.

, .

0

, " -post-build" "build.xml". .

0

All Articles