[maven-jlink-plugin] branch MJLINK-41_launcherargs created (now e4c7b99)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[maven-jlink-plugin] branch MJLINK-41_launcherargs created (now e4c7b99)

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

slachiewicz pushed a change to branch MJLINK-41_launcherargs
in repository https://gitbox.apache.org/repos/asf/maven-jlink-plugin.git.


      at e4c7b99  [MJLINK-41] add support for --add-options argument (JDK14+).

This branch includes the following new commits:

     new e4c7b99  [MJLINK-41] add support for --add-options argument (JDK14+).

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Reply | Threaded
Open this post in threaded view
|

[maven-jlink-plugin] 01/01: [MJLINK-41] add support for --add-options argument (JDK14+).

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

slachiewicz pushed a commit to branch MJLINK-41_launcherargs
in repository https://gitbox.apache.org/repos/asf/maven-jlink-plugin.git

commit e4c7b99f5bf89dc1800a26f6b7864c1b78ec3ffa
Author: Benjamin Marwell <[hidden email]>
AuthorDate: Thu Nov 12 17:54:16 2020 +0100

    [MJLINK-41] add support for --add-options argument (JDK14+).
---
 .../cli-options/add-options/invoker.properties     | 19 +++++++
 src/it/projects/cli-options/add-options/pom.xml    | 65 ++++++++++++++++++++++
 .../add-options/src/main/configs/config.test       | 21 +++++++
 .../projects/cli-options/add-options/verify.groovy | 34 +++++++++++
 .../org/apache/maven/plugins/jlink/JLinkMojo.java  | 27 +++++++++
 5 files changed, 166 insertions(+)

diff --git a/src/it/projects/cli-options/add-options/invoker.properties b/src/it/projects/cli-options/add-options/invoker.properties
new file mode 100644
index 0000000..03b85d3
--- /dev/null
+++ b/src/it/projects/cli-options/add-options/invoker.properties
@@ -0,0 +1,19 @@
+# suppress inspection "UnusedProperty" for whole file
+# 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.java.version = 14+
+invoker.goals = clean package
diff --git a/src/it/projects/cli-options/add-options/pom.xml b/src/it/projects/cli-options/add-options/pom.xml
new file mode 100644
index 0000000..84d6851
--- /dev/null
+++ b/src/it/projects/cli-options/add-options/pom.xml
@@ -0,0 +1,65 @@
+<?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-cli-options-add-options</artifactId>
+  <version>101.0</version>
+  <packaging>jlink</packaging>
+  <name>Maven</name>
+  <url>http://maven.apache.org</url>
+  <description>Test JLink CLI Options --add-options.</description>
+  <properties>
+    <maven.compiler.release>14</maven.compiler.release>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+  <dependencies>
+    <dependency>
+      <groupId>localhost</groupId>
+      <artifactId>first-jar-module-info</artifactId>
+      <version>99.0</version>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.8.0</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jlink-plugin</artifactId>
+        <version>@project.version@</version>
+        <extensions>true</extensions>
+        <configuration>
+          <addOptions>
+            <addOption>-Xmx128m</addOption>
+            <addOption>--enable-preview</addOption>
+            <addOption>-Dvar=value</addOption>
+          </addOptions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/projects/cli-options/add-options/src/main/configs/config.test b/src/it/projects/cli-options/add-options/src/main/configs/config.test
new file mode 100644
index 0000000..405149a
--- /dev/null
+++ b/src/it/projects/cli-options/add-options/src/main/configs/config.test
@@ -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.
+ */
+
+Test configuration file which should be located in config/config.test in
+resulting jmod file.
\ No newline at end of file
diff --git a/src/it/projects/cli-options/add-options/verify.groovy b/src/it/projects/cli-options/add-options/verify.groovy
new file mode 100644
index 0000000..32e21da
--- /dev/null
+++ b/src/it/projects/cli-options/add-options/verify.groovy
@@ -0,0 +1,34 @@
+
+/*
+ * 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.jar.*
+import org.codehaus.plexus.util.*
+
+File target = new File( basedir, "target" )
+assert target.isDirectory()
+
+File artifact = new File( target, "maven-jlink-plugin-cli-options-add-options-101.0.zip" )
+assert artifact.isFile()
+
+File jlinkArgs = new File( target, "jlinkArgs" )
+assert jlinkArgs.isFile()
+
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 14bebdc..6cea8ac 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
@@ -102,6 +102,27 @@ public class JLinkMojo
     private String launcher;
 
     /**
+     * These JVM arguments will be appended to the {@code lib/modules} file.<br>
+     * <strong>This parameter requires at least JDK 14.<br></strong>
+     *
+     * <p>The command line equivalent is: {@code jlink --add-options="…"}.</p>
+     *
+     * <p>Example:</p>
+     *
+     * <pre>
+     *   &lt;addOptions&gt;
+     *     &lt;addOption&gt;-Xmx256m&lt;/addOption&gt;
+     *     &lt;addOption&gt;--enable-preview&lt;/addOption&gt;
+     *     &lt;addOption&gt;-Dvar=value&lt;/addOption&gt;
+     *   &lt;/addOptions&gt;
+     * </pre>
+     *
+     * <p>Above example will result in {@code jlink --add-options="-Xmx256m" --enable-preview -Dvar=value"}.</p>
+     */
+    @Parameter
+    private List<String> addOptions;
+
+    /**
      * Limit the universe of observable modules. The following gives an example of the configuration which can be used
      * in the <code>pom.xml</code> file.
      *
@@ -579,6 +600,12 @@ public class JLinkMojo
             argsFile.println( "--launcher" );
             argsFile.println( launcher );
         }
+        if ( addOptions != null )
+        {
+            // needs JDK 14+
+            argsFile.println( "--add-options" );
+            argsFile.printf( "\"%s\"%n", String.join( " ", addOptions ) );
+        }
 
         if ( disablePlugin != null )
         {