[
https://issues.apache.org/jira/browse/MRRESOURCES-155?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17907598#comment-17907598
]
ASF GitHub Bot commented on MRRESOURCES-155:
--------------------------------------------
elharo commented on code in PR #79:
URL:
https://github.com/apache/maven-remote-resources-plugin/pull/79#discussion_r1894638665
##########
src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java:
##########
@@ -350,6 +350,14 @@ public abstract class AbstractProcessRemoteResourcesMojo
extends AbstractMojo {
@Parameter(defaultValue = "${project.build.outputTimestamp}")
private String outputTimestamp;
+ /**
+ * Indicate if project workspace files with teh same name should be used
instead of from bundle.
Review Comment:
teh --> the
instead of the ones from the bundle
##########
src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java:
##########
@@ -605,7 +613,7 @@ protected Map<Organization, List<MavenProject>>
getProjectsSortedByOrganization(
return organizations;
}
- protected boolean copyResourceIfExists(File file, String relFileName,
VelocityContext context)
+ protected boolean copyResourceIfExists(File outputFile, String
relFileName, VelocityContext context)
Review Comment:
relFileName, what is this? Is rel "relative" or release? If relative, how is
a file name relative? Please rename for clarity.
##########
src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java:
##########
@@ -622,9 +630,10 @@ protected boolean copyResourceIfExists(File file, String
relFileName, VelocityCo
source = templateSource;
}
- if (source.exists() && !source.equals(file)) {
+ if (source.exists() && !source.equals(outputFile)) {
if (source == templateSource) {
- try (CachingOutputStream os = new
CachingOutputStream(file)) {
+ getLog().debug("Use project resource '" + source + "' as
resource with Velocity");
+ try (CachingOutputStream os = new
CachingOutputStream(outputFile)) {
Review Comment:
You don't need to next the try blocks. Stream, writer, and reader can all be
set up in the initial clause in parentheses
##########
src/it/process-project-file/pom.xml:
##########
@@ -0,0 +1,56 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its</groupId>
+ <artifactId>mrrp-process</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-remote-resources-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <resourceBundles>
+
<resourceBundle>org.apache.maven.its:mrrp-bundle-a:1.0-SNAPSHOT</resourceBundle>
Review Comment:
SNAPSHOT OK here?
##########
src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java:
##########
@@ -906,46 +932,53 @@ protected void processResourceBundles(ClassLoader
classLoader, VelocityContext c
// Don't overwrite resource that are already being provided.
- File f = new File(outputDirectory, projectResource);
+ File outputFile = new File(outputDirectory, projectResource);
+
+ FileUtils.mkdir(outputFile.getParentFile().getAbsolutePath());
+
+ // resource exists in project resources
+ if (copyResourceIfExists(outputFile, projectResource,
context)) {
+ continue;
+ }
- FileUtils.mkdir(f.getParentFile().getAbsolutePath());
+ if (copyProjectRootIfExists(outputFile, projectResource)) {
+ continue;
+ }
- if (!copyResourceIfExists(f, projectResource, context)) {
- if (doVelocity) {
- try (CachingOutputStream os = new
CachingOutputStream(f)) {
- String bundleEncoding = bundle.getSourceEncoding();
- if (bundleEncoding == null) {
- bundleEncoding = encoding;
- }
- try (Writer writer = new OutputStreamWriter(os,
bundleEncoding)) {
- velocity.mergeTemplate(bundleResource,
bundleEncoding, context, writer);
- }
+ if (doVelocity) {
+ try (CachingOutputStream os = new
CachingOutputStream(outputFile)) {
+ String bundleEncoding = bundle.getSourceEncoding();
+ if (bundleEncoding == null) {
+ bundleEncoding = encoding;
}
- } else {
- URL resUrl = classLoader.getResource(bundleResource);
- if (resUrl != null) {
- FileUtils.copyURLToFile(resUrl, f);
+ try (Writer writer = new OutputStreamWriter(os,
bundleEncoding)) {
+ velocity.mergeTemplate(bundleResource,
bundleEncoding, context, writer);
}
}
+ } else {
+ URL resUrl = classLoader.getResource(bundleResource);
Review Comment:
resUrl --> resourceUrl or maybe just url.
##########
src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java:
##########
@@ -906,46 +932,53 @@ protected void processResourceBundles(ClassLoader
classLoader, VelocityContext c
// Don't overwrite resource that are already being provided.
- File f = new File(outputDirectory, projectResource);
+ File outputFile = new File(outputDirectory, projectResource);
+
+ FileUtils.mkdir(outputFile.getParentFile().getAbsolutePath());
+
+ // resource exists in project resources
+ if (copyResourceIfExists(outputFile, projectResource,
context)) {
+ continue;
+ }
- FileUtils.mkdir(f.getParentFile().getAbsolutePath());
+ if (copyProjectRootIfExists(outputFile, projectResource)) {
+ continue;
+ }
- if (!copyResourceIfExists(f, projectResource, context)) {
- if (doVelocity) {
- try (CachingOutputStream os = new
CachingOutputStream(f)) {
- String bundleEncoding = bundle.getSourceEncoding();
- if (bundleEncoding == null) {
- bundleEncoding = encoding;
- }
- try (Writer writer = new OutputStreamWriter(os,
bundleEncoding)) {
- velocity.mergeTemplate(bundleResource,
bundleEncoding, context, writer);
- }
+ if (doVelocity) {
+ try (CachingOutputStream os = new
CachingOutputStream(outputFile)) {
+ String bundleEncoding = bundle.getSourceEncoding();
+ if (bundleEncoding == null) {
+ bundleEncoding = encoding;
}
- } else {
- URL resUrl = classLoader.getResource(bundleResource);
- if (resUrl != null) {
- FileUtils.copyURLToFile(resUrl, f);
+ try (Writer writer = new OutputStreamWriter(os,
bundleEncoding)) {
+ velocity.mergeTemplate(bundleResource,
bundleEncoding, context, writer);
}
}
+ } else {
+ URL resUrl = classLoader.getResource(bundleResource);
+ if (resUrl != null) {
+ FileUtils.copyURLToFile(resUrl, outputFile);
+ }
+ }
- File appendedResourceFile = new
File(appendedResourcesDirectory, projectResource);
- File appendedVmResourceFile = new
File(appendedResourcesDirectory, projectResource + ".vm");
+ 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(f,
true)) {
- IOUtil.copy(in, out);
- }
+ 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");
+ } else if (appendedVmResourceFile.exists()) {
+ getLog().info("Filtering appended resource: " +
projectResource + ".vm");
- try (Reader reader = new
FileReader(appendedVmResourceFile);
- Writer writer = getWriter(bundle, f)) {
- Velocity.init();
- Velocity.evaluate(context, writer,
"remote-resources", reader);
- }
+ try (Reader reader = new
FileReader(appendedVmResourceFile);
Review Comment:
needs an encoding, or use Files.newReader instead
> Allow to override bundle resources by project workspace files
> -------------------------------------------------------------
>
> Key: MRRESOURCES-155
> URL: https://issues.apache.org/jira/browse/MRRESOURCES-155
> Project: Maven Remote Resources Plugin
> Issue Type: New Feature
> Reporter: Slawomir Jaranowski
> Assignee: Slawomir Jaranowski
> Priority: Major
> Fix For: 3.3.0
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)