[forge-issues] [JBoss JIRA] (FORGE-2273) MavenFacet - Write properties sorted A..Z
George Gastaldi (JIRA)
issues at jboss.org
Tue Mar 10 15:15:21 EDT 2015
[ https://issues.jboss.org/browse/FORGE-2273?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13048711#comment-13048711 ]
George Gastaldi commented on FORGE-2273:
----------------------------------------
Unfortunately the Maven model is not flexible enough to allow writing this in a transparent way. The best solution would be to pass a {{SortedProperties}} object to the {{pom.setProperties()}} method, like the following:
{code:java}
/**
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.addon.maven.projects;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
/**
* Introduces an ordered {@link Properties#keySet()}
*
* @author <a href="mailto:ggastald at redhat.com">George Gastaldi</a>
*/
public class SortedProperties extends Properties
{
private static final long serialVersionUID = 1L;
@Override
public Set<Object> keySet()
{
return new TreeSet<Object>(super.keySet());
}
}
{code}
Then you can do the following before calling setMode():
{code:java}
Model pom = ...
SortedProperties sortedProps = new SortedProperties();
sortedProps.putAll(pom.getProperties());
pom.setProperties(sortedProps);
{code}
> MavenFacet - Write properties sorted A..Z
> -----------------------------------------
>
> Key: FORGE-2273
> URL: https://issues.jboss.org/browse/FORGE-2273
> Project: Forge
> Issue Type: Enhancement
> Components: Build Tools - Maven
> Affects Versions: 2.15.0.Final
> Reporter: Claus Ibsen
> Priority: Minor
> Labels: Starter
> Fix For: 2.x Future
>
>
> We have a custom addon that adds various commands.
> We have a docket setup command that enables docker to a maven project. And for that we set some values in the <properties> section of the maven pom.xml.
> To update and set those, we use the following code:
> {code}
> // update properties section in pom.xml
> MavenFacet maven = project.getFacet(MavenFacet.class);
> Model pom = maven.getModel();
> Properties properties = pom.getProperties();
> properties.put("docker.registryPrefix", "${env.DOCKER_REGISTRY}/");
> properties.put("docker.from", fromImage);
> properties.put("docker.image", "${docker.registryPrefix}fabric8/${project.artifactId}:${project.version}");
> properties.put("docker.assemblyDescriptorRef", descriptorRef);
> properties.put("docker.port.container.jolokia", "8778");
> if (war) {
> properties.put("docker.port.container.http", "8080");
> }
> // to save then set the model
> maven.setModel(pom);
> {code}
> Which then generates the following in the pom.xml
> {code}
> <properties>
> <docker.port.container.http>8080</docker.port.container.http>
> <docker.registryPrefix>${env.DOCKER_REGISTRY}/</docker.registryPrefix>
> <docker.image>${docker.registryPrefix}fabric8/${project.artifactId}:${project.version}</docker.image>
> <maven.compiler.target>1.7</maven.compiler.target>
> <docker.port.container.jolokia>8778</docker.port.container.jolokia>
> <docker.from>fabric8/tomcat-8.0</docker.from>
> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> <docker.assemblyDescriptorRef>rootWar</docker.assemblyDescriptorRef>
> <maven.compiler.source>1.7</maven.compiler.source>
> </properties>
> {code}
> Notice the order of the properties is "random". It would be great if forge would sort the properties A..Z so they are more human readable.
--
This message was sent by Atlassian JIRA
(v6.3.11#6341)
More information about the forge-issues
mailing list