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);
}
}
Aggregations