[MCOMPILER-296] Add jpms.args to the META-INF folder

git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1805828 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 5fafc54..4b6d22d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -113,7 +113,7 @@
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-java</artifactId>
-      <version>0.9.1</version>
+      <version>0.9.2</version>
     </dependency>
 
     <dependency>
@@ -221,7 +221,7 @@
       <plugin>
         <groupId>org.codehaus.plexus</groupId>
         <artifactId>plexus-component-metadata</artifactId>
-        <version>1.7</version>
+        <version>1.7.1</version>
         <executions>
           <execution>
             <id>descriptors</id>
diff --git a/src/it/jpms_add-exports/invoker.properties b/src/it/jpms_add-exports/invoker.properties
new file mode 100644
index 0000000..9511718
--- /dev/null
+++ b/src/it/jpms_add-exports/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 = 9+
diff --git a/src/it/jpms_add-exports/pom.xml b/src/it/jpms_add-exports/pom.xml
new file mode 100644
index 0000000..6f9b948
--- /dev/null
+++ b/src/it/jpms_add-exports/pom.xml
@@ -0,0 +1,52 @@
+<?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.compiler.it</groupId>

+  <artifactId>illegal-access</artifactId>

+  <version>1.0-SNAPSHOT</version>

+

+  <properties>

+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

+  </properties>

+

+  <build>

+    <pluginManagement>

+      <plugins>

+        <plugin>

+          <groupId>org.apache.maven.plugins</groupId>

+          <artifactId>maven-compiler-plugin</artifactId>

+          <version>@project.version@</version>

+          <configuration>

+            <release>9</release>

+            <compilerArgs>

+              <arg>--add-exports</arg>

+              <arg>app/org.maven.test=ALL_UNNAMED</arg>

+            </compilerArgs>

+          </configuration>

+        </plugin>

+      </plugins>

+    </pluginManagement>

+  </build>

+</project>

diff --git a/src/it/jpms_add-exports/src/main/java/module-info.java b/src/it/jpms_add-exports/src/main/java/module-info.java
new file mode 100644
index 0000000..c48284e
--- /dev/null
+++ b/src/it/jpms_add-exports/src/main/java/module-info.java
@@ -0,0 +1,22 @@
+/*

+ * 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 app 

+{

+        

+}
\ No newline at end of file
diff --git a/src/it/jpms_add-exports/src/main/java/org/maven/test/Main.java b/src/it/jpms_add-exports/src/main/java/org/maven/test/Main.java
new file mode 100644
index 0000000..51d5c4a
--- /dev/null
+++ b/src/it/jpms_add-exports/src/main/java/org/maven/test/Main.java
@@ -0,0 +1,36 @@
+package org.maven.test;

+

+/*

+ * 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 {

+    

+    /**

+     * @param args

+     */

+    public static void main(String[] args) {

+        try {

+            Class.forName( "jdk.internal.util.Preconditions" ).newInstance();    

+        }

+        catch ( Exception e  )

+        {

+            // noop

+        }

+    }

+}

