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
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]