jagame commented on issue #259:
URL: 
https://github.com/apache/maven-archetype/issues/259#issuecomment-2776981236

   An possible "fix" should be too simple as modify 
RemoteCatalogArchetypeDataSource:
   ```java
   @Named("remote-catalog")
   @Singleton
   public class RemoteCatalogArchetypeDataSource extends 
CatalogArchetypeDataSource implements ArchetypeDataSource {
       private static final Logger LOGGER = 
LoggerFactory.getLogger(RemoteCatalogArchetypeDataSource.class);
   
       @Inject
       private RepositorySystem repositorySystem;
   
       /**
        * Id of the repository used to download catalog file. Proxy or 
authentication info can
        * be setup in settings.xml.
        */
       public static final String ARCHETYPE_REPOSITORY_ID = "archetype";
   
       public static final String CENTRAL_REPOSITORY_ID = "central";
   
       @Override
       public ArchetypeCatalog getArchetypeCatalog(
               RepositorySystemSession repositorySession, 
List<RemoteRepository> remoteRepositories)
               throws ArchetypeDataSourceException {
           ArchetypeCatalog mergedArchetypeCatalogs = new ArchetypeCatalog();
           for(RemoteRepository repository : remoteRepositories) {
               ArchetypeCatalog catalog = 
getArchetypeCatalog(repositorySession, repository);
               
mergedArchetypeCatalogs.getArchetypes().addAll(catalog.getArchetypes());
           }
           return mergedArchetypeCatalogs;
       }
   
       private ArchetypeCatalog getArchetypeCatalog(
               RepositorySystemSession repositorySession, RemoteRepository 
repository)
               throws ArchetypeDataSourceException {
           Optional<MetadataResult> optMetadataResult = 
requestMetadata(repositorySession, repository);
           if(!optMetadataResult.isPresent()) {
               return new ArchetypeCatalog();
           }
   
           try {
               return readCatalog(
                       new 
XmlStreamReader(optMetadataResult.get().getMetadata().getFile())
               );
           } catch (IOException e) {
               throw new ArchetypeDataSourceException(e);
           }
       }
   
       private Optional<MetadataResult> requestMetadata(RepositorySystemSession 
repositorySession, RemoteRepository remoteRepository) {
           if(!isArchetypeCatalogRepository(remoteRepository)) {
               return Optional.empty();
           }
   
           MetadataRequest request = new MetadataRequest();
           request.setRepository(remoteRepository);
           request.setMetadata(new DefaultMetadata(ARCHETYPE_CATALOG_FILENAME, 
Metadata.Nature.RELEASE));
   
           MetadataResult metadataResult = repositorySystem
                   .resolveMetadata(repositorySession, 
Collections.singletonList(request))
                   .get(0);
   
           if (metadataResult.isResolved()) {
               return Optional.of(metadataResult);
           } else {
               LOGGER.error("No {} had been resolved for repository {}",
                       ARCHETYPE_CATALOG_FILENAME, remoteRepository.getId(), 
metadataResult.getException()
               );
               return Optional.empty();
           }
       }
   
       private boolean isArchetypeCatalogRepository(RemoteRepository 
remoteRepository) {
           if (remoteRepository == null || remoteRepository.getId() == null) {
               return false;
           }
   
           return ARCHETYPE_REPOSITORY_ID.equals(remoteRepository.getId())
                   || remoteRepository.getId().endsWith('-' + 
ARCHETYPE_REPOSITORY_ID)
                   || CENTRAL_REPOSITORY_ID.equals(remoteRepository.getId());
       }
   
       @Override
       public File updateCatalog(RepositorySystemSession repositorySession, 
Archetype archetype)
               throws ArchetypeDataSourceException {
           throw new ArchetypeDataSourceException("Not supported yet.");
       }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to