use of org.codehaus.plexus.interpolation.InterpolationException in project maven-plugins by apache.
the class DocumentDescriptorReader method readAndFilterDocumentDescriptor.
/**
* Read and filter the <code>docDescriptor</code> file.
*
* @param docDescriptor not null, corresponding to non-localized descriptor file.
* @return a DocumentModel instance.
* @throws XmlPullParserException if an error occurs during parsing.
* @throws IOException if an error occurs during reading.
*/
public DocumentModel readAndFilterDocumentDescriptor(File docDescriptor) throws XmlPullParserException, IOException {
if (locale != null) {
String descriptorFilename = docDescriptor.getName();
String localized = FileUtils.removeExtension(descriptorFilename) + '_' + locale.getLanguage() + '.' + FileUtils.getExtension(descriptorFilename);
File localizedDocDescriptor = new File(docDescriptor.getParentFile(), localized);
if (localizedDocDescriptor.exists()) {
docDescriptor = localizedDocDescriptor;
}
}
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.InterpolationException in project maven-plugins by apache.
the class ArtifactsPackagingTask method performPackaging.
/**
* {@inheritDoc}
*/
public void performPackaging(WarPackagingContext context) throws MojoExecutionException {
try {
final ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
final List<String> duplicates = findDuplicates(context, artifacts);
for (Artifact artifact : artifacts) {
String targetFileName = getArtifactFinalName(context, artifact);
context.getLog().debug("Processing: " + targetFileName);
if (duplicates.contains(targetFileName)) {
context.getLog().debug("Duplicate found: " + targetFileName);
targetFileName = artifact.getGroupId() + "-" + targetFileName;
context.getLog().debug("Renamed to: " + targetFileName);
}
context.getWebappStructure().registerTargetFileName(artifact, targetFileName);
if (!artifact.isOptional() && filter.include(artifact)) {
try {
String type = artifact.getType();
if ("tld".equals(type)) {
copyFile(id, context, artifact.getFile(), TLD_PATH + targetFileName);
} else if ("aar".equals(type)) {
copyFile(id, context, artifact.getFile(), SERVICES_PATH + targetFileName);
} else if ("mar".equals(type)) {
copyFile(id, context, artifact.getFile(), MODULES_PATH + targetFileName);
} else if ("xar".equals(type)) {
copyFile(id, context, artifact.getFile(), EXTENSIONS_PATH + targetFileName);
} else if ("jar".equals(type) || "ejb".equals(type) || "ejb-client".equals(type) || "test-jar".equals(type) || "bundle".equals(type)) {
copyFile(id, context, artifact.getFile(), LIB_PATH + targetFileName);
} else if ("par".equals(type)) {
targetFileName = targetFileName.substring(0, targetFileName.lastIndexOf('.')) + ".jar";
copyFile(id, context, artifact.getFile(), LIB_PATH + targetFileName);
} else if ("war".equals(type)) {
// Nothing to do here, it is an overlay and it's already handled
context.getLog().debug("war artifacts are handled as overlays, ignoring [" + artifact + "]");
} else if ("zip".equals(type)) {
// Nothing to do here, it is an overlay and it's already handled
context.getLog().debug("zip artifacts are handled as overlays, ignoring [" + artifact + "]");
} else {
context.getLog().debug("Artifact of type [" + type + "] is not supported, ignoring [" + artifact + "]");
}
} catch (IOException e) {
throw new MojoExecutionException("Failed to copy file for artifact [" + artifact + "]", e);
}
}
}
} catch (InterpolationException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
use of org.codehaus.plexus.interpolation.InterpolationException 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.InterpolationException in project maven-plugins by apache.
the class GenerateApplicationXmlMojo method buildEnvEntries.
/**
* Builds the env-entries based on the configuration.
*
* @return a list of EnvEntry object(s)
* @throws EarPluginException if the configuration is invalid
*/
private List<EnvEntry> buildEnvEntries() throws EarPluginException {
final List<EnvEntry> result = new ArrayList<EnvEntry>();
if (envEntries == null) {
return result;
}
try {
StringSearchInterpolator ssi = new StringSearchInterpolator();
ValueSource vs = new MapBasedValueSource(project.getProperties());
ssi.addValueSource(vs);
final PlexusConfiguration[] allEnvEntries = envEntries.getChildren(EnvEntry.ENV_ENTRY);
getLog().debug("buildEnvEntries: allEnvEntries:" + allEnvEntries);
getLog().debug("buildEnvEntries: allEnvEntries size:" + allEnvEntries.length);
for (PlexusConfiguration envEntry : allEnvEntries) {
// CHECKSTYLE_OFF: LineLength
final String childDescription = interpolate(ssi, envEntry.getChild(EnvEntry.DESCRIPTION).getValue());
final String childEnvEntryName = interpolate(ssi, envEntry.getChild(EnvEntry.ENV_ENTRY_NAME).getValue());
final String childEnvEntryType = interpolate(ssi, envEntry.getChild(EnvEntry.ENV_ENTRY_TYPE).getValue());
final String childEnvEntryValue = interpolate(ssi, envEntry.getChild(EnvEntry.ENV_ENTRY_VALUE).getValue());
final String childEnvLookupNameValue = interpolate(ssi, envEntry.getChild(EnvEntry.ENV_LOOKUP_NAME).getValue());
try {
result.add(new EnvEntry(childDescription, childEnvEntryName, childEnvEntryType, childEnvEntryValue, childEnvLookupNameValue));
} catch (IllegalArgumentException e) {
throw new EarPluginException("Invalid env-entry [" + envEntry + "]", e);
}
}
return result;
} catch (InterpolationException e) {
throw new EarPluginException("Interpolation exception:", e);
}
}
use of org.codehaus.plexus.interpolation.InterpolationException in project indy by Commonjava.
the class KojiUtils method getRepositoryName.
public String getRepositoryName(final KojiBuildInfo build) {
StringSearchInterpolator interpolator = new StringSearchInterpolator();
interpolator.addValueSource(new ObjectBasedValueSource(build));
try {
return interpolator.interpolate(isBinaryBuild(build) ? config.getBinayNamingFormat() : config.getNamingFormat());
} catch (InterpolationException e) {
throw new RuntimeException("Cannot resolve expressions in Koji configuration.", e);
}
}
Aggregations