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


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Doctor.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.net.ServerSocket;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.camel.catalog.CamelCatalog;
+import org.apache.camel.catalog.DefaultCamelCatalog;
+import org.apache.camel.dsl.jbang.core.common.VersionHelper;
+import org.apache.camel.tooling.maven.MavenDownloaderImpl;
+import org.apache.camel.tooling.maven.MavenResolutionException;
+import picocli.CommandLine.Command;
+
+@Command(name = "doctor", description = "Checks the environment and reports 
potential issues",
+         sortOptions = false, showDefaultValues = true)
+public class Doctor extends CamelCommand {
+
+    public Doctor(CamelJBangMain main) {
+        super(main);
+    }
+
+    @Override
+    public Integer doCall() throws Exception {
+        printer().println("Camel JBang Doctor");
+        printer().println("==================");
+        printer().println();
+
+        checkJava();
+        checkJBang();
+        checkCamelVersion();
+        checkMavenRepository();
+        checkContainerRuntime();
+        checkCommonPorts();
+        checkDiskSpace();
+
+        return 0;
+    }
+
+    private void checkJava() {
+        String version = System.getProperty("java.version");
+        String vendor = System.getProperty("java.vendor", "");
+        int major = Runtime.version().feature();
+        String status;
+        if (major >= 21) {
+            status = "OK";
+        } else if (major >= 17) {
+            status = "OK (consider upgrading to 21 or 25 for better 
performance)";
+        } else {
+            status = "UNSUPPORTED (17+ required)";
+        }
+        printer().printf("  Java:        %s (%s) [%s]%n", version, vendor, 
status);
+    }
+
+    private void checkJBang() {
+        String version = VersionHelper.getJBangVersion();
+        if (version != null) {
+            printer().printf("  JBang:       %s (OK)%n", version);
+        } else {
+            printer().printf("  JBang:       not detected%n");
+        }
+    }
+
+    private void checkCamelVersion() {
+        CamelCatalog catalog = new DefaultCamelCatalog();
+        String version = catalog.getCatalogVersion();
+        printer().printf("  Camel:       %s%n", version);
+    }
+
+    private void checkMavenRepository() {
+        MavenDownloaderImpl downloader = new MavenDownloaderImpl();
+        try {
+            downloader.build();
+            CamelCatalog catalog = new DefaultCamelCatalog();
+            String version = catalog.getCatalogVersion();
+            downloader.resolveArtifacts(
+                    List.of("org.apache.camel:camel-api:" + version),
+                    Set.of(), false, false);
+            printer().printf("  Maven:       artifact resolution OK%n");
+        } catch (MavenResolutionException e) {
+            printer().printf("  Maven:       artifact resolution failed 
(%s)%n", e.getMessage());
+        } catch (Exception e) {
+            printer().printf("  Maven:       error (%s)%n", e.getMessage());
+        }
+    }
+
+    private void checkContainerRuntime() {
+        // check docker first, then podman as fallback
+        for (String cmd : new String[] { "docker", "podman" }) {
+            try {
+                Process p = new ProcessBuilder(cmd, "info")
+                        .redirectErrorStream(true)
+                        .start();
+                // drain output to prevent blocking
+                
p.getInputStream().transferTo(java.io.OutputStream.nullOutputStream());

Review Comment:
   Uses a fully qualified class name `java.io.OutputStream.nullOutputStream()`. 
Per project conventions, this should use an import.
   
   ```suggestion
                   
p.getInputStream().transferTo(OutputStream.nullOutputStream());
   ```
   
   And add `import java.io.OutputStream;` to the imports.



##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Shell.java:
##########
@@ -151,8 +153,35 @@ private static void printBanner(org.jline.shell.Shell 
shell, String camelVersion
             }
             writer.println(banner);
         }
-        writer.println("Type 'help' for available commands, 'exit' to quit.");
+        int routeCount = countRouteFiles();
+        if (routeCount == 0) {
+            writer.println("No routes found in current directory.");
+            writer.println("  Quick start:  init MyRoute.yaml && run *");
+            writer.println("  Templates:    init --list");
+            writer.println("  Docs:         doc <component>");
+            writer.println("  Need help?    help");
+        } else {
+            writer.printf("Found %d route file(s) in current directory.%n", 
routeCount);
+            writer.println("  Run:   run *");
+            writer.println("  Watch: run * --dev");
+        }
         writer.println();
         writer.flush();
     }
+
+    private static int countRouteFiles() {
+        try (Stream<Path> files = Files.list(Paths.get("."))) {
+            return (int) files.filter(Files::isRegularFile)
+                    .filter(p -> {
+                        String name = p.getFileName().toString();
+                        return name.endsWith(".yaml") && 
!name.endsWith(".kamelet.yaml")

Review Comment:
   This predicate mixes `&&` and `||` without explicit parentheses. Java 
operator precedence makes it correct, but adding parentheses would make the 
intent clearer and prevent future mistakes:
   
   ```suggestion
                           return (name.endsWith(".yaml") && 
!name.endsWith(".kamelet.yaml")
                                   && !name.equals("application.yaml"))
                                   || (name.endsWith(".xml") && 
!name.equals("pom.xml"))
                                   || name.endsWith(".java");
   ```



##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java:
##########
@@ -355,13 +364,75 @@ public boolean disarrangeLogging() {
 
     @Override
     public Integer doCall() throws Exception {
+        // handle --example
+        if (exampleList || (example != null && example.isEmpty())) {
+            return listExamples();
+        }
+        if (example != null) {
+            return runExample();
+        }
+
         if (!exportRun) {
             printConfigurationValues("Running integration with the following 
configuration:");
         }
         // run
         return run();
     }
 
+    private int listExamples() {
+        printer().println("Available built-in examples:");
+        printer().println();
+        printer().printf("  %-20s %s%n", "timer-log", "Simple timer that logs 
messages every second");
+        printer().printf("  %-20s %s%n", "rest-api", "REST API with hello 
endpoints");
+        printer().printf("  %-20s %s%n", "cron-log", "Scheduled task that logs 
every 5 seconds");
+        printer().println();
+        printer().println("Usage: camel run --example <name>");
+        printer().println("       camel run --example <name> --dev");
+        return 0;
+    }
+
+    private static final List<String> EXAMPLE_NAMES = List.of("timer-log", 
"rest-api", "cron-log");
+
+    private int runExample() throws Exception {
+        String resourcePath = "examples/" + example + ".yaml";
+        InputStream is = 
Run.class.getClassLoader().getResourceAsStream(resourcePath);
+        if (is == null) {
+            List<String> suggestions
+                    = 
org.apache.camel.main.util.SuggestSimilarHelper.didYouMean(EXAMPLE_NAMES, 
example);

Review Comment:
   This uses a fully qualified class name inline. Per project conventions (and 
the CI OpenRewrite check), `SuggestSimilarHelper` should be imported — the same 
way it's done in `CatalogBaseCommand.java` in this PR.
   
   ```suggestion
                       = SuggestSimilarHelper.didYouMean(EXAMPLE_NAMES, 
example);
   ```
   
   And add `import org.apache.camel.main.util.SuggestSimilarHelper;` to the 
imports.



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