Skip to content

Commit 73e32d1

Browse files
authored
[MPLUGIN-377] Upgrade to maven 3.x and avoid using deprecated API (#37)
1 parent 960d150 commit 73e32d1

File tree

10 files changed

+164
-81
lines changed

10 files changed

+164
-81
lines changed

maven-plugin-plugin/pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@
4949
<artifactId>maven-core</artifactId>
5050
<scope>provided</scope>
5151
</dependency>
52-
<dependency>
53-
<groupId>org.apache.maven</groupId>
54-
<artifactId>maven-compat</artifactId>
55-
<scope>provided</scope>
56-
</dependency>
5752
<dependency>
5853
<groupId>org.apache.maven.plugin-tools</groupId>
5954
<artifactId>maven-plugin-tools-api</artifactId>

maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ under the License.
5050
<artifactId>maven-core</artifactId>
5151
<version>@mavenVersion@</version>
5252
</dependency>
53-
<dependency>
54-
<groupId>org.apache.maven</groupId>
55-
<artifactId>maven-compat</artifactId>
56-
<version>@mavenVersion@</version>
57-
</dependency>
5853
<dependency>
5954
<groupId>org.apache.maven.plugin-tools</groupId>
6055
<artifactId>maven-plugin-annotations</artifactId>

maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java

+9-18
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@
3131
import java.util.ResourceBundle;
3232

3333
import org.apache.maven.artifact.repository.ArtifactRepository;
34-
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
35-
import org.apache.maven.artifact.versioning.VersionRange;
3634
import org.apache.maven.doxia.sink.Sink;
3735
import org.apache.maven.doxia.siterenderer.Renderer;
38-
import org.apache.maven.execution.RuntimeInformation;
3936
import org.apache.maven.model.Plugin;
4037
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
4138
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@@ -51,6 +48,7 @@
5148
import org.apache.maven.reporting.AbstractMavenReport;
5249
import org.apache.maven.reporting.AbstractMavenReportRenderer;
5350
import org.apache.maven.reporting.MavenReportException;
51+
import org.apache.maven.rtinfo.RuntimeInformation;
5452
import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
5553
import org.apache.maven.tools.plugin.PluginToolsRequest;
5654
import org.apache.maven.tools.plugin.extractor.ExtractionException;
@@ -341,29 +339,22 @@ private PluginDescriptor extractPluginDescriptor()
341339
* (because of Maven MNG-6109 bug that won't give accurate 'since' info when reading plugin.xml).
342340
*
343341
* @return the proper pluginDescriptorBuilder
344-
* @see https://issues.apache.org/jira/browse/MNG-6109
345-
* @see https://issues.apache.org/jira/browse/MPLUGIN-319
342+
* @see <a href="https://issues.apache.org/jira/browse/MNG-6109">MNG-6109</a>
343+
* @see <a href="https://issues.apache.org/jira/browse/MPLUGIN-319">MPLUGIN-319</a>
346344
*/
347345
private PluginDescriptorBuilder getPluginDescriptorBuilder()
348346
{
349347
PluginDescriptorBuilder pluginDescriptorBuilder;
350-
try
348+
349+
if ( rtInfo.isMavenVersion( "(3.3.9,)" ) )
351350
{
352-
VersionRange versionRange = VersionRange.createFromVersionSpec( "(3.3.9,)" );
353-
if ( versionRange.containsVersion( rtInfo.getApplicationVersion() ) )
354-
{
355-
pluginDescriptorBuilder = new PluginDescriptorBuilder();
356-
}
357-
else
358-
{
359-
pluginDescriptorBuilder = new MNG6109PluginDescriptorBuilder();
360-
}
351+
pluginDescriptorBuilder = new PluginDescriptorBuilder();
361352
}
362-
catch ( InvalidVersionSpecificationException e )
353+
else
363354
{
364-
return new MNG6109PluginDescriptorBuilder();
355+
pluginDescriptorBuilder = new MNG6109PluginDescriptorBuilder();
365356
}
366-
357+
367358
return pluginDescriptorBuilder;
368359
}
369360

maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.apache.maven.artifact.Artifact;
2323
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
24-
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
2524
import org.apache.maven.artifact.repository.metadata.Versioning;
2625
import org.apache.maven.plugin.AbstractMojo;
2726
import org.apache.maven.plugin.MojoExecutionException;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package org.apache.maven.plugin.plugin.metadata;
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+
import java.util.Iterator;
23+
import java.util.List;
24+
25+
import org.apache.maven.artifact.repository.ArtifactRepository;
26+
import org.apache.maven.artifact.repository.metadata.AbstractRepositoryMetadata;
27+
import org.apache.maven.artifact.repository.metadata.Metadata;
28+
import org.apache.maven.artifact.repository.metadata.Plugin;
29+
30+
/**
31+
* Metadata for the group directory of the repository.
32+
*
33+
* @author <a href="mailto:[email protected]">Brett Porter</a>
34+
*/
35+
public class GroupRepositoryMetadata
36+
extends AbstractRepositoryMetadata
37+
{
38+
private final String groupId;
39+
40+
public GroupRepositoryMetadata( String groupId )
41+
{
42+
super( new Metadata() );
43+
this.groupId = groupId;
44+
}
45+
46+
public boolean storedInGroupDirectory()
47+
{
48+
return true;
49+
}
50+
51+
public boolean storedInArtifactVersionDirectory()
52+
{
53+
return false;
54+
}
55+
56+
public String getGroupId()
57+
{
58+
return groupId;
59+
}
60+
61+
public String getArtifactId()
62+
{
63+
return null;
64+
}
65+
66+
public String getBaseVersion()
67+
{
68+
return null;
69+
}
70+
71+
public void addPluginMapping( String goalPrefix,
72+
String artifactId )
73+
{
74+
addPluginMapping( goalPrefix, artifactId, artifactId );
75+
}
76+
77+
public void addPluginMapping( String goalPrefix,
78+
String artifactId,
79+
String name )
80+
{
81+
List<Plugin> plugins = getMetadata().getPlugins();
82+
boolean found = false;
83+
for ( Iterator<Plugin> i = plugins.iterator(); i.hasNext() && !found; )
84+
{
85+
Plugin plugin = i.next();
86+
if ( plugin.getPrefix().equals( goalPrefix ) )
87+
{
88+
found = true;
89+
}
90+
}
91+
if ( !found )
92+
{
93+
Plugin plugin = new Plugin();
94+
plugin.setPrefix( goalPrefix );
95+
plugin.setArtifactId( artifactId );
96+
plugin.setName( name );
97+
98+
99+
getMetadata().addPlugin( plugin );
100+
}
101+
}
102+
103+
public Object getKey()
104+
{
105+
return groupId;
106+
}
107+
108+
public boolean isSnapshot()
109+
{
110+
return false;
111+
}
112+
113+
public ArtifactRepository getRepository()
114+
{
115+
return null;
116+
}
117+
118+
public void setRepository( ArtifactRepository remoteRepository )
119+
{
120+
// intentionally blank
121+
}
122+
}

maven-plugin-tools-annotations/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@
4848
<groupId>org.apache.maven</groupId>
4949
<artifactId>maven-artifact</artifactId>
5050
</dependency>
51-
<dependency>
52-
<groupId>org.apache.maven</groupId>
53-
<artifactId>maven-compat</artifactId>
54-
</dependency>
5551
<dependency>
5652
<groupId>org.apache.maven.plugin-tools</groupId>
5753
<artifactId>maven-plugin-tools-api</artifactId>

maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/JavaAnnotationsMojoDescriptorExtractor.java

+30-41
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,16 @@
3737
import java.util.TreeSet;
3838

3939
import org.apache.maven.artifact.Artifact;
40-
import org.apache.maven.artifact.factory.ArtifactFactory;
41-
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
42-
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
43-
import org.apache.maven.artifact.resolver.ArtifactResolver;
40+
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
41+
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
4442
import org.apache.maven.plugin.descriptor.DuplicateParameterException;
4543
import org.apache.maven.plugin.descriptor.InvalidParameterException;
4644
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
4745
import org.apache.maven.plugin.descriptor.MojoDescriptor;
4846
import org.apache.maven.plugin.descriptor.PluginDescriptor;
4947
import org.apache.maven.plugin.descriptor.Requirement;
5048
import org.apache.maven.project.MavenProject;
49+
import org.apache.maven.repository.RepositorySystem;
5150
import org.apache.maven.tools.plugin.ExtendedMojoDescriptor;
5251
import org.apache.maven.tools.plugin.PluginToolsRequest;
5352
import org.apache.maven.tools.plugin.extractor.ExtractionException;
@@ -60,6 +59,7 @@
6059
import org.apache.maven.tools.plugin.extractor.annotations.scanner.MojoAnnotationsScanner;
6160
import org.apache.maven.tools.plugin.extractor.annotations.scanner.MojoAnnotationsScannerRequest;
6261
import org.apache.maven.tools.plugin.util.PluginUtils;
62+
import org.codehaus.plexus.archiver.ArchiverException;
6363
import org.codehaus.plexus.archiver.UnArchiver;
6464
import org.codehaus.plexus.archiver.manager.ArchiverManager;
6565
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
@@ -90,10 +90,7 @@ public class JavaAnnotationsMojoDescriptorExtractor
9090
private MojoAnnotationsScanner mojoAnnotationsScanner;
9191

9292
@org.codehaus.plexus.component.annotations.Requirement
93-
private ArtifactResolver artifactResolver;
94-
95-
@org.codehaus.plexus.component.annotations.Requirement
96-
private ArtifactFactory artifactFactory;
93+
private RepositorySystem repositorySystem;
9794

9895
@org.codehaus.plexus.component.annotations.Requirement
9996
private ArchiverManager archiverManager;
@@ -203,10 +200,21 @@ protected Map<String, JavaClass> discoverClassesFromSourcesJar( Artifact artifac
203200
try
204201
{
205202
Artifact sourcesArtifact =
206-
artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(),
207-
artifact.getVersion(), artifact.getType(), classifier );
208-
209-
artifactResolver.resolve( sourcesArtifact, request.getRemoteRepos(), request.getLocal() );
203+
repositorySystem.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(),
204+
artifact.getVersion(), artifact.getType(), classifier );
205+
206+
ArtifactResolutionRequest req = new ArtifactResolutionRequest();
207+
req.setArtifact( sourcesArtifact );
208+
req.setLocalRepository( request.getLocal() );
209+
req.setRemoteRepositories( request.getRemoteRepos() );
210+
ArtifactResolutionResult res = repositorySystem.resolve( req );
211+
if ( res.hasMissingArtifacts() || res.hasExceptions() )
212+
{
213+
getLogger().warn(
214+
"Unable to get sources artifact for " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
215+
+ artifact.getVersion() + ". Some javadoc tags (@since, @deprecated and comments) won't be used" );
216+
return Collections.emptyMap();
217+
}
210218

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

229-
return discoverClasses( request.getEncoding(), Arrays.asList( extractDirectory ),
237+
return discoverClasses( request.getEncoding(), Arrays.asList( extractDirectory ),
230238
request.getDependencies() );
231239
}
232-
catch ( ArtifactResolutionException e )
233-
{
234-
throw new ExtractionException( e.getMessage(), e );
235-
}
236-
catch ( ArtifactNotFoundException e )
237-
{
238-
//throw new ExtractionException( e.getMessage(), e );
239-
getLogger().debug( "skip ArtifactNotFoundException:" + e.getMessage() );
240-
getLogger().warn(
241-
"Unable to get sources artifact for " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
242-
+ artifact.getVersion() + ". Some javadoc tags (@since, @deprecated and comments) won't be used" );
243-
return Collections.emptyMap();
244-
}
245-
catch ( NoSuchArchiverException e )
240+
catch ( ArchiverException | NoSuchArchiverException e )
246241
{
247242
throw new ExtractionException( e.getMessage(), e );
248243
}
249244
}
250245

251246
/**
252247
* from sources scan to get @since and @deprecated and description of classes and fields.
253-
*
254-
* @param mojoAnnotatedClasses
255-
* @param javaClassesMap
256248
*/
257249
protected void populateDataFromJavadoc( Map<String, MojoAnnotatedClass> mojoAnnotatedClasses,
258250
Map<String, JavaClass> javaClassesMap )
@@ -289,8 +281,7 @@ protected void populateDataFromJavadoc( Map<String, MojoAnnotatedClass> mojoAnno
289281

290282
// populate parameters
291283
Map<String, ParameterAnnotationContent> parameters =
292-
getParametersParentHierarchy( entry.getValue(), new HashMap<String, ParameterAnnotationContent>(),
293-
mojoAnnotatedClasses );
284+
getParametersParentHierarchy( entry.getValue(), mojoAnnotatedClasses );
294285
parameters = new TreeMap<>( parameters );
295286
for ( Map.Entry<String, ParameterAnnotationContent> parameter : parameters.entrySet() )
296287
{
@@ -387,7 +378,7 @@ private Map<String, JavaField> extractFieldParameterTags( JavaClass javaClass,
387378
{
388379
try
389380
{
390-
Map<String, JavaField> rawParams = new TreeMap<String, com.thoughtworks.qdox.model.JavaField>();
381+
Map<String, JavaField> rawParams = new TreeMap<>();
391382

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

561552
// Parameter annotations
562553
Map<String, ParameterAnnotationContent> parameters =
563-
getParametersParentHierarchy( mojoAnnotatedClass, new HashMap<String, ParameterAnnotationContent>(),
564-
mojoAnnotatedClasses );
554+
getParametersParentHierarchy( mojoAnnotatedClass, mojoAnnotatedClasses );
565555

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

595585
// Component annotations
596586
Map<String, ComponentAnnotationContent> components =
597-
getComponentsParentHierarchy( mojoAnnotatedClass, new HashMap<String, ComponentAnnotationContent>(),
598-
mojoAnnotatedClasses );
587+
getComponentsParentHierarchy( mojoAnnotatedClass, mojoAnnotatedClasses );
599588

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

662651

663652
protected Map<String, ParameterAnnotationContent> getParametersParentHierarchy(
664-
MojoAnnotatedClass mojoAnnotatedClass, Map<String, ParameterAnnotationContent> parameters,
665-
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
653+
MojoAnnotatedClass mojoAnnotatedClass,
654+
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
666655
{
667656
List<ParameterAnnotationContent> parameterAnnotationContents = new ArrayList<>();
668657

@@ -699,8 +688,8 @@ protected List<ParameterAnnotationContent> getParametersParent( MojoAnnotatedCla
699688
}
700689

701690
protected Map<String, ComponentAnnotationContent> getComponentsParentHierarchy(
702-
MojoAnnotatedClass mojoAnnotatedClass, Map<String, ComponentAnnotationContent> components,
703-
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
691+
MojoAnnotatedClass mojoAnnotatedClass,
692+
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
704693
{
705694
List<ComponentAnnotationContent> componentAnnotationContents = new ArrayList<>();
706695

maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w
179179
* @param w not null
180180
* @param helpDescriptor will clean html content from description fields
181181
*/
182+
@SuppressWarnings( "deprecation" )
182183
protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w, boolean helpDescriptor )
183184
{
184185
w.startElement( "mojo" );

0 commit comments

Comments
 (0)