37
37
import java .util .TreeSet ;
38
38
39
39
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 ;
44
42
import org .apache .maven .plugin .descriptor .DuplicateParameterException ;
45
43
import org .apache .maven .plugin .descriptor .InvalidParameterException ;
46
44
import org .apache .maven .plugin .descriptor .InvalidPluginDescriptorException ;
47
45
import org .apache .maven .plugin .descriptor .MojoDescriptor ;
48
46
import org .apache .maven .plugin .descriptor .PluginDescriptor ;
49
47
import org .apache .maven .plugin .descriptor .Requirement ;
50
48
import org .apache .maven .project .MavenProject ;
49
+ import org .apache .maven .repository .RepositorySystem ;
51
50
import org .apache .maven .tools .plugin .ExtendedMojoDescriptor ;
52
51
import org .apache .maven .tools .plugin .PluginToolsRequest ;
53
52
import org .apache .maven .tools .plugin .extractor .ExtractionException ;
60
59
import org .apache .maven .tools .plugin .extractor .annotations .scanner .MojoAnnotationsScanner ;
61
60
import org .apache .maven .tools .plugin .extractor .annotations .scanner .MojoAnnotationsScannerRequest ;
62
61
import org .apache .maven .tools .plugin .util .PluginUtils ;
62
+ import org .codehaus .plexus .archiver .ArchiverException ;
63
63
import org .codehaus .plexus .archiver .UnArchiver ;
64
64
import org .codehaus .plexus .archiver .manager .ArchiverManager ;
65
65
import org .codehaus .plexus .archiver .manager .NoSuchArchiverException ;
@@ -90,10 +90,7 @@ public class JavaAnnotationsMojoDescriptorExtractor
90
90
private MojoAnnotationsScanner mojoAnnotationsScanner ;
91
91
92
92
@ 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 ;
97
94
98
95
@ org .codehaus .plexus .component .annotations .Requirement
99
96
private ArchiverManager archiverManager ;
@@ -203,10 +200,21 @@ protected Map<String, JavaClass> discoverClassesFromSourcesJar( Artifact artifac
203
200
try
204
201
{
205
202
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
+ }
210
218
211
219
if ( sourcesArtifact .getFile () == null || !sourcesArtifact .getFile ().exists () )
212
220
{
@@ -226,33 +234,17 @@ protected Map<String, JavaClass> discoverClassesFromSourcesJar( Artifact artifac
226
234
unArchiver .setDestDirectory ( extractDirectory );
227
235
unArchiver .extract ();
228
236
229
- return discoverClasses ( request .getEncoding (), Arrays .asList ( extractDirectory ),
237
+ return discoverClasses ( request .getEncoding (), Arrays .asList ( extractDirectory ),
230
238
request .getDependencies () );
231
239
}
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 )
246
241
{
247
242
throw new ExtractionException ( e .getMessage (), e );
248
243
}
249
244
}
250
245
251
246
/**
252
247
* from sources scan to get @since and @deprecated and description of classes and fields.
253
- *
254
- * @param mojoAnnotatedClasses
255
- * @param javaClassesMap
256
248
*/
257
249
protected void populateDataFromJavadoc ( Map <String , MojoAnnotatedClass > mojoAnnotatedClasses ,
258
250
Map <String , JavaClass > javaClassesMap )
@@ -289,8 +281,7 @@ protected void populateDataFromJavadoc( Map<String, MojoAnnotatedClass> mojoAnno
289
281
290
282
// populate parameters
291
283
Map <String , ParameterAnnotationContent > parameters =
292
- getParametersParentHierarchy ( entry .getValue (), new HashMap <String , ParameterAnnotationContent >(),
293
- mojoAnnotatedClasses );
284
+ getParametersParentHierarchy ( entry .getValue (), mojoAnnotatedClasses );
294
285
parameters = new TreeMap <>( parameters );
295
286
for ( Map .Entry <String , ParameterAnnotationContent > parameter : parameters .entrySet () )
296
287
{
@@ -387,7 +378,7 @@ private Map<String, JavaField> extractFieldParameterTags( JavaClass javaClass,
387
378
{
388
379
try
389
380
{
390
- Map <String , JavaField > rawParams = new TreeMap <String , com . thoughtworks . qdox . model . JavaField >();
381
+ Map <String , JavaField > rawParams = new TreeMap <>();
391
382
392
383
// we have to add the parent fields first, so that they will be overwritten by the local fields if
393
384
// that actually happens...
@@ -560,8 +551,7 @@ private List<MojoDescriptor> toMojoDescriptors( Map<String, MojoAnnotatedClass>
560
551
561
552
// Parameter annotations
562
553
Map <String , ParameterAnnotationContent > parameters =
563
- getParametersParentHierarchy ( mojoAnnotatedClass , new HashMap <String , ParameterAnnotationContent >(),
564
- mojoAnnotatedClasses );
554
+ getParametersParentHierarchy ( mojoAnnotatedClass , mojoAnnotatedClasses );
565
555
566
556
for ( ParameterAnnotationContent parameterAnnotationContent : new TreeSet <>( parameters .values () ) )
567
557
{
@@ -594,8 +584,7 @@ private List<MojoDescriptor> toMojoDescriptors( Map<String, MojoAnnotatedClass>
594
584
595
585
// Component annotations
596
586
Map <String , ComponentAnnotationContent > components =
597
- getComponentsParentHierarchy ( mojoAnnotatedClass , new HashMap <String , ComponentAnnotationContent >(),
598
- mojoAnnotatedClasses );
587
+ getComponentsParentHierarchy ( mojoAnnotatedClass , mojoAnnotatedClasses );
599
588
600
589
for ( ComponentAnnotationContent componentAnnotationContent : new TreeSet <>( components .values () ) )
601
590
{
@@ -661,8 +650,8 @@ protected ExecuteAnnotationContent findExecuteInParentHierarchy( MojoAnnotatedCl
661
650
662
651
663
652
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 )
666
655
{
667
656
List <ParameterAnnotationContent > parameterAnnotationContents = new ArrayList <>();
668
657
@@ -699,8 +688,8 @@ protected List<ParameterAnnotationContent> getParametersParent( MojoAnnotatedCla
699
688
}
700
689
701
690
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 )
704
693
{
705
694
List <ComponentAnnotationContent > componentAnnotationContents = new ArrayList <>();
706
695
0 commit comments