diff --git a/src/it/jpms_add-exports/verify.groovy b/src/it/jpms_add-exports/verify.groovy
new file mode 100644
index 0000000..0cddccf
--- /dev/null
+++ b/src/it/jpms_add-exports/verify.groovy
@@ -0,0 +1,23 @@
+/*

+ * 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 jpmsArgs = new File( basedir, 'target/classes/META-INF/jpms.args' );

+def lines = jpmsArgs.readLines();

+assert lines[0] == "--add-exports"

+assert lines[1] == "app/org.maven.test=ALL_UNNAMED"

diff --git a/src/it/jpms_patch-module/invoker.properties b/src/it/jpms_patch-module/invoker.properties
new file mode 100644
index 0000000..416082c
--- /dev/null
+++ b/src/it/jpms_patch-module/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 = 9+
+invoker.goals = test-compile
diff --git a/src/it/jpms_patch-module/pom.xml b/src/it/jpms_patch-module/pom.xml
new file mode 100644
index 0000000..80bd412
--- /dev/null
+++ b/src/it/jpms_patch-module/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.compiler.it</groupId>

+  <artifactId>patch-module</artifactId>

+  <version>1.0-SNAPSHOT</version>

+

+  <properties>

+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

+  </properties>

+

+  <build>

+    <pluginManagement>

+      <plugins>

+        <plugin>

+          <groupId>org.apache.maven.plugins</groupId>

+          <artifactId>maven-compiler-plugin</artifactId>

+          <version>@project.version@</version>

+          <configuration>

+            <release>9</release>

+          </configuration>

+        </plugin>

+      </plugins>

+    </pluginManagement>

+  </build>

+</project>

diff --git a/src/it/jpms_patch-module/src/main/java/module-info.java b/src/it/jpms_patch-module/src/main/java/module-info.java
new file mode 100644
index 0000000..c48284e
--- /dev/null
+++ b/src/it/jpms_patch-module/src/main/java/module-info.java
@@ -0,0 +1,22 @@
+/*

+ * 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 app 

+{

+        

+}
\ No newline at end of file
diff --git a/src/it/jpms_patch-module/src/main/java/org/maven/test/Main.java b/src/it/jpms_patch-module/src/main/java/org/maven/test/Main.java
new file mode 100644
index 0000000..51d5c4a
--- /dev/null
+++ b/src/it/jpms_patch-module/src/main/java/org/maven/test/Main.java
@@ -0,0 +1,36 @@
+package org.maven.test;

+

+/*

+ * 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 {

+    

+    /**

+     * @param args

+     */

+    public static void main(String[] args) {

+        try {

+            Class.forName( "jdk.internal.util.Preconditions" ).newInstance();    

+        }

+        catch ( Exception e  )

+        {

+            // noop

+        }

+    }

+}

diff --git a/src/it/jpms_patch-module/src/test/java/org/maven/test/MainTest.java b/src/it/jpms_patch-module/src/test/java/org/maven/test/MainTest.java
new file mode 100644
index 0000000..a6fd3af
--- /dev/null
+++ b/src/it/jpms_patch-module/src/test/java/org/maven/test/MainTest.java
@@ -0,0 +1,30 @@
+package org.maven.test;

+

+/*

+ * 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 MainTest {

+    

+    /**

+     * @param args

+     */

+    public static void main(String[] args) {

+        Main.main( args );

+    }

+}

diff --git a/src/it/jpms_patch-module/verify.groovy b/src/it/jpms_patch-module/verify.groovy
new file mode 100644
index 0000000..92e0972
--- /dev/null
+++ b/src/it/jpms_patch-module/verify.groovy
@@ -0,0 +1,25 @@
+/*

+ * 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 jpmsArgs = new File( basedir, 'target/test-classes/META-INF/jpms.args' );

+def lines = jpmsArgs.readLines();

+assert lines[0] == "--patch-module"

+assert lines[1] == "app=_"

+assert lines[2] == "--add-reads"

+assert lines[3] == "app=ALL-UNNAMED"

diff --git a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
index 84bb300..294ae23 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
@@ -20,11 +20,18 @@
  */
 
 import java.io.File;
+import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -68,6 +75,7 @@
 import org.codehaus.plexus.compiler.util.scan.mapping.SingleTargetSourceMapping;
 import org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping;
 import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping;
