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 179c0ca Take a resource bundle's version from the project's
dependencies (#330)
179c0ca is described below
commit 179c0ca25f425b912a3534b756ce4a20e20043d1
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Wed Oct 28 17:38:55 2026 +0100
Take a resource bundle's version from the project's dependencies (#330)
Fixes #154. A resourceBundle given as groupId:artifactId takes its version
from the project's dependency on that artifact, or else from its
dependencyManagement, and resolves the plain jar.
---
.../resources/generate-from-managed-bundle/pom.xml | 64 +++++++++++++++
.../remote/AbstractProcessRemoteResourcesMojo.java | 48 +++++++++++-
src/site/markdown/usage.md.vm | 2 +
.../plugin/resources/remote/BundleVersionTest.java | 91 ++++++++++++++++++++++
.../remote/it/ITGenerateFromManagedBundle.java | 47 +++++++++++
5 files changed, 250 insertions(+), 2 deletions(-)
diff --git a/src/it/resources/generate-from-managed-bundle/pom.xml
b/src/it/resources/generate-from-managed-bundle/pom.xml
new file mode 100644
index 0000000..7947931
--- /dev/null
+++ b/src/it/resources/generate-from-managed-bundle/pom.xml
@@ -0,0 +1,64 @@
+<?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>generate-from-managed-bundle</artifactId>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.plugin.rresource.it</groupId>
+ <artifactId>resource-bundle-with-template</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-remote-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>remote-resources</id>
+ <goals>
+ <goal>process</goal>
+ </goals>
+ <configuration>
+ <resourceBundles>
+
<resourceBundle>org.apache.maven.plugin.rresource.it:resource-bundle-with-template</resourceBundle>
+ </resourceBundles>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
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 b4e4c96..e03a227 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
@@ -58,6 +58,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Organization;
import org.apache.maven.model.Resource;
@@ -219,6 +220,9 @@ public abstract class AbstractProcessRemoteResourcesMojo
extends AbstractMojo {
/**
* The resource bundles that will be retrieved and processed,
* expressed with
<code>groupId:artifactId:version[:type[:classifier]]</code> format.
+ * Since 3.4.0, a bundle given as <code>groupId:artifactId</code> takes
its version from the project's
+ * dependency on that artifact, or else from its
<code>dependencyManagement</code>. Such a bundle always
+ * resolves the plain jar; give the version to name a type or classifier.
*/
@Parameter(property = "resourceBundles", required = true)
private List<String> resourceBundles;
@@ -463,7 +467,7 @@ public abstract class AbstractProcessRemoteResourcesMojo
extends AbstractMojo {
configureLocator();
validate();
- List<File> resourceBundleArtifacts =
downloadBundles(resourceBundles);
+ List<File> resourceBundleArtifacts =
downloadBundles(versionedBundles());
supplementModels = loadSupplements(supplementalModels);
classLoader = initalizeClassloader(resourceBundleArtifacts);
@@ -831,7 +835,7 @@ public abstract class AbstractProcessRemoteResourcesMojo
extends AbstractMojo {
int bundleCount = 1;
- for (String artifactDescriptor : resourceBundles) {
+ for (String artifactDescriptor : versionedBundles()) {
// groupId:artifactId:version, groupId:artifactId:version:type
// or groupId:artifactId:version:type:classifier
// use the same splitting as downloadBundles() so both are
consistent;
@@ -931,6 +935,46 @@ public abstract class AbstractProcessRemoteResourcesMojo
extends AbstractMojo {
return context;
}
+ /**
+ * Returns the resource bundle descriptors with a version added to each
one given as
+ * <code>groupId:artifactId</code>, taken from the project's dependencies
or dependency management.
+ */
+ List<String> versionedBundles() throws MojoExecutionException {
+ List<String> result = new ArrayList<>();
+ for (String descriptor : resourceBundles) {
+ String[] s = descriptor.split(":", -1);
+ if (s.length == 2 && !s[0].isEmpty() && !s[1].isEmpty()) {
+ String version = dependencyVersion(s[0], s[1]);
+ if (version == null) {
+ throw new MojoExecutionException("The resource bundle " +
descriptor
+ + " has no version, and the project has no
dependency or managed dependency on it. "
+ + "Add the version, as in <resourceBundle>" +
descriptor + ":1.0</resourceBundle>, "
+ + "or manage the version of " + descriptor + " in
dependencyManagement.");
+ }
+ result.add(descriptor + ":" + version);
+ } else {
+ result.add(descriptor);
+ }
+ }
+ return result;
+ }
+
+ private String dependencyVersion(String groupId, String artifactId) {
+ List<Dependency> candidates = new
ArrayList<>(project.getDependencies());
+ if (project.getDependencyManagement() != null) {
+
candidates.addAll(project.getDependencyManagement().getDependencies());
+ }
+ for (Dependency dependency : candidates) {
+ if (groupId.equals(dependency.getGroupId())
+ && artifactId.equals(dependency.getArtifactId())
+ && dependency.getVersion() != null
+ && !dependency.getVersion().isEmpty()) {
+ return dependency.getVersion();
+ }
+ }
+ return null;
+ }
+
private List<File> downloadBundles(List<String> bundles) throws
MojoExecutionException {
List<File> bundleArtifacts = new ArrayList<>();
diff --git a/src/site/markdown/usage.md.vm b/src/site/markdown/usage.md.vm
index 9050cc2..9c39bae 100644
--- a/src/site/markdown/usage.md.vm
+++ b/src/site/markdown/usage.md.vm
@@ -97,6 +97,8 @@ To use remote resource bundles you need to configure the
plugin as follows:
This will retrieve the `apache-jar-resource-bundle-1.0.jar` from the remote
repositories specified in your POM, process each resource in the bundle and
deposit them in your projects `${esc.d}{basedir}/target/classes` directory.
+Since version 3.4.0, a bundle can be given as `groupId:artifactId` when the
project declares a dependency on it or manages its version in
`dependencyManagement`; the plugin then takes the version from there and
resolves the plain jar. Give the full
`groupId:artifactId:version:type:classifier` form for any other type or
classifier.
+
Using SPDX License IDs in Templates
----------------------------------
diff --git
a/src/test/java/org/apache/maven/plugin/resources/remote/BundleVersionTest.java
b/src/test/java/org/apache/maven/plugin/resources/remote/BundleVersionTest.java
new file mode 100644
index 0000000..d7444fd
--- /dev/null
+++
b/src/test/java/org/apache/maven/plugin/resources/remote/BundleVersionTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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;
+
+import java.lang.reflect.Field;
+import java.util.Arrays;
+
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Model;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class BundleVersionTest {
+
+ @Test
+ void versionComesFromDependency() throws Exception {
+ Model model = new Model();
+ model.addDependency(dependency("org.example", "bundle", "1.2"));
+ assertEquals(
+ Arrays.asList("org.example:bundle:1.2"),
+ mojo(model, "org.example:bundle").versionedBundles());
+ }
+
+ @Test
+ void versionComesFromDependencyManagement() throws Exception {
+ Model model = new Model();
+ DependencyManagement management = new DependencyManagement();
+ management.addDependency(dependency("org.example", "bundle", "2.0"));
+ model.setDependencyManagement(management);
+ assertEquals(
+ Arrays.asList("org.example:bundle:2.0"),
+ mojo(model, "org.example:bundle").versionedBundles());
+ }
+
+ @Test
+ void versionedDescriptorsAreKept() throws Exception {
+ assertEquals(
+ Arrays.asList("org.example:bundle:1.0:jar"),
+ mojo(new Model(),
"org.example:bundle:1.0:jar").versionedBundles());
+ }
+
+ @Test
+ void missingVersionFails() throws Exception {
+ AbstractProcessRemoteResourcesMojo mojo = mojo(new Model(),
"org.example:bundle");
+ MojoExecutionException e = assertThrows(MojoExecutionException.class,
mojo::versionedBundles);
+ assertTrue(e.getMessage().contains("has no version"), e.getMessage());
+ }
+
+ private static Dependency dependency(String groupId, String artifactId,
String version) {
+ Dependency dependency = new Dependency();
+ dependency.setGroupId(groupId);
+ dependency.setArtifactId(artifactId);
+ dependency.setVersion(version);
+ return dependency;
+ }
+
+ private static AbstractProcessRemoteResourcesMojo mojo(Model model,
String... bundles) throws Exception {
+ AbstractProcessRemoteResourcesMojo mojo = new
ProcessRemoteResourcesMojo(null, null, null, null, null);
+ set(mojo, "project", new MavenProject(model));
+ set(mojo, "resourceBundles", Arrays.asList(bundles));
+ return mojo;
+ }
+
+ private static void set(Object target, String name, Object value) throws
Exception {
+ Field field =
AbstractProcessRemoteResourcesMojo.class.getDeclaredField(name);
+ field.setAccessible(true);
+ field.set(target, value);
+ }
+}
diff --git
a/src/test/java/org/apache/maven/plugin/resources/remote/it/ITGenerateFromManagedBundle.java
b/src/test/java/org/apache/maven/plugin/resources/remote/it/ITGenerateFromManagedBundle.java
new file mode 100644
index 0000000..739bdef
--- /dev/null
+++
b/src/test/java/org/apache/maven/plugin/resources/remote/it/ITGenerateFromManagedBundle.java
@@ -0,0 +1,47 @@
+/*
+ * 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.net.URISyntaxException;
+
+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.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class ITGenerateFromManagedBundle extends AbstractIT {
+ @Test
+ public void test() throws IOException, URISyntaxException {
+ File dir = TestUtils.getTestDir("generate-from-managed-bundle");
+ MavenRunner verifier = TestUtils.newVerifier(dir);
+
+ verifier.addCliArgument("generate-resources");
+ verifier.execute();
+ verifier.verifyErrorFreeLog();
+
+ File output = new File(dir,
"target/maven-shared-archive-resources/DEPENDENCIES");
+ String content = FileUtils.fileRead(output);
+
+ assertTrue(content.contains("Built-In:"));
+ }
+}