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


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/BeanRefChecks.java:
##########
@@ -337,8 +342,51 @@ static int indentOf(String line) {
     }
 
     /**
-     * A class named with its package that is neither next to the route nor on 
the CLI classpath: the wrong package
-     * (org.apache.camel.support.StringAggregationStrategy) or a missing 
dependency. Null when the class is fine.
+     * The classes camel run resolves to a Maven dependency and downloads on 
demand (camel-kamelet-main's
+     * camel-main-known-dependencies.properties, 
camel-component-known-dependencies.properties and the generated
+     * camel-thirdparty-known-dependencies.properties of CAMEL-24809), so a 
#class:org.postgresql.ds.PGSimpleDataSource
+     * bean is fine without a dependency declared even though the class is not 
on the CLI classpath. Matched the way the
+     * runtime matches: the class name, then each enclosing package.
+     */
+    private static volatile Map<String, String> knownDependencies;
+
+    static String knownDependency(String fqcn) {
+        Map<String, String> known = knownDependencies;
+        if (known == null) {
+            known = new HashMap<>();
+            for (String name : new String[] {
+                    "camel-main-known-dependencies.properties", 
"camel-component-known-dependencies.properties",
+                    "camel-thirdparty-known-dependencies.properties" }) {
+                try {
+                    Enumeration<URL> resources = 
BeanRefChecks.class.getClassLoader().getResources(name);
+                    while (resources.hasMoreElements()) {
+                        try (InputStream is = 
resources.nextElement().openStream()) {
+                            Properties prop = new Properties();
+                            prop.load(is);
+                            for (String key : prop.stringPropertyNames()) {
+                                known.put(key, prop.getProperty(key));
+                            }
+                        }
+                    }
+                } catch (Exception e) {
+                    // the mapping is an optimisation of the message, not a 
requirement

Review Comment:
   Swallowing every exception matches the runtime's loader 
(`KnownDependenciesResolver.doLoadKnownDependencies` does the same), and these 
check classes carry no logger, so fine as is; worth a debug line if a logger is 
ever added here.



##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/BeanRefChecks.java:
##########
@@ -337,8 +342,51 @@ static int indentOf(String line) {
     }
 
     /**
-     * A class named with its package that is neither next to the route nor on 
the CLI classpath: the wrong package
-     * (org.apache.camel.support.StringAggregationStrategy) or a missing 
dependency. Null when the class is fine.
+     * The classes camel run resolves to a Maven dependency and downloads on 
demand (camel-kamelet-main's
+     * camel-main-known-dependencies.properties, 
camel-component-known-dependencies.properties and the generated
+     * camel-thirdparty-known-dependencies.properties of CAMEL-24809), so a 
#class:org.postgresql.ds.PGSimpleDataSource
+     * bean is fine without a dependency declared even though the class is not 
on the CLI classpath. Matched the way the
+     * runtime matches: the class name, then each enclosing package.
+     */
+    private static volatile Map<String, String> knownDependencies;
+
+    static String knownDependency(String fqcn) {
+        Map<String, String> known = knownDependencies;
+        if (known == null) {
+            known = new HashMap<>();
+            for (String name : new String[] {
+                    "camel-main-known-dependencies.properties", 
"camel-component-known-dependencies.properties",
+                    "camel-thirdparty-known-dependencies.properties" }) {
+                try {
+                    Enumeration<URL> resources = 
BeanRefChecks.class.getClassLoader().getResources(name);
+                    while (resources.hasMoreElements()) {
+                        try (InputStream is = 
resources.nextElement().openStream()) {
+                            Properties prop = new Properties();
+                            prop.load(is);
+                            for (String key : prop.stringPropertyNames()) {
+                                known.put(key, prop.getProperty(key));
+                            }
+                        }
+                    }
+                } catch (Exception e) {
+                    // the mapping is an optimisation of the message, not a 
requirement
+                }
+            }
+            knownDependencies = known;
+        }
+        String prefix = fqcn;
+        String gav = known.get(prefix);
+        while (gav == null && prefix.lastIndexOf('.') != -1) {

Review Comment:
   A typo inside a mapped package is no longer caught here: 
`org.postgresql.ds.PGSimpleDataSourc` matches `org.postgresql`, the validator 
stays silent, and the runtime downloads the driver and then fails at startup 
with class not found. That is the runtime resolver's own behaviour and the 
validator is meant to agree with it, but it is a small loss against the 
previous check. A later improvement could open the jar when it is already in 
the local repository and check the class is in it.



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