Search in sources :

Example 1 with RemoteResourcesBundleXpp3Writer

use of org.apache.maven.plugin.resources.remote.io.xpp3.RemoteResourcesBundleXpp3Writer in project maven-plugins by apache.

the class BundleRemoteResourcesMojo method execute.

public void execute() throws MojoExecutionException {
    if (!resourcesDirectory.exists()) {
        getLog().info("skip non existing resourceDirectory " + resourcesDirectory.getAbsolutePath());
        return;
    }
    if (StringUtils.isEmpty(sourceEncoding)) {
        getLog().warn("sourceEncoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING + ", i.e. build is platform dependent!");
        sourceEncoding = ReaderFactory.FILE_ENCODING;
    }
    // Look at the content of the resourcesDirectory and create a manifest of the files
    // so that velocity can easily process any resources inside the JAR that need to be processed.
    RemoteResourcesBundle remoteResourcesBundle = new RemoteResourcesBundle();
    remoteResourcesBundle.setSourceEncoding(sourceEncoding);
    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setBasedir(resourcesDirectory);
    if (includes != null && includes.length != 0) {
        scanner.setIncludes(includes);
    } else {
        scanner.setIncludes(DEFAULT_INCLUDES);
    }
    if (excludes != null && excludes.length != 0) {
        scanner.setExcludes(excludes);
    }
    scanner.addDefaultExcludes();
    scanner.scan();
    List<String> includedFiles = Arrays.asList(scanner.getIncludedFiles());
    for (String resource : includedFiles) {
        remoteResourcesBundle.addRemoteResource(StringUtils.replace(resource, '\\', '/'));
    }
    RemoteResourcesBundleXpp3Writer w = new RemoteResourcesBundleXpp3Writer();
    Writer writer = null;
    try {
        File f = new File(outputDirectory, RESOURCES_MANIFEST);
        FileUtils.mkdir(f.getParentFile().getAbsolutePath());
        writer = new FileWriter(f);
        w.write(writer, remoteResourcesBundle);
        writer.close();
        writer = null;
    } catch (IOException e) {
        throw new MojoExecutionException("Error creating remote resources manifest.", e);
    } finally {
        IOUtil.close(writer);
    }
}
Also used : RemoteResourcesBundleXpp3Writer(org.apache.maven.plugin.resources.remote.io.xpp3.RemoteResourcesBundleXpp3Writer) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) FileWriter(java.io.FileWriter) RemoteResourcesBundleXpp3Writer(org.apache.maven.plugin.resources.remote.io.xpp3.RemoteResourcesBundleXpp3Writer) Writer(java.io.Writer)

Aggregations

File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 RemoteResourcesBundleXpp3Writer (org.apache.maven.plugin.resources.remote.io.xpp3.RemoteResourcesBundleXpp3Writer)1 DirectoryScanner (org.codehaus.plexus.util.DirectoryScanner)1