gnodet-bot commented on code in PR #26623:
URL: https://github.com/apache/camel/pull/26623#discussion_r4056618666


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/GroovyImportChecks.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.dsl.jbang.core.commands.ai;
+
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static 
org.apache.camel.dsl.jbang.core.commands.ai.YamlLines.countLeadingSpaces;
+
+/**
+ * Checks on the imports of the Groovy expressions of a YAML route 
(CAMEL-24843). A Groovy script compiles against the
+ * application's classpath: an import of a library the application does not 
declare fails at runtime with "unable to
+ * resolve class", which names the class and nothing else. The check names the 
library when it is a known one and says
+ * how to declare it for the runtime; with the Camel CLI a known library is 
downloaded when the script is compiled, so
+ * only an unknown one is reported there.
+ */
+public final class GroovyImportChecks {
+
+    private static final Pattern IMPORT
+            = 
Pattern.compile("^\\s*import\\s+(static\\s+)?([a-zA-Z][.\\w]*(?:\\.\\*)?)\\s*;?\\s*$");
+    /** Packages every application has: the JDK, Groovy and Camel itself. */
+    private static final List<String> ALWAYS_PRESENT
+            = List.of("java.", "javax.", "jakarta.", "groovy.", 
"org.codehaus.groovy.", "org.apache.camel.");
+
+    private GroovyImportChecks() {
+    }
+
+    /**
+     * @param content      the YAML route file
+     * @param runtime      null or "jbang" for the Camel CLI (a known library 
is downloaded when the script is
+     *                     compiled), "main", "spring-boot" or "quarkus" for a 
Maven project (the library must be
+     *                     declared in the pom)
+     * @param projectTypes the classes the project declares itself (simple 
name to fully qualified name), from the Java
+     *                     and Groovy files next to the route
+     */
+    public static List<String> validateYamlGroovyImports(String content, 
String runtime, Map<String, String> projectTypes) {

Review Comment:
   💡 **Missing `@return` in Javadoc.** The method is public API and returns a 
`List<String>` (the list of validation error messages), but the Javadoc block 
has no `@return` tag.
   
   ```suggestion
        * @return a list of validation error messages (empty if no issues found)
        */
       public static List<String> validateYamlGroovyImports(String content, 
String runtime, Map<String, String> projectTypes) {
   ```



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