[MJLINK-80] Support additional resources
diff --git a/pom.xml b/pom.xml
index acff4da..2841799 100644
--- a/pom.xml
+++ b/pom.xml
@@ -127,6 +127,11 @@
<version>2.11.0</version>
</dependency>
<dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-filtering</artifactId>
+ <version>3.3.1</version>
+ </dependency>
+ <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.2.0</version>
diff --git a/src/it/projects/MJLINK-80_additionalResources/pom.xml b/src/it/projects/MJLINK-80_additionalResources/pom.xml
new file mode 100644
index 0000000..c8a6c99
--- /dev/null
+++ b/src/it/projects/MJLINK-80_additionalResources/pom.xml
@@ -0,0 +1,54 @@
+<?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>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jlink-plugin-mjlink-80</artifactId>
+ <version>42.0.0</version>
+ <packaging>jlink</packaging>
+ <description>Test adding extra resources</description>
+ <properties>
+ <maven.compiler.release>9</maven.compiler.release>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jlink-plugin</artifactId>
+ <version>@project.version@</version>
+ <extensions>true</extensions>
+ <configuration>
+ <addModules>
+ <module>java.base</module>
+ </addModules>
+ <additionalResources>
+ <resource>
+ <directory>src/jlink/resources</directory>
+ </resource>
+ </additionalResources>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/projects/MJLINK-80_additionalResources/src/jlink/resources/README.md b/src/it/projects/MJLINK-80_additionalResources/src/jlink/resources/README.md
new file mode 100644
index 0000000..2ebf0fe
--- /dev/null
+++ b/src/it/projects/MJLINK-80_additionalResources/src/jlink/resources/README.md
@@ -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.
+-->
+
+This application has been created with the JLink tool!
\ No newline at end of file
diff --git a/src/it/projects/MJLINK-80_additionalResources/verify.groovy b/src/it/projects/MJLINK-80_additionalResources/verify.groovy
new file mode 100644
index 0000000..0a05897
--- /dev/null
+++ b/src/it/projects/MJLINK-80_additionalResources/verify.groovy
@@ -0,0 +1,29 @@
+
+/*
+ * 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.
+ */
+
+import java.io.*;
+import java.util.*;
+import java.util.zip.*;
+
+assert new File( basedir, 'target/maven-jlink/default/README.md' ).exists()
+
+def file = new File( basedir, 'target/maven-jlink-plugin-mjlink-80-42.0.0.zip')
+
+assert new ZipFile(file).getEntry('README.md')
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
index fcb57c0..a73857c 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
@@ -53,6 +53,7 @@
import org.apache.commons.io.FileUtils;
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
@@ -62,6 +63,9 @@
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
+import org.apache.maven.shared.filtering.MavenFilteringException;
+import org.apache.maven.shared.filtering.MavenResourcesExecution;
+import org.apache.maven.shared.filtering.MavenResourcesFiltering;
import org.apache.maven.toolchain.Toolchain;
import org.apache.maven.toolchain.ToolchainPrivate;
import org.apache.maven.toolchain.java.DefaultJavaToolChain;
@@ -357,6 +361,17 @@
@Component
private MavenProjectHelper projectHelper;
+ /**
+ * These file are added to the image after calling the jlink, but before creating the zipfile.
+ *
+ * @since 3.2.0
+ */
+ @Parameter
+ private List<Resource> additionalResources;
+
+ @Component(role = MavenResourcesFiltering.class, hint = "default")
+ private MavenResourcesFiltering mavenResourcesFiltering;
+
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
failIfParametersAreNotInTheirValidValueRanges();
@@ -400,6 +415,20 @@
throw new MojoFailureException("Unable to find jlink command: " + e.getMessage(), e);
}
+ // Add additional resources
+ try {
+ mavenResourcesFiltering.filterResources(new MavenResourcesExecution(
+ additionalResources,
+ outputDirectoryImage,
+ getProject(),
+ "UTF-8",
+ Collections.emptyList(),
+ Collections.emptyList(),
+ getSession()));
+ } catch (MavenFilteringException e) {
+ throw new MojoFailureException("Unable to copy the additional resources: " + e.getMessage(), e);
+ }
+
File createZipArchiveFromImage = createZipArchiveFromImage(buildDirectory, outputDirectoryImage);
if (hasClassifier()) {