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

Sort maven properties (proposal with code example) #185

Open
rob-valor opened this issue Aug 29, 2024 · 0 comments
Open

Sort maven properties (proposal with code example) #185

rob-valor opened this issue Aug 29, 2024 · 0 comments

Comments

@rob-valor
Copy link

rob-valor commented Aug 29, 2024

When setting jgitver.resolve-project-version to true the properties in the pom file are rewritten but these are stored in a java.util.Properties which in turn is a java.util.Hashtable<Object,Object>. So when these properties are serialized to a new pom.xml file, the order of the properties is mixed up.

This can easily be fixed by using a custom Properties class which returns the key set as a TreeSet:

package fr.brouillard.oss.jgitver;

import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;

class SortedProperties extends Properties {
  public SortedProperties(Properties properties) {
    properties.forEach((key, value) -> setProperty(key.toString(), value.toString()));
  }

  @Override
  public Set<Object> keySet() {
    return new TreeSet<>(super.keySet());
  }
}

Use this class as properties for the model that is rewritten as the new pom.xml file. Insert at JGitverUtils:219:

   model.setProperties(new SortedProperties(model.getProperties()));

That way, the properties are nicely sorted instead of being mixed up.

I'm not able to build the project myself because I get a [ERROR] java.lang.ClassNotFoundException: org.apache.maven.surefire.junit4.JUnit4Provider when building with ./mvnw package. I installed it locally by building without tests and verified the result in a project.

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

1 participant