use of org.apache.maven.shared.filtering.MavenFilteringException in project maven-plugins by apache.
the class ProcessRemoteResourcesMojo method copyResourceIfExists.
protected boolean copyResourceIfExists(File file, String relFileName, VelocityContext context) throws IOException, MojoExecutionException {
for (Resource resource : resources) {
File resourceDirectory = new File(resource.getDirectory());
if (!resourceDirectory.exists()) {
continue;
}
// TODO - really should use the resource includes/excludes and name mapping
File source = new File(resourceDirectory, relFileName);
File templateSource = new File(resourceDirectory, relFileName + TEMPLATE_SUFFIX);
if (!source.exists() && templateSource.exists()) {
source = templateSource;
}
if (source.exists() && !source.equals(file)) {
if (source == templateSource) {
Reader reader = null;
Writer writer = null;
DeferredFileOutputStream os = new DeferredFileOutputStream(velocityFilterInMemoryThreshold, file);
try {
if (encoding != null) {
reader = new InputStreamReader(new FileInputStream(source), encoding);
writer = new OutputStreamWriter(os, encoding);
} else {
reader = ReaderFactory.newPlatformReader(source);
writer = WriterFactory.newPlatformWriter(os);
}
velocity.evaluate(context, writer, "", reader);
writer.close();
writer = null;
reader.close();
reader = null;
} catch (ParseErrorException e) {
throw new MojoExecutionException("Error rendering velocity resource: " + source, e);
} catch (MethodInvocationException e) {
throw new MojoExecutionException("Error rendering velocity resource: " + source, e);
} catch (ResourceNotFoundException e) {
throw new MojoExecutionException("Error rendering velocity resource: " + source, e);
} finally {
IOUtil.close(writer);
IOUtil.close(reader);
}
fileWriteIfDiffers(os);
} else if (resource.isFiltering()) {
MavenFileFilterRequest req = setupRequest(resource, source, file);
try {
fileFilter.copyFile(req);
} catch (MavenFilteringException e) {
throw new MojoExecutionException("Error filtering resource: " + source, e);
}
} else {
FileUtils.copyFile(source, file);
}
// exclude the original (so eclipse doesn't complain about duplicate resources)
resource.addExclude(relFileName);
return true;
}
}
return false;
}
use of org.apache.maven.shared.filtering.MavenFilteringException in project maven-plugins by apache.
the class RarMojo method resourceHandling.
private void resourceHandling() throws MojoExecutionException {
Resource resource = new Resource();
resource.setDirectory(rarSourceDirectory.getAbsolutePath());
resource.setTargetPath(getBuildDir().getAbsolutePath());
resource.setFiltering(filterRarSourceDirectory);
List<Resource> resources = new ArrayList<Resource>();
resources.add(resource);
if (rarResources != null && !rarResources.isEmpty()) {
resources.addAll(rarResources);
}
MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(resources, getBuildDir(), project, encoding, filters, 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.setDelimiters(delimiters, useDefaultDelimiters);
if (nonFilteredFileExtensions != null) {
mavenResourcesExecution.setNonFilteredFileExtensions(nonFilteredFileExtensions);
}
try {
mavenResourcesFiltering.filterResources(mavenResourcesExecution);
} catch (MavenFilteringException e) {
throw new MojoExecutionException("Error copying RAR resources", e);
}
}
use of org.apache.maven.shared.filtering.MavenFilteringException in project maven-plugins by apache.
the class EjbMojo method generateEjb.
private File generateEjb() throws MojoExecutionException {
File jarFile = EjbHelper.getJarFile(outputDirectory, jarName, getClassifier());
getLog().info("Building EJB " + jarName + " with EJB version " + ejbVersion);
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(jarFile);
File deploymentDescriptor = new File(sourceDirectory, ejbJar);
checkEJBVersionCompliance(deploymentDescriptor);
try {
List<String> defaultExcludes = Lists.newArrayList(ejbJar, "**/package.html");
List<String> defaultIncludes = DEFAULT_INCLUDES_LIST;
IncludesExcludes ie = new IncludesExcludes(Collections.<String>emptyList(), excludes, defaultIncludes, defaultExcludes);
archiver.getArchiver().addDirectory(sourceDirectory, ie.resultingIncludes(), ie.resultingExcludes());
// FIXME: We should be able to filter more than just the deployment descriptor?
if (deploymentDescriptor.exists()) {
// EJB-34 Filter ejb-jar.xml
if (filterDeploymentDescriptor) {
filterDeploymentDescriptor(deploymentDescriptor);
}
archiver.getArchiver().addFile(deploymentDescriptor, ejbJar);
}
// create archive
archiver.createArchive(session, project, archive);
} catch (ArchiverException e) {
throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
} catch (ManifestException e) {
throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
} catch (IOException e) {
throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
} catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
} catch (MavenFilteringException e) {
throw new MojoExecutionException("There was a problem filtering the deployment descriptor: " + e.getMessage(), e);
}
return jarFile;
}
use of org.apache.maven.shared.filtering.MavenFilteringException in project maven-plugins by apache.
the class EarMojo method getFilterWrappers.
private List<FileUtils.FilterWrapper> getFilterWrappers() throws MojoExecutionException {
if (filterWrappers == null) {
try {
MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution();
mavenResourcesExecution.setMavenProject(getProject());
mavenResourcesExecution.setEscapedBackslashesInFilePath(escapedBackslashesInFilePath);
mavenResourcesExecution.setFilters(filters);
mavenResourcesExecution.setEscapeString(escapeString);
filterWrappers = mavenFileFilter.getDefaultFilterWrappers(mavenResourcesExecution);
} catch (MavenFilteringException e) {
getLog().error("Fail to build filtering wrappers " + e.getMessage());
throw new MojoExecutionException(e.getMessage(), e);
}
}
return filterWrappers;
}
use of org.apache.maven.shared.filtering.MavenFilteringException in project maven-plugins by apache.
the class EarMojo method execute.
/** {@inheritDoc} */
public void execute() throws MojoExecutionException, MojoFailureException {
// Initializes ear modules
super.execute();
zipArchiver.setUseJvmChmod(useJvmChmod);
zipUnArchiver.setUseJvmChmod(useJvmChmod);
final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion(version);
// Initializes unpack types
List<String> unpackTypesList = createUnpackList();
// Copy modules
copyModules(javaEEVersion, unpackTypesList);
// Copy source files
try {
File earSourceDir = earSourceDirectory;
if (earSourceDir.exists()) {
getLog().info("Copy ear sources to " + getWorkDirectory().getAbsolutePath());
String[] fileNames = getEarFiles(earSourceDir);
for (String fileName : fileNames) {
copyFile(new File(earSourceDir, fileName), new File(getWorkDirectory(), fileName));
}
}
if (applicationXml != null && !"".equals(applicationXml)) {
// rename to application.xml
getLog().info("Including custom application.xml[" + applicationXml + "]");
File metaInfDir = new File(getWorkDirectory(), META_INF);
copyFile(new File(applicationXml), new File(metaInfDir, "/application.xml"));
}
} catch (IOException e) {
throw new MojoExecutionException("Error copying EAR sources", e);
} catch (MavenFilteringException e) {
throw new MojoExecutionException("Error filtering EAR sources", e);
}
// Check if deployment descriptor is there
File ddFile = new File(getWorkDirectory(), APPLICATION_XML_URI);
if (!ddFile.exists() && (javaEEVersion.lt(JavaEEVersion.FIVE))) {
// CHECKSTYLE_OFF: LineLength
throw new MojoExecutionException("Deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist.");
// CHECKSTYLE_ON: LineLength
}
try {
File earFile = getEarFile(outputDirectory, finalName, classifier);
final MavenArchiver archiver = new EarMavenArchiver(getModules());
final JarArchiver theJarArchiver = getJarArchiver();
getLog().debug("Jar archiver implementation [" + theJarArchiver.getClass().getName() + "]");
archiver.setArchiver(theJarArchiver);
archiver.setOutputFile(earFile);
getLog().debug("Excluding " + Arrays.asList(getPackagingExcludes()) + " from the generated EAR.");
getLog().debug("Including " + Arrays.asList(getPackagingIncludes()) + " in the generated EAR.");
archiver.getArchiver().addDirectory(getWorkDirectory(), getPackagingIncludes(), getPackagingExcludes());
archiver.createArchive(session, getProject(), archive);
if (classifier != null) {
projectHelper.attachArtifact(getProject(), "ear", classifier, earFile);
} else {
getProject().getArtifact().setFile(earFile);
}
} catch (Exception e) {
throw new MojoExecutionException("Error assembling EAR", e);
}
}
Aggregations