You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/05/14 14:39:55 UTC
[camel] branch main updated: CAMEL-19349: camel-jbang - Dev console
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 5a3908bc6e3 CAMEL-19349: camel-jbang - Dev console
5a3908bc6e3 is described below
commit 5a3908bc6e33348e3dd5411392fb2209ff326930
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun May 14 11:17:28 2023 +0200
CAMEL-19349: camel-jbang - Dev console
---
bom/camel-bom/pom.xml | 5 ++
dsl/camel-jbang/{ => camel-jbang-console}/pom.xml | 35 +++++---
.../services/org/apache/camel/dev-console/jbang | 2 +
.../org/apache/camel/dev-console/source-dir | 2 +
.../services/org/apache/camel/other.properties | 7 ++
.../src/generated/resources/jbang-console.json | 15 ++++
.../camel/jbang/console/JBangDevConsole.java | 53 ++++++++++++
.../camel/jbang/console/SourceDirDevConsole.java | 99 ++++++++++++++++++++++
.../apache/camel/jbang/console/VersionHelper.java | 45 ++++++++++
dsl/camel-jbang/camel-jbang-core/pom.xml | 4 +
dsl/camel-jbang/pom.xml | 1 +
parent/pom.xml | 5 ++
12 files changed, 263 insertions(+), 10 deletions(-)
diff --git a/bom/camel-bom/pom.xml b/bom/camel-bom/pom.xml
index b8d16e65519..18339812ba8 100644
--- a/bom/camel-bom/pom.xml
+++ b/bom/camel-bom/pom.xml
@@ -1047,6 +1047,11 @@
<artifactId>camel-jaxb</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jbang-console</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jbang-core</artifactId>
diff --git a/dsl/camel-jbang/pom.xml b/dsl/camel-jbang/camel-jbang-console/pom.xml
similarity index 63%
copy from dsl/camel-jbang/pom.xml
copy to dsl/camel-jbang/camel-jbang-console/pom.xml
index 6a640aea6d3..7a8f64e092b 100644
--- a/dsl/camel-jbang/pom.xml
+++ b/dsl/camel-jbang/camel-jbang-console/pom.xml
@@ -18,23 +18,38 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel</groupId>
- <artifactId>dsl</artifactId>
+ <artifactId>camel-jbang-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
- <artifactId>camel-jbang-parent</artifactId>
- <packaging>pom</packaging>
-
- <name>Camel :: JBang :: Parent</name>
- <description>Camel JBang Modules (parent)</description>
+ <artifactId>camel-jbang-console</artifactId>
+ <packaging>jar</packaging>
+
+ <name>Camel :: JBang :: Console</name>
+ <description>Camel JBang Console</description>
+
+ <properties>
+ <firstVersion>3.21.0</firstVersion>
+ <label>jbang</label>
+ <supportLevel>Preview</supportLevel>
+ </properties>
+
+ <dependencies>
+ <!-- camel -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-console</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-support</artifactId>
+ </dependency>
+ </dependencies>
- <modules>
- <module>camel-jbang-core</module>
- <module>camel-jbang-main</module>
- </modules>
</project>
diff --git a/dsl/camel-jbang/camel-jbang-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/jbang b/dsl/camel-jbang/camel-jbang-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/jbang
new file mode 100644
index 00000000000..300cfbb5ff3
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/jbang
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.jbang.console.JBangDevConsole
diff --git a/dsl/camel-jbang/camel-jbang-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/source-dir b/dsl/camel-jbang/camel-jbang-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/source-dir
new file mode 100644
index 00000000000..ba24e6f495f
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/source-dir
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.jbang.console.SourceDirDevConsole
diff --git a/dsl/camel-jbang/camel-jbang-console/src/generated/resources/META-INF/services/org/apache/camel/other.properties b/dsl/camel-jbang/camel-jbang-console/src/generated/resources/META-INF/services/org/apache/camel/other.properties
new file mode 100644
index 00000000000..7430e8554e8
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-console/src/generated/resources/META-INF/services/org/apache/camel/other.properties
@@ -0,0 +1,7 @@
+# Generated by camel build tools - do NOT edit this file!
+name=jbang-console
+groupId=org.apache.camel
+artifactId=camel-jbang-console
+version=4.0.0-SNAPSHOT
+projectName=Camel :: JBang :: Console
+projectDescription=Camel JBang Console
diff --git a/dsl/camel-jbang/camel-jbang-console/src/generated/resources/jbang-console.json b/dsl/camel-jbang/camel-jbang-console/src/generated/resources/jbang-console.json
new file mode 100644
index 00000000000..ff53cfed550
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-console/src/generated/resources/jbang-console.json
@@ -0,0 +1,15 @@
+{
+ "other": {
+ "kind": "other",
+ "name": "jbang-console",
+ "title": "Jbang Console",
+ "description": "Camel JBang Console",
+ "deprecated": false,
+ "firstVersion": "3.21.0",
+ "label": "jbang",
+ "supportLevel": "Preview",
+ "groupId": "org.apache.camel",
+ "artifactId": "camel-jbang-console",
+ "version": "4.0.0-SNAPSHOT"
+ }
+}
diff --git a/dsl/camel-jbang/camel-jbang-console/src/main/java/org/apache/camel/jbang/console/JBangDevConsole.java b/dsl/camel-jbang/camel-jbang-console/src/main/java/org/apache/camel/jbang/console/JBangDevConsole.java
new file mode 100644
index 00000000000..9645b901540
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-console/src/main/java/org/apache/camel/jbang/console/JBangDevConsole.java
@@ -0,0 +1,53 @@
+/*
+ * 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.jbang.console;
+
+import java.util.Map;
+
+import org.apache.camel.spi.annotations.DevConsole;
+import org.apache.camel.support.console.AbstractDevConsole;
+import org.apache.camel.util.json.JsonObject;
+
+@DevConsole("jbang")
+public class JBangDevConsole extends AbstractDevConsole {
+
+ public JBangDevConsole() {
+ super("camel", "jbang", "Camel JBang", "Information about Camel JBang");
+ }
+
+ @Override
+ protected String doCallText(Map<String, Object> options) {
+ final StringBuilder sb = new StringBuilder();
+
+ String v = VersionHelper.getJBangVersion();
+ if (v != null) {
+ sb.append(String.format("JBang: %s", v));
+ }
+
+ return sb.toString();
+ }
+
+ @Override
+ protected Map<String, Object> doCallJson(Map<String, Object> options) {
+ JsonObject root = new JsonObject();
+ String v = VersionHelper.getJBangVersion();
+ if (v != null) {
+ root.put("version", v);
+ }
+ return root;
+ }
+}
diff --git a/dsl/camel-jbang/camel-jbang-console/src/main/java/org/apache/camel/jbang/console/SourceDirDevConsole.java b/dsl/camel-jbang/camel-jbang-console/src/main/java/org/apache/camel/jbang/console/SourceDirDevConsole.java
new file mode 100644
index 00000000000..8b6d9524f44
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-console/src/main/java/org/apache/camel/jbang/console/SourceDirDevConsole.java
@@ -0,0 +1,99 @@
+/*
+ * 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.jbang.console;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Map;
+
+import org.apache.camel.spi.annotations.DevConsole;
+import org.apache.camel.support.RouteOnDemandReloadStrategy;
+import org.apache.camel.support.console.AbstractDevConsole;
+import org.apache.camel.util.TimeUtils;
+import org.apache.camel.util.json.JsonArray;
+import org.apache.camel.util.json.JsonObject;
+
+@DevConsole("source-dir")
+public class SourceDirDevConsole extends AbstractDevConsole {
+
+ public SourceDirDevConsole() {
+ super("camel", "source-dir", "Source Directory", "Information about Camel JBang source files");
+ }
+
+ @Override
+ protected String doCallText(Map<String, Object> options) {
+ final StringBuilder sb = new StringBuilder();
+
+ RouteOnDemandReloadStrategy reload = getCamelContext().hasService(RouteOnDemandReloadStrategy.class);
+ if (reload != null) {
+ sb.append(String.format("Directory: %s%n", reload.getFolder()));
+ // list files in this directory
+ File dir = new File(reload.getFolder());
+ if (dir.exists() && dir.isDirectory()) {
+ File[] files = dir.listFiles();
+ if (files != null) {
+ sb.append("Files:\n");
+ // sort files by name (ignore case)
+ Arrays.sort(files, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
+ for (File f : files) {
+ boolean skip = f.getName().startsWith(".") || f.isHidden();
+ if (!skip) {
+ long size = f.length();
+ long ts = f.lastModified();
+ String age = ts > 0 ? TimeUtils.printSince(ts) : "n/a";
+ sb.append(String.format(" %s (size: %d age: %s)%n", f.getName(), size, age));
+ }
+ }
+ }
+ }
+ }
+
+ return sb.toString();
+ }
+
+ @Override
+ protected Map<String, Object> doCallJson(Map<String, Object> options) {
+ JsonObject root = new JsonObject();
+
+ RouteOnDemandReloadStrategy reload = getCamelContext().hasService(RouteOnDemandReloadStrategy.class);
+ if (reload != null) {
+ root.put("dir", reload.getFolder());
+ // list files in this directory
+ File dir = new File(reload.getFolder());
+ if (dir.exists() && dir.isDirectory()) {
+ File[] files = dir.listFiles();
+ if (files != null) {
+ // sort files by name (ignore case)
+ Arrays.sort(files, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
+ JsonArray arr = new JsonArray();
+ root.put("files", arr);
+ for (File f : files) {
+ boolean skip = f.getName().startsWith(".") || f.isHidden();
+ if (!skip) {
+ JsonObject jo = new JsonObject();
+ jo.put("name", f.getName());
+ jo.put("size", f.length());
+ jo.put("lastModified", f.lastModified());
+ arr.add(jo);
+ }
+ }
+ }
+ }
+ }
+ return root;
+ }
+}
diff --git a/dsl/camel-jbang/camel-jbang-console/src/main/java/org/apache/camel/jbang/console/VersionHelper.java b/dsl/camel-jbang/camel-jbang-console/src/main/java/org/apache/camel/jbang/console/VersionHelper.java
new file mode 100644
index 00000000000..ba1351cf128
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-console/src/main/java/org/apache/camel/jbang/console/VersionHelper.java
@@ -0,0 +1,45 @@
+/*
+ * 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.jbang.console;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.camel.util.IOHelper;
+
+public final class VersionHelper {
+
+ private VersionHelper() {
+ }
+
+ public static String getJBangVersion() {
+ try {
+ File file = new File(System.getProperty("user.home"), ".jbang/cache/version.txt");
+ if (file.exists() && file.isFile()) {
+ FileInputStream fis = new FileInputStream(file);
+ String text = IOHelper.loadText(fis);
+ IOHelper.close(fis);
+ text = text.trim();
+ return text;
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ return null;
+ }
+
+}
diff --git a/dsl/camel-jbang/camel-jbang-core/pom.xml b/dsl/camel-jbang/camel-jbang-core/pom.xml
index 3993f78c25b..ab582b110be 100644
--- a/dsl/camel-jbang/camel-jbang-core/pom.xml
+++ b/dsl/camel-jbang/camel-jbang-core/pom.xml
@@ -47,6 +47,10 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-main</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jbang-console</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-kamelet-main</artifactId>
diff --git a/dsl/camel-jbang/pom.xml b/dsl/camel-jbang/pom.xml
index 6a640aea6d3..56288858e3b 100644
--- a/dsl/camel-jbang/pom.xml
+++ b/dsl/camel-jbang/pom.xml
@@ -34,6 +34,7 @@
<description>Camel JBang Modules (parent)</description>
<modules>
+ <module>camel-jbang-console</module>
<module>camel-jbang-core</module>
<module>camel-jbang-main</module>
</modules>
diff --git a/parent/pom.xml b/parent/pom.xml
index 784f068041c..0a94dc87ddf 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -2511,6 +2511,11 @@
<artifactId>camel-java-joor-dsl</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jbang-console</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-js-dsl</artifactId>