davsclaus commented on code in PR #29778:
URL: https://github.com/apache/camel/pull/29778#discussion_r4560690233


##########
tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenDownloader.java:
##########
@@ -79,6 +80,23 @@ default List<MavenArtifact> resolveArtifacts(
         return resolveArtifacts(rootGav, dependencyGAVs, extraRepositories, 
transitively, useApacheSnapshots);
     }
 
+    /**
+     * Resolves the artifacts as {@link #resolveArtifacts(String, List, Set, 
boolean, boolean, Predicate)} does, with
+     * the versions of the managed artifacts: a transitive dependency on one 
of them gets its version, as with the
+     * dependencyManagement of a Maven project. For example, the libraries 
already loaded, so a library is not resolved
+     * again in another version.
+     *
+     * @param managed the artifacts whose version is used for the transitive 
dependencies on them, or null
+     */

Review Comment:
   Added in e5f4644d4046.
   
   _Claude Code on behalf of Claus Ibsen (davsclaus)_



##########
dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/MavenDependencyDownloader.java:
##########
@@ -639,6 +646,10 @@ public void artifactDownloaded(
         mavenDownloader = mavenDownloaderImpl;
     }
 
+    private static String managementKey(MavenGav gav) {
+        return gav.getGroupId() + ":" + gav.getArtifactId() + ":" + 
gav.getClassifier() + ":" + gav.getPackaging();

Review Comment:
   Done in e5f4644d4046 with `Objects.toString(..., "")`.
   
   _Claude Code on behalf of Claus Ibsen (davsclaus)_



##########
tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenDownloaderImpl.java:
##########
@@ -601,10 +617,74 @@ public List<MavenArtifact> resolveArtifacts(
                     session.getDependencySelector(), new 
AvailableDependencySelector(available)));
             session = availableSession;
         }
+        if (managed != null && !managed.isEmpty() && transitively) {
+            // the versions of the managed artifacts, whatever their classifier
+            Map<String, String> versions = new HashMap<>();
+            for (MavenGav gav : managed) {
+                versions.putIfAbsent(gav.getGroupId() + ":" + 
gav.getArtifactId(), gav.getVersion());
+            }
+            DefaultRepositorySystemSession managedSession = new 
DefaultRepositorySystemSession(session);
+            managedSession.setDependencyManager(
+                    new 
ManagedVersionDependencyManager(session.getDependencyManager(), versions, 0));
+            session = managedSession;
+        }
         return doResolveArtifacts(rootGav, dependencyGAVs, extraRepositories,
                 transitively, useApacheSnapshots, session);
     }
 
+    /**
+     * Gives the transitive dependencies on the managed artifacts their 
version, whatever their classifier (such as a
+     * native JAR of another platform), as the dependencyManagement of a Maven 
project would. The dependencies asked for
+     * directly keep their version.
+     */
+    static final class ManagedVersionDependencyManager implements 
DependencyManager {
+
+        private final DependencyManager delegate;
+        private final Map<String, String> versions;
+        private final int depth;
+
+        ManagedVersionDependencyManager(DependencyManager delegate, 
Map<String, String> versions, int depth) {
+            this.delegate = delegate;
+            this.versions = versions;
+            this.depth = depth;
+        }
+
+        @Override
+        public DependencyManagement manageDependency(Dependency dependency) {
+            DependencyManagement management = delegate != null ? 
delegate.manageDependency(dependency) : null;
+            // depth 1 are the dependencies asked for
+            if (depth >= 2) {
+                Artifact a = dependency.getArtifact();
+                String version = versions.get(a.getGroupId() + ":" + 
a.getArtifactId());
+                if (version != null && !version.equals(a.getVersion())) {
+                    if (management == null) {
+                        management = new DependencyManagement();
+                    }
+                    management.setVersion(version);
+                }

Review Comment:
   Keeping it as is: in Maven Resolver 1.9.27 both `ClassicDependencyManager` 
and `DefaultDependencyManager` create a new `DependencyManagement` in every 
`manageDependency` call, so the instance is not shared or cached. The suggested 
copy would also drop the scope, optional flag, exclusions and properties the 
delegate set, and those must stay.
   
   _Claude Code on behalf of Claus Ibsen (davsclaus)_



-- 
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]

Reply via email to