3737import java .util .TreeSet ;
3838
3939import 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 ;
4442import org .apache .maven .plugin .descriptor .DuplicateParameterException ;
4543import org .apache .maven .plugin .descriptor .InvalidParameterException ;
4644import org .apache .maven .plugin .descriptor .InvalidPluginDescriptorException ;
4745import org .apache .maven .plugin .descriptor .MojoDescriptor ;
4846import org .apache .maven .plugin .descriptor .PluginDescriptor ;
4947import org .apache .maven .plugin .descriptor .Requirement ;
5048import org .apache .maven .project .MavenProject ;
49+ import org .apache .maven .repository .RepositorySystem ;
5150import org .apache .maven .tools .plugin .ExtendedMojoDescriptor ;
5251import org .apache .maven .tools .plugin .PluginToolsRequest ;
5352import org .apache .maven .tools .plugin .extractor .ExtractionException ;
6059import org .apache .maven .tools .plugin .extractor .annotations .scanner .MojoAnnotationsScanner ;
6160import org .apache .maven .tools .plugin .extractor .annotations .scanner .MojoAnnotationsScannerRequest ;
6261import org .apache .maven .tools .plugin .util .PluginUtils ;
62+ import org .codehaus .plexus .archiver .ArchiverException ;
6363import org .codehaus .plexus .archiver .UnArchiver ;
6464import org .codehaus .plexus .archiver .manager .ArchiverManager ;
6565import 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
0 commit comments