The AntXMLContext stores the id-object pair in the project instance via public void configureId(Object element, Attributes attr) { String id = attr.getValue("id"); if (id != null) { project.addIdReference(id, element); } }
In the Projct class this is stored in a HashMap /** Map of id references - used for indicating broken build files */ private final HashMap<String, Object> idReferences = new HashMap<>(); public void addIdReference(final String id, final Object value) { idReferences.put(id, value); } But I haven't found a place where this private field is read... Jan > -----Ursprüngliche Nachricht----- > Von: Jan Matèrne (jhm) [mailto:apa...@materne.de] > Gesendet: Dienstag, 29. Oktober 2019 08:48 > An: 'Ant Developers List' > Betreff: AW: Script task specification > > I placed some system-outs in the parsing code. > The parsing is done by ProjectHelper2. Id is stored via AntXMLContext to > the "UnknownElement". > > C:\projekte\apache-ant-svn\sandbox\script>ant > Buildfile: C:\projekte\apache-ant-svn\sandbox\script\build.xml > PH2.ElemeentHandler.onStartElement tag=echo taskname=echo > AntXMLContext.configureId > element=org.apache.tools.ant.UnknownElement@1f89ab83 id=foo > PH2.ElemeentHandler.onStartElement tag=script taskname=script > AntXMLContext.configureId > element=org.apache.tools.ant.UnknownElement@383534aa id=null > > > main: > [script] PH2.ElemeentHandler.onStartElement tag=antlib > taskname=antlib > [script] AntXMLContext.configureId > element=org.apache.tools.ant.UnknownElement@50cbc42f id=null > [script] PH2.ElemeentHandler.onStartElement tag=componentdef > taskname=componentdef > ... more element definitions ... > > BUILD FAILED > C:\projekte\apache-ant-svn\sandbox\script\build.xml:9: > org.mozilla.javascript.EcmaError: ReferenceError: "foo" is not defined. > > > > Jan > > > > -----Ursprüngliche Nachricht----- > > Von: Jan Matèrne (jhm) [mailto:apa...@materne.de] > > Gesendet: Dienstag, 29. Oktober 2019 08:03 > > An: 'Ant Developers List' > > Betreff: AW: Script task specification > > > > It seems that the task must be executed before. > > If you add a >depends="sub"< on the main target, that works. > > > > So the question is: when are id's stored? > > The parsing is done via ProjectHelper's and their SAX-Parser-Handlers. > > On the first view I would say, that the id is stored while parsing - > > so before exucution. > > > > > > Jan > > > > > -----Ursprüngliche Nachricht----- > > > Von: Gintautas Grigelionis [mailto:g.grigelio...@gmail.com] > > > Gesendet: Montag, 28. Oktober 2019 14:25 > > > An: Ant Developers List > > > Betreff: Script task specification > > > > > > The documentation of the script task states: > > > > > > "All items (tasks, targets, etc) of the running project are > > > accessible from the script, using either their name or id attributes > > > (as long as their names are considered valid Java identifiers, that > is). " > > > > > > However, the following fails: > > > > > > <?xml version="1.0"?> > > > <project name="test" default="main" basedir="."> > > > <target name="sub"> > > > <echo id="foo">Executing a task</echo> > > > </target> > > > > > > <!-- tests the script stuff --> > > > <target name="main"> > > > <script language="javascript"><![CDATA[ > > > foo.setMessage("I'm a foo!") > > > sub.execute() > > > ]]></script> > > > </target> > > > </project> > > > > > > Surely there are more limitations? Besides, failure modes are > > > different in Rhino (unable to create engine) and Nashorn (reference > > not defined). > > > > > > Regards, > > > Gintas > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: dev-unsubscr...@ant.apache.org For additional > > commands, e-mail: dev-h...@ant.apache.org > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@ant.apache.org For additional > commands, e-mail: dev-h...@ant.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@ant.apache.org For additional commands, e-mail: dev-h...@ant.apache.org