This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch jsh in repository https://gitbox.apache.org/repos/asf/camel.git
commit ff89854c04858a8baf197e0247eea32933d2d42a Author: Claus Ibsen <[email protected]> AuthorDate: Mon Oct 7 16:27:41 2024 +0200 CAMEL-21203: Remove camel-jsh-dsl --- bom/camel-bom/pom.xml | 5 - .../org/apache/camel/catalog/others.properties | 1 - .../org/apache/camel/catalog/others/jsh-dsl.json | 16 --- .../camel/model/ProcessorDefinitionHelper.java | 2 +- docs/components/modules/others/nav.adoc | 1 - docs/components/modules/others/pages/jsh-dsl.adoc | 1 - .../ROOT/pages/camel-4x-upgrade-guide-4_9.adoc | 6 + .../dsl/jbang/core/commands/ExportBaseCommand.java | 2 - .../camel/dsl/jbang/core/common/GistHelper.java | 2 +- .../camel/dsl/jbang/core/common/GitHubHelper.java | 3 +- .../camel/dsl/jbang/core/common/ProcessHelper.java | 2 +- .../camel/dsl/jbang/core/common/SourceHelper.java | 2 +- .../src/main/resources/templates/jsh.tmpl | 4 - dsl/camel-jsh-dsl/pom.xml | 132 -------------------- .../services/org/apache/camel/other.properties | 8 -- .../services/org/apache/camel/routes-loader/jsh | 2 - .../src/generated/resources/jsh-dsl.json | 16 --- dsl/camel-jsh-dsl/src/main/docs/jsh-dsl.adoc | 54 -------- .../main/java/org/apache/camel/dsl/jsh/Jsh.java | 136 --------------------- .../org/apache/camel/dsl/jsh/JshClassLoader.java | 53 -------- .../apache/camel/dsl/jsh/JshLoaderDelegate.java | 80 ------------ .../camel/dsl/jsh/JshRoutesBuilderLoader.java | 113 ----------------- .../apache/camel/dsl/jsh/JshSourceLoaderTest.java | 61 --------- .../src/test/resources/log4j2-test.properties | 31 ----- .../src/test/resources/routes/MyRoute.jsh | 20 --- .../download/DependencyDownloaderRoutesLoader.java | 2 - dsl/pom.xml | 1 - parent/pom.xml | 5 - 28 files changed, 11 insertions(+), 750 deletions(-) diff --git a/bom/camel-bom/pom.xml b/bom/camel-bom/pom.xml index 6966d410ae5..4c09a139943 100644 --- a/bom/camel-bom/pom.xml +++ b/bom/camel-bom/pom.xml @@ -1212,11 +1212,6 @@ <artifactId>camel-jsch</artifactId> <version>4.9.0-SNAPSHOT</version> </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-jsh-dsl</artifactId> - <version>4.9.0-SNAPSHOT</version> - </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-jslt</artifactId> diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others.properties b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others.properties index 2460d2239ce..9e000195a09 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others.properties +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others.properties @@ -19,7 +19,6 @@ jasypt java-joor-dsl jfr js-dsl -jsh-dsl jta kamelet-main langchain4j-tokenizer diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others/jsh-dsl.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others/jsh-dsl.json deleted file mode 100644 index e0267935e30..00000000000 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others/jsh-dsl.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "other": { - "kind": "other", - "name": "jsh-dsl", - "title": "JavaShell DSL", - "description": "Camel DSL with JavaShell", - "deprecated": true, - "firstVersion": "3.15.0", - "label": "dsl", - "supportLevel": "Experimental", - "metadata": { "routes.language": "jsh" }, - "groupId": "org.apache.camel", - "artifactId": "camel-jsh-dsl", - "version": "4.9.0-SNAPSHOT" - } -} diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java index 1ec906b5540..ff5494d7c86 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java @@ -386,7 +386,7 @@ public final class ProcessorDefinitionHelper { node.setLocation(resource.getLocation()); String ext = FileUtil.onlyExt(resource.getLocation(), true); - if ("groovy".equals(ext) || "js".equals(ext) || "jsh".equals(ext)) { + if ("groovy".equals(ext) || "js".equals(ext)) { // we cannot get line number for groovy/java-script/java-shell return; } diff --git a/docs/components/modules/others/nav.adoc b/docs/components/modules/others/nav.adoc index 22da3dc7faa..a8928cbd20d 100644 --- a/docs/components/modules/others/nav.adoc +++ b/docs/components/modules/others/nav.adoc @@ -16,7 +16,6 @@ *** xref:groovy-dsl.adoc[Groovy DSL] *** xref:java-joor-dsl.adoc[Java DSL (runtime compiled)] *** xref:js-dsl.adoc[JavaScript DSL] -*** xref:jsh-dsl.adoc[JavaShell DSL] *** xref:java-xml-jaxb-dsl.adoc[Jaxb XML Dsl] *** xref:kamelet-main.adoc[Kamelet Main] *** xref:java-xml-io-dsl.adoc[XML Io Dsl] diff --git a/docs/components/modules/others/pages/jsh-dsl.adoc b/docs/components/modules/others/pages/jsh-dsl.adoc deleted file mode 120000 index 829109a436e..00000000000 --- a/docs/components/modules/others/pages/jsh-dsl.adoc +++ /dev/null @@ -1 +0,0 @@ -../../../../../dsl/camel-jsh-dsl/src/main/docs/jsh-dsl.adoc \ No newline at end of file diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_9.adoc b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_9.adoc index 669eabcddfc..f91717e3fe8 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_9.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_9.adoc @@ -98,6 +98,12 @@ via `@TestInstance(TestInstance.Lifecycle.PER_CLASS)`), as this is considered a future. The logs will print a warning message if this behavior is detected. +=== Removed deprecated components + +The following components has been removed + +- `camel-jsh-dsl` - This DSL was an experiment. The Camel team is only focusing on Java, XML and YAML DSL. + === Removed API ==== Kotlin DSL diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java index dfe8f508c79..a1f32bdf759 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java @@ -450,8 +450,6 @@ public abstract class ExportBaseCommand extends CamelCommand { answer.add("mvn:org.apache.camel:camel-groovy-dsl"); } else if ("js".equals(ext)) { answer.add("mvn:org.apache.camel:camel-js-dsl"); - } else if ("jsh".equals(ext)) { - answer.add("mvn:org.apache.camel:camel-jsh-dsl"); } else if ("xml".equals(ext)) { answer.add("mvn:org.apache.camel:camel-xml-io-dsl"); } else if ("yaml".equals(ext)) { diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/GistHelper.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/GistHelper.java index 1a63e3c3086..be79242041b 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/GistHelper.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/GistHelper.java @@ -104,7 +104,7 @@ public final class GistHelper { } else if (routes != null) { if ("java".equalsIgnoreCase(ext) || "xml".equalsIgnoreCase(ext) || "yaml".equalsIgnoreCase(ext) - || "groovy".equalsIgnoreCase(ext) || "js".equalsIgnoreCase(ext) || "jsh".equalsIgnoreCase(ext)) { + || "groovy".equalsIgnoreCase(ext) || "js".equalsIgnoreCase(ext)) { String rawUrl = c.get("raw_url").asText(); String u = asGistSingleUrl(rawUrl); routes.add(u); diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/GitHubHelper.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/GitHubHelper.java index faa897e36fc..be8f770770a 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/GitHubHelper.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/GitHubHelper.java @@ -128,8 +128,7 @@ public final class GitHubHelper { } else if (routes != null) { if ("java".equalsIgnoreCase(ext) || "xml".equalsIgnoreCase(ext) || "yaml".equalsIgnoreCase(ext) || "camel.yaml".equalsIgnoreCase(ext) - || "groovy".equalsIgnoreCase(ext) || "js".equalsIgnoreCase(ext) - || "jsh".equalsIgnoreCase(ext)) { + || "groovy".equalsIgnoreCase(ext) || "js".equalsIgnoreCase(ext)) { String htmlUrl = c.get("html_url").asText(); String u = asGithubSingleUrl(htmlUrl); routes.add(u); diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/ProcessHelper.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/ProcessHelper.java index 297d4a4d569..0ea3e1a5b13 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/ProcessHelper.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/ProcessHelper.java @@ -27,7 +27,7 @@ import org.apache.camel.util.json.JsonObject; public final class ProcessHelper { - private static final String[] DSL_EXT = new String[] { "groovy", "java", "js", "jsh", "xml", "yaml" }; + private static final String[] DSL_EXT = new String[] { "groovy", "java", "js", "xml", "yaml" }; private static final Pattern PATTERN = Pattern.compile("([\\w|\\-.])+"); private ProcessHelper() { diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/SourceHelper.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/SourceHelper.java index 79a02bed93c..c83b82ca3fe 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/SourceHelper.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/SourceHelper.java @@ -38,7 +38,7 @@ import org.apache.camel.util.IOHelper; public class SourceHelper { private static final String[] ACCEPTED_FILE_EXT - = new String[] { "java", "groovy", "js", "jsh", "xml", "yaml" }; + = new String[] { "java", "groovy", "js", "xml", "yaml" }; public static Source resolveSource(String source) { List<Source> resolved = resolveSources(Collections.singletonList(source)); diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/jsh.tmpl b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/jsh.tmpl deleted file mode 100644 index b5b1ee95c5e..00000000000 --- a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/jsh.tmpl +++ /dev/null @@ -1,4 +0,0 @@ -builder.from("timer:tick?period=1000") - .setBody() - .simple('Hello Camel from ${routeId}') - .log('${body}'); diff --git a/dsl/camel-jsh-dsl/pom.xml b/dsl/camel-jsh-dsl/pom.xml deleted file mode 100644 index 46fe415929e..00000000000 --- a/dsl/camel-jsh-dsl/pom.xml +++ /dev/null @@ -1,132 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - 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. - ---> -<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/maven-v4_0_0.xsd"> - - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.camel</groupId> - <artifactId>dsl</artifactId> - <version>4.9.0-SNAPSHOT</version> - </parent> - - <artifactId>camel-jsh-dsl</artifactId> - <packaging>jar</packaging> - <name>Camel :: JavaShell DSL (deprecated)</name> - <description>Camel DSL with JavaShell</description> - - <properties> - <firstVersion>3.15.0</firstVersion> - <title>JavaShell DSL</title> - <label>dsl</label> - <supportLevel>Experimental</supportLevel> - <sourcecheckExcludes> - **/resources/**/My*.java - </sourcecheckExcludes> - <sourcecheckExcludesComma> - ${sourcecheckExcludes}, - </sourcecheckExcludesComma> - <annotations> - routes.language=jsh - </annotations> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-endpointdsl-support</artifactId> - </dependency> - - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-main</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-direct</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-rest</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-mock</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-core-languages</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-bean</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-log</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-telegram</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-seda</artifactId> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.assertj</groupId> - <artifactId>assertj-core</artifactId> - <version>${assertj-version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-test-junit5</artifactId> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-slf4j2-impl</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-jcl</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - -</project> diff --git a/dsl/camel-jsh-dsl/src/generated/resources/META-INF/services/org/apache/camel/other.properties b/dsl/camel-jsh-dsl/src/generated/resources/META-INF/services/org/apache/camel/other.properties deleted file mode 100644 index e0c2c8f34d8..00000000000 --- a/dsl/camel-jsh-dsl/src/generated/resources/META-INF/services/org/apache/camel/other.properties +++ /dev/null @@ -1,8 +0,0 @@ -# Generated by camel build tools - do NOT edit this file! -name=jsh-dsl -groupId=org.apache.camel -artifactId=camel-jsh-dsl -version=4.9.0-SNAPSHOT -projectName=Camel :: JavaShell DSL (deprecated) -projectDescription=Camel DSL with JavaShell -annotations=routes.language=jsh diff --git a/dsl/camel-jsh-dsl/src/generated/resources/META-INF/services/org/apache/camel/routes-loader/jsh b/dsl/camel-jsh-dsl/src/generated/resources/META-INF/services/org/apache/camel/routes-loader/jsh deleted file mode 100644 index f8cf758092d..00000000000 --- a/dsl/camel-jsh-dsl/src/generated/resources/META-INF/services/org/apache/camel/routes-loader/jsh +++ /dev/null @@ -1,2 +0,0 @@ -# Generated by camel build tools - do NOT edit this file! -class=org.apache.camel.dsl.jsh.JshRoutesBuilderLoader diff --git a/dsl/camel-jsh-dsl/src/generated/resources/jsh-dsl.json b/dsl/camel-jsh-dsl/src/generated/resources/jsh-dsl.json deleted file mode 100644 index e0267935e30..00000000000 --- a/dsl/camel-jsh-dsl/src/generated/resources/jsh-dsl.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "other": { - "kind": "other", - "name": "jsh-dsl", - "title": "JavaShell DSL", - "description": "Camel DSL with JavaShell", - "deprecated": true, - "firstVersion": "3.15.0", - "label": "dsl", - "supportLevel": "Experimental", - "metadata": { "routes.language": "jsh" }, - "groupId": "org.apache.camel", - "artifactId": "camel-jsh-dsl", - "version": "4.9.0-SNAPSHOT" - } -} diff --git a/dsl/camel-jsh-dsl/src/main/docs/jsh-dsl.adoc b/dsl/camel-jsh-dsl/src/main/docs/jsh-dsl.adoc deleted file mode 100644 index 86a0ba901ca..00000000000 --- a/dsl/camel-jsh-dsl/src/main/docs/jsh-dsl.adoc +++ /dev/null @@ -1,54 +0,0 @@ -= JavaShell DSL Component (deprecated) -:doctitle: JavaShell DSL -:shortname: jsh-dsl -:artifactid: camel-jsh-dsl -:description: Camel DSL with JavaShell -:since: 3.15 -:supportlevel: Experimental-deprecated -:deprecated: *deprecated* -:tabs-sync-option: -//Manually maintained attributes -:group: DSL - -*Since Camel {since}* - -IMPORTANT: This DSL is deprecated and experimental support level and is not recommended being used for production. - -The `jsh-dsl` is used for runtime compiling JavaShell routes in an existing running Camel integration. -This was invented for Camel K and later ported to Apache Camel. - -This means that Camel will load the `.jsh` source during startup and use the JavaShell compiler to transform -this into Camel routes. - -== Example - -The following `example.js` source file: - -.example.jsh -[source,java] ----- -builder.from("timer:tick") - .setBody() - .constant("Hello Camel K!") - .to("log:info"); ----- - -Can then be loaded and run with Camel CLI or Camel K. - -.Running with Camel K - -[source,bash] ----- -kamel run example.jsh ----- - -.Running with Camel CLI - -[source,bash] ----- -camel run example.jsh ----- - -== See Also - -See xref:manual:ROOT:dsl.adoc[DSL] diff --git a/dsl/camel-jsh-dsl/src/main/java/org/apache/camel/dsl/jsh/Jsh.java b/dsl/camel-jsh-dsl/src/main/java/org/apache/camel/dsl/jsh/Jsh.java deleted file mode 100644 index 38bb67d4037..00000000000 --- a/dsl/camel-jsh-dsl/src/main/java/org/apache/camel/dsl/jsh/Jsh.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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.jsh; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import javax.script.ScriptException; - -import jdk.jshell.JShell; -import jdk.jshell.Snippet; -import jdk.jshell.SnippetEvent; -import jdk.jshell.SourceCodeAnalysis; -import jdk.jshell.spi.ExecutionControl; -import jdk.jshell.spi.ExecutionControlProvider; -import jdk.jshell.spi.ExecutionEnv; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Deprecated -public final class Jsh { - private static final Logger LOGGER = LoggerFactory.getLogger(Jsh.class); - private static final ThreadLocal<Map<String, Object>> BINDINGS = ThreadLocal.withInitial(ConcurrentHashMap::new); - - private Jsh() { - // no-op - } - - public static List<String> compile(JShell jshell, String script) throws ScriptException { - List<String> snippets = new ArrayList<>(); - - while (!script.isEmpty()) { - SourceCodeAnalysis.CompletionInfo ci = jshell.sourceCodeAnalysis().analyzeCompletion(script); - if (!ci.completeness().isComplete()) { - throw new ScriptException("Incomplete script:\n" + script); - } - - snippets.add(ci.source()); - script = ci.remaining(); - } - - return snippets; - } - - public static void setBinding(JShell jshell, String name, Object value) throws ScriptException { - ObjectHelper.notNull(jshell, "jshell"); - ObjectHelper.notNull(name, "name"); - ObjectHelper.notNull(value, "value"); - - setBinding(jshell, name, value, value.getClass()); - } - - public static <T> void setBinding(JShell jshell, String name, T value, Class<? extends T> type) throws ScriptException { - ObjectHelper.notNull(jshell, "jshell"); - ObjectHelper.notNull(name, "name"); - ObjectHelper.notNull(value, "value"); - ObjectHelper.notNull(type, "type"); - - setBinding(name, value); - - // As JShell leverages LocalExecutionControl as execution engine and thus JShell - // runs in the current process it is possible to access to local classes, we use - // such capability to inject bindings as variables. - String snippet = String.format( - "var %s = %s.getBinding(\"%s\", %s.class);", - name, - Jsh.class.getName(), - name, - type.getName()); - - eval(jshell, snippet); - } - - public static Object getBinding(String name) { - return BINDINGS.get().get(name); - } - - public static <T> T getBinding(String name, Class<T> type) { - Object answer = BINDINGS.get().get(name); - return answer != null ? type.cast(answer) : null; - } - - public static void setBinding(String name, Object value) { - BINDINGS.get().put(name, value); - } - - public static void clearBindings() { - BINDINGS.get().clear(); - } - - public static void eval(JShell jshell, String snippet) throws ScriptException { - LOGGER.debug("Evaluating {}", snippet); - - List<SnippetEvent> events = jshell.eval(snippet); - - for (SnippetEvent event : events) { - if (event.exception() != null) { - throw new ScriptException(event.exception()); - } - if (event.status() != Snippet.Status.VALID) { - throw new ScriptException("Error evaluating snippet:\n" + event.snippet().source()); - } - } - } - - public static ExecutionControlProvider wrapExecutionControl(String name, ExecutionControl delegate) { - return new ExecutionControlProvider() { - @Override - public String name() { - return name; - } - - @Override - public ExecutionControl generate(ExecutionEnv env, Map<String, String> parameters) throws Throwable { - return delegate; - } - }; - } -} diff --git a/dsl/camel-jsh-dsl/src/main/java/org/apache/camel/dsl/jsh/JshClassLoader.java b/dsl/camel-jsh-dsl/src/main/java/org/apache/camel/dsl/jsh/JshClassLoader.java deleted file mode 100644 index 089fd786a21..00000000000 --- a/dsl/camel-jsh-dsl/src/main/java/org/apache/camel/dsl/jsh/JshClassLoader.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.jsh; - -import java.util.HashMap; -import java.util.Map; - -import jdk.jshell.spi.ExecutionControl; - -/** - * An implementation of a {@link ClassLoader} that allow hold class bytecode. - */ -@Deprecated -final class JshClassLoader extends ClassLoader { - private final Map<String, ExecutionControl.ClassBytecodes> types; - - JshClassLoader(ClassLoader parent) { - super(parent); - this.types = new HashMap<>(); - } - - void addClassBytecodes(ExecutionControl.ClassBytecodes classBytecodes) { - types.put(toResourceString(classBytecodes.name()), classBytecodes); - } - - @Override - protected Class<?> findClass(String name) throws ClassNotFoundException { - final String key = toResourceString(name); - final ExecutionControl.ClassBytecodes cb = types.get(key); - - return cb == null - ? super.findClass(name) - : super.defineClass(name, cb.bytecodes(), 0, cb.bytecodes().length); - } - - private static String toResourceString(String name) { - return name.replace('.', '/') + ".class"; - } -} diff --git a/dsl/camel-jsh-dsl/src/main/java/org/apache/camel/dsl/jsh/JshLoaderDelegate.java b/dsl/camel-jsh-dsl/src/main/java/org/apache/camel/dsl/jsh/JshLoaderDelegate.java deleted file mode 100644 index 972ccf3aeb3..00000000000 --- a/dsl/camel-jsh-dsl/src/main/java/org/apache/camel/dsl/jsh/JshLoaderDelegate.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.jsh; - -import java.util.HashMap; -import java.util.Map; - -import jdk.jshell.execution.LoaderDelegate; -import jdk.jshell.spi.ExecutionControl; - -/** - * A simple implementation of {@link LoaderDelegate} tailored for camel-k use case. - */ -@Deprecated -final class JshLoaderDelegate implements LoaderDelegate { - private final JshClassLoader loader; - private final Map<String, Class<?>> types; - - public JshLoaderDelegate(JshClassLoader loader) { - this.loader = loader; - this.types = new HashMap<>(); - } - - @SuppressWarnings("PMD.PreserveStackTrace") - @Override - public void load(ExecutionControl.ClassBytecodes[] cbs) - throws ExecutionControl.ClassInstallException, ExecutionControl.EngineTerminationException { - - boolean[] loaded = new boolean[cbs.length]; - try { - for (ExecutionControl.ClassBytecodes cb : cbs) { - loader.addClassBytecodes(cb); - } - for (int i = 0; i < cbs.length; ++i) { - Class<?> type = loader.loadClass(cbs[i].name()); - type.getDeclaredMethods(); - - types.put(cbs[i].name(), type); - - loaded[i] = true; - } - } catch (Exception ex) { - throw new ExecutionControl.ClassInstallException("load: " + ex.getMessage(), loaded); - } - } - - @Override - public void classesRedefined(ExecutionControl.ClassBytecodes[] cbcs) { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public void addToClasspath(String cp) { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public Class<?> findClass(String name) throws ClassNotFoundException { - Class<?> type = types.get(name); - if (type != null) { - return type; - } - - throw new ClassNotFoundException(name + " not found"); - } -} diff --git a/dsl/camel-jsh-dsl/src/main/java/org/apache/camel/dsl/jsh/JshRoutesBuilderLoader.java b/dsl/camel-jsh-dsl/src/main/java/org/apache/camel/dsl/jsh/JshRoutesBuilderLoader.java deleted file mode 100644 index c3df4c82763..00000000000 --- a/dsl/camel-jsh-dsl/src/main/java/org/apache/camel/dsl/jsh/JshRoutesBuilderLoader.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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.jsh; - -import java.io.Reader; - -import javax.script.ScriptException; - -import jdk.jshell.JShell; -import jdk.jshell.execution.DirectExecutionControl; -import jdk.jshell.execution.LoaderDelegate; -import jdk.jshell.spi.ExecutionControl; -import jdk.jshell.spi.ExecutionControlProvider; -import org.apache.camel.CamelContext; -import org.apache.camel.Experimental; -import org.apache.camel.RoutesBuilder; -import org.apache.camel.api.management.ManagedAttribute; -import org.apache.camel.api.management.ManagedResource; -import org.apache.camel.builder.endpoint.EndpointRouteBuilder; -import org.apache.camel.spi.Registry; -import org.apache.camel.spi.Resource; -import org.apache.camel.spi.RoutesBuilderLoader; -import org.apache.camel.spi.annotations.RoutesLoader; -import org.apache.camel.support.RoutesBuilderLoaderSupport; -import org.apache.camel.util.IOHelper; - -/** - * A {@link RoutesBuilderLoader} implementation based on {@link JShell}. - */ -@ManagedResource(description = "Managed JShell RoutesBuilderLoader") -@Experimental -@RoutesLoader("jsh") -@Deprecated -public class JshRoutesBuilderLoader extends RoutesBuilderLoaderSupport { - public static final String EXTENSION = "jsh"; - - @ManagedAttribute(description = "Supported file extension") - @Override - public String getSupportedExtension() { - return EXTENSION; - } - - @Override - public RoutesBuilder loadRoutesBuilder(Resource resource) throws Exception { - return EndpointRouteBuilder.loadEndpointRoutesBuilder(resource, JshRoutesBuilderLoader::eval); - } - - private static void eval(Reader reader, EndpointRouteBuilder builder) throws Exception { - final ClassLoader tccl = Thread.currentThread().getContextClassLoader(); - final String content = IOHelper.toString(reader); - - // - // By default the jdk.jshell.execution.DefaultLoaderDelegate uses a - // custom URL class-loader and does not provide any option to set the - // parent which causes the ThreadLocal hack used to inject bindings - // to fail as there are two copies of the JSH class (one from the - // Quarkus class loader and one for the custom one). - // - final JshClassLoader jshcl = new JshClassLoader(tccl); - final LoaderDelegate delegate = new JshLoaderDelegate(jshcl); - final ExecutionControl control = new DirectExecutionControl(delegate); - final ExecutionControlProvider provider = Jsh.wrapExecutionControl("jsh-direct", control); - - Thread.currentThread().setContextClassLoader(jshcl); - - // - // Leverage DirectExecutionControl as execution engine to make JShell running - // in the current process and give a chance to bind variables to the script - // using ThreadLocal hack. - // - try (JShell jshell = JShell.builder().executionEngine(provider, null).build()) { - // - // since we can't set a base class for the snippet as we do for other - // languages (groovy) we need to introduce a top level variable - // that users need to use to access the RouteBuilder, like: - // - // builder.from("timer:tick") - // .to("log:info") - // - // context and thus registry can easily be retrieved from the registered - // variable `builder` but for a better UX, add them as top level vars. - // - Jsh.setBinding(jshell, "builder", builder, EndpointRouteBuilder.class); - Jsh.setBinding(jshell, "context", builder.getContext(), CamelContext.class); - Jsh.setBinding(jshell, "registry", builder.getContext().getRegistry(), Registry.class); - - for (String snippet : Jsh.compile(jshell, content)) { - Jsh.eval(jshell, snippet); - } - } catch (ScriptException e) { - throw new RuntimeException(e); - } finally { - // remove contextual bindings once the snippet has been evaluated - Jsh.clearBindings(); - // restore original TCCL - Thread.currentThread().setContextClassLoader(tccl); - } - } -} diff --git a/dsl/camel-jsh-dsl/src/test/java/org/apache/camel/dsl/jsh/JshSourceLoaderTest.java b/dsl/camel-jsh-dsl/src/test/java/org/apache/camel/dsl/jsh/JshSourceLoaderTest.java deleted file mode 100644 index 5f6d74bb94a..00000000000 --- a/dsl/camel-jsh-dsl/src/test/java/org/apache/camel/dsl/jsh/JshSourceLoaderTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.jsh; - -import java.util.Collection; - -import org.apache.camel.RoutesBuilder; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.impl.DefaultCamelContext; -import org.apache.camel.model.ProcessorDefinition; -import org.apache.camel.model.ToDefinition; -import org.apache.camel.spi.Resource; -import org.apache.camel.support.PluginHelper; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - -import static org.assertj.core.api.Assertions.assertThat; - -public class JshSourceLoaderTest { - - @ParameterizedTest - @ValueSource(strings = { - "/routes/MyRoute.jsh" - }) - void testLoadRoutes(String location) throws Exception { - try (DefaultCamelContext context = new DefaultCamelContext()) { - Resource resource = PluginHelper.getResourceLoader(context).resolveResource(location); - Collection<RoutesBuilder> builders = PluginHelper.getRoutesLoader(context).findRoutesBuilders(resource); - - assertThat(builders).hasSize(1); - - RouteBuilder builder = (RouteBuilder) builders.iterator().next(); - builder.setCamelContext(context); - builder.configure(); - - Assertions.assertThat(builder.getRouteCollection().getRoutes()) - .hasSize(1) - .first() - .satisfies(rd -> { - Assertions.assertThat(rd.getInput().getEndpointUri()).matches("timer:.*tick"); - Assertions.assertThat(rd.getOutputs().get(0)).isInstanceOf(ProcessorDefinition.class); - Assertions.assertThat(rd.getOutputs().get(1)).isInstanceOf(ToDefinition.class); - }); - } - } -} diff --git a/dsl/camel-jsh-dsl/src/test/resources/log4j2-test.properties b/dsl/camel-jsh-dsl/src/test/resources/log4j2-test.properties deleted file mode 100644 index 55f5c41ab59..00000000000 --- a/dsl/camel-jsh-dsl/src/test/resources/log4j2-test.properties +++ /dev/null @@ -1,31 +0,0 @@ -## --------------------------------------------------------------------------- -## 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. -## --------------------------------------------------------------------------- - -appender.file.type = File -appender.file.name = file -appender.file.fileName = target/camel-jsh-dsl-test.log -appender.file.layout.type = PatternLayout -appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n - -appender.out.type = Console -appender.out.name = out -appender.out.layout.type = PatternLayout -appender.out.layout.pattern = [%30.30t] %-30.30c{1} %-5p %m%n - -rootLogger.level = INFO -rootLogger.appenderRef.file.ref = file -#rootLogger.appenderRef.out.ref = out diff --git a/dsl/camel-jsh-dsl/src/test/resources/routes/MyRoute.jsh b/dsl/camel-jsh-dsl/src/test/resources/routes/MyRoute.jsh deleted file mode 100644 index 99bfe4f50dd..00000000000 --- a/dsl/camel-jsh-dsl/src/test/resources/routes/MyRoute.jsh +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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. - */ - -builder.from("timer:tick") - .process(e -> {}) - .to("log:info"); \ No newline at end of file diff --git a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderRoutesLoader.java b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderRoutesLoader.java index f6745bc9d0c..9272fe3eee1 100644 --- a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderRoutesLoader.java +++ b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderRoutesLoader.java @@ -66,8 +66,6 @@ public class DependencyDownloaderRoutesLoader extends DefaultRoutesLoader { downloadLoader("camel-endpointdsl"); } else if ("js".equals(extension)) { downloadLoader("camel-js-dsl"); - } else if ("jsh".equals(extension)) { - downloadLoader("camel-jsh-dsl"); } else if ("xml".equals(extension) || "camel.xml".equals(extension)) { downloadLoader("camel-xml-io-dsl"); diff --git a/dsl/pom.xml b/dsl/pom.xml index 354217d1cc0..5cb6e938494 100644 --- a/dsl/pom.xml +++ b/dsl/pom.xml @@ -52,7 +52,6 @@ <module>camel-xml-jaxb-dsl-test</module> <module>camel-yaml-dsl</module> <module>camel-js-dsl</module> - <module>camel-jsh-dsl</module> <module>camel-kamelet-main</module> <module>camel-jbang</module> </modules> diff --git a/parent/pom.xml b/parent/pom.xml index 452648682ae..567d355ddd7 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -2698,11 +2698,6 @@ <artifactId>camel-js-dsl</artifactId> <version>${project.version}</version> </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-jsh-dsl</artifactId> - <version>${project.version}</version> - </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-kamelet-main</artifactId>