+import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor;
 
 /**
  * TODO: At least one step could be optimized, currently the plugin will do two
@@ -83,6 +91,7 @@
 public abstract class AbstractCompilerMojo
     extends AbstractMojo
 {
+    protected static final String PS = System.getProperty( "path.separator" );
 
     static final String DEFAULT_SOURCE = "1.5";
     
@@ -492,6 +501,8 @@
 
     protected abstract List<String> getModulepathElements();
 
+    protected abstract Map<String, JavaModuleDescriptor> getPathElements();
+
     protected abstract List<String> getCompileSourceRoots();
     
     protected abstract void preparePaths( Set<File> sourceFiles );
@@ -863,7 +874,7 @@
                 }
             }
         }
-
+        
         // ----------------------------------------------------------------------
         // Dump configuration
         // ----------------------------------------------------------------------
@@ -922,6 +933,118 @@
                 getLog().debug( ce );
             }
         }
+        
+
+        List<String> jpmsLines = new ArrayList<String>();
+        
+        // See http://openjdk.java.net/jeps/261
+        final List<String> runtimeArgs = Arrays.asList( "--upgrade-module-path", 
+                                                  "--add-exports",
+                                                  "--add-reads", 
+                                                  "--add-modules", 
+                                                  "--limit-modules" );
+        
+        // Custom arguments are all added as keys to an ordered Map
+        Iterator<Map.Entry<String, String>> entryIter =
+            compilerConfiguration.getCustomCompilerArgumentsEntries().iterator();
+        while ( entryIter.hasNext() )
+        {
+            Map.Entry<String, String> entry = entryIter.next();
+            
+            if ( runtimeArgs.contains( entry.getKey() ) )
+            {
+                jpmsLines.add( entry.getKey() );
+                
+                String value = entry.getValue();
+                if ( value == null )
+                {
+                    entry = entryIter.next();
+                    value = entry.getKey();
+                }
+                jpmsLines.add( value );
+            }
+            else if ( "--patch-module".equals( entry.getKey() ) )
+            {
+                jpmsLines.add( "--patch-module" );
+                
+                String value = entry.getValue();
+                if ( value == null )
+                {
+                    entry = entryIter.next();
+                    value = entry.getKey();
+                }
+                
+                String[] values = value.split( "=" );
+
+                StringBuilder patchModule = new StringBuilder( values[0] );
+                patchModule.append( '=' );
+
+                Set<String> patchModules = new LinkedHashSet<>();
+                Set<Path> sourceRoots = new HashSet<>( getCompileSourceRoots().size() );
+                for ( String sourceRoot : getCompileSourceRoots() )
+                {
+                    sourceRoots.add( Paths.get( sourceRoot ) );
+                }
+
+                String[] files = values[1].split( PS );
+
+                for ( String file : files )
+                {
+                    Path filePath = Paths.get( file );
+                    if ( getOutputDirectory().toPath().equals( filePath ) )
+                    {
+                        patchModules.add( "_" ); // this jar
+                    }
+                    else if ( sourceRoots.contains( filePath ) )
+                    {
+                        patchModules.add( "_" ); // this jar
+                    }
+                    else
+                    {
+                        JavaModuleDescriptor descriptor = getPathElements().get( file );
+                        
+                        if ( descriptor == null )
+                        {
+                            getLog().warn( "Can't locate " + file );
+                        }
+                        else if ( !values[0].equals( descriptor.name() ) )
+                        {
+                            patchModules.add( descriptor.name() );
+                        }
+                    }
+                }
+
+                StringBuilder sb = new StringBuilder();
+                
+                for ( String mod : patchModules )
+                {
+                    if ( sb.length() > 0 )
+                    {
+                        sb.append( ", " );
+                    }
+                    // use 'invalid' separator to ensure values are transformed
+                    sb.append( mod );
+                }
+
+                jpmsLines.add( patchModule + sb.toString() );
+            }
+        }
+        
+        if ( !jpmsLines.isEmpty() ) 
+        {
+            Path jpmsArgs = Paths.get( getOutputDirectory().getAbsolutePath(), "META-INF/jpms.args" );
+            try
+            {
+                Files.createDirectories( jpmsArgs.getParent() );
+                
+                Files.write( jpmsArgs, jpmsLines, Charset.defaultCharset() );
+            }
+            catch ( IOException e )
+            {
+                getLog().warn( e.getMessage() );
+            }
+        }
+
 
         // ----------------------------------------------------------------------
         // Compile!
diff --git a/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
index be6f096..d1956ae 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
@@ -25,12 +25,14 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
@@ -45,7 +47,6 @@
 import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
 import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor;
 import org.codehaus.plexus.languages.java.jpms.LocationManager;
-import org.codehaus.plexus.languages.java.jpms.QDoxModuleInfoParser;
 import org.codehaus.plexus.languages.java.jpms.ResolvePathsRequest;
 import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult;
 import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult.ModuleNameSource;
@@ -117,19 +118,21 @@
     @Parameter
     private boolean allowPartialRequirements;
 
-    private QDoxModuleInfoParser moduleInfoParser = new QDoxModuleInfoParser();
-
-    private LocationManager locationManager = new LocationManager();
+    @Component
+    private LocationManager locationManager;
 
     private List<String> classpathElements;
 
     private List<String> modulepathElements;
+    
+    private Map<String, JavaModuleDescriptor> pathElements;
 
     protected List<String> getCompileSourceRoots()
     {
         return compileSourceRoots;
     }
 
+    @Override
     protected List<String> getClasspathElements()
     {
         return classpathElements;
@@ -141,6 +144,13 @@
         return modulepathElements;
     }
 
+    @Override
+    protected Map<String, JavaModuleDescriptor> getPathElements()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+    
     protected File getOutputDirectory()
     {
         return outputDirectory;
@@ -168,21 +178,14 @@
     {
         assert compilePath != null;
 
-        JavaModuleDescriptor moduleDescriptor = null;
+        File moduleDescriptorPath = null;
 
         boolean hasModuleDescriptor = false;
         for ( File sourceFile : sourceFiles )
         {
             if ( "module-info.java".equals( sourceFile.getName() ) )
             {
-                try
-                {
-                    moduleDescriptor = moduleInfoParser.fromSourcePath( sourceFile.getParentFile().toPath() );
-                }
-                catch ( IOException e )
-                {
-                    getLog().warn( "Failed to parse module-info.java: " + e.getMessage() );
-                }
+                moduleDescriptorPath = sourceFile;
                 hasModuleDescriptor = true;
                 break;
             }
@@ -196,14 +199,16 @@
 
             modulepathElements = new ArrayList<String>( compilePath.size() );
             classpathElements = new ArrayList<String>( compilePath.size() );
+            pathElements = new LinkedHashMap<String, JavaModuleDescriptor>( compilePath.size() );
 
-            ResolvePathsResult<File> analyzerResult;
+            ResolvePathsResult<File> resolvePathsResult;
             try
             {
                 Collection<File> dependencyArtifacts = getCompileClasspathElements( getProject() );
                 
                 ResolvePathsRequest<File> request =
-                    ResolvePathsRequest.withFiles( dependencyArtifacts ).setMainModuleDescriptor( moduleDescriptor );
+                    ResolvePathsRequest.withFiles( dependencyArtifacts )
+                                       .setMainModuleDescriptor( moduleDescriptorPath );
                 
                 Toolchain toolchain = getToolchain();
                 if ( toolchain != null && toolchain instanceof DefaultJavaToolChain )
@@ -211,9 +216,11 @@
                     request.setJdkHome( new File( ( (DefaultJavaToolChain) toolchain ).getJavaHome() ) );
                 }
 
-                analyzerResult = locationManager.resolvePaths( request );
+                resolvePathsResult = locationManager.resolvePaths( request );
+                
+                JavaModuleDescriptor moduleDescriptor = resolvePathsResult.getMainModuleDescriptor();
 
-                for ( Map.Entry<File, ModuleNameSource> entry : analyzerResult.getModulepathElements().entrySet() )
+                for ( Map.Entry<File, ModuleNameSource> entry : resolvePathsResult.getModulepathElements().entrySet() )
                 {
                     if ( ModuleNameSource.FILENAME.equals( entry.getValue() ) )
                     {
@@ -234,12 +241,17 @@
                     }
                 }
                 
-                for ( File file : analyzerResult.getClasspathElements() )
+                for ( Map.Entry<File, JavaModuleDescriptor> entry : resolvePathsResult.getPathElements().entrySet() )
+                {
+                    pathElements.put( entry.getKey().getPath(), entry.getValue() );
+                }
+                
+                for ( File file : resolvePathsResult.getClasspathElements() )
                 {
                     classpathElements.add( file.getPath() );
                 }
                 
-                for ( File file : analyzerResult.getModulepathElements().keySet() )
+                for ( File file : resolvePathsResult.getModulepathElements().keySet() )
                 {
                     modulepathElements.add( file.getPath() );
                 }
diff --git a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
index 9f4c7c0..f784016 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
@@ -25,6 +25,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -39,7 +40,6 @@
 import org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner;
 import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner;
 import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
-import org.codehaus.plexus.languages.java.jpms.AsmModuleInfoParser;
 import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor;
 import org.codehaus.plexus.languages.java.jpms.LocationManager;
 import org.codehaus.plexus.languages.java.jpms.ResolvePathsRequest;
@@ -57,8 +57,6 @@
 public class TestCompilerMojo
     extends AbstractCompilerMojo
 {
-    protected static final String PS = System.getProperty( "path.separator" );
-    
     /**
      * Set this to 'true' to bypass compilation of test sources.
      * Its use is NOT RECOMMENDED, but quite convenient on occasion.
@@ -159,10 +157,10 @@
     @Parameter( defaultValue = "${project.testClasspathElements}", readonly = true )
     private List<String> testPath;
 
-    private AsmModuleInfoParser asmModuleInfoParser = new AsmModuleInfoParser();
-    
     private LocationManager locationManager = new LocationManager();
 
+    private Map<String, JavaModuleDescriptor> pathElements;
+    
     private Collection<String> classpathElements;
 
     private Collection<String> modulepathElements;
@@ -183,6 +181,12 @@
         return compileSourceRoots;
     }
 
+    @Override
+    protected Map<String, JavaModuleDescriptor> getPathElements()
+    {
+        return pathElements;
+    }
+
     protected List<String> getClasspathElements()
     {
         return new ArrayList<>( classpathElements );
@@ -223,6 +227,7 @@
         {
             if ( Integer.valueOf( release ) < 9 )
             {
+                pathElements = Collections.emptyMap();
                 modulepathElements = Collections.emptyList();
                 classpathElements = testPath;
                 return;
@@ -230,6 +235,7 @@
         }
         else if ( Double.valueOf( getTarget() ) < Double.valueOf( MODULE_INFO_TARGET ) )
         {
+            pathElements = Collections.emptyMap();
             modulepathElements = Collections.emptyList();
             classpathElements = testPath;
             return;
@@ -258,20 +264,18 @@
         {
             if ( hasMainModuleDescriptor )
             {
-                JavaModuleDescriptor moduleDescriptor;
                 ResolvePathsResult<String> result;
                 
                 try
                 {
-                    moduleDescriptor = getModuleDescriptor( mainOutputDirectory );
-
                     ResolvePathsRequest<String> request =
-                        ResolvePathsRequest.withStrings( testPath ).setMainModuleDescriptor( moduleDescriptor );
+                        ResolvePathsRequest.withStrings( testPath )
+                                           .setMainModuleDescriptor( mainOutputDirectory.getAbsolutePath() );
                     
                     Toolchain toolchain = getToolchain();
                     if ( toolchain != null && toolchain instanceof DefaultJavaToolChain )
                     {
-                        request.setJdkHome( new File( ( (DefaultJavaToolChain) toolchain ).getJavaHome() ) );
+                        request.setJdkHome( ( (DefaultJavaToolChain) toolchain ).getJavaHome() );
                     }
                     
                     result = locationManager.resolvePaths( request );
@@ -281,6 +285,11 @@
                     throw new RuntimeException( e );
                 }
                 
+                JavaModuleDescriptor moduleDescriptor = result.getMainModuleDescriptor();
+                
+                pathElements = new LinkedHashMap<String, JavaModuleDescriptor>( result.getPathElements().size() );
+                pathElements.putAll( result.getPathElements() );
+                                
                 modulepathElements = result.getModulepathElements().keySet();
                 classpathElements = result.getClasspathElements();
                 
@@ -290,16 +299,16 @@
                 }
                 compilerArgs.add( "--patch-module" );
                 
-                StringBuilder addReadsValue = new StringBuilder( moduleDescriptor.name() )
+                StringBuilder patchModuleValue = new StringBuilder( moduleDescriptor.name() )
                                 .append( '=' )
                                 .append( mainOutputDirectory )
                                 .append( PS );
                 for ( String root : compileSourceRoots )
                 {
-                    addReadsValue.append( root ).append( PS );
+                    patchModuleValue.append( root ).append( PS );
                 }
                 
-                compilerArgs.add( addReadsValue.toString() );
+                compilerArgs.add( patchModuleValue.toString() );
                 
                 compilerArgs.add( "--add-reads" );
                 compilerArgs.add( moduleDescriptor.name() + "=ALL-UNNAMED" );
@@ -312,11 +321,6 @@
         }
     }
 
-    private JavaModuleDescriptor getModuleDescriptor( File mainOutputDirectory ) throws IOException
-    {
-        return asmModuleInfoParser.getModuleDescriptor( mainOutputDirectory.toPath() );
-    }
-
     protected SourceInclusionScanner getSourceInclusionScanner( int staleMillis )
     {
         SourceInclusionScanner scanner;
diff --git a/src/site/apt/examples/jpms_args.apt.vm b/src/site/apt/examples/jpms_args.apt.vm
new file mode 100644
index 0000000..0d9cd42
--- /dev/null
+++ b/src/site/apt/examples/jpms_args.apt.vm
@@ -0,0 +1,62 @@
+ ------

+ jpms.args

+ ------

+ Robert Scholte

+ ------

+ 2017-08-22

+ ------

+

+~~ 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.

+

+~~ NOTE: For help with the syntax of this file, see:

+~~ http://maven.apache.org/doxia/references/apt-format.html

+

+JPMS.ARGS

+

+  Java 9 comes with a new set of arguments related to the Java Platform Modular System. Besides the module path are

+  other new arguments which can change the behavior of the application. These can be used during both compile time

+  and runtime. This information is not stored in any class, but it can be interesting to know at runtime which extra

+  arguments were used at compile time.

+  

+  If any of these arguments is used, the <<<META-INF/jpms.args>>> is created.

+  Every argument gets its own line.

+  The following arguments will end up in this file:

+  

+  * <<<--upgrade-module-path>>>

+  

+  * <<<--add-exports>>>

+  

+  * <<<--add-reads>>>

+  

+  * <<<--add-modules>>>

+  

+  * <<<--limit-modules>>>

+  

+  * <<<--patch-module>>>

+  

+  []

+  

+  The <<<--patch-module>>> values are different compared to the original values passed to the compiler. Occording to

+  the specification it looks like <<<--patch-module \<module\>=\<file\>(\<pathsep\>\<file\>)\*>>>

+  However, files are system specific. For that reason the module names are used. If the jar itself contains the 

+  patchcode, then an <<<_>>> (underscore) is used. As separators a <<<, >>> (comma + space) is used.

+  

++---  

+  --patch-module

+  <module>=<module>(, <module>)*

++---  
\ No newline at end of file
diff --git a/src/site/fml/faq.fml b/src/site/fml/faq.fml
index e481bb2..5079d9c 100644
--- a/src/site/fml/faq.fml
+++ b/src/site/fml/faq.fml
@@ -39,5 +39,11 @@
         </p>
       </answer>
     </faq>
+    <faq id="jpms.args">
+      <question>Why is there sometimes a <code>META-INF/jpms.args</code> created?</question>
+      <answer>
+        <p>Read <a href="examples/jpms_args.html">jpms.args</a> for all the details.</p>
+      </answer>
+    </faq>
   </part>
 </faqs>