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.List;
import java.util.Map;
import java.util.Properties;
import org.apache.maven.model.Profile;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
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;
private List profiles;
private Settings settings;
private Properties additionalProperties;
/**
* A new resolver for property references.
*
* @param project
* the project from which to resolve the properties.
* @param profiles
* the profiles that shall be respected.
*/
public PomPropertyResolver(MavenProject project, Settings settings, List profiles,
Properties additionalProperties) {
this.project = project;
this.profiles = profiles;
this.settings = settings;
this.additionalProperties = additionalProperties;
}
/**
* @return all resolved properties (direct and indirect).
*/
public Map getProperties() {
resolveAllProperties();
return this.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 this.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 (this.properties != null) {
return;
}
this.properties = Maps.newHashMap();
// 1. get the properties of all profiles from the settings.
for (org.apache.maven.settings.Profile profile : this.settings.getProfiles()) {
if (!this.profiles.contains(profile.getId())) {
continue;
}
for (Map.Entry