You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/10/28 11:06:32 UTC
[camel-quarkus] 03/04: core: create a CamelServiceFilterBuildItem
to let extension filter services automatically discovered and instantiated
at augmentation phase
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 2bac3e17366c4ec92fdbd9b1dc726dedac973f47
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Oct 28 10:16:43 2019 +0100
core: create a CamelServiceFilterBuildItem to let extension filter services automatically discovered and instantiated at augmentation phase
---
.../quarkus/core/deployment/BuildProcessor.java | 18 +++++--
.../deployment/CamelServiceFilterBuildItem.java | 32 ++++++++++++
.../quarkus/core/deployment/CamelSupport.java | 34 ++----------
.../camel/quarkus/core/CamelServiceFilter.java | 23 ++++++++
.../camel/quarkus/core/CamelServiceInfo.java | 61 ++++++++++++++++++++++
.../http/deployment/PlatformHttpProcessor.java | 14 ++++-
.../executor/deployment/BuildProcessor.java | 13 +++++
7 files changed, 160 insertions(+), 35 deletions(-)
diff --git a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/BuildProcessor.java b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/BuildProcessor.java
index f2bbbbc..3516a69 100644
--- a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/BuildProcessor.java
+++ b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/BuildProcessor.java
@@ -60,13 +60,24 @@ class BuildProcessor {
beanProducer.produce(AdditionalBeanBuildItem.unremovableOf(CamelProducers.class));
}
+ /*
+ * Configure filters for core services.
+ */
+ @BuildStep
+ void coreServiceFilter(BuildProducer<CamelServiceFilterBuildItem> filterBuildItems) {
+ filterBuildItems.produce(
+ new CamelServiceFilterBuildItem(si -> si.path.endsWith("META-INF/services/org/apache/camel/properties-component-factory"))
+ );
+ }
+
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelRegistryBuildItem registry(
CamelRecorder recorder,
RecorderContext recorderContext,
ApplicationArchivesBuildItem applicationArchives,
- List<CamelBeanBuildItem> registryItems) {
+ List<CamelBeanBuildItem> registryItems,
+ List<CamelServiceFilterBuildItem> serviceFilters) {
RuntimeValue<Registry> registry = recorder.createRegistry();
@@ -78,10 +89,7 @@ class BuildProcessor {
// to the camel context directly by extension so it does not make sense to
// instantiate them in this phase.
//
- boolean blacklisted = si.path.endsWith("reactive-executor")
- || si.path.endsWith("platform-http")
- || si.path.endsWith("properties-component-factory");
-
+ boolean blacklisted = serviceFilters.stream().anyMatch(filter -> filter.getPredicate().test(si));
if (blacklisted) {
LOGGER.debug("Ignore service: {}", si);
}
diff --git a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelServiceFilterBuildItem.java b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelServiceFilterBuildItem.java
new file mode 100644
index 0000000..faf7614
--- /dev/null
+++ b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelServiceFilterBuildItem.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.core.deployment;
+
+import io.quarkus.builder.item.MultiBuildItem;
+import org.apache.camel.quarkus.core.CamelServiceFilter;
+
+public final class CamelServiceFilterBuildItem extends MultiBuildItem {
+ private final CamelServiceFilter predicate;
+
+ public CamelServiceFilterBuildItem(CamelServiceFilter predicate) {
+ this.predicate = predicate;
+ }
+
+ public CamelServiceFilter getPredicate() {
+ return predicate;
+ }
+}
diff --git a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelSupport.java b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelSupport.java
index 29b254f..db77fc1 100644
--- a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelSupport.java
+++ b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelSupport.java
@@ -35,6 +35,7 @@ import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.quarkus.core.CamelServiceInfo;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
@@ -86,23 +87,22 @@ public final class CamelSupport {
.map(ClassInfo::toString);
}
- public static Stream<ServiceInfo> services(ApplicationArchivesBuildItem applicationArchivesBuildItem) {
+ public static Stream<CamelServiceInfo> services(ApplicationArchivesBuildItem applicationArchivesBuildItem) {
return CamelSupport.resources(applicationArchivesBuildItem, CamelSupport.CAMEL_SERVICE_BASE_PATH)
.map(CamelSupport::services)
.flatMap(Collection::stream);
}
- private static List<ServiceInfo> services(Path p) {
- List<ServiceInfo> answer = new ArrayList<>();
+ private static List<CamelServiceInfo> services(Path p) {
+ List<CamelServiceInfo> answer = new ArrayList<>();
- String name = p.getFileName().toString();
try (InputStream is = Files.newInputStream(p)) {
Properties props = new Properties();
props.load(is);
for (Map.Entry<Object, Object> entry : props.entrySet()) {
String k = entry.getKey().toString();
if (k.equals("class")) {
- answer.add(new ServiceInfo(p, name, entry.getValue().toString()));
+ answer.add(new CamelServiceInfo(p, entry.getValue().toString()));
}
}
} catch (Exception e) {
@@ -112,28 +112,4 @@ public final class CamelSupport {
return answer;
}
- /**
- * Utility class to describe a camel service which is a result of reading
- * services from resources belonging to META-INF/services/org/apache/camel.
- */
- public static class ServiceInfo {
- public final Path path;
- public final String name;
- public final String type;
-
- public ServiceInfo(Path path, String name, String type) {
- this.path = path;
- this.name = name;
- this.type = type;
- }
-
- @Override
- public String toString() {
- return "ServiceInfo{"
- + "path='" + path.toString() + '\''
- + ", name=" + name
- + ", type=" + type
- + '}';
- }
- }
}
diff --git a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelServiceFilter.java b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelServiceFilter.java
new file mode 100644
index 0000000..25ebd51
--- /dev/null
+++ b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelServiceFilter.java
@@ -0,0 +1,23 @@
+/*
+ * 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.core;
+
+import java.util.function.Predicate;
+
+@FunctionalInterface
+public interface CamelServiceFilter extends Predicate<CamelServiceInfo> {
+}
diff --git a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelServiceInfo.java b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelServiceInfo.java
new file mode 100644
index 0000000..2c9ddd1
--- /dev/null
+++ b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelServiceInfo.java
@@ -0,0 +1,61 @@
+/*
+ * 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.core;
+
+import java.nio.file.Path;
+
+/**
+ * Utility class to describe a camel service which is a result of reading
+ * services from resources belonging to META-INF/services/org/apache/camel.
+ */
+public class CamelServiceInfo {
+ /**
+ * The path of the service file like META-INF/services/org/apache/camel/component/file.
+ */
+ public final Path path;
+
+ /**
+ * The name of the service entry which is derived from the service path. As example the
+ * name for a service with path <code>META-INF/services/org/apache/camel/component/file</code>
+ * will be <code>file</code>
+ */
+ public final String name;
+
+ /**
+ * The full qualified class name of the service.
+ */
+ public final String type;
+
+ public CamelServiceInfo(Path path, String type) {
+ this(path, path.getFileName().toString(), type);
+ }
+
+ public CamelServiceInfo(Path path, String name, String type) {
+ this.path = path;
+ this.name = name;
+ this.type = type;
+ }
+
+ @Override
+ public String toString() {
+ return "ServiceInfo{"
+ + "path='" + path.toString() + '\''
+ + ", name=" + name
+ + ", type=" + type
+ + '}';
+ }
+}
diff --git a/extensions/platform-http/deployment/src/main/java/org/apache/camel/quarkus/component/platform/http/deployment/PlatformHttpProcessor.java b/extensions/platform-http/deployment/src/main/java/org/apache/camel/quarkus/component/platform/http/deployment/PlatformHttpProcessor.java
index 955a013..7311c48 100644
--- a/extensions/platform-http/deployment/src/main/java/org/apache/camel/quarkus/component/platform/http/deployment/PlatformHttpProcessor.java
+++ b/extensions/platform-http/deployment/src/main/java/org/apache/camel/quarkus/component/platform/http/deployment/PlatformHttpProcessor.java
@@ -19,6 +19,7 @@ package org.apache.camel.quarkus.component.platform.http.deployment;
import java.util.ArrayList;
import java.util.List;
+import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
@@ -33,11 +34,11 @@ import org.apache.camel.quarkus.component.platform.http.runtime.PlatformHttpHand
import org.apache.camel.quarkus.component.platform.http.runtime.PlatformHttpRecorder;
import org.apache.camel.quarkus.component.platform.http.runtime.QuarkusPlatformHttpEngine;
import org.apache.camel.quarkus.core.deployment.CamelRuntimeBeanBuildItem;
+import org.apache.camel.quarkus.core.deployment.CamelServiceFilterBuildItem;
import org.apache.camel.quarkus.core.deployment.UploadAttacherBuildItem;
class PlatformHttpProcessor {
-
private static final String FEATURE = "camel-platform-http";
@BuildStep
@@ -45,6 +46,17 @@ class PlatformHttpProcessor {
return new FeatureBuildItem(FEATURE);
}
+ /*
+ * The platform-http component is programmatically configured by the extension thus
+ * we can safely prevent camel-quarkus-core to instantiate a default instance.
+ */
+ @BuildStep
+ void serviceFilter(BuildProducer<CamelServiceFilterBuildItem> filterBuildItems) {
+ filterBuildItems.produce(
+ new CamelServiceFilterBuildItem(si -> si.path.endsWith("META-INF/services/org/apache/camel/component/platform-http"))
+ );
+ }
+
@Record(ExecutionTime.RUNTIME_INIT)
@BuildStep
PlatformHttpEngineBuildItem platformHttpEngine(
diff --git a/extensions/reactive-executor/deployment/src/main/java/org/apache/camel/quarkus/reactive/executor/deployment/BuildProcessor.java b/extensions/reactive-executor/deployment/src/main/java/org/apache/camel/quarkus/reactive/executor/deployment/BuildProcessor.java
index 77020e9..8f9641e 100644
--- a/extensions/reactive-executor/deployment/src/main/java/org/apache/camel/quarkus/reactive/executor/deployment/BuildProcessor.java
+++ b/extensions/reactive-executor/deployment/src/main/java/org/apache/camel/quarkus/reactive/executor/deployment/BuildProcessor.java
@@ -16,15 +16,28 @@
*/
package org.apache.camel.quarkus.reactive.executor.deployment;
+import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.vertx.deployment.VertxBuildItem;
import org.apache.camel.quarkus.core.Flags;
import org.apache.camel.quarkus.core.deployment.CamelReactiveExecutorBuildItem;
+import org.apache.camel.quarkus.core.deployment.CamelServiceFilterBuildItem;
import org.apache.camel.quarkus.reactive.executor.ReactiveExecutorRecorder;
public class BuildProcessor {
+ /*
+ * The reactive executor is programmatically configured by the extension thus
+ * we can safely prevent camel-quarkus-core to instantiate a default instance.
+ */
+ @BuildStep
+ void serviceFilter(BuildProducer<CamelServiceFilterBuildItem> filterBuildItems) {
+ filterBuildItems.produce(
+ new CamelServiceFilterBuildItem(si -> si.path.endsWith("META-INF/services/org/apache/camel/reactive-executor"))
+ );
+ }
+
@Record(value = ExecutionTime.RUNTIME_INIT, optional = true)
@BuildStep(onlyIf = Flags.MainEnabled.class)
CamelReactiveExecutorBuildItem reactiveExecutor(ReactiveExecutorRecorder recorder, VertxBuildItem vertx) {