This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/maven-remote-resources-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 3ddc0ae Take resource overrides from the build the output is attached
to (#332)
3ddc0ae is described below
commit 3ddc0ae8cbf9b90b305977a0a9ed6074cc448e48
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Wed Oct 28 20:25:49 2026 +0100
Take resource overrides from the build the output is attached to (#332)
Fixes #183. With attachToMain=false, a same-named file in
src/main/resources replaced the bundled one for tests and went missing from the
main jar. Overrides now come from the main resources only when the output is
attached to the main build, else from the test resources.
---
.../resources/attach-to-test-only/bundle/pom.xml | 62 ++++++++++++++++++
.../bundle/src/main/resources/META-INF/beans.xml | 21 +++++++
.../resources/attach-to-test-only/project/pom.xml | 55 ++++++++++++++++
.../project/src/main/resources/META-INF/beans.xml | 21 +++++++
.../remote/AbstractProcessRemoteResourcesMojo.java | 17 ++++-
.../resources/remote/it/ITAttachToTestOnly.java | 73 ++++++++++++++++++++++
6 files changed, 248 insertions(+), 1 deletion(-)
diff --git a/src/it/resources/attach-to-test-only/bundle/pom.xml
b/src/it/resources/attach-to-test-only/bundle/pom.xml
new file mode 100644
index 0000000..6ae6e3c
--- /dev/null
+++ b/src/it/resources/attach-to-test-only/bundle/pom.xml
@@ -0,0 +1,62 @@
+<?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
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.plugin.rresource.it</groupId>
+ <artifactId>it-parent</artifactId>
+ <version>${project.version}</version>
+ <relativePath>../../it-parent/pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.maven.plugin.rresource.it.atto</groupId>
+ <artifactId>bundle</artifactId>
+ <version>1.0</version>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-remote-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>bundle</goal>
+ </goals>
+ <configuration>
+ <includes>
+ <include>**/*.xml</include>
+ </includes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <distributionManagement>
+ <repository>
+ <id>it-remote</id>
+ <url>file:${remoteRepository}</url>
+ </repository>
+ </distributionManagement>
+</project>
diff --git
a/src/it/resources/attach-to-test-only/bundle/src/main/resources/META-INF/beans.xml
b/src/it/resources/attach-to-test-only/bundle/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..6e09a73
--- /dev/null
+++
b/src/it/resources/attach-to-test-only/bundle/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,21 @@
+<?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.
+-->
+<!-- from bundle -->
+<beans/>
diff --git a/src/it/resources/attach-to-test-only/project/pom.xml
b/src/it/resources/attach-to-test-only/project/pom.xml
new file mode 100644
index 0000000..08ad712
--- /dev/null
+++ b/src/it/resources/attach-to-test-only/project/pom.xml
@@ -0,0 +1,55 @@
+<?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
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.plugin.rresource.it</groupId>
+ <artifactId>it-parent</artifactId>
+ <version>${project.version}</version>
+ <relativePath>../../it-parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>attach-to-test-only</artifactId>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-remote-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>process</goal>
+ </goals>
+ <configuration>
+ <resourceBundles>
+
<resourceBundle>org.apache.maven.plugin.rresource.it.atto:bundle:1.0</resourceBundle>
+ </resourceBundles>
+ <attachToMain>false</attachToMain>
+ <attachToTest>true</attachToTest>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git
a/src/it/resources/attach-to-test-only/project/src/main/resources/META-INF/beans.xml
b/src/it/resources/attach-to-test-only/project/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..46a4147
--- /dev/null
+++
b/src/it/resources/attach-to-test-only/project/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,21 @@
+<?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.
+-->
+<!-- from project -->
+<beans/>
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 e03a227..31e5694 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
@@ -237,6 +237,7 @@ public abstract class AbstractProcessRemoteResourcesMojo
extends AbstractMojo {
/**
* Attaches the resources to the main build of the project as a resource
directory.
+ * A file of the same name in the project's main resources is then used
instead of the bundled one.
*
* @since 1.5
*/
@@ -245,6 +246,8 @@ public abstract class AbstractProcessRemoteResourcesMojo
extends AbstractMojo {
/**
* Attaches the resources to the test build of the project as a resource
directory.
+ * When <code>attachToMain</code> is <code>false</code>, a file of the
same name in the project's test
+ * resources is then used instead of the bundled one, and the main
resources are left untouched.
*
* @since 1.5
*/
@@ -691,10 +694,22 @@ public abstract class AbstractProcessRemoteResourcesMojo
extends AbstractMojo {
return organizations;
}
+ /**
+ * Returns the project resources that may override a bundled resource: the
main resources when the output is
+ * attached to the main build, else the test resources when it is attached
to the test build only. A file there
+ * is used instead of the bundled one and excluded from that resource set,
so it is not copied twice.
+ */
+ private List<Resource> overridingResources() {
+ if (attachToMain) {
+ return project.getResources();
+ }
+ return attachToTest ? project.getTestResources() :
Collections.emptyList();
+ }
+
protected boolean copyResourceIfExists(
File outputFile, String bundleResourceName, VelocityContext
context, String encoding)
throws IOException, MojoExecutionException {
- for (Resource resource : project.getResources()) {
+ for (Resource resource : overridingResources()) {
File resourceDirectory = new File(resource.getDirectory());
if (!resourceDirectory.exists()) {
diff --git
a/src/test/java/org/apache/maven/plugin/resources/remote/it/ITAttachToTestOnly.java
b/src/test/java/org/apache/maven/plugin/resources/remote/it/ITAttachToTestOnly.java
new file mode 100644
index 0000000..70bbe45
--- /dev/null
+++
b/src/test/java/org/apache/maven/plugin/resources/remote/it/ITAttachToTestOnly.java
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugin.resources.remote.it;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.util.jar.JarFile;
+
+import org.apache.maven.plugin.resources.remote.it.support.MavenRunner;
+import org.apache.maven.plugin.resources.remote.it.support.TestUtils;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * With <code>attachToMain=false</code>, a same-named file in the main
resources must neither replace the bundled
+ * one for tests nor go missing from the main jar (#183).
+ */
+public class ITAttachToTestOnly extends AbstractIT {
+ @Test
+ public void test() throws IOException, URISyntaxException {
+ File dir = TestUtils.getTestDir("attach-to-test-only");
+
+ MavenRunner verifier = TestUtils.newVerifier(new File(dir, "bundle"));
+ verifier.addCliArgument("deploy");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ File projectDir = new File(dir, "project");
+ verifier = TestUtils.newVerifier(projectDir);
+ verifier.deleteArtifacts("org.apache.maven.plugin.rresource.it.atto");
+ verifier.addCliArgument("package");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ String testResource = FileUtils.fileRead(new File(projectDir,
"target/test-classes/META-INF/beans.xml"));
+ assertTrue(testResource.contains("from bundle"), testResource);
+
+ File[] jars = new File(projectDir, "target").listFiles((d, name) ->
name.endsWith(".jar"));
+ assertNotNull(jars);
+ assertEquals(1, jars.length, "expected one jar in target");
+ try (JarFile jar = new JarFile(jars[0])) {
+ assertNotNull(jar.getEntry("META-INF/beans.xml"), "the main jar
lost its own META-INF/beans.xml");
+ try (InputStream in =
jar.getInputStream(jar.getEntry("META-INF/beans.xml"))) {
+ String mainResource = IOUtil.toString(in,
StandardCharsets.UTF_8.name());
+ assertTrue(mainResource.contains("from project"),
mainResource);
+ }
+ }
+ }
+}