Search in sources :

Example 6 with MavenFilteringException

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);
    }
}
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 7 with MavenFilteringException

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
}
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 8 with MavenFilteringException

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

the class ChangesMojo method getChangesFromFile.

/* --------------------------------------------------------------------- */
/* Private methods */
/* --------------------------------------------------------------------- */
/**
     * Parses specified changes.xml file. It also makes filtering if needed. If specified file doesn't exist it will log
     * warning and return <code>null</code>.
     *
     * @param changesXml changes xml file to parse
     * @param project maven project to parse changes for
     * @param additionalProperties additional properties used for filtering
     * @return parsed <code>ChangesXML</code> instance or null if file doesn't exist
     * @throws MavenReportException if any errors occurs while parsing
     */
private ChangesXML getChangesFromFile(File changesXml, MavenProject project, Properties additionalProperties) throws MavenReportException {
    if (!changesXml.exists()) {
        getLog().warn("changes.xml file " + changesXml.getAbsolutePath() + " does not exist.");
        return null;
    }
    if (filteringChanges) {
        if (!filteredOutputDirectory.exists()) {
            filteredOutputDirectory.mkdirs();
        }
        XmlStreamReader xmlStreamReader = null;
        try {
            // so we get encoding from the file itself
            xmlStreamReader = new XmlStreamReader(changesXml);
            String encoding = xmlStreamReader.getEncoding();
            File resultFile = new File(filteredOutputDirectory, project.getGroupId() + "." + project.getArtifactId() + "-changes.xml");
            final MavenFileFilterRequest mavenFileFilterRequest = new MavenFileFilterRequest(changesXml, resultFile, true, project, Collections.<String>emptyList(), false, encoding, session, additionalProperties);
            mavenFileFilter.copyFile(mavenFileFilterRequest);
            changesXml = resultFile;
            xmlStreamReader.close();
            xmlStreamReader = null;
        } catch (IOException e) {
            throw new MavenReportException("Exception during filtering changes file : " + e.getMessage(), e);
        } catch (MavenFilteringException e) {
            throw new MavenReportException("Exception during filtering changes file : " + e.getMessage(), e);
        } finally {
            IOUtil.close(xmlStreamReader);
        }
    }
    return new ChangesXML(changesXml, getLog());
}
Also used : MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) MavenFileFilterRequest(org.apache.maven.shared.filtering.MavenFileFilterRequest) XmlStreamReader(org.apache.commons.io.input.XmlStreamReader) IOException(java.io.IOException) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 9 with MavenFilteringException

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);
    }
}
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 10 with MavenFilteringException

use of org.apache.maven.shared.filtering.MavenFilteringException in project sling by apache.

the class AbstractUsingBundleListMojo method readSlingProperties.

private void readSlingProperties(final File propsFile, final int mode) throws MojoExecutionException {
    if (propsFile.exists()) {
        File tmp = null;
        try {
            tmp = File.createTempFile("sling", "props");
            mavenFileFilter.copyFile(propsFile, tmp, true, project, Collections.EMPTY_LIST, true, System.getProperty("file.encoding"), mavenSession);
            final Properties loadedProps = PropertyUtils.loadPropertyFile(tmp, null);
            if (mode == 0) {
                if (this.slingProperties == null) {
                    this.slingProperties = loadedProps;
                } else {
                    this.copyProperties(loadedProps, this.slingProperties);
                }
                filterProperties(this.slingProperties);
            } else if (mode == 1) {
                if (this.slingWebappProperties == null) {
                    this.slingWebappProperties = loadedProps;
                } else {
                    this.copyProperties(loadedProps, this.slingWebappProperties);
                }
                filterProperties(this.slingWebappProperties);
            } else {
                if (this.slingStandaloneProperties == null) {
                    this.slingStandaloneProperties = loadedProps;
                } else {
                    this.copyProperties(loadedProps, this.slingStandaloneProperties);
                }
                filterProperties(this.slingStandaloneProperties);
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Unable to create filtered properties file", e);
        } catch (MavenFilteringException e) {
            throw new MojoExecutionException("Unable to create filtered properties file", e);
        } finally {
            if (tmp != null) {
                tmp.delete();
            }
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) IOException(java.io.IOException) BundleListUtils.interpolateProperties(org.apache.sling.maven.projectsupport.BundleListUtils.interpolateProperties) Properties(java.util.Properties) File(java.io.File)

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