Search in sources :

Example 1 with MavenResourcesExecution

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

Example 2 with MavenResourcesExecution

use of org.apache.maven.shared.filtering.MavenResourcesExecution in project maven-plugins by apache.

the class EjbMojo method filterDeploymentDescriptor.

private void filterDeploymentDescriptor(File deploymentDescriptor) throws MavenFilteringException, IOException {
    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(sourceDirectory, ejbJar + ".unfiltered");
    FileUtils.copyFile(deploymentDescriptor, unfilteredDeploymentDescriptor);
    mavenFileFilter.copyFile(unfilteredDeploymentDescriptor, deploymentDescriptor, true, filterWrappers, getEncoding(unfilteredDeploymentDescriptor));
    // Remove the temporary file
    FileUtils.forceDelete(unfilteredDeploymentDescriptor);
}
Also used : FilterWrapper(org.apache.maven.shared.utils.io.FileUtils.FilterWrapper) MavenResourcesExecution(org.apache.maven.shared.filtering.MavenResourcesExecution) File(java.io.File)

Example 3 with MavenResourcesExecution

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

Example 4 with MavenResourcesExecution

use of org.apache.maven.shared.filtering.MavenResourcesExecution 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
}
Also used : MavenResourcesExecution(org.apache.maven.shared.filtering.MavenResourcesExecution) 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) FilterWrapper(org.apache.maven.shared.utils.io.FileUtils.FilterWrapper) File(java.io.File)

Example 5 with MavenResourcesExecution

use of org.apache.maven.shared.filtering.MavenResourcesExecution in project maven-plugins by apache.

the class AbstractWarMojo method buildWebapp.

/**
     * Builds the webapp for the specified project with the new packaging task thingy.
     * Classes, libraries and tld files are copied to the <tt>webappDirectory</tt> during this phase.
     *
     * @param mavenProject the maven project
     * @param webapplicationDirectory the target directory
     * @throws MojoExecutionException if an error occurred while packaging the webapp
     * @throws MojoFailureException if an unexpected error occurred while packaging the webapp
     * @throws IOException if an error occurred while copying the files
     */
public void buildWebapp(MavenProject mavenProject, File webapplicationDirectory) throws MojoExecutionException, MojoFailureException, IOException {
    WebappStructure cache;
    if (useCache && cacheFile.exists()) {
        // CHECKSTYLE_OFF: LineLength
        cache = new WebappStructure(mavenProject.getDependencies(), webappStructureSerialier.fromXml(cacheFile));
    // CHECKSTYLE_ON: LineLength
    } else {
        cache = new WebappStructure(mavenProject.getDependencies(), null);
    }
    // CHECKSTYLE_OFF: LineLength
    final long startTime = System.currentTimeMillis();
    getLog().info("Assembling webapp [" + mavenProject.getArtifactId() + "] in [" + webapplicationDirectory + "]");
    final OverlayManager overlayManager = new OverlayManager(overlays, mavenProject, getDependentWarIncludes(), getDependentWarExcludes(), currentProjectOverlay);
    final List<WarPackagingTask> packagingTasks = getPackagingTasks(overlayManager);
    // CHECKSTYLE_ON: LineLength
    List<FileUtils.FilterWrapper> defaultFilterWrappers;
    try {
        MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution();
        mavenResourcesExecution.setEscapeString(escapeString);
        mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering);
        mavenResourcesExecution.setMavenProject(mavenProject);
        // if these are NOT set, just use the defaults, which are '${*}' and '@'.
        mavenResourcesExecution.setDelimiters(delimiters, useDefaultDelimiters);
        if (nonFilteredFileExtensions != null) {
            mavenResourcesExecution.setNonFilteredFileExtensions(nonFilteredFileExtensions);
        }
        if (filters == null) {
            filters = getProject().getBuild().getFilters();
        }
        mavenResourcesExecution.setFilters(filters);
        mavenResourcesExecution.setEscapedBackslashesInFilePath(escapedBackslashesInFilePath);
        mavenResourcesExecution.setMavenSession(this.session);
        mavenResourcesExecution.setEscapeString(this.escapeString);
        mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering);
        defaultFilterWrappers = mavenFileFilter.getDefaultFilterWrappers(mavenResourcesExecution);
    } catch (MavenFilteringException e) {
        getLog().error("fail to build filering wrappers " + e.getMessage());
        throw new MojoExecutionException(e.getMessage(), e);
    }
    final WarPackagingContext context = new DefaultWarPackagingContext(webapplicationDirectory, cache, overlayManager, defaultFilterWrappers, getNonFilteredFileExtensions(), filteringDeploymentDescriptors, this.artifactFactory, resourceEncoding, useJvmChmod);
    for (WarPackagingTask warPackagingTask : packagingTasks) {
        warPackagingTask.performPackaging(context);
    }
    // Post packaging
    final List<WarPostPackagingTask> postPackagingTasks = getPostPackagingTasks();
    for (WarPostPackagingTask task : postPackagingTasks) {
        task.performPostPackaging(context);
    }
    getLog().info("Webapp assembled in [" + (System.currentTimeMillis() - startTime) + " msecs]");
}
Also used : OverlayManager(org.apache.maven.plugins.war.overlay.OverlayManager) MavenResourcesExecution(org.apache.maven.shared.filtering.MavenResourcesExecution) WarPackagingContext(org.apache.maven.plugins.war.packaging.WarPackagingContext) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) WarPostPackagingTask(org.apache.maven.plugins.war.packaging.WarPostPackagingTask) WebappStructure(org.apache.maven.plugins.war.util.WebappStructure) WarPackagingTask(org.apache.maven.plugins.war.packaging.WarPackagingTask)

Aggregations

MavenResourcesExecution (org.apache.maven.shared.filtering.MavenResourcesExecution)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 MavenFilteringException (org.apache.maven.shared.filtering.MavenFilteringException)6 File (java.io.File)2 ArrayList (java.util.ArrayList)2 FilterWrapper (org.apache.maven.shared.utils.io.FileUtils.FilterWrapper)2 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Properties (java.util.Properties)1 MavenArchiver (org.apache.maven.archiver.MavenArchiver)1 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)1 Resource (org.apache.maven.model.Resource)1 OverlayManager (org.apache.maven.plugins.war.overlay.OverlayManager)1 WarPackagingContext (org.apache.maven.plugins.war.packaging.WarPackagingContext)1 WarPackagingTask (org.apache.maven.plugins.war.packaging.WarPackagingTask)1 WarPostPackagingTask (org.apache.maven.plugins.war.packaging.WarPostPackagingTask)1 WebappStructure (org.apache.maven.plugins.war.util.WebappStructure)1 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)1 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)1