You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "slawekjaranowski (via GitHub)" <gi...@apache.org> on 2024/09/13 18:23:34 UTC

[PR] [ARCHETYPE-655] Get rid of Wagon API to download catalogs [maven-archetype]

slawekjaranowski opened a new pull request, #215:
URL: https://github.com/apache/maven-archetype/pull/215

   https://issues.apache.org/jira/browse/ARCHETYPE-655


-- 
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-unsubscribe@maven.apache.org

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


Re: [PR] [ARCHETYPE-655] Get rid of Wagon API to download catalogs [maven-archetype]

Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on PR #215:
URL: https://github.com/apache/maven-archetype/pull/215#issuecomment-2358157875

   @cstamas can you look?


-- 
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-unsubscribe@maven.apache.org

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


Re: [PR] [ARCHETYPE-655] Get rid of Wagon API to download catalogs [maven-archetype]

Posted by "cstamas (via GitHub)" <gi...@apache.org>.
cstamas commented on PR #215:
URL: https://github.com/apache/maven-archetype/pull/215#issuecomment-2358193196

   Don't get me wrong, I am _not -1 on this PR_, but anyone looking at the code will raise eyebrows when look into how is remote catalog fetched :smile: 


-- 
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-unsubscribe@maven.apache.org

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


Re: [PR] [ARCHETYPE-655] Get rid of Wagon API to download catalogs [maven-archetype]

Posted by "cstamas (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@maven.apache.org

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


Re: [PR] [ARCHETYPE-655] Get rid of Wagon API to download catalogs [maven-archetype]

Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski merged PR #215:
URL: https://github.com/apache/maven-archetype/pull/215


-- 
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-unsubscribe@maven.apache.org

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


Re: [PR] [ARCHETYPE-655] Get rid of Wagon API to download catalogs [maven-archetype]

Posted by "HannesWell (via GitHub)" <gi...@apache.org>.
HannesWell commented on PR #215:
URL: https://github.com/apache/maven-archetype/pull/215#issuecomment-2692874706

   Is it intentional that this changes the logic how the `archetypeRepository` is selected among the specified `RemoteRepositoriey` in the `RemoteCatalogArchetypeDataSource`?
   
   Previously a repo with `ARCHETYPE_REPOSITORY_ID` was always preferred:
   https://github.com/apache/maven-archetype/blob/cc906677b5539b538c7ae640d894142ecf57fdc0/archetype-common/src/main/java/org/apache/maven/archetype/source/RemoteCatalogArchetypeDataSource.java#L102-L109
   
   now always the first one one that is either `archetype` or `central` is selected:
   https://github.com/apache/maven-archetype/blob/367a9fe79a6698c5a6fc1fbcbfb239819d5ba9c2/archetype-common/src/main/java/org/apache/maven/archetype/source/RemoteCatalogArchetypeDataSource.java#L90-L102


-- 
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-unsubscribe@maven.apache.org

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