This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch camel-main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/camel-main by this push:
new 6adfc3adea Add cli-connector support for Camel JBang runtime=quarkus
6adfc3adea is described below
commit 6adfc3adeaf94a6695dd63497843563707aa4100
Author: James Netherton <[email protected]>
AuthorDate: Wed May 1 14:30:03 2024 +0100
Add cli-connector support for Camel JBang runtime=quarkus
---
.../pages/reference/extensions/cli-connector.adoc | 19 ++++++++++
extensions-jvm/cli-connector/deployment/pom.xml | 6 +++
.../deployment/CliConnectorProcessor.java | 25 ++++++++++++
.../deployment/CliConnectorDisabledTest.java | 43 +++++++++++++++++++++
.../deployment/CliConnectorEnabledTest.java | 44 ++++++++++++++++++++++
.../cli/connector/CamelCliConnectorConfig.java | 30 +++++++++++++++
.../cli/connector/CamelCliConnectorRecorder.java | 32 ++++++++++++++++
.../cli/connector/QuarkusCliConnectorFactory.java | 27 +++++++++++++
.../cli/connector/QuarkusLocalCliConnector.java | 38 +++++++++++++++++++
9 files changed, 264 insertions(+)
diff --git a/docs/modules/ROOT/pages/reference/extensions/cli-connector.adoc
b/docs/modules/ROOT/pages/reference/extensions/cli-connector.adoc
index 536be15ea0..61c3634c42 100644
--- a/docs/modules/ROOT/pages/reference/extensions/cli-connector.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/cli-connector.adoc
@@ -39,3 +39,22 @@ Please refer to the above link for usage and configuration
details.
ifeval::[{doc-show-user-guide-link} == true]
Check the xref:user-guide/index.adoc[User guide] for more information about
writing Camel Quarkus applications.
endif::[]
+
+[id="extensions-cli-connector-additional-camel-quarkus-configuration"]
+== Additional Camel Quarkus configuration
+
+[width="100%",cols="80,5,15",options="header"]
+|===
+| Configuration property | Type | Default
+
+
+|icon:lock[title=Fixed at build time]
[[quarkus.camel.cli.enabled]]`link:#quarkus.camel.cli.enabled[quarkus.camel.cli.enabled]`
+
+Sets whether to enable Camel CLI Connector support.
+| `boolean`
+| `true`
+|===
+
+[.configuration-legend]
+{doc-link-icon-lock}[title=Fixed at build time] Configuration property fixed
at build time. All other configuration properties are overridable at runtime.
+
diff --git a/extensions-jvm/cli-connector/deployment/pom.xml
b/extensions-jvm/cli-connector/deployment/pom.xml
index 37c9ba9e97..dfb39cb1eb 100644
--- a/extensions-jvm/cli-connector/deployment/pom.xml
+++ b/extensions-jvm/cli-connector/deployment/pom.xml
@@ -46,6 +46,12 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-cli-connector</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-junit5-internal</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git
a/extensions-jvm/cli-connector/deployment/src/main/java/org/apache/camel/quarkus/component/cli/connector/deployment/CliConnectorProcessor.java
b/extensions-jvm/cli-connector/deployment/src/main/java/org/apache/camel/quarkus/component/cli/connector/deployment/CliConnectorProcessor.java
index 0edcf224df..dcad85e99d 100644
---
a/extensions-jvm/cli-connector/deployment/src/main/java/org/apache/camel/quarkus/component/cli/connector/deployment/CliConnectorProcessor.java
+++
b/extensions-jvm/cli-connector/deployment/src/main/java/org/apache/camel/quarkus/component/cli/connector/deployment/CliConnectorProcessor.java
@@ -16,14 +16,23 @@
*/
package org.apache.camel.quarkus.component.cli.connector.deployment;
+import java.util.function.BooleanSupplier;
+
+import io.quarkus.builder.Version;
import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.annotations.BuildSteps;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;
+import
org.apache.camel.quarkus.component.cli.connector.CamelCliConnectorConfig;
+import
org.apache.camel.quarkus.component.cli.connector.CamelCliConnectorRecorder;
import org.apache.camel.quarkus.core.JvmOnlyRecorder;
+import org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem;
+import org.apache.camel.spi.CliConnectorFactory;
import org.jboss.logging.Logger;
+@BuildSteps(onlyIf = CliConnectorProcessor.CliConnectorEnabled.class)
class CliConnectorProcessor {
private static final Logger LOG =
Logger.getLogger(CliConnectorProcessor.class);
@@ -34,6 +43,14 @@ class CliConnectorProcessor {
return new FeatureBuildItem(FEATURE);
}
+ @BuildStep
+ @Record(value = ExecutionTime.STATIC_INIT)
+ CamelBeanBuildItem camelBeanBuildItem(CamelCliConnectorRecorder recorder) {
+ return new CamelBeanBuildItem("quarkusCliConnectorFactory",
+ CliConnectorFactory.class.getName(),
+ recorder.createCliConnectorFactory(Version.getVersion()));
+ }
+
/**
* Remove this once this extension starts supporting the native mode.
*/
@@ -43,4 +60,12 @@ class CliConnectorProcessor {
JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time
recorder.warnJvmInNative(FEATURE); // warn at runtime
}
+
+ static class CliConnectorEnabled implements BooleanSupplier {
+ CamelCliConnectorConfig config;
+
+ public boolean getAsBoolean() {
+ return config.enabled;
+ }
+ }
}
diff --git
a/extensions-jvm/cli-connector/deployment/src/test/java/org/apache/camel/quarkus/component/cli/connector/deployment/CliConnectorDisabledTest.java
b/extensions-jvm/cli-connector/deployment/src/test/java/org/apache/camel/quarkus/component/cli/connector/deployment/CliConnectorDisabledTest.java
new file mode 100644
index 0000000000..408882b394
--- /dev/null
+++
b/extensions-jvm/cli-connector/deployment/src/test/java/org/apache/camel/quarkus/component/cli/connector/deployment/CliConnectorDisabledTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.quarkus.component.cli.connector.deployment;
+
+import io.quarkus.test.QuarkusUnitTest;
+import jakarta.inject.Inject;
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.CliConnectorFactory;
+import org.apache.camel.support.CamelContextHelper;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class CliConnectorDisabledTest {
+ @RegisterExtension
+ static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+ .overrideConfigKey("quarkus.camel.cli.enabled", "false")
+ .withEmptyApplication();
+
+ @Inject
+ CamelContext context;
+
+ @Test
+ void cliConnectorDisabled() {
+ CliConnectorFactory factory =
CamelContextHelper.findSingleByType(context, CliConnectorFactory.class);
+ assertNull(factory);
+ }
+}
diff --git
a/extensions-jvm/cli-connector/deployment/src/test/java/org/apache/camel/quarkus/component/cli/connector/deployment/CliConnectorEnabledTest.java
b/extensions-jvm/cli-connector/deployment/src/test/java/org/apache/camel/quarkus/component/cli/connector/deployment/CliConnectorEnabledTest.java
new file mode 100644
index 0000000000..3760435e28
--- /dev/null
+++
b/extensions-jvm/cli-connector/deployment/src/test/java/org/apache/camel/quarkus/component/cli/connector/deployment/CliConnectorEnabledTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.quarkus.component.cli.connector.deployment;
+
+import io.quarkus.test.QuarkusUnitTest;
+import jakarta.inject.Inject;
+import org.apache.camel.CamelContext;
+import
org.apache.camel.quarkus.component.cli.connector.QuarkusCliConnectorFactory;
+import org.apache.camel.spi.CliConnectorFactory;
+import org.apache.camel.support.CamelContextHelper;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class CliConnectorEnabledTest {
+ @RegisterExtension
+ static final QuarkusUnitTest CONFIG = new
QuarkusUnitTest().withEmptyApplication();
+
+ @Inject
+ CamelContext context;
+
+ @Test
+ void cliConnectorEnabled() {
+ CliConnectorFactory factory =
CamelContextHelper.findSingleByType(context, CliConnectorFactory.class);
+ assertNotNull(factory);
+ assertInstanceOf(QuarkusCliConnectorFactory.class, factory);
+ }
+}
diff --git
a/extensions-jvm/cli-connector/runtime/src/main/java/org/apache/camel/quarkus/component/cli/connector/CamelCliConnectorConfig.java
b/extensions-jvm/cli-connector/runtime/src/main/java/org/apache/camel/quarkus/component/cli/connector/CamelCliConnectorConfig.java
new file mode 100644
index 0000000000..78ca502e79
--- /dev/null
+++
b/extensions-jvm/cli-connector/runtime/src/main/java/org/apache/camel/quarkus/component/cli/connector/CamelCliConnectorConfig.java
@@ -0,0 +1,30 @@
+/*
+ * 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.quarkus.component.cli.connector;
+
+import io.quarkus.runtime.annotations.ConfigItem;
+import io.quarkus.runtime.annotations.ConfigPhase;
+import io.quarkus.runtime.annotations.ConfigRoot;
+
+@ConfigRoot(name = "camel.cli", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
+public class CamelCliConnectorConfig {
+ /**
+ * Sets whether to enable Camel CLI Connector support.
+ */
+ @ConfigItem(defaultValue = "true")
+ public boolean enabled;
+}
diff --git
a/extensions-jvm/cli-connector/runtime/src/main/java/org/apache/camel/quarkus/component/cli/connector/CamelCliConnectorRecorder.java
b/extensions-jvm/cli-connector/runtime/src/main/java/org/apache/camel/quarkus/component/cli/connector/CamelCliConnectorRecorder.java
new file mode 100644
index 0000000000..3e3225e8c3
--- /dev/null
+++
b/extensions-jvm/cli-connector/runtime/src/main/java/org/apache/camel/quarkus/component/cli/connector/CamelCliConnectorRecorder.java
@@ -0,0 +1,32 @@
+/*
+ * 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.quarkus.component.cli.connector;
+
+import io.quarkus.runtime.RuntimeValue;
+import io.quarkus.runtime.annotations.Recorder;
+import org.apache.camel.spi.CliConnectorFactory;
+
+@Recorder
+public class CamelCliConnectorRecorder {
+ public RuntimeValue<CliConnectorFactory> createCliConnectorFactory(String
version) {
+ QuarkusCliConnectorFactory factory = new QuarkusCliConnectorFactory();
+ factory.setEnabled(true);
+ factory.setRuntime("Quarkus");
+ factory.setRuntimeVersion(version);
+ return new RuntimeValue<>(factory);
+ }
+}
diff --git
a/extensions-jvm/cli-connector/runtime/src/main/java/org/apache/camel/quarkus/component/cli/connector/QuarkusCliConnectorFactory.java
b/extensions-jvm/cli-connector/runtime/src/main/java/org/apache/camel/quarkus/component/cli/connector/QuarkusCliConnectorFactory.java
new file mode 100644
index 0000000000..90aa4481a6
--- /dev/null
+++
b/extensions-jvm/cli-connector/runtime/src/main/java/org/apache/camel/quarkus/component/cli/connector/QuarkusCliConnectorFactory.java
@@ -0,0 +1,27 @@
+/*
+ * 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.quarkus.component.cli.connector;
+
+import org.apache.camel.cli.connector.DefaultCliConnectorFactory;
+import org.apache.camel.spi.CliConnector;
+
+public class QuarkusCliConnectorFactory extends DefaultCliConnectorFactory {
+ @Override
+ public CliConnector createConnector() {
+ return new QuarkusLocalCliConnector(this);
+ }
+}
diff --git
a/extensions-jvm/cli-connector/runtime/src/main/java/org/apache/camel/quarkus/component/cli/connector/QuarkusLocalCliConnector.java
b/extensions-jvm/cli-connector/runtime/src/main/java/org/apache/camel/quarkus/component/cli/connector/QuarkusLocalCliConnector.java
new file mode 100644
index 0000000000..e6714075c2
--- /dev/null
+++
b/extensions-jvm/cli-connector/runtime/src/main/java/org/apache/camel/quarkus/component/cli/connector/QuarkusLocalCliConnector.java
@@ -0,0 +1,38 @@
+/*
+ * 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.quarkus.component.cli.connector;
+
+import io.quarkus.runtime.LaunchMode;
+import org.apache.camel.cli.connector.LocalCliConnector;
+import org.apache.camel.spi.CliConnectorFactory;
+
+public class QuarkusLocalCliConnector extends LocalCliConnector {
+ public QuarkusLocalCliConnector(CliConnectorFactory cliConnectorFactory) {
+ super(cliConnectorFactory);
+ }
+
+ @Override
+ public void sigterm() {
+ if (LaunchMode.current().equals(LaunchMode.DEVELOPMENT)) {
+ // If Camel JBang launched us in dev mode, then stopping the
CamelContext is not enough as dev mode will remain running.
+ // Therefore, init app shutdown which will still shut Camel down
gracefully
+ System.exit(0);
+ } else {
+ super.sigterm();
+ }
+ }
+}