[MDEP-571] JDK9: Issue with list goal fails with java.lang.NoSuchMethodException

Only find public inherited methods through reflection with getMethod instead of getDeclaredMethod.

git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1799110 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/it/projects/mdep-571-list-java9/invoker.properties b/src/it/projects/mdep-571-list-java9/invoker.properties
new file mode 100644
index 0000000..972d39d
--- /dev/null
+++ b/src/it/projects/mdep-571-list-java9/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 = ${project.groupId}:${project.artifactId}:${project.version}:list
diff --git a/src/it/projects/mdep-571-list-java9/pom.xml b/src/it/projects/mdep-571-list-java9/pom.xml
new file mode 100644
index 0000000..a5cdbfe
--- /dev/null
+++ b/src/it/projects/mdep-571-list-java9/pom.xml
@@ -0,0 +1,35 @@
+<?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.dependency</groupId>
+  <artifactId>mdep-571-list-java9</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+  <description>Test that dependency:list doesn't fail on JRE9</description>
+  <dependencies>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.7.6</version>
+    </dependency>
+  </dependencies>
+</project>
diff --git a/src/it/projects/mdep-571-list-java9/verify.groovy b/src/it/projects/mdep-571-list-java9/verify.groovy
new file mode 100644
index 0000000..b58833d
--- /dev/null
+++ b/src/it/projects/mdep-571-list-java9/verify.groovy
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+File file = new File( basedir, "build.log" );
+assert file.exists();
+
+String buildLog = file.getText( "UTF-8" );
+assert buildLog.contains( 'org.slf4j:slf4j-api:jar:1.7.6:compile -- module' );
+
+return true;
diff --git a/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyStatusSets.java b/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyStatusSets.java
index e25c571..53cbb0a 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyStatusSets.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyStatusSets.java
@@ -258,27 +258,28 @@
         try
         {
             // Use Java9 code to get moduleName, don't try to do it better with own implementation
-            Class moduleFinderClass = Class.forName( "java.lang.module.ModuleFinder" );
+            Class<?> moduleFinderClass = Class.forName( "java.lang.module.ModuleFinder" );
 
             java.nio.file.Path path = artifactFile.toPath();
             
-            Method ofMethod = moduleFinderClass.getDeclaredMethod( "of", java.nio.file.Path[].class );
+            Method ofMethod = moduleFinderClass.getMethod( "of", java.nio.file.Path[].class );
             Object moduleFinderInstance = ofMethod.invoke( null, new Object[] { new java.nio.file.Path[] { path } } );
             
-            Method findAllMethod = moduleFinderClass.getDeclaredMethod( "findAll" );
+            Method findAllMethod = moduleFinderClass.getMethod( "findAll" );
+            @SuppressWarnings( "unchecked" )
             Set<Object> moduleReferences = (Set<Object>) findAllMethod.invoke( moduleFinderInstance );
             
             Object moduleReference = moduleReferences.iterator().next();
-            Method descriptorMethod = moduleReference.getClass().getDeclaredMethod( "descriptor" );
+            Method descriptorMethod = moduleReference.getClass().getMethod( "descriptor" );
             Object moduleDescriptorInstance = descriptorMethod.invoke( moduleReference );
             
-            Method nameMethod = moduleDescriptorInstance.getClass().getDeclaredMethod( "name" );
+            Method nameMethod = moduleDescriptorInstance.getClass().getMethod( "name" );
             String name = (String) nameMethod.invoke( moduleDescriptorInstance );
             
             moduleDescriptor = new ModuleDescriptor();
             moduleDescriptor.name = name;
             
-            Method isAutomaticMethod = moduleDescriptorInstance.getClass().getDeclaredMethod( "isAutomatic" );
+            Method isAutomaticMethod = moduleDescriptorInstance.getClass().getMethod( "isAutomatic" );
             moduleDescriptor.automatic = (Boolean) isAutomaticMethod.invoke( moduleDescriptorInstance );
         }
         catch ( ClassNotFoundException e )