You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Andreas Sewe <an...@buildingblobs.com> on 2020/08/06 16:18:44 UTC

Namespace-aware alternative to @Parameter PlexusConfiguration

Hi,

I am writing a Maven plugin (for XQuery) whose <configuration> should
allow variables to be bound to XML fragments. Moreover, the variable
names are XML QNames (like all names in XQuery), i.e., (URI, String) pairs.

An example:

  <configuration>
    <variables
        xmlns:local="http://www.w3.org/2005/xquery-local-functions"
        xmlns:html="http://www.w3.org/1999/xhtml/">
      <local:fragment>
        <html:strong>Some element</html:strong>
      </local:fragment>
    </variables>
  </configuration>

The above should bind the <html:strong> element to the QName of
("http://www.w3.org/2005/xquery-local-functions", "fragment"), as
specified in the query's prolog:

  declare variable local:fragement as element() external;

Now the question is how to get access to the DOM below my mojo's
<variables> parameter.

From the maven-antrun-plugin's <target> parameter [1], I figured out
that I can use the following:

   @Parameter
   PlexusConfiguration variables;

But this has two shortcomings:

- The element-attribute tree I get isn't aware of namespaces

- And I cannot navigate the XML to <variables> parent in order to work
around this by looking for xmlns attributes on ancestor elements myself.

Granted, PlexusConfiguration does at least allow my to implement the
above example (albeit with manually implemented namespace handling), but
it lacks proper namespace-awareness, as I cannot do the following:

  <configuration
     xmlns:local="http://www.w3.org/2005/xquery-local-functions"
     xmlns:html="http://www.w3.org/1999/xhtml/">
    <variables
      <local:fragment>
        <html:strong>Some element</html:strong>
      </local:fragment>
    </variables>
  </configuration>

Not the best example, but moving the namespace-declarations upwards has
its uses, e.g., all the way to the <project> element to cover multiple
<variables> configuration elements.

So, does there exist some kind of escape-hatch like the following:

   @Parameter
   XmlDom variables;

The <project> element itself is in a namespace, after all, so maybe
Maven is internally namespace-aware.

Best wishes,

Andreas

[1]
<https://github.com/apache/maven-antrun-plugin/blob/master/src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java#L200>