Search in sources :

Example 11 with MavenFilteringException

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) ParseErrorException(org.apache.velocity.exception.ParseErrorException) Resource(org.apache.maven.model.Resource) RemoteResourcesBundleXpp3Reader(org.apache.maven.plugin.resources.remote.io.xpp3.RemoteResourcesBundleXpp3Reader) Reader(java.io.Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) SupplementalDataModelXpp3Reader(org.apache.maven.plugin.resources.remote.io.xpp3.SupplementalDataModelXpp3Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) FileReader(java.io.FileReader) FileInputStream(java.io.FileInputStream) MavenFileFilterRequest(org.apache.maven.shared.filtering.MavenFileFilterRequest) OutputStreamWriter(java.io.OutputStreamWriter) MethodInvocationException(org.apache.velocity.exception.MethodInvocationException) DeferredFileOutputStream(org.apache.commons.io.output.DeferredFileOutputStream) ResourceNotFoundException(org.apache.velocity.exception.ResourceNotFoundException) File(java.io.File) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) FileWriter(java.io.FileWriter)

Example 12 with MavenFilteringException

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);
    }
}
Also used : MavenResourcesExecution(org.apache.maven.shared.filtering.MavenResourcesExecution) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) Resource(org.apache.maven.model.Resource) ArrayList(java.util.ArrayList)

Example 13 with MavenFilteringException

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;
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) File(java.io.File)

Example 14 with MavenFilteringException

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;
}
Also used : MavenResourcesExecution(org.apache.maven.shared.filtering.MavenResourcesExecution) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException)

Example 15 with MavenFilteringException

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) JavaEEVersion(org.apache.maven.plugins.ear.util.JavaEEVersion) EarMavenArchiver(org.apache.maven.plugins.ear.util.EarMavenArchiver) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) EarMavenArchiver(org.apache.maven.plugins.ear.util.EarMavenArchiver) File(java.io.File) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Aggregations

MavenFilteringException (org.apache.maven.shared.filtering.MavenFilteringException)18 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)15 File (java.io.File)12 IOException (java.io.IOException)10 MavenResourcesExecution (org.apache.maven.shared.filtering.MavenResourcesExecution)6 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 MavenArchiver (org.apache.maven.archiver.MavenArchiver)3 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)3 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)3 FileReader (java.io.FileReader)2 Reader (java.io.Reader)2 LinkedHashSet (java.util.LinkedHashSet)2 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)2 Resource (org.apache.maven.model.Resource)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 MavenFileFilterRequest (org.apache.maven.shared.filtering.MavenFileFilterRequest)2 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 InputStreamReader (java.io.InputStreamReader)1