diff --git a/src/it/process-project-file/common2.txt b/src/it/process-project-file/common2.txt
new file mode 100644
index 0000000..8cc47b8
--- /dev/null
+++ b/src/it/process-project-file/common2.txt
@@ -0,0 +1,18 @@
+# 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.
+
+using project's workspace file
diff --git a/src/it/process-project-file/invoker.properties b/src/it/process-project-file/invoker.properties
new file mode 100644
index 0000000..0097f00
--- /dev/null
+++ b/src/it/process-project-file/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals = generate-resources
diff --git a/src/it/process-project-file/pom.xml b/src/it/process-project-file/pom.xml
new file mode 100644
index 0000000..a1621ff
--- /dev/null
+++ b/src/it/process-project-file/pom.xml
@@ -0,0 +1,56 @@
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.its
+ mrrp-process
+ 1.0-SNAPSHOT
+ pom
+
+
+ UTF-8
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-remote-resources-plugin
+ @project.version@
+
+
+ org.apache.maven.its:mrrp-bundle-a:1.0-SNAPSHOT
+
+ true
+
+
+
+
+ process
+
+
+
+
+
+
+
diff --git a/src/it/process-project-file/verify.groovy b/src/it/process-project-file/verify.groovy
new file mode 100644
index 0000000..7a0721a
--- /dev/null
+++ b/src/it/process-project-file/verify.groovy
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+dir = new File( basedir, 'target/maven-shared-archive-resources' )
+
+assert new File( dir, 'a/a.txt' ).text.contains( 'mrrp-bundle-a' )
+
+assert new File( dir, 'common.txt' ).text.contains( 'mrrp-bundle-a' ) // bundle a is first in classpath
+assert new File( dir, 'common-vm.txt' ).text.contains( 'mrrp-bundle-a org.apache.maven.its:mrrp-process' )
+
+// bundle content overridden by local project's workspace file
+assert new File( dir, 'common2.txt' ).text.contains( 'using project\'s workspace file' )
+
+return true;
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java b/src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java
index 53fb02a..6c2cdee 100644
--- a/src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java
+++ b/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.
+ *
+ * @since 3.3.0
+ */
+ @Parameter(defaultValue = "false")
+ private boolean useProjectFiles;
+
/**
* Map of artifacts to supplemental project object models.
*/
@@ -605,7 +613,7 @@ protected Map> getProjectsSortedByOrganization(
return organizations;
}
- protected boolean copyResourceIfExists(File file, String relFileName, VelocityContext context)
+ protected boolean copyResourceIfExists(File outputFile, String relFileName, VelocityContext context)
throws IOException, MojoExecutionException {
for (Resource resource : project.getResources()) {
File resourceDirectory = new File(resource.getDirectory());
@@ -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)) {
try (Reader reader = getReader(source);
Writer writer = getWriter(os)) {
velocity.evaluate(context, writer, "", reader);
@@ -633,8 +642,9 @@ protected boolean copyResourceIfExists(File file, String relFileName, VelocityCo
}
}
} else if (resource.isFiltering()) {
+ getLog().debug("Use project resource '" + source + "' as resource with filtering");
- MavenFileFilterRequest req = setupRequest(resource, source, file);
+ MavenFileFilterRequest req = setupRequest(resource, source, outputFile);
try {
fileFilter.copyFile(req);
@@ -642,7 +652,8 @@ protected boolean copyResourceIfExists(File file, String relFileName, VelocityCo
throw new MojoExecutionException("Error filtering resource: " + source, e);
}
} else {
- FilteringUtils.copyFile(source, file, null, null);
+ getLog().debug("Use project resource '" + source + "' as resource");
+ FilteringUtils.copyFile(source, outputFile, null, null);
}
// exclude the original (so eclipse doesn't complain about duplicate resources)
@@ -654,6 +665,21 @@ protected boolean copyResourceIfExists(File file, String relFileName, VelocityCo
return false;
}
+ private boolean copyProjectRootIfExists(File outputFile, String projectResource) throws IOException {
+ if (!useProjectFiles) {
+ return false;
+ }
+
+ File source = new File(project.getBasedir(), projectResource);
+ if (source.exists()) {
+ getLog().debug("Use project file '" + source + "' as resource");
+ FilteringUtils.copyFile(source, outputFile, null, null);
+ return true;
+ }
+
+ return false;
+ }
+
private Reader getReader(File source) throws IOException {
return Files.newBufferedReader(source.toPath(), Charset.forName(encoding));
}
@@ -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);
+ Writer writer = getWriter(bundle, outputFile)) {
+ Velocity.init();
+ Velocity.evaluate(context, writer, "remote-resources", reader);
}
}
}