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


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Doctor.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.HttpURLConnection;
+import java.net.ServerSocket;
+import java.net.URI;
+
+import org.apache.camel.catalog.CamelCatalog;
+import org.apache.camel.catalog.DefaultCamelCatalog;
+import org.apache.camel.dsl.jbang.core.common.VersionHelper;
+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();
+        checkMavenCentral();
+        checkDocker();
+        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 = major >= 21 ? "OK" : "WARN (21+ 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 checkMavenCentral() {
+        try {
+            HttpURLConnection conn = (HttpURLConnection) 
URI.create("https://repo1.maven.org/maven2/";)

Review Comment:
   Some companies uses maven proxies and do not allow direct connection to 
online maven repos.
   



##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Doctor.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.HttpURLConnection;
+import java.net.ServerSocket;
+import java.net.URI;
+
+import org.apache.camel.catalog.CamelCatalog;
+import org.apache.camel.catalog.DefaultCamelCatalog;
+import org.apache.camel.dsl.jbang.core.common.VersionHelper;
+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();
+        checkMavenCentral();
+        checkDocker();
+        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 = major >= 21 ? "OK" : "WARN (21+ 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 checkMavenCentral() {
+        try {
+            HttpURLConnection conn = (HttpURLConnection) 
URI.create("https://repo1.maven.org/maven2/";)
+                    .toURL().openConnection();
+            conn.setConnectTimeout(5000);
+            conn.setReadTimeout(5000);
+            conn.setRequestMethod("HEAD");
+            int code = conn.getResponseCode();
+            conn.disconnect();
+            printer().printf("  Maven:       %s%n", code == 200 ? "reachable 
(OK)" : "returned " + code);
+        } catch (Exception e) {
+            printer().printf("  Maven:       unreachable (%s)%n", 
e.getMessage());
+        }
+    }
+
+    private void checkDocker() {
+        try {
+            Process p = new ProcessBuilder("docker", "info")

Review Comment:
   if people use podman, then I guess they can alias docker as podman, but 
maybe we need to check for both of them just to be sure if any of them is there
   
   also you dont really need docker to use jbang, it works also great without 
(albeit test-infra uses docker)



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