[ https://issues.apache.org/jira/browse/ARCHETYPE-655?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17882678#comment-17882678 ]
ASF GitHub Bot commented on ARCHETYPE-655: ------------------------------------------ cstamas commented on code in PR #215: URL: https://github.com/apache/maven-archetype/pull/215#discussion_r1764863712 ########## archetype-common/src/main/java/org/apache/maven/archetype/source/RemoteCatalogArchetypeDataSource.java: ########## @@ -77,303 +57,56 @@ public class RemoteCatalogArchetypeDataSource extends CatalogArchetypeDataSource public static final String CENTRAL_REPOSITORY_ID = "central"; @Override - public ArchetypeCatalog getArchetypeCatalog(ProjectBuildingRequest buildingRequest) - throws ArchetypeDataSourceException { - // With M3 artifactRepositories are already injected with their mirror, including the new id - // First look for mirrorId of both 'central' and 'archetype' - final String archetypeRepoId; - Mirror archetypeMirror = getMirror(ARCHETYPE_REPOSITORY_ID); - if (archetypeMirror != null) { - archetypeRepoId = archetypeMirror.getId(); - } else { - archetypeRepoId = ARCHETYPE_REPOSITORY_ID; - } - - final String centralRepoId; - Mirror centralMirror = getMirror(CENTRAL_REPOSITORY_ID); - if (centralMirror != null) { - centralRepoId = centralMirror.getId(); - } else { - centralRepoId = CENTRAL_REPOSITORY_ID; - } - - ArtifactRepository centralRepository = null; - ArtifactRepository archetypeRepository = null; - for (ArtifactRepository remoteRepository : buildingRequest.getRemoteRepositories()) { - if (archetypeRepoId.equals(remoteRepository.getId())) { - archetypeRepository = remoteRepository; - break; - } else if (centralRepoId.equals(remoteRepository.getId())) { - centralRepository = remoteRepository; - } - } - - if (archetypeRepository == null) { - archetypeRepository = centralRepository; - } - - try { - return downloadCatalog(archetypeRepository); - } catch (IOException e) { - throw new ArchetypeDataSourceException(e); - } catch (WagonException e) { - throw new ArchetypeDataSourceException(e); - } - } - - @Override - public File updateCatalog(ProjectBuildingRequest buildingRequest, Archetype archetype) + public ArchetypeCatalog getArchetypeCatalog( + RepositorySystemSession repositorySession, List<RemoteRepository> remoteRepositories) throws ArchetypeDataSourceException { - throw new ArchetypeDataSourceException("Not supported yet."); - } - - private ArchetypeCatalog downloadCatalog(ArtifactRepository repository) - throws WagonException, IOException, ArchetypeDataSourceException { - getLogger().debug("Searching for remote catalog: " + repository.getUrl() + "/" + ARCHETYPE_CATALOG_FILENAME); - - // We use wagon to take advantage of a Proxy that has already been setup in a Maven environment. - Repository wagonRepository = new Repository(repository.getId(), repository.getUrl()); - - AuthenticationInfo authInfo = getAuthenticationInfo(wagonRepository.getId()); - ProxyInfo proxyInfo = getProxy(wagonRepository.getProtocol()); - - Wagon wagon = getWagon(wagonRepository); - - File catalog = File.createTempFile("archetype-catalog", ".xml"); - try { - wagon.connect(wagonRepository, authInfo, proxyInfo); - wagon.get(ARCHETYPE_CATALOG_FILENAME, catalog); - - return readCatalog(ReaderFactory.newXmlReader(catalog)); - } finally { - disconnectWagon(wagon); - catalog.delete(); - } - } - - private void disconnectWagon(Wagon wagon) { - try { - wagon.disconnect(); - } catch (Exception e) { - getLogger().warn("Problem disconnecting from wagon - ignoring: " + e.getMessage()); - } - } - - // - - private Wagon getWagon(Repository repository) throws UnsupportedProtocolException { - return getWagon(repository.getProtocol()); - } - - private Wagon getWagon(String protocol) throws UnsupportedProtocolException { - if (protocol == null) { - throw new UnsupportedProtocolException("Unspecified protocol"); - } - - String hint = protocol.toLowerCase(java.util.Locale.ENGLISH); - - Wagon wagon = wagons.get(hint); - if (wagon == null) { - throw new UnsupportedProtocolException( - "Cannot find wagon which supports the requested protocol: " + protocol); - } - - return wagon; - } - - private AuthenticationInfo getAuthenticationInfo(String id) { - MavenSession session = legacySupport.getSession(); - if (session != null && id != null) { - MavenExecutionRequest request = session.getRequest(); + MetadataRequest request = new MetadataRequest(); Review Comment: Neat trick, but I'd rather do it like here: https://github.com/apache/maven/blob/master/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultTransportProvider.java and https://github.com/apache/maven/blob/master/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultTransportProvider.java > Get rid of Wagon API to download catalogs > ----------------------------------------- > > Key: ARCHETYPE-655 > URL: https://issues.apache.org/jira/browse/ARCHETYPE-655 > Project: Maven Archetype > Issue Type: Improvement > Reporter: Konrad Windszus > Assignee: Slawomir Jaranowski > Priority: Major > Fix For: 3.3.0 > > > Currently the {{RemoteCatalogArchetypeDataSource}} relies on Wagon API to > download the catalog from a Maven repository > ([https://github.com/apache/maven-archetype/blob/3a2b725198c3823fd5d7e9f88b665b2e4515a202/archetype-common/src/main/java/org/apache/maven/archetype/source/RemoteCatalogArchetypeDataSource.java#L127-L149]). > > Instead the Maven Resolver API should be used directly. At the same time some > more flexibility with regards to repository ids would be beneficial (in order > to support multiple custom catalogs or to reuse existing repository/server > sections in the {{{}settings.xml{}}}). In the best case even merging catalog > XMLs from multiple repos (with deduplication) should be supported. > -- This message was sent by Atlassian Jira (v8.20.10#820010)