You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2020/12/14 23:48:39 UTC
[maven-jlink-plugin] 01/01: [MJLINK-41] add support for
--add-options argument (JDK14+).
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 84f538245bc685b3f0a2fd244ae02f96e55afcf8
Author: Benjamin Marwell <bm...@apache.org>
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 f8ff013..af00fc2 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
@@ -101,6 +101,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>
+ * <addOptions>
+ * <addOption>-Xmx256m</addOption>
+ * <addOption>--enable-preview</addOption>
+ * <addOption>-Dvar=value</addOption>
+ * </addOptions>
+ * </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.
*
@@ -601,6 +622,12 @@ public class JLinkMojo
jlinkArgs.add( "--launcher" );
jlinkArgs.add( launcher );
}
+ if ( addOptions != null )
+ {
+ // needs JDK 14+
+ argsFile.println( "--add-options" );
+ argsFile.printf( "\"%s\"%n", String.join( " ", addOptions ) );
+ }
if ( disablePlugin != null )
{