Skip to content

Commit

Permalink
[MPLUGIN-377] Upgrade to maven 3.x and avoid using deprecated API (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Oct 21, 2021
1 parent 960d150 commit 73e32d1
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 81 deletions.
5 changes: 0 additions & 5 deletions maven-plugin-plugin/pom.xml
Expand Up @@ -49,11 +49,6 @@
<artifactId>maven-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-tools-api</artifactId>
Expand Down
Expand Up @@ -50,11 +50,6 @@ under the License.
<artifactId>maven-core</artifactId>
<version>@mavenVersion@</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>@mavenVersion@</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
Expand Down
Expand Up @@ -31,11 +31,8 @@
import java.util.ResourceBundle;

import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.doxia.siterenderer.Renderer;
import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
Expand All @@ -51,6 +48,7 @@
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import org.apache.maven.tools.plugin.extractor.ExtractionException;
Expand Down Expand Up @@ -341,29 +339,22 @@ private PluginDescriptor extractPluginDescriptor()
* (because of Maven MNG-6109 bug that won't give accurate 'since' info when reading plugin.xml).
*
* @return the proper pluginDescriptorBuilder
* @see https://issues.apache.org/jira/browse/MNG-6109
* @see https://issues.apache.org/jira/browse/MPLUGIN-319
* @see <a href="https://issues.apache.org/jira/browse/MNG-6109">MNG-6109</a>
* @see <a href="https://issues.apache.org/jira/browse/MPLUGIN-319">MPLUGIN-319</a>
*/
private PluginDescriptorBuilder getPluginDescriptorBuilder()
{
PluginDescriptorBuilder pluginDescriptorBuilder;
try

if ( rtInfo.isMavenVersion( "(3.3.9,)" ) )
{
VersionRange versionRange = VersionRange.createFromVersionSpec( "(3.3.9,)" );
if ( versionRange.containsVersion( rtInfo.getApplicationVersion() ) )
{
pluginDescriptorBuilder = new PluginDescriptorBuilder();
}
else
{
pluginDescriptorBuilder = new MNG6109PluginDescriptorBuilder();
}
pluginDescriptorBuilder = new PluginDescriptorBuilder();
}
catch ( InvalidVersionSpecificationException e )
else
{
return new MNG6109PluginDescriptorBuilder();
pluginDescriptorBuilder = new MNG6109PluginDescriptorBuilder();
}

return pluginDescriptorBuilder;
}

Expand Down
Expand Up @@ -21,7 +21,6 @@

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Versioning;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down
@@ -0,0 +1,122 @@
package org.apache.maven.plugin.plugin.metadata;

/*
* 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.util.Iterator;
import java.util.List;

import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.AbstractRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.Plugin;

/**
* Metadata for the group directory of the repository.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public class GroupRepositoryMetadata
extends AbstractRepositoryMetadata
{
private final String groupId;

public GroupRepositoryMetadata( String groupId )
{
super( new Metadata() );
this.groupId = groupId;
}

public boolean storedInGroupDirectory()
{
return true;
}

public boolean storedInArtifactVersionDirectory()
{
return false;
}

public String getGroupId()
{
return groupId;
}

public String getArtifactId()
{
return null;
}

public String getBaseVersion()
{
return null;
}

public void addPluginMapping( String goalPrefix,
String artifactId )
{
addPluginMapping( goalPrefix, artifactId, artifactId );
}

public void addPluginMapping( String goalPrefix,
String artifactId,
String name )
{
List<Plugin> plugins = getMetadata().getPlugins();
boolean found = false;
for ( Iterator<Plugin> i = plugins.iterator(); i.hasNext() && !found; )
{
Plugin plugin = i.next();
if ( plugin.getPrefix().equals( goalPrefix ) )
{
found = true;
}
}
if ( !found )
{
Plugin plugin = new Plugin();
plugin.setPrefix( goalPrefix );
plugin.setArtifactId( artifactId );
plugin.setName( name );


getMetadata().addPlugin( plugin );
}
}

public Object getKey()
{
return groupId;
}

public boolean isSnapshot()
{
return false;
}

public ArtifactRepository getRepository()
{
return null;
}

public void setRepository( ArtifactRepository remoteRepository )
{
// intentionally blank
}
}
4 changes: 0 additions & 4 deletions maven-plugin-tools-annotations/pom.xml
Expand Up @@ -48,10 +48,6 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-tools-api</artifactId>
Expand Down
Expand Up @@ -37,17 +37,16 @@
import java.util.TreeSet;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.plugin.descriptor.DuplicateParameterException;
import org.apache.maven.plugin.descriptor.InvalidParameterException;
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.Requirement;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.tools.plugin.ExtendedMojoDescriptor;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import org.apache.maven.tools.plugin.extractor.ExtractionException;
Expand All @@ -60,6 +59,7 @@
import org.apache.maven.tools.plugin.extractor.annotations.scanner.MojoAnnotationsScanner;
import org.apache.maven.tools.plugin.extractor.annotations.scanner.MojoAnnotationsScannerRequest;
import org.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.UnArchiver;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
Expand Down Expand Up @@ -90,10 +90,7 @@ public class JavaAnnotationsMojoDescriptorExtractor
private MojoAnnotationsScanner mojoAnnotationsScanner;

@org.codehaus.plexus.component.annotations.Requirement
private ArtifactResolver artifactResolver;

@org.codehaus.plexus.component.annotations.Requirement
private ArtifactFactory artifactFactory;
private RepositorySystem repositorySystem;

@org.codehaus.plexus.component.annotations.Requirement
private ArchiverManager archiverManager;
Expand Down Expand Up @@ -203,10 +200,21 @@ protected Map<String, JavaClass> discoverClassesFromSourcesJar( Artifact artifac
try
{
Artifact sourcesArtifact =
artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion(), artifact.getType(), classifier );

artifactResolver.resolve( sourcesArtifact, request.getRemoteRepos(), request.getLocal() );
repositorySystem.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion(), artifact.getType(), classifier );

ArtifactResolutionRequest req = new ArtifactResolutionRequest();
req.setArtifact( sourcesArtifact );
req.setLocalRepository( request.getLocal() );
req.setRemoteRepositories( request.getRemoteRepos() );
ArtifactResolutionResult res = repositorySystem.resolve( req );
if ( res.hasMissingArtifacts() || res.hasExceptions() )
{
getLogger().warn(
"Unable to get sources artifact for " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
+ artifact.getVersion() + ". Some javadoc tags (@since, @deprecated and comments) won't be used" );
return Collections.emptyMap();
}

if ( sourcesArtifact.getFile() == null || !sourcesArtifact.getFile().exists() )
{
Expand All @@ -226,33 +234,17 @@ protected Map<String, JavaClass> discoverClassesFromSourcesJar( Artifact artifac
unArchiver.setDestDirectory( extractDirectory );
unArchiver.extract();

return discoverClasses( request.getEncoding(), Arrays.asList( extractDirectory ),
return discoverClasses( request.getEncoding(), Arrays.asList( extractDirectory ),
request.getDependencies() );
}
catch ( ArtifactResolutionException e )
{
throw new ExtractionException( e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
{
//throw new ExtractionException( e.getMessage(), e );
getLogger().debug( "skip ArtifactNotFoundException:" + e.getMessage() );
getLogger().warn(
"Unable to get sources artifact for " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
+ artifact.getVersion() + ". Some javadoc tags (@since, @deprecated and comments) won't be used" );
return Collections.emptyMap();
}
catch ( NoSuchArchiverException e )
catch ( ArchiverException | NoSuchArchiverException e )
{
throw new ExtractionException( e.getMessage(), e );
}
}

/**
* from sources scan to get @since and @deprecated and description of classes and fields.
*
* @param mojoAnnotatedClasses
* @param javaClassesMap
*/
protected void populateDataFromJavadoc( Map<String, MojoAnnotatedClass> mojoAnnotatedClasses,
Map<String, JavaClass> javaClassesMap )
Expand Down Expand Up @@ -289,8 +281,7 @@ protected void populateDataFromJavadoc( Map<String, MojoAnnotatedClass> mojoAnno

// populate parameters
Map<String, ParameterAnnotationContent> parameters =
getParametersParentHierarchy( entry.getValue(), new HashMap<String, ParameterAnnotationContent>(),
mojoAnnotatedClasses );
getParametersParentHierarchy( entry.getValue(), mojoAnnotatedClasses );
parameters = new TreeMap<>( parameters );
for ( Map.Entry<String, ParameterAnnotationContent> parameter : parameters.entrySet() )
{
Expand Down Expand Up @@ -387,7 +378,7 @@ private Map<String, JavaField> extractFieldParameterTags( JavaClass javaClass,
{
try
{
Map<String, JavaField> rawParams = new TreeMap<String, com.thoughtworks.qdox.model.JavaField>();
Map<String, JavaField> rawParams = new TreeMap<>();

// we have to add the parent fields first, so that they will be overwritten by the local fields if
// that actually happens...
Expand Down Expand Up @@ -560,8 +551,7 @@ private List<MojoDescriptor> toMojoDescriptors( Map<String, MojoAnnotatedClass>

// Parameter annotations
Map<String, ParameterAnnotationContent> parameters =
getParametersParentHierarchy( mojoAnnotatedClass, new HashMap<String, ParameterAnnotationContent>(),
mojoAnnotatedClasses );
getParametersParentHierarchy( mojoAnnotatedClass, mojoAnnotatedClasses );

for ( ParameterAnnotationContent parameterAnnotationContent : new TreeSet<>( parameters.values() ) )
{
Expand Down Expand Up @@ -594,8 +584,7 @@ private List<MojoDescriptor> toMojoDescriptors( Map<String, MojoAnnotatedClass>

// Component annotations
Map<String, ComponentAnnotationContent> components =
getComponentsParentHierarchy( mojoAnnotatedClass, new HashMap<String, ComponentAnnotationContent>(),
mojoAnnotatedClasses );
getComponentsParentHierarchy( mojoAnnotatedClass, mojoAnnotatedClasses );

for ( ComponentAnnotationContent componentAnnotationContent : new TreeSet<>( components.values() ) )
{
Expand Down Expand Up @@ -661,8 +650,8 @@ protected ExecuteAnnotationContent findExecuteInParentHierarchy( MojoAnnotatedCl


protected Map<String, ParameterAnnotationContent> getParametersParentHierarchy(
MojoAnnotatedClass mojoAnnotatedClass, Map<String, ParameterAnnotationContent> parameters,
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
MojoAnnotatedClass mojoAnnotatedClass,
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
{
List<ParameterAnnotationContent> parameterAnnotationContents = new ArrayList<>();

Expand Down Expand Up @@ -699,8 +688,8 @@ protected List<ParameterAnnotationContent> getParametersParent( MojoAnnotatedCla
}

protected Map<String, ComponentAnnotationContent> getComponentsParentHierarchy(
MojoAnnotatedClass mojoAnnotatedClass, Map<String, ComponentAnnotationContent> components,
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
MojoAnnotatedClass mojoAnnotatedClass,
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
{
List<ComponentAnnotationContent> componentAnnotationContents = new ArrayList<>();

Expand Down
Expand Up @@ -179,6 +179,7 @@ protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w
* @param w not null
* @param helpDescriptor will clean html content from description fields
*/
@SuppressWarnings( "deprecation" )
protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w, boolean helpDescriptor )
{
w.startElement( "mojo" );
Expand Down

0 comments on commit 73e32d1

Please sign in to comment.