Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit dad71e3

Browse files
author
Guillaume Boué
committed
[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
1 parent 50ea41a commit dad71e3

4 files changed

Lines changed: 87 additions & 6 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.java.version = 1.9+
19+
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:list
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<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">
23+
<modelVersion>4.0.0</modelVersion>
24+
<groupId>org.apache.maven.plugins.dependency</groupId>
25+
<artifactId>mdep-571-list-java9</artifactId>
26+
<version>1.0.0-SNAPSHOT</version>
27+
<description>Test that dependency:list doesn't fail on JRE9</description>
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.slf4j</groupId>
31+
<artifactId>slf4j-api</artifactId>
32+
<version>1.7.6</version>
33+
</dependency>
34+
</dependencies>
35+
</project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
File file = new File( basedir, "build.log" );
21+
assert file.exists();
22+
23+
String buildLog = file.getText( "UTF-8" );
24+
assert buildLog.contains( 'org.slf4j:slf4j-api:jar:1.7.6:compile -- module' );
25+
26+
return true;

maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyStatusSets.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,27 +258,28 @@ private ModuleDescriptor getModuleDescriptor( File artifactFile )
258258
try
259259
{
260260
// Use Java9 code to get moduleName, don't try to do it better with own implementation
261-
Class moduleFinderClass = Class.forName( "java.lang.module.ModuleFinder" );
261+
Class<?> moduleFinderClass = Class.forName( "java.lang.module.ModuleFinder" );
262262

263263
java.nio.file.Path path = artifactFile.toPath();
264264

265-
Method ofMethod = moduleFinderClass.getDeclaredMethod( "of", java.nio.file.Path[].class );
265+
Method ofMethod = moduleFinderClass.getMethod( "of", java.nio.file.Path[].class );
266266
Object moduleFinderInstance = ofMethod.invoke( null, new Object[] { new java.nio.file.Path[] { path } } );
267267

268-
Method findAllMethod = moduleFinderClass.getDeclaredMethod( "findAll" );
268+
Method findAllMethod = moduleFinderClass.getMethod( "findAll" );
269+
@SuppressWarnings( "unchecked" )
269270
Set<Object> moduleReferences = (Set<Object>) findAllMethod.invoke( moduleFinderInstance );
270271

271272
Object moduleReference = moduleReferences.iterator().next();
272-
Method descriptorMethod = moduleReference.getClass().getDeclaredMethod( "descriptor" );
273+
Method descriptorMethod = moduleReference.getClass().getMethod( "descriptor" );
273274
Object moduleDescriptorInstance = descriptorMethod.invoke( moduleReference );
274275

275-
Method nameMethod = moduleDescriptorInstance.getClass().getDeclaredMethod( "name" );
276+
Method nameMethod = moduleDescriptorInstance.getClass().getMethod( "name" );
276277
String name = (String) nameMethod.invoke( moduleDescriptorInstance );
277278

278279
moduleDescriptor = new ModuleDescriptor();
279280
moduleDescriptor.name = name;
280281

281-
Method isAutomaticMethod = moduleDescriptorInstance.getClass().getDeclaredMethod( "isAutomatic" );
282+
Method isAutomaticMethod = moduleDescriptorInstance.getClass().getMethod( "isAutomatic" );
282283
moduleDescriptor.automatic = (Boolean) isAutomaticMethod.invoke( moduleDescriptorInstance );
283284
}
284285
catch ( ClassNotFoundException e )

0 commit comments

Comments
 (0)