Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writers don't sort members from super to this #71

Open
michael-o opened this issue Nov 14, 2020 · 8 comments
Open

Writers don't sort members from super to this #71

michael-o opened this issue Nov 14, 2020 · 8 comments

Comments

@michael-o
Copy link
Member

Have a model which references a superclass:
https://github.com/apache/maven/blob/72688805c4f95f8ab4ca9ab2ac2cd114667790c9/maven-settings/src/main/mdo/settings.mdo#L506-L508
The generated SettingsXpp3Writer sorts:

    private void writeServer( Server server, String tagName, XmlSerializer serializer )
        throws java.io.IOException
    {
        serializer.startTag( NAMESPACE, tagName );
        if ( server.getUsername() != null )
        {
            serializer.startTag( NAMESPACE, "username" ).text( server.getUsername() ).endTag( NAMESPACE, "username" );
        }
        if ( server.getPassword() != null )
        {
            serializer.startTag( NAMESPACE, "password" ).text( server.getPassword() ).endTag( NAMESPACE, "password" );
        }
        if ( server.getPrivateKey() != null )
        {
            serializer.startTag( NAMESPACE, "privateKey" ).text( server.getPrivateKey() ).endTag( NAMESPACE, "privateKey" );
        }
        if ( server.getPassphrase() != null )
        {
            serializer.startTag( NAMESPACE, "passphrase" ).text( server.getPassphrase() ).endTag( NAMESPACE, "passphrase" );
        }
        if ( server.getFilePermissions() != null )
        {
            serializer.startTag( NAMESPACE, "filePermissions" ).text( server.getFilePermissions() ).endTag( NAMESPACE, "filePermissions" );
        }
        if ( server.getDirectoryPermissions() != null )
        {
            serializer.startTag( NAMESPACE, "directoryPermissions" ).text( server.getDirectoryPermissions() ).endTag( NAMESPACE, "directoryPermissions" );
        }
        if ( server.getConfiguration() != null )
        {
            ((Xpp3Dom) server.getConfiguration()).writeToSerializer( NAMESPACE, serializer );
        }
        if ( ( server.getId() != null ) && !server.getId().equals( "default" ) )
        {
            serializer.startTag( NAMESPACE, "id" ).text( server.getId() ).endTag( NAMESPACE, "id" );
        }
        serializer.endTag( NAMESPACE, tagName );
    } //-- void writeServer( Server, String, XmlSerializer )

All members from the super class at the end which makes the output look awkward. Super elements come last while the should be first.

Here is a sample output:

  <servers>
    <server>
      <username>maven</username>
      <password>***</password>
      <id>repoman</id>
    </server>
  </servers>

Expected output is:

super
super
..
super
this.

@michael-o
Copy link
Member Author

@rfscholte Have a look at.

@rfscholte
Copy link
Member

It took a while to discover what's happening here, but now I know: there is a property that controls the order of fields: https://codehaus-plexus.github.io/modello/modello.html#class_field xml.insertParentFieldsUpTo.
Currently by default it is indeed first thsi followed by super. By setting this attribute to the last field of the superclass, you'll get your preferred order.
I do agree that this is weird, and with 2.0.0 I might decide to change the order. But only as long as we can still control the order.

@michael-o
Copy link
Member Author

Ah ok, that would be helpful for 2.0.0. Is this one safe to be changed for Maven before 4.0.0?

@rfscholte
Copy link
Member

For now I suggest to xml.insertParentFieldsUpTo as I have no idea yet how much time other improvements will take and, as said, if it will still be possible the control the order.

@michael-o
Copy link
Member Author

The field is a string, I consider the documentation mediocre:

mosipov@bsd1srv:/usr/home/mosipov/var/Projekte/maven (master=)
$ grep -r xml.insertParentFieldsUpTo .
./maven-model/src/main/mdo/maven.mdo:        <field xdoc.separator="blank" xml.insertParentFieldsUpTo="modules">
./maven-model/src/main/mdo/maven.mdo:        <field xdoc.separator="blank" xml.insertParentFieldsUpTo="pluginRepositories">
./maven-model/src/main/mdo/maven.mdo:        <field xdoc.separator="blank" xml.insertParentFieldsUpTo="reporting">

@rfscholte
Copy link
Member

This field should be part of a class with a superclass. The xml.insertParentFieldsUpTo refers to a field name of that superclass.

@slachiewicz
Copy link
Member

can we close this ?

@michael-o
Copy link
Member Author

can we close this ?

Not really because I don't consider the docs of this field https://codehaus-plexus.github.io/modello/modello.html really helpful unless I am missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants