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

sor 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 9c16bdd  [MJLINK-40] add --include-locales option.
9c16bdd is described below

commit 9c16bdddf57471d47765ac5460690a9ec00a5011
Author: Benjamin Marwell <bmarw...@apache.org>
AuthorDate: Wed Oct 28 22:28:54 2020 +0100

    [MJLINK-40] add --include-locales option.
---
 .../MJLINK-40_includeLocales/invoker.properties    | 19 +++++
 src/it/projects/MJLINK-40_includeLocales/pom.xml   | 81 ++++++++++++++++++++++
 .../MJLINK-40_includeLocales/verify.groovy         | 54 +++++++++++++++
 .../org/apache/maven/plugins/jlink/JLinkMojo.java  | 35 ++++++++++
 4 files changed, 189 insertions(+)

diff --git a/src/it/projects/MJLINK-40_includeLocales/invoker.properties 
b/src/it/projects/MJLINK-40_includeLocales/invoker.properties
new file mode 100644
index 0000000..81d8d2f
--- /dev/null
+++ b/src/it/projects/MJLINK-40_includeLocales/invoker.properties
@@ -0,0 +1,19 @@
+# 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 install
diff --git a/src/it/projects/MJLINK-40_includeLocales/pom.xml 
b/src/it/projects/MJLINK-40_includeLocales/pom.xml
new file mode 100644
index 0000000..72b1050
--- /dev/null
+++ b/src/it/projects/MJLINK-40_includeLocales/pom.xml
@@ -0,0 +1,81 @@
+<?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/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.plugins.jlink.its</groupId>
+  <artifactId>mjlink40</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+  <packaging>jlink</packaging>
+
+  <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>
+
+  <dependencies>
+    <dependency>
+      <!-- use a dependency with a module-info.class -->
+      <artifactId>asm</artifactId>
+      <groupId>org.ow2.asm</groupId>
+      <version>6.0</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jlink-plugin</artifactId>
+        <version>@project.version@</version>
+        <extensions>true</extensions>
+        <configuration>
+          <noHeaderFiles>true</noHeaderFiles>
+          <noManPages>true</noManPages>
+          <verbose>true</verbose>
+          <includeLocales>
+            <includeLocale>en</includeLocale>
+            <includeLocale>ja</includeLocale>
+            <includeLocale>de</includeLocale>
+            <includeLocale>*-IN</includeLocale>
+          </includeLocales>
+        </configuration>
+      </plugin>
+    </plugins>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>3.8.0</version>
+          <configuration>
+            <source>${maven.compiler.source}</source>
+            <target>${maven.compiler.target}</target>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+
+</project>
diff --git a/src/it/projects/MJLINK-40_includeLocales/verify.groovy 
b/src/it/projects/MJLINK-40_includeLocales/verify.groovy
new file mode 100644
index 0000000..1887547
--- /dev/null
+++ b/src/it/projects/MJLINK-40_includeLocales/verify.groovy
@@ -0,0 +1,54 @@
+/*
+ * 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 = false;
+
+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 jlinkArgs = new File( target, "jlinkArgs" );
+    if ( !jlinkArgs.exists() || jlinkArgs.isDirectory() )
+    {
+        System.err.println( "jlinkArgs file is missing or is a directory." );
+        return false;
+    }
+
+    def line = jlinkArgs.eachLine { line ->
+        if (line.equals('en,ja,de,*-IN'))
+        {
+            result = true;
+        }
+    }
+}
+catch( Throwable e )
+{
+    e.printStackTrace();
+}
+
+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 557dc32..14bebdc 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
@@ -229,6 +229,27 @@ public class JLinkMojo
     private List<String> suggestProviders;
 
     /**
+     * Includes the list of locales where langtag is a BCP 47 language tag.
+     *
+     * <p>This option supports locale matching as defined in RFC 4647.
+     * Ensure that you add the module jdk.localedata when using this 
option.</p>
+     *
+     * <p>The command line equivalent is: 
<code>--include-locales=en,ja,*-IN</code>.</p>
+     *
+     * <pre>
+     * &lt;includeLocales&gt;
+     *   &lt;includeLocale&gt;en&lt;/includeLocale&gt;
+     *   &lt;includeLocale&gt;ja&lt;/includeLocale&gt;
+     *   &lt;includeLocale&gt;*-IN&lt;/includeLocale&gt;
+     *   .
+     *   .
+     * &lt;/includeLocales&gt;
+     * </pre>
+     */
+    @Parameter
+    private List<String> includeLocales;
+
+    /**
      * This will turn on verbose mode. The jlink command line equivalent is: 
<code>--verbose</code>
      */
     @Parameter( defaultValue = "false" )
@@ -608,6 +629,15 @@ public class JLinkMojo
             argsFile.append( '"' ).append( sb.replace( "\\", "\\\\" ) 
).println( '"' );
         }
 
+        if ( hasIncludeLocales() )
+        {
+            argsFile.println( "--add-modules" );
+            argsFile.println( "jdk.localedata" );
+            argsFile.println( "--include-locales" );
+            String sb = getCommaSeparatedList( includeLocales );
+            argsFile.println( sb );
+        }
+
         if ( pluginModulePath != null )
         {
             argsFile.println( "--plugin-module-path" );
@@ -633,6 +663,11 @@ public class JLinkMojo
         return cmd;
     }
 
+    private boolean hasIncludeLocales()
+    {
+        return includeLocales != null && !includeLocales.isEmpty();
+    }
+
     private boolean hasSuggestProviders()
     {
         return suggestProviders != null && !suggestProviders.isEmpty();

Reply via email to