com.itemis.maven.plugins.unleash.util.PomPropertyResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unleash-maven-plugin Show documentation
Show all versions of unleash-maven-plugin Show documentation
This plugin provides a generic alternative to the error-prone default release plugin provided by Maven. It is designed to require a minimal effort of work for releasing modules and being extensible to integrate in every project setup.
package com.itemis.maven.plugins.unleash.util;
import java.util.Map;
import org.apache.maven.model.Profile;
import org.apache.maven.project.MavenProject;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Maps;
/**
* A resolver for direct and indirect (parents) property references that respects all profiles.
* The resolve also respects the correct overriding order of the property definitions.
*
* @author Stanley Hillner
* @since 2.4.3
*/
public class PomPropertyResolver {
private MavenProject project;
private Map properties;
/**
* A new resolver for property references.
*
* @param project
* the project from which to resolve the properties.
*/
public PomPropertyResolver(MavenProject project) {
this.project = project;
}
/**
* @return all resolved properties (direct and indirect).
*/
public Map getProperties() {
resolveAllProperties();
return properties;
}
/**
* @param key
* the property key.
* @return the value of the property or {@code null} if the key is not known.
*/
public String getProperty(String key) {
resolveAllProperties();
return properties.get(key);
}
/**
* Resolves property references from the input string if there are any.
*
* @param s
* the input string which might contain property references.
* @return the input string with expanded property references.
*/
public String expandPropertyReferences(String s) {
resolveAllProperties();
return resolveReferences(s);
}
private void resolveAllProperties() {
if (properties != null) {
return;
}
properties = Maps.newHashMap();
// after that add the direct properties to override the ones of the parents
for (Map.Entry