use of org.codehaus.plexus.interpolation.PrefixedObjectValueSource in project maven-plugins by apache.
the class DoapUtil method interpolate.
/**
* Interpolate a string with project and settings.
*
* @param value could be null
* @param project not null
* @param settings could be null
* @return the value trimmed and interpolated or null if the interpolation doesn't work.
* @since 1.1
*/
public static String interpolate(String value, final MavenProject project, Settings settings) {
if (project == null) {
throw new IllegalArgumentException("project is required");
}
if (value == null) {
return value;
}
if (!value.contains("${")) {
return value.trim();
}
RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
try {
interpolator.addValueSource(new EnvarBasedValueSource());
} catch (IOException e) {
// ignore
}
interpolator.addValueSource(new PropertiesBasedValueSource(System.getProperties()));
interpolator.addValueSource(new PropertiesBasedValueSource(project.getProperties()));
interpolator.addValueSource(new PrefixedObjectValueSource("project", project));
interpolator.addValueSource(new PrefixedObjectValueSource("pom", project));
interpolator.addValueSource(new ObjectBasedValueSource(project) {
@Override
public Object getValue(String expression) {
try {
return ReflectionValueExtractor.evaluate(expression, project, true);
} catch (Exception e) {
addFeedback("Failed to extract \'" + expression + "\' from: " + project, e);
}
return null;
}
});
if (settings != null) {
interpolator.addValueSource(new PrefixedObjectValueSource("settings", settings));
}
String interpolatedValue = value;
try {
interpolatedValue = interpolator.interpolate(value).trim();
} catch (InterpolationException e) {
// ignore
}
if (interpolatedValue.startsWith("${")) {
return null;
}
return interpolatedValue;
}
use of org.codehaus.plexus.interpolation.PrefixedObjectValueSource in project sling by apache.
the class BundleListUtils method createInterpolator.
public static Interpolator createInterpolator(MavenProject project, MavenSession mavenSession) {
StringSearchInterpolator interpolator = new StringSearchInterpolator();
final Properties props = new Properties();
props.putAll(project.getProperties());
props.putAll(mavenSession.getSystemProperties());
props.putAll(mavenSession.getUserProperties());
interpolator.addValueSource(new PropertiesBasedValueSource(props));
// add ${project.foo}
interpolator.addValueSource(new PrefixedObjectValueSource(Arrays.asList("project", "pom"), project, true));
// add ${session.foo}
interpolator.addValueSource(new PrefixedObjectValueSource("session", mavenSession));
// add ${settings.foo}
final Settings settings = mavenSession.getSettings();
if (settings != null) {
interpolator.addValueSource(new PrefixedObjectValueSource("settings", settings));
}
return interpolator;
}
Aggregations