This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new e8365c96290 KnownDependenciesResolver to support packages (#17035)
e8365c96290 is described below

commit e8365c96290154498e797b00895dee2cba2be76a
Author: Bartosz Popiela <bartosz...@gmail.com>
AuthorDate: Wed Feb 5 20:19:53 2025 +0100

    KnownDependenciesResolver to support packages (#17035)
    
    * Enhance KnownDependenciesResolver to iterate over packages up to the root 
package
    
    * add ASF headers
---
 .../main/download/KnownDependenciesResolver.java   | 11 ++++-
 .../download/KnownDependenciesResolverTest.java    | 57 ++++++++++++++++++++++
 .../camel-main-known-dependencies.properties       | 19 ++++++++
 3 files changed, 86 insertions(+), 1 deletion(-)

diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/KnownDependenciesResolver.java
 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/KnownDependenciesResolver.java
index 0879be27a96..dc5e3747941 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/KnownDependenciesResolver.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/KnownDependenciesResolver.java
@@ -66,7 +66,7 @@ public final class KnownDependenciesResolver {
 
     public MavenGav mavenGavForClass(String className) {
         MavenGav answer = null;
-        String gav = mappings.get(className);
+        String gav = findGav(className);
         if (gav != null) {
             answer = MavenGav.parseGav(gav, camelContext.getVersion());
         }
@@ -80,4 +80,13 @@ public final class KnownDependenciesResolver {
         }
         return answer;
     }
+
+    private String findGav(String prefix) {
+        String gav = mappings.get(prefix);
+        while (gav == null && prefix.lastIndexOf(".") != -1) {
+            prefix = prefix.substring(0, prefix.lastIndexOf("."));
+            gav = mappings.get(prefix);
+        }
+        return gav;
+    }
 }
diff --git 
a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/KnownDependenciesResolverTest.java
 
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/KnownDependenciesResolverTest.java
new file mode 100644
index 00000000000..7689b2b27e5
--- /dev/null
+++ 
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/KnownDependenciesResolverTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.main.download;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.apache.camel.impl.engine.SimpleCamelContext;
+import org.apache.camel.tooling.maven.MavenGav;
+import org.junit.jupiter.api.Test;
+
+public class KnownDependenciesResolverTest {
+
+  @Test
+  void mavenGavForClass_returnsClassScopedDependency() {
+    KnownDependenciesResolver resolver = new KnownDependenciesResolver(new 
SimpleCamelContext(), null, null);
+    resolver.loadKnownDependencies();
+
+    MavenGav dependency = resolver.mavenGavForClass(SomeClass.class.getName());
+
+    assertNotNull(dependency);
+    assertEquals(dependency.getGroupId(), "com.example");
+    assertEquals(dependency.getArtifactId(), "class-scoped");
+    assertEquals(dependency.getVersion(), "1.0.0");
+  }
+
+  @Test
+  void mavenGavForClass_returnsPackageScopedDependency() {
+    KnownDependenciesResolver resolver = new KnownDependenciesResolver(new 
SimpleCamelContext(), null, null);
+    resolver.loadKnownDependencies();
+
+    MavenGav dependency = 
resolver.mavenGavForClass(SomeClass.class.getPackage().getName());
+
+
+    assertNotNull(dependency);
+    assertEquals(dependency.getGroupId(), "org.example");
+    assertEquals(dependency.getArtifactId(), "package-scoped");
+    assertEquals(dependency.getVersion(), "2.0.0");
+  }
+
+  public static class SomeClass {
+  }
+}
\ No newline at end of file
diff --git 
a/dsl/camel-kamelet-main/src/test/resources/camel-main-known-dependencies.properties
 
b/dsl/camel-kamelet-main/src/test/resources/camel-main-known-dependencies.properties
new file mode 100644
index 00000000000..e51f347a82a
--- /dev/null
+++ 
b/dsl/camel-kamelet-main/src/test/resources/camel-main-known-dependencies.properties
@@ -0,0 +1,19 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+##      http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+org.apache.camel.main.download.KnownDependenciesResolverTest$SomeClass=com.example:class-scoped:1.0.0
+org.apache.camel.main=org.example:package-scoped:2.0.0
\ No newline at end of file

Reply via email to