ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wolfgang Häfelinger <whaefelin...@epo.org>
Subject Re: how to access a MacroDef?
Date Wed, 07 Jun 2006 12:30:03 GMT
Hmm, I have seen that project.createTask() does more or less the same as I 
do. However,
I do not understand what caching my task and invalidation means. Perhaps I 
do not to care
about it anyway.

Another thing I tried is to call my macro or task with attributes. I got 
it working for macros:

        <macrodef name="atest">
          <attribute name="foo" />
        <sequential>
           <echo>This is the atest macro where foo = @{foo}</echo>
        </sequential>
      </macrodef>

        atest = project.createTask("atest");
      if (! (atest instanceof MacroInstance)) {
         throw new BuildException("atest is not a macro");
      }
      MacroInstance inst = (MacroInstance)atest;
      inst.setDynamicAttribute("foo",bar");
      atest.execute();

I tried then something similar for (ordinary?) tasks without success. 
That's what I
want to do be able to do:

 <run-macro name="echo">
   <arg name="message" value="hello" />
 </run-macro>

I implemented this somehow like

task = project.createTask("echo");
if (task instanceof MacroInstance)
{
   ..
}
else
{
  /* call echo with attribute message */
  RuntimeConfigurable rtc = task.getRuntimeConfigurableWrapper();
  rtc.setAttribute("message","hello");
}
task.execute();
 
I can see that indeed echo is called but it's being called without
my arguments.

Any hint on this as well?

Wolfgang.






"Peter Reilly" <peter.kitt.reilly@gmail.com> 
07-06-2006 12:20
Please respond to
"Ant Developers List" <dev@ant.apache.org>


To
"Ant Developers List" <dev@ant.apache.org>
cc

Subject
Re: how to access a MacroDef?






Since macro defs are tasks, it would be better to use the
project.createTask() method, and not try to use the
internal (although exposed trough the public classes and methods)
mechanizes of Ant.

    <macrodef name="atest">
        <sequential>
           <echo>This is the atest macro</echo>
        </sequential>
    </macrodef>

    <script language="beanshell">
       import org.apache.tools.ant.taskdefs.MacroInstance;
       import org.apache.tools.ant.BuildException;
       atest = project.createTask("atest");
       if (! (atest instanceof MacroInstance)) {
           throw new BuildException("atest is not a macro");
       }
       atest.execute();

    </script>

It would be necessary to call setOwningTarget as project.createTask()
does not know the current target.

Peter


On 6/7/06, Wolfgang Häfelinger <whaefelinger@epo.org> wrote:
>
> Allright, it appears much more easier than expected.
>
> ComponentHelper componenthelper;
> Object obj;
> MacroInstance instance;
>
> componenthelper = ComponentHelper.getComponentHelper(project());
> obj             = componentHelper.createComponent(mymacroname);
> instance        = (MacroInstance)obj;
> instance.execute();
>
> Appears that there's no need to call setProject() or setOwningTarget() 
on
> the macro's
> instance.
>
> However, not sure whether this is the "right" way to do. Perhaps Peter 
can
> comment
> on this.
>
> Thanks for all help so far.
>
> Wolfgang.
>
>
>
>
> "Dominique Devienne" <ddevienne@gmail.com>
> 06-06-2006 19:41
> Please respond to
> "Ant Developers List" <dev@ant.apache.org>
>
>
> To
> "Ant Developers List" <dev@ant.apache.org>
> cc
>
> Subject
> Re: how to access a MacroDef?
>
>
>
>
>
>
> > I tried something like
> >
> >  ComponentHelper componenthelper =
> > ComponentHelper.getComponentHelper(project());
> >  MacroDef def = (MacroDef)
> > componenthelper.getTaskDefinitions().get(mymacroname);
> >
> > just in order to understand that Hastable getTaskDefinitions() 
contains
> a
> > String => Class relation.
> >
> > So where are those MacroDef's hidden?
>
> So your 'def' is null, right?
>
> Try not casting it to MacroDef, and see which kind of Java Class is
> returned, if any. It may be an UnknownElement (my guess), a
> MacroInstance, etc...
>
> From the UE, you may be able to get a MacroInstance or a MacroDef, and
> if the later, configure it into a MacroInstance, which is what you
> want to run.
>
> I vaguely know this code only. Peter's the expert. --D
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>



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


Mime
View raw message