Skip to content

Commit

Permalink
Merge camel-quarkus-main into camel-quarkus-core #2358
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Mar 24, 2021
1 parent 2937812 commit 59a885c
Show file tree
Hide file tree
Showing 57 changed files with 443 additions and 184 deletions.
18 changes: 18 additions & 0 deletions docs/modules/ROOT/pages/reference/extensions/core.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,24 @@ A comma separated list of Ant-path style patterns to match class names that shou
What to do if it is not possible to extract CSimple expressions from a route definition at build time.
| `org.apache.camel.quarkus.core.CamelConfig.FailureRemedy`
| `warn`

|icon:lock[title=Fixed at build time] [[quarkus.camel.main.enabled]]`link:#quarkus.camel.main.enabled[quarkus.camel.main.enabled]`

If `true` all `camel-main` features are enabled; otherwise no `camel-main` features are enabled. See described the link:https://camel.apache.org/camel-quarkus/latest/user-guide/bootstrap.html#_camel_main[Bootstrap] section of Camel Quarkus documentation for more details.
| `boolean`
| `true`

|icon:lock[title=Fixed at build time] [[quarkus.camel.main.shutdown.timeout]]`link:#quarkus.camel.main.shutdown.timeout[quarkus.camel.main.shutdown.timeout]`

A timeout (with millisecond precision) to wait for `CamelMain++#++stop()` to finish
| `java.time.Duration`
| `PT3S`

|icon:lock[title=Fixed at build time] [[quarkus.camel.main.arguments.on-unknown]]`link:#quarkus.camel.main.arguments.on-unknown[quarkus.camel.main.arguments.on-unknown]`

The action to take when `CamelMain` encounters an unknown argument. fail - Prints the `CamelMain` usage statement and throws a `RuntimeException` ignore - Suppresses any warnings and the application startup proceeds as normal warn - Prints the `CamelMain` usage statement but allows the application startup to proceed as normal
| `org.apache.camel.quarkus.core.CamelConfig.FailureRemedy`
| `warn`
|===

[.configuration-legend]
Expand Down
24 changes: 0 additions & 24 deletions docs/modules/ROOT/pages/reference/extensions/main.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,3 @@ Bootstrap Camel using Camel Main which brings advanced auto-configuration capabi
----

Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.

== 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.main.shutdown.timeout]]`link:#quarkus.camel.main.shutdown.timeout[quarkus.camel.main.shutdown.timeout]`

A timeout (with millisecond precision) to wait for `CamelMain++#++stop()` to finish
| `java.time.Duration`
| `PT3S`

|icon:lock[title=Fixed at build time] [[quarkus.camel.main.arguments.on-unknown]]`link:#quarkus.camel.main.arguments.on-unknown[quarkus.camel.main.arguments.on-unknown]`

The action to take when `CamelMain` encounters an unknown argument. fail - Prints the `CamelMain` usage statement and throws a `RuntimeException` ignore - Suppresses any warnings and the application startup proceeds as normal warn - Prints the `CamelMain` usage statement but allows the application startup to proceed as normal
| `org.apache.camel.quarkus.core.CamelConfig.FailureRemedy`
| `warn`
|===

