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 f716b02 CAMEL-16585: camel-kamelet - Main class to easily bootstrap
Camel with Kamelets
f716b02 is described below
commit f716b0277d49c6b79ac7a0404458354ceccf36f4
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri May 21 17:12:31 2021 +0200
CAMEL-16585: camel-kamelet - Main class to easily bootstrap Camel with
Kamelets
---
bom/camel-bom/pom.xml | 5 +
.../org/apache/camel/catalog/docs.properties | 1 +
.../apache/camel/catalog/docs/kamelet-main.adoc | 12 ++
.../org/apache/camel/catalog/others.properties | 1 +
.../apache/camel/catalog/others/kamelet-main.json | 14 ++
components/camel-kamelet-main/pom.xml | 63 +++++++++
.../services/org/apache/camel/other.properties | 7 +
.../src/generated/resources/kamelet-main.json | 14 ++
.../src/main/docs/kamelet-main.adoc | 25 ++++
.../java/org/apache/camel/main/KameletMain.java | 146 +++++++++++++++++++++
core/camel-allcomponents/pom.xml | 4 +
docs/components/modules/others/nav.adoc | 1 +
.../modules/others/pages/kamelet-main.adoc | 14 ++
parent/pom.xml | 5 +
14 files changed, 312 insertions(+)
diff --git a/bom/camel-bom/pom.xml b/bom/camel-bom/pom.xml
index c2a1927..d628467 100644
--- a/bom/camel-bom/pom.xml
+++ b/bom/camel-bom/pom.xml
@@ -1169,6 +1169,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-kamelet-main</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-kamelet-reify</artifactId>
<version>${project.version}</version>
</dependency>
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs.properties
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs.properties
index 8477780..ffd4ec8 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs.properties
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs.properties
@@ -271,6 +271,7 @@ jta
kafka-component
kamelet-component
kamelet-eip
+kamelet-main
kamelet-reify-component
kubernetes-config-maps-component
kubernetes-custom-resources-component
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kamelet-main.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kamelet-main.adoc
new file mode 100644
index 0000000..24c1ab9
--- /dev/null
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kamelet-main.adoc
@@ -0,0 +1,12 @@
+[[kamelet-main-other]]
+= Kamelet Main Component
+:docTitle: Kamelet Main
+:artifactId: camel-kamelet-main
+:description: Main to run Kamelet standalone
+:since: 3.11
+:supportLevel: Preview
+include::{cq-version}@camel-quarkus:ROOT:partial$reference/others/kamelet-main.adoc[opts=optional]
+
+*Since Camel {since}*
+
+A `main` class that is opinionated to boostrap and run Camel standalone with
Kameleets for development and demo purposes.
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 128d3a1..d3a6df5 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
@@ -11,6 +11,7 @@ hystrix
jasypt
jfr
jta
+kamelet-main
leveldb
leveldb-legacy
lra
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others/kamelet-main.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others/kamelet-main.json
new file mode 100644
index 0000000..c5d3e34
--- /dev/null
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others/kamelet-main.json
@@ -0,0 +1,14 @@
+{
+ "other": {
+ "kind": "other",
+ "name": "kamelet-main",
+ "title": "Kamelet Main",
+ "description": "Main to run Kamelet standalone",
+ "deprecated": false,
+ "firstVersion": "3.11.0",
+ "supportLevel": "Preview",
+ "groupId": "org.apache.camel",
+ "artifactId": "camel-kamelet-main",
+ "version": "3.11.0-SNAPSHOT"
+ }
+}
diff --git a/components/camel-kamelet-main/pom.xml
b/components/camel-kamelet-main/pom.xml
new file mode 100644
index 0000000..1cdb924
--- /dev/null
+++ b/components/camel-kamelet-main/pom.xml
@@ -0,0 +1,63 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>3.11.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-kamelet-main</artifactId>
+ <packaging>jar</packaging>
+
+ <name>Camel :: Kamelet Main</name>
+ <description>Main to run Kamelet standalone</description>
+
+ <properties>
+ <firstVersion>3.11.0</firstVersion>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-main</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-kamelet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-bean</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-yaml-dsl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-resourceresolver-github</artifactId>
+ </dependency>
+
+ </dependencies>
+
+</project>
diff --git
a/components/camel-kamelet-main/src/generated/resources/META-INF/services/org/apache/camel/other.properties
b/components/camel-kamelet-main/src/generated/resources/META-INF/services/org/apache/camel/other.properties
new file mode 100644
index 0000000..c7f9e9d
--- /dev/null
+++
b/components/camel-kamelet-main/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=kamelet-main
+groupId=org.apache.camel
+artifactId=camel-kamelet-main
+version=3.11.0-SNAPSHOT
+projectName=Camel :: Kamelet Main
+projectDescription=Main to run Kamelet standalone
diff --git
a/components/camel-kamelet-main/src/generated/resources/kamelet-main.json
b/components/camel-kamelet-main/src/generated/resources/kamelet-main.json
new file mode 100644
index 0000000..c5d3e34
--- /dev/null
+++ b/components/camel-kamelet-main/src/generated/resources/kamelet-main.json
@@ -0,0 +1,14 @@
+{
+ "other": {
+ "kind": "other",
+ "name": "kamelet-main",
+ "title": "Kamelet Main",
+ "description": "Main to run Kamelet standalone",
+ "deprecated": false,
+ "firstVersion": "3.11.0",
+ "supportLevel": "Preview",
+ "groupId": "org.apache.camel",
+ "artifactId": "camel-kamelet-main",
+ "version": "3.11.0-SNAPSHOT"
+ }
+}
diff --git a/components/camel-kamelet-main/src/main/docs/kamelet-main.adoc
b/components/camel-kamelet-main/src/main/docs/kamelet-main.adoc
new file mode 100644
index 0000000..2120967
--- /dev/null
+++ b/components/camel-kamelet-main/src/main/docs/kamelet-main.adoc
@@ -0,0 +1,25 @@
+[[kamelet-main-other]]
+= Kamelet Main Component
+:docTitle: Kamelet Main
+:artifactId: camel-kamelet-main
+:description: Main to run Kamelet standalone
+:since: 3.11
+:supportLevel: Preview
+include::{cq-version}@camel-quarkus:ROOT:partial$reference/others/kamelet-main.adoc[opts=optional]
+
+*Since Camel {since}*
+
+A `main` class that is opinionated to boostrap and run Camel standalone with
Kameleets for development and demo purposes.
+
+== Initial configuration
+
+The `KameletMain` is pre-configured with the following properties:
+
+[source,properties]
+----
+camel.component.kamelet.location =
classpath:/kamelets,github:apache:camel-kamelets
+camel.main.routes-include-pattern = classpath:camel/*
+camel.main.lightweight = true
+----
+
+These settings can be overridden by configuration in `application.properties`.
\ No newline at end of file
diff --git
a/components/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
b/components/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
new file mode 100644
index 0000000..eece4d2
--- /dev/null
+++
b/components/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
@@ -0,0 +1,146 @@
+/*
+ * 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.main;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.spi.Registry;
+
+/**
+ * A Main class for booting up Camel with Kamelet in standalone mode.
+ */
+public class KameletMain extends MainCommandLineSupport {
+
+ protected static KameletMain instance;
+ protected final MainRegistry registry = new MainRegistry();
+
+ public static void main(String... args) throws Exception {
+ KameletMain main = new KameletMain();
+ instance = main;
+ int code = main.run(args);
+ if (code != 0) {
+ System.exit(code);
+ }
+ // normal exit
+ }
+
+ /**
+ * Returns the currently executing main
+ *
+ * @return the current running instance
+ */
+ public static KameletMain getInstance() {
+ return instance;
+ }
+
+ /**
+ * Binds the given <code>name</code> to the <code>bean</code> object, so
that it can be looked up inside the
+ * CamelContext this command line tool runs with.
+ *
+ * @param name the used name through which we do bind
+ * @param bean the object to bind
+ */
+ public void bind(String name, Object bean) {
+ registry.bind(name, bean);
+ }
+
+ /**
+ * Using the given <code>name</code> does lookup for the bean being
already bound using the
+ * {@link #bind(String, Object)} method.
+ *
+ * @see Registry#lookupByName(String)
+ */
+ public Object lookup(String name) {
+ return registry.lookupByName(name);
+ }
+
+ /**
+ * Using the given <code>name</code> and <code>type</code> does lookup for
the bean being already bound using the
+ * {@link #bind(String, Object)} method.
+ *
+ * @see Registry#lookupByNameAndType(String, Class)
+ */
+ public <T> T lookup(String name, Class<T> type) {
+ return registry.lookupByNameAndType(name, type);
+ }
+
+ /**
+ * Using the given <code>type</code> does lookup for the bean being
already bound using the
+ * {@link #bind(String, Object)} method.
+ *
+ * @see Registry#findByTypeWithName(Class)
+ */
+ public <T> Map<String, T> lookupByType(Class<T> type) {
+ return registry.findByTypeWithName(type);
+ }
+
+ // Implementation methods
+ //
-------------------------------------------------------------------------
+
+ @Override
+ protected void doInit() throws Exception {
+ super.doInit();
+ initCamelContext();
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ if (getCamelContext() != null) {
+ try {
+ // if we were veto started then mark as completed
+ getCamelContext().start();
+ } finally {
+ if (getCamelContext().isVetoStarted()) {
+ completed();
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ super.doStop();
+ if (getCamelContext() != null) {
+ getCamelContext().stop();
+ }
+ }
+
+ @Override
+ protected ProducerTemplate findOrCreateCamelTemplate() {
+ if (getCamelContext() != null) {
+ return getCamelContext().createProducerTemplate();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ protected CamelContext createCamelContext() {
+ // do not build/init camel context yet
+ DefaultCamelContext answer = new DefaultCamelContext(false);
+ answer.setRegistry(registry);
+ instance.addInitialProperty("camel.component.kamelet.location",
"classpath:/kamelets,github:apache:camel-kamelets");
+ instance.addInitialProperty("camel.main.routes-include-pattern",
"classpath:camel/*");
+ instance.addInitialProperty("camel.main.lightweight", "true");
+ return answer;
+ }
+
+}
diff --git a/core/camel-allcomponents/pom.xml b/core/camel-allcomponents/pom.xml
index f8bdfba..287b971 100644
--- a/core/camel-allcomponents/pom.xml
+++ b/core/camel-allcomponents/pom.xml
@@ -799,6 +799,10 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-kamelet-main</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-kamelet-reify</artifactId>
</dependency>
<dependency>
diff --git a/docs/components/modules/others/nav.adoc
b/docs/components/modules/others/nav.adoc
index 4e956a8..0f420a8 100644
--- a/docs/components/modules/others/nav.adoc
+++ b/docs/components/modules/others/nav.adoc
@@ -15,6 +15,7 @@
** xref:jasypt.adoc[Jasypt]
** xref:jfr.adoc[Jfr]
** xref:jta.adoc[JTA]
+** xref:kamelet-main.adoc[Kamelet Main]
** xref:leveldb.adoc[LevelDB]
** xref:leveldb-legacy.adoc[LevelDB-legacy]
** xref:lra.adoc[LRA]
diff --git a/docs/components/modules/others/pages/kamelet-main.adoc
b/docs/components/modules/others/pages/kamelet-main.adoc
new file mode 100644
index 0000000..06aa14d
--- /dev/null
+++ b/docs/components/modules/others/pages/kamelet-main.adoc
@@ -0,0 +1,14 @@
+[[kamelet-main-other]]
+= Kamelet Main Component
+//THIS FILE IS COPIED: EDIT THE SOURCE FILE:
+:page-source: components/camel-kamelet-main/src/main/docs/kamelet-main.adoc
+:docTitle: Kamelet Main
+:artifactId: camel-kamelet-main
+:description: Main to run Kamelet standalone
+:since: 3.11
+:supportLevel: Preview
+include::{cq-version}@camel-quarkus:ROOT:partial$reference/others/kamelet-main.adoc[opts=optional]
+
+*Since Camel {since}*
+
+A `main` class that is opinionated to boostrap and run Camel standalone with
Kameleets for development and demo purposes.
diff --git a/parent/pom.xml b/parent/pom.xml
index 030fb7d..0be7baa 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1776,6 +1776,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-kamelet-main</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-kamelet-reify</artifactId>
<version>${project.version}</version>
</dependency>