-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cli-connector support for Camel JBang runtime=quarkus
- Loading branch information
1 parent
a74a7da
commit 6adfc3a
Showing
9 changed files
with
264 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...org/apache/camel/quarkus/component/cli/connector/deployment/CliConnectorDisabledTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
.../org/apache/camel/quarkus/component/cli/connector/deployment/CliConnectorEnabledTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...c/main/java/org/apache/camel/quarkus/component/cli/connector/CamelCliConnectorConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
32 changes: 32 additions & 0 deletions
32
...main/java/org/apache/camel/quarkus/component/cli/connector/CamelCliConnectorRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ain/java/org/apache/camel/quarkus/component/cli/connector/QuarkusCliConnectorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
.../main/java/org/apache/camel/quarkus/component/cli/connector/QuarkusLocalCliConnector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |