You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Daniel Barclay <Da...@digitalfocus.com> on 2001/05/01 17:41:25 UTC

idea: subelements in addition to attributes to allow using entities

For Ant2, have you all considered allowing using subelements (in addition 
to attributes) to specify scalar task options?


I wanted to define a group of javac options in one place and use the group
in multiple javac tasks. 

(I wanted to be able to define one group that contained various options, 
so that an additional option could be added to the group without having 
to edit all the task instances.  I didn't really want to have a set of 
properties, one property per option, and have to edit all the task instances 
if I added a new option to the set.)


I can't use properties like this:

  someProp=debug="off" deprecation="on"

  ...
  <javac ${someprop} ... />

since property substitution happens way after XML parsing.


I thought about using an XML entity, but I can't do this:

  <!DOCTYPE whatever [
    <!ENTITY myOptions 'debug="off" deprecation="on"'>
  ]>
  ...
  <javac &myOptions; ... />

because entity references are not allowed at that level in tags. 


If javac task options could be configured with subelements, then
I could do this:

  <!DOCTYPE whatever [
    <!ENTITY myOptions '<debug>off<debug> </deprecation>on</deprecation>'>
  ]>
  ...
  <javac ...>
    &myOptions;
  </javac>

Unfortunately, I can't do that for most task options, because they can
be set only via attributes.


In your redesign for Ant2, could you consider automatically allowing
nested elements as an alternative for any attributes defined for a 
task?


At a higher level (requirements vs. a particular solution), could
you think about how to support bundled options?

This main options I can think of are:
- allowing nested elements whose names match already-defined attribute 
  names
- having a special attribute whose XML string value is a list of
  attribute names and values e.g. (<javac ... special='${myOptions}' ... />)

Nested elements might also allow for defaulting and overriding, something
like this:

  <javac ...>
    &projectJavacMiscFlags;		<!-- apply any misc. flags ... -->
    <debug>on<\debug>			<!-- ... but force debugging on,
                                             even if previously set -->
  </javac>



(Such nested elements that are just alternatives for attribute could be
grouped under some other element if segregated nested elements would be 
better, e.g.:

  <javac ...>
    <something>
      &projectJavacMiscFlags;		
      <debug>on<\debug>			
    <something>
    ...currently-defined nested elements...
  </javac>

)


(By the way, can Ant's XML parser process DTDs enough to apply DTD-defined 
default attribute values without doing full validation?)



Thanks,
Daniel
-- 
Daniel Barclay
Digital Focus
Daniel.Barclay@digitalfocus.com

Re: idea: subelements in addition to attributes to allow using entities

Posted by Peter Donald <do...@apache.org>.
I think what you want to do will be provided - just not by the mechanisms
you describe ;) The main way we have discussed doing it is via
templating/styling. One approach would be to use CSS stylesheets to
"render" the default attributes for each task. Alternatively you could run
the file through some sort of transformer/templating language (ie xslt or
velocity)  to get same sort of funcitonality.

Cheers,

Pete

*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof."                   |
|              - John Kenneth Galbraith               |
*-----------------------------------------------------*