[MPLUGIN-272] Descriptor goal fail with java 8 and interface with default method: upgrade QDox

Upgraded QDox from 1.12.1 to 2.0-M3

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1648726 13f79535-47bb-0310-9956-ffa450edef68
master
Robert Scholte 2014-12-31 15:59:28 +00:00
parent 35ca9b5a80
commit 7426d551af
7 changed files with 257 additions and 74 deletions

View File

@ -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.8+
invoker.goals.1 = clean verify

View File

@ -0,0 +1,83 @@
<?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>test-plugin</groupId>
<artifactId>test-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>@project.version@</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<goalPrefix>FOO</goalPrefix>
</configuration>
<executions>
<execution>
<id>default-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
<configuration>
</configuration>
<phase>process-classes</phase>
</execution>
<execution>
<id>help-descriptor</id>
<goals>
<goal>helpmojo</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,37 @@
package fr.ca;
/*
* 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 org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
/**
* Created by clement.agarini on 04/08/14.
*/
@Mojo(name="test-plugin",defaultPhase = LifecyclePhase.GENERATE_SOURCES)
public class MyMojo extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
}
}

View File

@ -0,0 +1,27 @@
package fr.ca;
/*
* 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 interface TestInterface {
public default void foo(){
}
}

View File

@ -19,10 +19,22 @@ package org.apache.maven.tools.plugin.annotations;
* under the License.
*/
import com.thoughtworks.qdox.JavaDocBuilder;
import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaField;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
@ -54,18 +66,11 @@ import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import com.thoughtworks.qdox.JavaProjectBuilder;
import com.thoughtworks.qdox.library.SortedClassLibraryBuilder;
import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaField;
/**
* JavaMojoDescriptorExtractor, a MojoDescriptor extractor to read descriptors from java classes with annotations.
@ -219,7 +224,8 @@ public class JavaAnnotationsMojoDescriptorExtractor
unArchiver.setDestDirectory( extractDirectory );
unArchiver.extract();
return discoverClasses( request.getEncoding(), Arrays.asList( extractDirectory ) );
return discoverClasses( request.getEncoding(), Arrays.asList( extractDirectory ),
request.getDependencies() );
}
catch ( ArtifactResolutionException e )
{
@ -377,7 +383,7 @@ public class JavaAnnotationsMojoDescriptorExtractor
if ( superClass != null )
{
if ( superClass.getFields().length > 0 )
if ( superClass.getFields().size() > 0 )
{
rawParams = extractFieldParameterTags( superClass, javaClassesMap );
}
@ -394,15 +400,11 @@ public class JavaAnnotationsMojoDescriptorExtractor
rawParams = new TreeMap<String, JavaField>();
}
JavaField[] classFields = javaClass.getFields();
if ( classFields != null )
for ( JavaField field : javaClass.getFields() )
{
for ( JavaField field : classFields )
{
rawParams.put( field.getName(), field );
}
rawParams.put( field.getName(), field );
}
return rawParams;
}
@ -429,27 +431,43 @@ public class JavaAnnotationsMojoDescriptorExtractor
sources.add( generatedPlugin );
}
return discoverClasses( encoding, sources );
return discoverClasses( encoding, sources, project.getArtifacts() );
}
protected Map<String, JavaClass> discoverClasses( final String encoding, List<File> sourceDirectories )
protected Map<String, JavaClass> discoverClasses( final String encoding, List<File> sourceDirectories,
Set<Artifact> artifacts )
{
JavaDocBuilder builder = new JavaDocBuilder();
JavaProjectBuilder builder = new JavaProjectBuilder( new SortedClassLibraryBuilder() );
builder.setEncoding( encoding );
// Build isolated Classloader with only the artifacts of the project (none of this plugin)
List<URL> urls = new ArrayList<URL>( artifacts.size() );
for ( Artifact artifact : artifacts )
{
try
{
urls.add( artifact.getFile().toURI().toURL() );
}
catch ( MalformedURLException e )
{
// noop
}
}
builder.addClassLoader( new URLClassLoader( urls.toArray( new URL[0] ), ClassLoader.getSystemClassLoader() ) );
for ( File source : sourceDirectories )
{
builder.addSourceTree( source );
}
JavaClass[] javaClasses = builder.getClasses();
Collection<JavaClass> javaClasses = builder.getClasses();
if ( javaClasses == null || javaClasses.length < 1 )
if ( javaClasses == null || javaClasses.size() < 1 )
{
return Collections.emptyMap();
}
Map<String, JavaClass> javaClassMap = new HashMap<String, JavaClass>( javaClasses.length );
Map<String, JavaClass> javaClassMap = new HashMap<String, JavaClass>( javaClasses.size() );
for ( JavaClass javaClass : javaClasses )
{

View File

@ -19,12 +19,17 @@ package org.apache.maven.tools.plugin.extractor.java;
* under the License.
*/
import com.thoughtworks.qdox.JavaDocBuilder;
import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaField;
import com.thoughtworks.qdox.model.Type;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.descriptor.InvalidParameterException;
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -33,19 +38,19 @@ import org.apache.maven.plugin.descriptor.Requirement;
import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.ExtendedMojoDescriptor;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
import org.apache.maven.tools.plugin.extractor.ExtractionException;
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
import org.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import com.thoughtworks.qdox.JavaProjectBuilder;
import com.thoughtworks.qdox.library.SortedClassLibraryBuilder;
import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaField;
import com.thoughtworks.qdox.model.JavaType;
/**
* Extracts Mojo descriptors from <a href="http://java.sun.com/">Java</a> sources.
@ -469,29 +474,13 @@ public class JavaJavadocMojoDescriptorExtractor
{
JavaField field = entry.getValue();
Type type = field.getType();
JavaType type = field.getType();
Parameter pd = new Parameter();
pd.setName( entry.getKey() );
if ( !type.isArray() )
{
pd.setType( type.getValue() );
}
else
{
StringBuilder value = new StringBuilder( type.getValue() );
int remaining = type.getDimensions();
while ( remaining-- > 0 )
{
value.append( "[]" );
}
pd.setType( value.toString() );
}
pd.setType( type.getFullyQualifiedName() );
pd.setDescription( field.getComment() );
@ -656,17 +645,12 @@ public class JavaJavadocMojoDescriptorExtractor
rawParams = new TreeMap<String, JavaField>();
}
JavaField[] classFields = javaClass.getFields();
if ( classFields != null )
for ( JavaField field : javaClass.getFields() )
{
for ( JavaField field : classFields )
if ( field.getTagByName( JavadocMojoAnnotation.PARAMETER ) != null
|| field.getTagByName( JavadocMojoAnnotation.COMPONENT ) != null )
{
if ( field.getTagByName( JavadocMojoAnnotation.PARAMETER ) != null
|| field.getTagByName( JavadocMojoAnnotation.COMPONENT ) != null )
{
rawParams.put( field.getName(), field );
}
rawParams.put( field.getName(), field );
}
}
return rawParams;
@ -676,7 +660,7 @@ public class JavaJavadocMojoDescriptorExtractor
public List<MojoDescriptor> execute( PluginToolsRequest request )
throws ExtractionException, InvalidPluginDescriptorException
{
JavaClass[] javaClasses = discoverClasses( request );
Collection<JavaClass> javaClasses = discoverClasses( request );
List<MojoDescriptor> descriptors = new ArrayList<MojoDescriptor>();
@ -704,11 +688,26 @@ public class JavaJavadocMojoDescriptorExtractor
* @return an array of java class
*/
@SuppressWarnings( "unchecked" )
protected JavaClass[] discoverClasses( final PluginToolsRequest request )
protected Collection<JavaClass> discoverClasses( final PluginToolsRequest request )
{
JavaDocBuilder builder = new JavaDocBuilder();
JavaProjectBuilder builder = new JavaProjectBuilder( new SortedClassLibraryBuilder() );
builder.setEncoding( request.getEncoding() );
// Build isolated Classloader with only the artifacts of the project (none of this plugin)
List<URL> urls = new ArrayList<URL>( request.getDependencies().size() );
for ( Artifact artifact : request.getDependencies() )
{
try
{
urls.add( artifact.getFile().toURI().toURL() );
}
catch ( MalformedURLException e )
{
// noop
}
}
builder.addClassLoader( new URLClassLoader( urls.toArray( new URL[0] ), ClassLoader.getSystemClassLoader() ) );
MavenProject project = request.getProject();
for ( String source : (List<String>) project.getCompileSourceRoots() )

View File

@ -217,7 +217,7 @@
<dependency>
<groupId>com.thoughtworks.qdox</groupId>
<artifactId>qdox</artifactId>
<version>1.12.1</version>
<version>2.0-M3</version>
</dependency>
<dependency>