Skip to content

need ways to generate both xs:sequence and xs:attribute into a same xs:complexType, for maven #482

Closed

Description

@XenoAmess

@slachiewicz
Hi.
In maven we need such grammar like:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>acm_test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>acm_test</name>

    <properties>
        <maven.compiler.source>23</maven.compiler.source>
        <maven.compiler.target>23</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-plugin-plugin</artifactId>
                <configuration>
                    <goalPrefix combine.self="override"/>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.1</version>
                <configuration combine.self="override">
                    <goals>deploy</goals>
                    <localCheckout>true</localCheckout>
                    <mavenExecutorId>forked-path</mavenExecutorId>
                    <tagNameFormat>${reactor.name}-@{project.version}</tagNameFormat>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.scm</groupId>
                        <artifactId>maven-scm-provider-hg</artifactId>
                        <version>1.9.2</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.maven.scm</groupId>
                        <artifactId>maven-scm-provider-gitexe</artifactId>
                        <version>1.9.2</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

</project>

please focuse on the <configuration combine.self="override"> part.

so we need the output xsd be:

    <xs:complexType>
      <xs:sequence>
        <xs:any minOccurs="0" maxOccurs="unbounded" processContents="skip"/>
      </xs:sequence>
      <xs:attribute name="combine.children" type="xs:string" use="optional">
  <xs:annotation>
    <xs:documentation source="version">4.0.0+</xs:documentation>
    <xs:documentation source="description">
        
        {@code combine.children}: available values are {@code merge} (default) and {@code append}.
        @see &amp;lt;a href=&amp;quot;https://maven.apache.org/pom.html#Plugins&amp;quot;&amp;gt;POM Reference documentation&amp;lt;/a&amp;gt;
        @see &amp;lt;a href=&amp;quot;https://codehaus-plexus.github.io/plexus-utils/apidocs/org/codehaus/plexus/util/xml/Xpp3DomUtils.html&amp;quot;&amp;gt;Xpp3DomUtils&amp;lt;/a&amp;gt;
        
      </xs:documentation>
  </xs:annotation>
</xs:attribute>
      <xs:attribute name="combine.self" type="xs:string" use="optional">
        <xs:annotation>
          <xs:documentation source="version">4.0.0+</xs:documentation>
          <xs:documentation source="description">
                  
                  {@code combine.self}: available values are {@code merge} (default) and {@code override}.
                  @see &amp;lt;a href=&amp;quot;https://maven.apache.org/pom.html#Plugins&amp;quot;&amp;gt;POM Reference documentation&amp;lt;/a&amp;gt;
                  @see &amp;lt;a href=&amp;quot;https://codehaus-plexus.github.io/plexus-utils/apidocs/org/codehaus/plexus/util/xml/Xpp3DomUtils.html&amp;quot;&amp;gt;Xpp3DomUtils&amp;lt;/a&amp;gt;
                  
                </xs:documentation>
        </xs:annotation>
      </xs:attribute>
    </xs:complexType>

though actually there be no ways for us to do it in modello now, as far as I get from modello sources codes.
so I want to modify some grammar of modello to add such feature.

one way be allow <fields> in <field>, and there be of course other ways, but I want to know about your ideas first.

