This is an automated email from the ASF dual-hosted git repository.

olamy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-jlink-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 4ad3570  [#502] - Add prefix to zip entries (#503)
4ad3570 is described below

commit 4ad3570632edd3ec1db6e16bba76bb86d8724db8
Author: Yasumasa Suenaga <yasue...@gmail.com>
AuthorDate: Fri Sep 19 08:17:07 2025 +0900

    [#502] - Add prefix to zip entries (#503)
    
    * [#502] - Add prefix to zip entries
---
 src/it/projects/GH-502_zipDirPrefix/pom.xml        | 48 ++++++++++++++++++++++
 .../java/com/corporate/project/HelloWorld.java     | 28 +++++++++++++
 .../src/main/java/module-info.java                 | 21 ++++++++++
 src/it/projects/GH-502_zipDirPrefix/verify.groovy  | 35 ++++++++++++++++
 .../org/apache/maven/plugins/jlink/JLinkMojo.java  | 18 +++++++-
 5 files changed, 149 insertions(+), 1 deletion(-)

diff --git a/src/it/projects/GH-502_zipDirPrefix/pom.xml 
b/src/it/projects/GH-502_zipDirPrefix/pom.xml
new file mode 100644
index 0000000..6bef325
--- /dev/null
+++ b/src/it/projects/GH-502_zipDirPrefix/pom.xml
@@ -0,0 +1,48 @@
+<?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-gh502</artifactId>
+  <version>42.0.0</version>
+  <packaging>jlink</packaging>
+  <description>Test adding prefix to zip entries</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>
+          <zipDirPrefix>prefix-test</zipDirPrefix>
+          
<launcher>helloworld=com.corporate.project/com.corporate.project.HelloWorld</launcher>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git 
a/src/it/projects/GH-502_zipDirPrefix/src/main/java/com/corporate/project/HelloWorld.java
 
b/src/it/projects/GH-502_zipDirPrefix/src/main/java/com/corporate/project/HelloWorld.java
new file mode 100644
index 0000000..eee9272
--- /dev/null
+++ 
b/src/it/projects/GH-502_zipDirPrefix/src/main/java/com/corporate/project/HelloWorld.java
@@ -0,0 +1,28 @@
+package com.corporate.project;
+
+/*
+ * 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.
+ */
+
+public class HelloWorld
+{
+  public static void main( String[] args )
+  {
+    System.out.println("Hello World");
+  }
+}
diff --git a/src/it/projects/GH-502_zipDirPrefix/src/main/java/module-info.java 
b/src/it/projects/GH-502_zipDirPrefix/src/main/java/module-info.java
new file mode 100644
index 0000000..26fea48
--- /dev/null
+++ b/src/it/projects/GH-502_zipDirPrefix/src/main/java/module-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+module com.corporate.project {
+}
diff --git a/src/it/projects/GH-502_zipDirPrefix/verify.groovy 
b/src/it/projects/GH-502_zipDirPrefix/verify.groovy
new file mode 100644
index 0000000..3c5b5c0
--- /dev/null
+++ b/src/it/projects/GH-502_zipDirPrefix/verify.groovy
@@ -0,0 +1,35 @@
+
+/*
+ * 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.
+ */
+
+def isWindows = System.getProperty('os.name').startsWith('Windows')
+def base = basedir.toString() + '/target'
+def archive = base + '/maven-jlink-plugin-gh502-42.0.0.zip'
+def unzipCommand = isWindows
+                     ? ['powershell.exe', 'Expand-Archive', '-Path', archive, 
'-DestinationPath', base]
+                     : ['unzip', '-d', base, archive]
+unzipCommand.execute().waitFor()
+
+def testCommand = base + '/prefix-test/bin/helloworld'
+if (isWindows) {
+  testCommand += '.bat'
+}
+def testProc = testCommand.execute()
+testProc.waitFor()
+assert testProc.text.trim() == 'Hello World'
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 a237afb..be4d37a 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
@@ -368,6 +368,19 @@ public class JLinkMojo extends AbstractJLinkMojo {
     @Parameter
     private List<Resource> additionalResources;
 
+    /**
+     * Add directory prefix to all of zip entries in top level 
files/directories.
+     *
+     * <p>For example, if this value is set to <code>prefix</code>,
+     * <code>bin/launcher</code> is transformed to 
<code>prefix/bin/launcher</code>.</p>
+     *
+     * <p>Empty String is set by default. It means no prefix.</p>
+     *
+     * @since 3.2.1
+     */
+    @Parameter(defaultValue = "")
+    private String zipDirPrefix;
+
     /**
      * Convenience interface for plugins to add or replace artifacts and 
resources on projects.
      */
@@ -593,7 +606,10 @@ public class JLinkMojo extends AbstractJLinkMojo {
 
     private File createZipArchiveFromImage(File outputDirectory, File 
outputDirectoryImage)
             throws MojoExecutionException {
-        zipArchiver.addDirectory(outputDirectoryImage);
+        if (zipDirPrefix != null && !zipDirPrefix.isEmpty() && 
!zipDirPrefix.endsWith("/")) {
+            zipDirPrefix += "/";
+        }
+        zipArchiver.addDirectory(outputDirectoryImage, zipDirPrefix);
 
         // configure for Reproducible Builds based on outputTimestamp value
         Optional<Instant> lastModified = 
MavenArchiver.parseBuildOutputTimestamp(outputTimestamp);

Reply via email to