Bug 17973 - A <final> target just like a <init> target
Summary: A <final> target just like a <init> target
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.2
Hardware: All other
: P3 enhancement with 3 votes (vote)
Target Milestone: 1.6.3
Assignee: Ant Notifications List
URL:
Keywords:
: 18402 19259 22651 24761 28620 32178 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-03-13 20:25 UTC by Ashwani
Modified: 2008-02-22 12:18 UTC (History)
7 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ashwani 2003-03-13 20:25:55 UTC
I have a requirement where I need to delink my symbolic links before my build,
and then link them back again at the end end of the successful build. In
addition to the linking, I also need to cleanup the environment everytime to
remove temporary files etc. 

It is very difficult and tedious to use depends or antcall in all the targets,
especially went the build files are spread around various projects. 

A final target in the build script would be best to allow such cleanup after the
build.
Comment 1 Jesse Stockall 2003-04-23 20:08:08 UTC
*** Bug 19259 has been marked as a duplicate of this bug. ***
Comment 2 Jan Mat 2003-08-22 07:40:42 UTC
*** Bug 22651 has been marked as a duplicate of this bug. ***
Comment 3 Jan Mat 2003-09-05 16:14:18 UTC
*** Bug 18402 has been marked as a duplicate of this bug. ***
Comment 4 Jan Mat 2003-11-18 07:52:20 UTC
*** Bug 24761 has been marked as a duplicate of this bug. ***
Comment 5 Glenn Opdycke-hansen 2003-11-18 14:51:18 UTC
If this Bug 24761 is marked as a dup of this bug, then I have a requirement 
that this fix includes a property that is set if a the build has failed prior 
to calling the <final> target. 
 
--glenn opdycke-hansen 
Comment 6 Jan Mat 2004-04-27 10:47:50 UTC
*** Bug 28620 has been marked as a duplicate of this bug. ***
Comment 7 Matt Benson 2005-05-26 18:51:49 UTC
*** Bug 19259 has been marked as a duplicate of this bug. ***
Comment 8 Matt Benson 2005-05-26 19:14:33 UTC
In the current version of Ant you can create your own target Executor. Actually,
I've written it for you:

import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.helper.DefaultExecutor;

/**
 * Executor that runs a final target.
 */
public class FinalTargetExecutor extends DefaultExecutor {
    public void executeTargets(Project project, String[] targetNames)
        throws BuildException {
        BuildException be = null;
        try {
            super.executeTargets(project, targetNames);
        } catch (BuildException e) {
            be = e;
        } finally {
            String ft = project.getProperty("finaltarget");
            if (ft != null) {
                try {
                    project.executeTarget(ft);
                } catch (BuildException e) {
                    project.log(e.getMessage());
                }
            }
            if (be != null) {
                throw be;
            }
        }
    }
}

all you have to do is set the property "finaltarget" to whatever target name you
want called.  As usual, this can be set inside the buildfile or overridden from
the command line.  Feel free to modify this to suit your needs.
Comment 9 Matt Benson 2005-05-26 19:17:51 UTC
There is a blurb about executors at "Running Ant" -> "Java System Properties" in
the manual.  You simply use -Dant.executor.class=classname to set it.
Comment 10 Matt Benson 2005-05-26 22:46:16 UTC
*** Bug 32178 has been marked as a duplicate of this bug. ***