thought1: <fields> in <field> approach?

    <class>
      <name>ConfigurationContainer</name>
      <version>4.0.0+</version>
      <description>Contains the configuration information of the container like Plugin.</description>
      <fields>
        <field>
          <name>inherited</name>
          <version>4.0.0+</version>
          <description>
            Whether any configuration should be propagated to child POMs. Note: While the type
            of this field is {@code String} for technical reasons, the semantic type is actually
            {@code Boolean}. Default value is {@code true}.
          </description>
          <type>String</type>
        </field>
        <field>
          <description>
            <![CDATA[
            <p>The configuration as DOM object.</p>
            <p>By default, every element content is trimmed, but starting with Maven 3.1.0, you can add
            {@code xml:space="preserve"} to elements you want to preserve whitespace.</p>
            <p>You can control how child POMs inherit configuration from parent POMs by adding {@code combine.children}
            or {@code combine.self} attributes to the children of the configuration element:</p>
            <ul>
            <li>{@code combine.children}: available values are {@code merge} (default) and {@code append},</li>
            <li>{@code combine.self}: available values are {@code merge} (default) and {@code override}.</li>
            </ul>

            @see <a href="https://maven.apache.org/pom.html#Plugins">POM Reference documentation</a>
            @see <a href="https://codehaus-plexus.github.io/plexus-utils/apidocs/org/codehaus/plexus/util/xml/Xpp3DomUtils.html">Xpp3DomUtils</a>
            ]]>
          </description>
          <name>configuration</name>
          <type>DOM</type>
          <fields>
            <field xml.attribute="true" xml.tagName="combine.children">
                <name>configurationCombineChildren</name>
                <version>4.0.0+</version>
                <description>
                  <![CDATA[
                  {@code combine.children}: available values are {@code merge} (default) and {@code append}.
                  @see &lt;a href=&quot;https://maven.apache.org/pom.html#Plugins&quot;&gt;POM Reference documentation&lt;/a&gt;
                  @see &lt;a href=&quot;https://codehaus-plexus.github.io/plexus-utils/apidocs/org/codehaus/plexus/util/xml/Xpp3DomUtils.html&quot;&gt;Xpp3DomUtils&lt;/a&gt;
                  ]]>
                </description>
                <type>String</type>
              </field>
              <field xml.attribute="true" xml.tagName="combine.self">
                <name>configurationCombineSelf</name>
                <version>4.0.0+</version>
                <description>
                  <![CDATA[
                  {@code combine.self}: available values are {@code merge} (default) and {@code override}.
                  @see &lt;a href=&quot;https://maven.apache.org/pom.html#Plugins&quot;&gt;POM Reference documentation&lt;/a&gt;
                  @see &lt;a href=&quot;https://codehaus-plexus.github.io/plexus-utils/apidocs/org/codehaus/plexus/util/xml/Xpp3DomUtils.html&quot;&gt;Xpp3DomUtils&lt;/a&gt;
                  ]]>
                </description>
                <type>String</type>
              </field>
          </fields>
        </field>
      </fields>
      <codeSegments>
        <codeSegment>
          <version>4.0.0+</version>
          <code>
            <![CDATA[
    public boolean isInherited() {
        return ( getInherited() != null ) ? Boolean.parseBoolean( getInherited() ) : true;
    }

            ]]>
          </code>
        </codeSegment>
        <codeSegment>
          <version>4.0.0/4.0.99</version>
          <code>
            <![CDATA[
    @Deprecated
    public void unsetInheritanceApplied() {
    }

            ]]>
          </code>
        </codeSegment>
      </codeSegments>
    </class>

Activity

  1. slachiewicz commented on Jan 21, 2025

    @slachiewicz
    Member

    Best would be to ask for feedback from @gnodet

  2. XenoAmess commented on Jan 22, 2025

    @XenoAmess
    ContributorAuthor

    @gnodet Any suggestions? or I just start the <fields> in <field> approach?

  3. gnodet commented on Jan 22, 2025

    @gnodet
    Member

    I think adding fields in field would not reflect the problem correctly. We should try to keep it more inlined with the schema definition.

    If we don't want to change the model, we should modify the modello generator to add an xs:anyattribute element when generating XML holders (maybe controlled with a boolean option), then have the model document it.

  4. XenoAmess commented on Jan 22, 2025

    @XenoAmess
    ContributorAuthor

    I think adding fields in field would not reflect the problem correctly. We should try to keep it more inlined with the schema definition.

    If we don't want to change the model, we should modify the modello generator to add an xs:anyattribute element when generating XML holders (maybe controlled with a boolean option), then have the model document it.

    you mean anyattribute instead of the more detailed two attributes? well I think it is..acceptable?let me have a try

  5. XenoAmess commented on Jan 24, 2025

    @XenoAmess
    ContributorAuthor

    @gnodet tried to completed a version at #483 , please have a look...

  6. added a commit that references this issue on Aug 8, 2026
    8554215
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions