You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2019/01/13 15:29:13 UTC
[maven-jlink-plugin] 01/03: Add 'sourceJdkModules' configuration
parameter.
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch MJLINK-6
in repository https://gitbox.apache.org/repos/asf/maven-jlink-plugin.git
commit 3e961d777283be1e107eb591b4a6e1100a2678a8
Author: Andre Tadeu de Carvalho <an...@gmail.com>
AuthorDate: Thu Jan 3 23:15:39 2019 -0200
Add 'sourceJdkModules' configuration parameter.
This parameter allows to create a distributable Java custom runtime image without setting JAVA_HOME/Toolschain. This allows to create a Java custom runtime image from one Operating System to another.
---
.../MJLINK-6_allowSetJmodPath/invoker.properties | 18 +++++++
src/it/projects/MJLINK-6_allowSetJmodPath/pom.xml | 59 ++++++++++++++++++++++
.../src/main/java/com/corporate/project/Main.java | 35 +++++++++++++
.../src/main/java/module-info.java | 24 +++++++++
.../MJLINK-6_allowSetJmodPath/verify.groovy | 50 ++++++++++++++++++
.../org/apache/maven/plugins/jlink/JLinkMojo.java | 17 ++++++-
6 files changed, 202 insertions(+), 1 deletion(-)
diff --git a/src/it/projects/MJLINK-6_allowSetJmodPath/invoker.properties b/src/it/projects/MJLINK-6_allowSetJmodPath/invoker.properties
new file mode 100644
index 0000000..8948d9b
--- /dev/null
+++ b/src/it/projects/MJLINK-6_allowSetJmodPath/invoker.properties
@@ -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.
+invoker.java.version = 1.9+
+invoker.goals = clean package
diff --git a/src/it/projects/MJLINK-6_allowSetJmodPath/pom.xml b/src/it/projects/MJLINK-6_allowSetJmodPath/pom.xml
new file mode 100644
index 0000000..44b3163
--- /dev/null
+++ b/src/it/projects/MJLINK-6_allowSetJmodPath/pom.xml
@@ -0,0 +1,59 @@
+<?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-6</artifactId>
+ <version>96.0</version>
+ <packaging>jlink</packaging>
+ <name>Maven</name>
+ <url>https://maven.apache.org</url>
+ <description>Test JLink create a distributable JVM that is not currently used</description>
+ <properties>
+ <maven.compiler.source>1.9</maven.compiler.source>
+ <maven.compiler.target>1.9</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.0</version>
+ <configuration>
+ <source>1.9</source>
+ <target>1.9</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jlink-plugin</artifactId>
+ <version>@project.version@</version>
+ <extensions>true</extensions>
+ <configuration>
+ <!-- <sourceJdkModules>/home/andre/Desktop/openjdk-11.0.1_windows-x64_bin/jdk-11.0.1</sourceJdkModules> -->
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/projects/MJLINK-6_allowSetJmodPath/src/main/java/com/corporate/project/Main.java b/src/it/projects/MJLINK-6_allowSetJmodPath/src/main/java/com/corporate/project/Main.java
new file mode 100644
index 0000000..1b4ca36
--- /dev/null
+++ b/src/it/projects/MJLINK-6_allowSetJmodPath/src/main/java/com/corporate/project/Main.java
@@ -0,0 +1,35 @@
+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 Main
+{
+ public static void main( String[] args )
+ {
+ System.out.println( "Main one from Java 9+" );
+ if ( args.length > 0 )
+ {
+ for ( String arg : args )
+ {
+ System.out.println( " Arg: '" + arg + "'" );
+ }
+ }
+ }
+}
diff --git a/src/it/projects/MJLINK-6_allowSetJmodPath/src/main/java/module-info.java b/src/it/projects/MJLINK-6_allowSetJmodPath/src/main/java/module-info.java
new file mode 100644
index 0000000..d35441d
--- /dev/null
+++ b/src/it/projects/MJLINK-6_allowSetJmodPath/src/main/java/module-info.java
@@ -0,0 +1,24 @@
+
+/*
+ * 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 {
+ requires java.base;
+ exports com.corporate.project;
+}
diff --git a/src/it/projects/MJLINK-6_allowSetJmodPath/verify.groovy b/src/it/projects/MJLINK-6_allowSetJmodPath/verify.groovy
new file mode 100644
index 0000000..f03fb3d
--- /dev/null
+++ b/src/it/projects/MJLINK-6_allowSetJmodPath/verify.groovy
@@ -0,0 +1,50 @@
+
+/*
+ * 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.*;
+
+boolean result = true;
+
+try
+{
+ File target = new File( basedir, "target" );
+ if ( !target.exists() || !target.isDirectory() )
+ {
+ System.err.println( "target file is missing or not a directory." );
+ return false;
+ }
+ File artifact = new File( target, "maven-jlink-plugin-mjlink-6-96.0.zip" );
+ if ( !artifact.exists() || artifact.isDirectory() )
+ {
+ System.err.println( "maven-jlink-plugin-mjlink-26-96.0.zip file is missing or is a directory." );
+ return false;
+ }
+
+}
+catch( Throwable e )
+{
+ e.printStackTrace();
+ result = false;
+}
+
+return result;
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 86cb01a..a5f69fa 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
@@ -30,6 +30,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -241,6 +242,12 @@ public class JLinkMojo
private ZipArchiver zipArchiver;
/**
+ * Set the JDK location to create a Java custom runtime image.
+ */
+ @Parameter
+ private String sourceJdkModules;
+
+ /**
* Name of the generated ZIP file in the <code>target</code> directory. This will not change the name of the
* installed/deployed file.
*/
@@ -260,7 +267,15 @@ public class JLinkMojo
// Really Hacky...do we have a better solution to find the jmods directory of the JDK?
File jLinkParent = jLinkExecuteable.getParentFile().getParentFile();
- File jmodsFolder = new File( jLinkParent, JMODS );
+ File jmodsFolder;
+ if ( StringUtils.isNotBlank( sourceJdkModules ) )
+ {
+ jmodsFolder = new File ( sourceJdkModules, JMODS );
+ }
+ else
+ {
+ jmodsFolder = new File( jLinkParent, JMODS );
+ }
getLog().debug( " Parent: " + jLinkParent.getAbsolutePath() );
getLog().debug( " jmodsFolder: " + jmodsFolder.getAbsolutePath() );