in src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java [877:992]
protected void processResourceBundles(ClassLoader classLoader, VelocityContext context)
throws MojoExecutionException {
List<Map.Entry<String, RemoteResourcesBundle>> remoteResources = new ArrayList<>();
int bundleCount = 0;
int resourceCount = 0;
// list remote resources form bundles
try {
RemoteResourcesBundleXpp3Reader bundleReader = new RemoteResourcesBundleXpp3Reader();
for (Enumeration<URL> e = classLoader.getResources(BundleRemoteResourcesMojo.RESOURCES_MANIFEST);
e.hasMoreElements(); ) {
URL url = e.nextElement();
bundleCount++;
getLog().debug("processResourceBundle on bundle#" + bundleCount + " " + url);
RemoteResourcesBundle bundle;
try (InputStream in = url.openStream()) {
bundle = bundleReader.read(in);
}
verifyRequiredProperties(bundle, url);
int n = 0;
for (String bundleResource : bundle.getRemoteResources()) {
n++;
resourceCount++;
getLog().debug("bundle#" + bundleCount + " resource#" + n + " " + bundleResource);
remoteResources.add(new AbstractMap.SimpleEntry<>(bundleResource, bundle));
}
}
} catch (IOException ioe) {
throw new MojoExecutionException("Error finding remote resources manifests", ioe);
} catch (XmlPullParserException xppe) {
throw new MojoExecutionException("Error parsing remote resource bundle descriptor.", xppe);
}
getLog().info("Copying " + resourceCount + " resource" + ((resourceCount > 1) ? "s" : "") + " from "
+ bundleCount + " bundle" + ((bundleCount > 1) ? "s" : "") + ".");
String velocityResource = null;
try {
for (Map.Entry<String, RemoteResourcesBundle> entry : remoteResources) {
String bundleResource = entry.getKey();
RemoteResourcesBundle bundle = entry.getValue();
String projectResource = bundleResource;
boolean doVelocity = false;
if (projectResource.endsWith(TEMPLATE_SUFFIX)) {
projectResource = projectResource.substring(0, projectResource.length() - 3);
velocityResource = bundleResource;
doVelocity = true;
}
// Don't overwrite resource that are already being provided.
File outputFile = new File(outputDirectory, projectResource);
FileUtils.mkdir(outputFile.getParentFile().getAbsolutePath());
// resource exists in project resources
if (copyResourceIfExists(outputFile, projectResource, context, bundle.getSourceEncoding())) {
continue;
}
if (copyProjectRootIfExists(outputFile, projectResource)) {
continue;
}
if (doVelocity) {
String bundleEncoding = bundle.getSourceEncoding();
if (bundleEncoding == null) {
bundleEncoding = encoding;
}
try (CachingOutputStream os = new CachingOutputStream(outputFile);
Writer writer = getWriter(bundleEncoding, os)) {
velocity.mergeTemplate(bundleResource, bundleEncoding, context, writer);
}
} else {
URL bundleResourceUrl = classLoader.getResource(bundleResource);
if (bundleResourceUrl != null) {
FileUtils.copyURLToFile(bundleResourceUrl, outputFile);
}
}
File appendedResourceFile = new File(appendedResourcesDirectory, projectResource);
File appendedVmResourceFile = new File(appendedResourcesDirectory, projectResource + ".vm");
if (appendedResourceFile.exists()) {
getLog().info("Copying appended resource: " + projectResource);
try (InputStream in = Files.newInputStream(appendedResourceFile.toPath());
OutputStream out = new FileOutputStream(outputFile, true)) {
IOUtil.copy(in, out);
}
} else if (appendedVmResourceFile.exists()) {
getLog().info("Filtering appended resource: " + projectResource + ".vm");
try (CachingOutputStream os = new CachingOutputStream(outputFile);
Reader reader = getReader(bundle.getSourceEncoding(), appendedVmResourceFile);
Writer writer = getWriter(bundle.getSourceEncoding(), os)) {
Velocity.init();
Velocity.evaluate(context, writer, "remote-resources", reader);
}
}
}
} catch (IOException ioe) {
throw new MojoExecutionException("Error reading remote resource", ioe);
} catch (VelocityException e) {
throw new MojoExecutionException("Error rendering Velocity resource '" + velocityResource + "'", e);
}
}