hi,

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 properties.

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:

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

getCurrentTarget
--> allways gives back value null

getImplicitTarget
--> 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;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.helper.AntXMLContext;

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();
                System.out.println(project.toString());
AntXMLContext context = (AntXMLContext) project.getReference("ant.parsing.context");
                context = new AntXMLContext(project);
                System.out.println(context.toString());
                org.apache.tools.ant.Target target1 = 
context.getImplicitTarget();
                org.apache.tools.ant.Target target2 = 
context.getCurrentTarget();
                org.apache.tools.ant.Target 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");
                }

                System.out.println(value);
       if (addproperty != null && value != null) {
           getProject().setNewProperty(addproperty, value);
       }
   }

}

_________________________________________________________________
Bescherm je Inbox: Phishing - hoe te herkennen, rapporteren en voorkomen http://www.msn.be/security/phishing/


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to