[.configuration-legend]
icon:lock[title=Fixed at build time] Configuration property fixed at build time. All other configuration properties are overridable at runtime.

Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Consume;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Overridable;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.runtime.RuntimeValue;
import org.apache.camel.CamelContext;
import org.apache.camel.quarkus.core.CamelConfig;
import org.apache.camel.quarkus.core.CamelContextRecorder;
import org.apache.camel.quarkus.core.CamelRuntime;
import org.apache.camel.quarkus.core.deployment.main.spi.CamelMainEnabled;
import org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.CamelFactoryFinderResolverBuildItem;
Expand Down Expand Up @@ -125,8 +125,7 @@ CamelContextBuildItem context(
* @param config a reference to the Camel Quarkus configuration
* @return a build item holding a {@link CamelRuntime} instance.
*/
@Overridable
@BuildStep
@BuildStep(onlyIfNot = CamelMainEnabled.class)
@Record(value = ExecutionTime.RUNTIME_INIT, optional = true)
/* @Consume(SyntheticBeansRuntimeInitBuildItem.class) makes sure that camel-main starts after the ArC container is
* fully initialized. This is required as under the hoods the camel registry may look-up beans form the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.main.deployment;
package org.apache.camel.quarkus.core.deployment.main;

import java.util.stream.Stream;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.main.deployment;
package org.apache.camel.quarkus.core.deployment.main;

import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -24,14 +24,15 @@

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem;
import org.apache.camel.quarkus.core.deployment.main.spi.CamelMainEnabled;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class CamelMainHotDeploymentProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(CamelMainHotDeploymentProcessor.class);
private static final String FILE_PREFIX = "file:";

@BuildStep
@BuildStep(onlyIf = CamelMainEnabled.class)
List<HotDeploymentWatchedFileBuildItem> locations() {
List<HotDeploymentWatchedFileBuildItem> items = CamelMainHelper.routesIncludePatter()
.filter(location -> location.startsWith(FILE_PREFIX))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.main.deployment;
package org.apache.camel.quarkus.core.deployment.main;

import java.util.stream.Collectors;

Expand All @@ -23,6 +23,7 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.quarkus.core.deployment.main.spi.CamelMainEnabled;
import org.apache.camel.quarkus.support.common.CamelCapabilities;
import org.apache.camel.support.ResourceHelper;
import org.apache.camel.util.AntPathMatcher;
Expand All @@ -31,7 +32,7 @@
public class CamelMainNativeImageProcessor {
private static final Logger LOG = Logger.getLogger(CamelMainNativeImageProcessor.class);

@BuildStep
@BuildStep(onlyIf = CamelMainEnabled.class)
ReflectiveClassBuildItem reflectiveCLasses() {
// TODO: The classes below are needed to fix https://github.com/apache/camel-quarkus/issues/1005
// but we need to investigate why it does not fail with Java 1.8
Expand All @@ -42,10 +43,10 @@ ReflectiveClassBuildItem reflectiveCLasses() {
org.apache.camel.model.Resilience4jConfigurationDefinition.class,
org.apache.camel.model.Resilience4jConfigurationCommon.class,
org.apache.camel.spi.RestConfiguration.class,
org.apache.camel.quarkus.main.CamelMainApplication.class);
org.apache.camel.quarkus.core.main.CamelMainApplication.class);
}

@BuildStep
@BuildStep(onlyIf = CamelMainEnabled.class)
private void camelNativeImageResources(
Capabilities capabilities,
BuildProducer<NativeImageResourceBuildItem> nativeResource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.main.deployment;
package org.apache.camel.quarkus.core.deployment.main;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -36,36 +36,35 @@
import org.apache.camel.quarkus.core.CamelConfig;
import org.apache.camel.quarkus.core.CamelRecorder;
import org.apache.camel.quarkus.core.CamelRuntime;
import org.apache.camel.quarkus.core.deployment.main.spi.CamelMainBuildItem;
import org.apache.camel.quarkus.core.deployment.main.spi.CamelMainEnabled;
import org.apache.camel.quarkus.core.deployment.main.spi.CamelMainListenerBuildItem;
import org.apache.camel.quarkus.core.deployment.main.spi.CamelRoutesCollectorBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.CamelRoutesBuilderClassBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.CamelRoutesLoaderBuildItems;
import org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeTaskBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.CamelServiceDestination;
import org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.ContainerBeansBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.RuntimeCamelContextCustomizerBuildItem;
import org.apache.camel.quarkus.main.CamelMain;
import org.apache.camel.quarkus.main.CamelMainApplication;
import org.apache.camel.quarkus.main.CamelMainConfig;
import org.apache.camel.quarkus.main.CamelMainProducers;
import org.apache.camel.quarkus.main.CamelMainRecorder;
import org.apache.camel.quarkus.main.deployment.spi.CamelMainBuildItem;
import org.apache.camel.quarkus.main.deployment.spi.CamelMainListenerBuildItem;
import org.apache.camel.quarkus.main.deployment.spi.CamelRoutesCollectorBuildItem;
import org.apache.camel.quarkus.core.main.CamelMain;
import org.apache.camel.quarkus.core.main.CamelMainApplication;
import org.apache.camel.quarkus.core.main.CamelMainConfig;
import org.apache.camel.quarkus.core.main.CamelMainProducers;
import org.apache.camel.quarkus.core.main.CamelMainRecorder;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CamelMainProcessor {
private static Logger LOGGER = LoggerFactory.getLogger(CamelMainProcessor.class);

@BuildStep
@BuildStep(onlyIf = CamelMainEnabled.class)
void unremovableBeans(BuildProducer<AdditionalBeanBuildItem> beanProducer) {
beanProducer.produce(AdditionalBeanBuildItem.unremovableOf(CamelMainProducers.class));
}

@Overridable
@BuildStep
@BuildStep(onlyIf = CamelMainEnabled.class)
@Record(value = ExecutionTime.STATIC_INIT, optional = true)
public CamelRoutesLoaderBuildItems.Registry routesLoader(CamelConfig config, CamelRecorder recorder) {
return config.routesDiscovery.enabled
Expand All @@ -74,7 +73,7 @@ public CamelRoutesLoaderBuildItems.Registry routesLoader(CamelConfig config, Cam
}

@Overridable
@BuildStep
@BuildStep(onlyIf = CamelMainEnabled.class)
@Record(value = ExecutionTime.STATIC_INIT, optional = true)
public CamelRoutesCollectorBuildItem routesCollector(
CamelMainRecorder recorder,
Expand All @@ -97,7 +96,7 @@ public CamelRoutesCollectorBuildItem routesCollector(
* @return a build item holding a {@link CamelMain} instance.
*/
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
@BuildStep(onlyIf = CamelMainEnabled.class)
CamelMainBuildItem main(
BeanContainerBuildItem beanContainer,
ContainerBeansBuildItem containerBeans,
Expand Down Expand Up @@ -142,7 +141,8 @@ CamelMainBuildItem main(
* <li>Circuit Breaker
* <li>Health
* </ul>
* <li>take control of the application life-cycle and initiates Quarkus shutdown according to some conditions as example
* <li>take control of the application life-cycle and initiates Quarkus shutdown according to some conditions as
* example
* after having processed a certain number of messages..
* </ul>
*
Expand All @@ -156,11 +156,13 @@ CamelMainBuildItem main(
* @param camelMainConfig a {@link CamelMainConfig}
* @return a build item holding a {@link CamelRuntime} instance.
*/
@BuildStep
@BuildStep(onlyIf = CamelMainEnabled.class)
@Record(value = ExecutionTime.RUNTIME_INIT, optional = true)
/* @Consume(SyntheticBeansRuntimeInitBuildItem.class) makes sure that camel-main starts after the ArC container is
/*
* @Consume(SyntheticBeansRuntimeInitBuildItem.class) makes sure that camel-main starts after the ArC container is
* fully initialized. This is required as under the hoods the camel registry may look-up beans form the
* container thus we need it to be fully initialized to avoid unexpected behaviors. */
* container thus we need it to be fully initialized to avoid unexpected behaviors.
*/
@Consume(SyntheticBeansRuntimeInitBuildItem.class)
CamelRuntimeBuildItem runtime(
CombinedIndexBuildItem index,
Expand Down Expand Up @@ -189,9 +191,17 @@ CamelRuntimeBuildItem runtime(
index.getIndex().getAnnotations(DotName.createSimple(QuarkusMain.class.getName())).isEmpty());
}

@BuildStep
@BuildStep(onlyIf = CamelMainEnabled.class)
AdditionalIndexedClassesBuildItem indexCamelMainApplication() {
// Required for launching CamelMain based applications from the IDE
return new AdditionalIndexedClassesBuildItem(CamelMainApplication.class.getName());
}

@BuildStep(onlyIfNot = CamelMainEnabled.class)
void coreServicePatterns(BuildProducer<CamelServicePatternBuildItem> services) {
services.produce(new CamelServicePatternBuildItem(
CamelServiceDestination.DISCOVERY,
false,
"META-INF/services/org/apache/camel/configurer/org.apache.camel.main.*"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.main.deployment.spi;
package org.apache.camel.quarkus.core.deployment.main.spi;

import io.quarkus.builder.item.SimpleBuildItem;
import io.quarkus.runtime.RuntimeValue;
import org.apache.camel.quarkus.main.CamelMain;
import org.apache.camel.quarkus.core.main.CamelMain;

/**
* Holds the {@link CamelMain} {@link RuntimeValue}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.core.deployment;
package org.apache.camel.quarkus.core.deployment.main.spi;

import java.util.function.BooleanSupplier;

public class CamelMainPresent implements BooleanSupplier {
import io.quarkus.runtime.RuntimeValue;
import org.apache.camel.quarkus.core.main.CamelMain;
import org.apache.camel.quarkus.core.main.CamelMainConfig;

/**
* Holds the {@link CamelMain} {@link RuntimeValue}.
*/
public class CamelMainEnabled implements BooleanSupplier {

private final CamelMainConfig mainConfig;

CamelMainEnabled(CamelMainConfig mainConfig) {
this.mainConfig = mainConfig;
}

@Override
public boolean getAsBoolean() {
try {
Class.forName("org.apache.camel.quarkus.main.CamelMain");
return true;
} catch (ClassNotFoundException e) {
return false;
}
return mainConfig.enabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.main.deployment.spi;
package org.apache.camel.quarkus.core.deployment.main.spi;

import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.runtime.RuntimeValue;
import org.apache.camel.main.MainListener;
import org.apache.camel.quarkus.main.CamelMain;
import org.apache.camel.quarkus.core.main.CamelMain;

/**
* A {@link MultiBuildItem} holding {@link MainListener}s to add to {@link CamelMain}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.main.deployment.spi;
package org.apache.camel.quarkus.core.deployment.main.spi;

import io.quarkus.builder.item.SimpleBuildItem;
import io.quarkus.runtime.RuntimeValue;
Expand Down

0 comments on commit 59a885c

Please sign in to comment.