use of org.apache.maven.shared.filtering.MavenFilteringException in project karaf by apache.
the class GenerateDescriptorMojo method filter.
protected void filter(File sourceFile, File targetFile) throws MojoExecutionException {
try {
if (StringUtils.isEmpty(encoding)) {
getLog().warn("File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING + ", i.e. build is platform dependent!");
}
targetFile.getParentFile().mkdirs();
final MavenResourcesExecution mre = new MavenResourcesExecution();
mre.setMavenProject(project);
mre.setMavenSession(mavenSession);
mre.setFilters(null);
mre.setEscapedBackslashesInFilePath(true);
final LinkedHashSet<String> delimiters = new LinkedHashSet<>();
delimiters.add("${*}");
mre.setDelimiters(delimiters);
@SuppressWarnings("rawtypes") List filters = mavenFileFilter.getDefaultFilterWrappers(mre);
mavenFileFilter.copyFile(sourceFile, targetFile, true, filters, encoding, true);
} catch (MavenFilteringException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
use of org.apache.maven.shared.filtering.MavenFilteringException in project maven-plugins by apache.
the class ReaderFormatter method createReaderFilter.
private static Reader createReaderFilter(@Nonnull Reader source, String escapeString, List<String> delimiters, AssemblerConfigurationSource configSource, boolean isPropertiesFile) throws IOException {
try {
MavenReaderFilterRequest filterRequest = new MavenReaderFilterRequest(source, true, configSource.getProject(), configSource.getFilters(), isPropertiesFile, configSource.getMavenSession(), null);
filterRequest.setEscapeString(escapeString);
// if these are NOT set, just use the defaults, which are '${*}' and '@'.
if (delimiters != null && !delimiters.isEmpty()) {
LinkedHashSet<String> delims = new LinkedHashSet<String>();
for (String delim : delimiters) {
if (delim == null) {
// FIXME: ${filter:*} could also trigger this condition. Need a better long-term solution.
delims.add("${*}");
} else {
delims.add(delim);
}
}
filterRequest.setDelimiters(delims);
} else {
filterRequest.setDelimiters(filterRequest.getDelimiters());
}
filterRequest.setInjectProjectBuildFilters(configSource.isIncludeProjectBuildFilters());
return configSource.getMavenReaderFilter().filter(filterRequest);
} catch (MavenFilteringException e) {
IOException ioe = new IOException("Error filtering file '" + source + "': " + e.getMessage());
// plain old Java 5...
ioe.initCause(e);
throw ioe;
}
}
use of org.apache.maven.shared.filtering.MavenFilteringException in project maven-plugins by apache.
the class ItFilter method filterResources.
/**
* @see org.apache.maven.shared.filtering.MavenResourcesFiltering#filterResources(org.apache.maven.shared.filtering.MavenResourcesExecution)
*/
public void filterResources(MavenResourcesExecution mavenResourcesExecution) throws MavenFilteringException {
System.out.println("ItFilter filterResources");
try {
File f = new File(mavenResourcesExecution.getOutputDirectory(), "foo.txt");
List<String> lines = new ArrayList<String>();
lines.add("foo");
lines.add("version=" + mavenResourcesExecution.getMavenProject().getVersion());
lines.add("toto=" + mavenResourcesExecution.getMavenSession().getSystemProperties().getProperty("toto"));
FileUtils.writeLines(f, lines);
} catch (IOException e) {
throw new MavenFilteringException(e.getMessage(), e);
}
}
use of org.apache.maven.shared.filtering.MavenFilteringException in project maven-plugins by apache.
the class ResourcesMojo method execute.
/** {@inheritDoc} */
public void execute() throws MojoExecutionException {
if (isSkip()) {
getLog().info("Skipping the execution.");
return;
}
if (StringUtils.isEmpty(encoding) && isFilteringEnabled(getResources())) {
getLog().warn("File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING + ", i.e. build is platform dependent!");
}
try {
List<String> combinedFilters = getCombinedFiltersList();
MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(getResources(), getOutputDirectory(), project, encoding, combinedFilters, Collections.<String>emptyList(), session);
mavenResourcesExecution.setEscapeWindowsPaths(escapeWindowsPaths);
// never include project build filters in this call, since we've already accounted for the POM build filters
// above, in getCombinedFiltersList().
mavenResourcesExecution.setInjectProjectBuildFilters(false);
mavenResourcesExecution.setEscapeString(escapeString);
mavenResourcesExecution.setOverwrite(overwrite);
mavenResourcesExecution.setIncludeEmptyDirs(includeEmptyDirs);
mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering);
mavenResourcesExecution.setFilterFilenames(fileNameFiltering);
mavenResourcesExecution.setAddDefaultExcludes(addDefaultExcludes);
// Handle subject of MRESOURCES-99
Properties additionalProperties = addSeveralSpecialProperties();
mavenResourcesExecution.setAdditionalProperties(additionalProperties);
// if these are NOT set, just use the defaults, which are '${*}' and '@'.
mavenResourcesExecution.setDelimiters(delimiters, useDefaultDelimiters);
if (nonFilteredFileExtensions != null) {
mavenResourcesExecution.setNonFilteredFileExtensions(nonFilteredFileExtensions);
}
mavenResourcesFiltering.filterResources(mavenResourcesExecution);
executeUserFilterComponents(mavenResourcesExecution);
} catch (MavenFilteringException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
use of org.apache.maven.shared.filtering.MavenFilteringException in project maven-plugins by apache.
the class AcrMojo method execute.
/** {@inheritDoc} */
public void execute() throws MojoExecutionException {
if (getLog().isInfoEnabled()) {
getLog().info("Building JavaEE Application client: " + jarName);
}
File jarFile = getAppClientJarFile(basedir, jarName);
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(jarFile);
try {
String[] mainJarExcludes = DEFAULT_EXCLUDES;
if (excludes != null && !excludes.isEmpty()) {
excludes.add(APP_CLIENT_XML);
mainJarExcludes = excludes.toArray(new String[excludes.size()]);
}
if (outputDirectory.exists()) {
archiver.getArchiver().addDirectory(outputDirectory, DEFAULT_INCLUDES, mainJarExcludes);
} else {
// CHECKSTYLE_OFF: LineLength
getLog().info("JAR will only contain the META-INF/application-client.xml as no content was marked for inclusion");
// CHECKSTYLE_ON: LineLength
}
File deploymentDescriptor = new File(outputDirectory, APP_CLIENT_XML);
if (deploymentDescriptor.exists()) {
if (filterDeploymentDescriptor) {
getLog().debug("Filtering deployment descriptor.");
MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution();
mavenResourcesExecution.setEscapeString(escapeString);
List<FilterWrapper> filterWrappers = mavenFileFilter.getDefaultFilterWrappers(project, filters, escapeBackslashesInFilePath, this.session, mavenResourcesExecution);
// Create a temporary file that we can copy-and-filter
File unfilteredDeploymentDescriptor = new File(outputDirectory, APP_CLIENT_XML + ".unfiltered");
FileUtils.copyFile(deploymentDescriptor, unfilteredDeploymentDescriptor);
mavenFileFilter.copyFile(unfilteredDeploymentDescriptor, deploymentDescriptor, true, filterWrappers, getEncoding(unfilteredDeploymentDescriptor));
// Remove the temporary file
FileUtils.forceDelete(unfilteredDeploymentDescriptor);
}
archiver.getArchiver().addFile(deploymentDescriptor, APP_CLIENT_XML);
}
// create archive
archiver.createArchive(session, project, archive);
// CHECKSTYLE_OFF: LineLength
} catch (ArchiverException e) {
throw new MojoExecutionException("There was a problem creating the JavaEE Application Client archive: " + e.getMessage(), e);
} catch (ManifestException e) {
throw new MojoExecutionException("There was a problem reading / creating the manifest for the JavaEE Application Client archive: " + e.getMessage(), e);
} catch (IOException e) {
throw new MojoExecutionException("There was a I/O problem creating the JavaEE Application Client archive: " + e.getMessage(), e);
} catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException("There was a problem resolving dependencies while creating the JavaEE Application Client archive: " + e.getMessage(), e);
} catch (MavenFilteringException e) {
throw new MojoExecutionException("There was a problem filtering the deployment descriptor: " + e.getMessage(), e);
}
project.getArtifact().setFile(jarFile);
// CHECKSTYLE_ON: LineLength
}
Aggregations