use of org.codehaus.plexus.interpolation.Interpolator in project maven-plugins by apache.
the class DocumentDescriptorReader method readAndFilterDocumentDescriptor.
/**
* Read and filter the <code>docDescriptor</code> file.
*
* @param docDescriptor not null.
* @return a DocumentModel instance.
* @throws XmlPullParserException if an error occurs during parsing.
* @throws IOException if an error occurs during reading.
*/
public DocumentModel readAndFilterDocumentDescriptor(final File docDescriptor) throws XmlPullParserException, IOException {
Reader reader = null;
try {
// System properties
final Properties filterProperties = System.getProperties();
// Project properties
if (project != null && project.getProperties() != null) {
filterProperties.putAll(project.getProperties());
}
final Interpolator interpolator = new RegexBasedInterpolator();
interpolator.addValueSource(new MapBasedValueSource(filterProperties));
interpolator.addValueSource(new EnvarBasedValueSource());
interpolator.addValueSource(new ObjectBasedValueSource(project) {
/** {@inheritDoc} */
public Object getValue(final String expression) {
try {
return ReflectionValueExtractor.evaluate(expression, project);
} catch (Exception e) {
addFeedback("Failed to extract \'" + expression + "\' from: " + project, e);
}
return null;
}
});
final DateBean bean = new DateBean();
interpolator.addValueSource(new ObjectBasedValueSource(bean));
reader = ReaderFactory.newXmlReader(docDescriptor);
final String interpolatedDoc = interpolator.interpolate(IOUtil.toString(reader));
reader.close();
reader = null;
if (log != null && log.isDebugEnabled()) {
log.debug("Interpolated document descriptor (" + docDescriptor.getAbsolutePath() + ")\n" + interpolatedDoc);
}
// No Strict
return new DocumentXpp3Reader().read(new StringReader(interpolatedDoc), false);
} catch (InterpolationException e) {
final IOException io = new IOException("Error interpolating document descriptor");
io.initCause(e);
throw io;
} finally {
IOUtil.close(reader);
}
}
use of org.codehaus.plexus.interpolation.Interpolator in project maven-plugins by apache.
the class AbstractInvokerMojo method getInvokerProperties.
/**
* Gets the (interpolated) invoker properties for an integration test.
*
* @param projectDirectory The base directory of the IT project, must not be <code>null</code>.
* @return The invoker properties, may be empty but never <code>null</code>.
* @throws org.apache.maven.plugin.MojoExecutionException If an I/O error occurred during reading the properties.
*/
private InvokerProperties getInvokerProperties(final File projectDirectory) throws MojoExecutionException {
Properties props = new Properties();
if (invokerPropertiesFile != null) {
File propertiesFile = new File(projectDirectory, invokerPropertiesFile);
if (propertiesFile.isFile()) {
InputStream in = null;
try {
in = new FileInputStream(propertiesFile);
props.load(in);
in.close();
in = null;
} catch (IOException e) {
throw new MojoExecutionException("Failed to read invoker properties: " + propertiesFile, e);
} finally {
IOUtil.close(in);
}
}
Interpolator interpolator = new RegexBasedInterpolator();
interpolator.addValueSource(new MapBasedValueSource(getInterpolationValueSource(false)));
// CHECKSTYLE_OFF: LineLength
for (String key : props.stringPropertyNames()) {
String value = props.getProperty(key);
try {
value = interpolator.interpolate(value, "");
} catch (InterpolationException e) {
throw new MojoExecutionException("Failed to interpolate invoker properties: " + propertiesFile, e);
}
props.setProperty(key, value);
}
// CHECKSTYLE_ON: LineLength
}
return new InvokerProperties(props);
}
use of org.codehaus.plexus.interpolation.Interpolator in project spring-boot by spring-projects.
the class RepositoryConfigurationFactory method addActiveProfileRepositories.
private static void addActiveProfileRepositories(List<Profile> activeProfiles, List<RepositoryConfiguration> configurations) {
for (Profile activeProfile : activeProfiles) {
Interpolator interpolator = new RegexBasedInterpolator();
interpolator.addValueSource(new PropertiesBasedValueSource(activeProfile.getProperties()));
for (Repository repository : activeProfile.getRepositories()) {
configurations.add(getRepositoryConfiguration(interpolator, repository));
}
}
}
use of org.codehaus.plexus.interpolation.Interpolator in project sling by apache.
the class BundleListUtils method interpolateProperties.
public static void interpolateProperties(BundleList bundleList, MavenProject project, MavenSession mavenSession) throws MojoExecutionException {
Interpolator interpolator = createInterpolator(project, mavenSession);
for (final StartLevel sl : bundleList.getStartLevels()) {
for (final Bundle bndl : sl.getBundles()) {
try {
bndl.setArtifactId(interpolator.interpolate(bndl.getArtifactId()));
bndl.setGroupId(interpolator.interpolate(bndl.getGroupId()));
bndl.setVersion(interpolator.interpolate(bndl.getVersion()));
bndl.setClassifier(interpolator.interpolate(bndl.getClassifier()));
bndl.setType(interpolator.interpolate(bndl.getType()));
} catch (InterpolationException e) {
throw new MojoExecutionException("Unable to interpolate properties for bundle " + bndl.toString(), e);
}
}
}
}
Aggregations