ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "none ofyourbusiness" <>
Subject Creating a task for getting the current target in a project
Date Mon, 23 Jan 2006 14:24:00 GMT

In our ant script we do an antcall at a certain moment. This antcall call's 
another xml ant script with a specific target. This called xml ant script 
contains a project with mulitple targets, and outside those targets, it also 
checks for the availability of certain 3th party jars and puts there path in 

This all works very well for most targets (fe: build, compile, pre-compile, 
etc), but for some targets (fe package and clean) these 3th party jars are 
not required. This causes these 2 targets to fail...

Thats why we would like to make these dependancies optional for these 2 
targets. We would like check for the availibilty of these jars only if the 
target is something else then "clean" or "package"

so first i looked for a system property that gives the current target, but 
that doesnt seem to exist. After this i tried making a task for this myself, 
but i couldnt get it working...

I hope someone of you could help me with this...

I tried using following methods:

--> works, but only when the task is called in the target itself
since we need it outside the target, this method is useless

--> allways gives back value null

--> result isnt null, but a toString() of the target results gives ""

So i didnt achieve much... :/

below you can find a copy of the source that ive been playing around with:

package com.eds.ant.taskdefs;


public class CurrentTarget extends Task {

	private String addproperty = null;

     * Defines the name of a property to be created from input. Behaviour is
     * according to property task which means that existing properties
     * cannot be overridden.
     * @param addproperty Name for the property to be created from input
    public void setAddproperty(String addproperty) {
        this.addproperty = addproperty;

     * Actual method executed by ant.
     * @throws BuildException on error
    public void execute() throws BuildException {
		if (addproperty == null || "".equals(addproperty.trim()))
			throw new BuildException("Property 'addproperty' was not set.");
		Project project = getProject();
		AntXMLContext context = (AntXMLContext) 
		context = new AntXMLContext(project);
		System.out.println(context.toString()); target1 = context.getImplicitTarget(); target2 = context.getCurrentTarget(); target3 = getOwningTarget();
		String value = null;
		if (target1 != null) {
			value = target1.toString();
			System.out.println("getimptar isnt empty " + value);
		} else {
			System.out.println("getimptar is empty");
		if (target2 != null) {
			value = target2.toString();
			System.out.println("getcurtar isnt empty " + value);
		} else {
			System.out.println("getcurtar is empty");
		if (target3 != null) {
			value = target3.toString();
			System.out.println("getowntar isnt empty " + value);
		} else {
			System.out.println("getowntar is empty");

        if (addproperty != null && value != null) {
            getProject().setNewProperty(addproperty, value);


Bescherm je Inbox: Phishing - hoe te herkennen, rapporteren en voorkomen

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message