This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new c22981e61b Enrich registry routes with source resource
c22981e61b is described below
commit c22981e61b68267b7a4bccad96083899c98c8ba9
Author: James Netherton <[email protected]>
AuthorDate: Tue Sep 2 11:17:11 2025 +0100
Enrich registry routes with source resource
Fixes #7683
---
.../quarkus/main/CamelMainRoutesCollector.java | 22 +++++++++++++++-
.../camel/quarkus/main/CamelCdiBeanRoute.java | 29 ++++++++++++++++++++++
.../camel/quarkus/main/CoreMainResource.java | 15 +++++++++++
.../apache/camel/quarkus/main/CoreMainTest.java | 23 +++++++++++++++++
4 files changed, 88 insertions(+), 1 deletion(-)
diff --git
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMainRoutesCollector.java
b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMainRoutesCollector.java
index 8595f531d0..1cfd8ad95e 100644
---
a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMainRoutesCollector.java
+++
b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMainRoutesCollector.java
@@ -22,6 +22,9 @@ import org.apache.camel.CamelContext;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.main.DefaultRoutesCollector;
import org.apache.camel.quarkus.core.RegistryRoutesLoader;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.spi.ResourceAware;
+import org.apache.camel.support.ResourceHelper;
public class CamelMainRoutesCollector extends DefaultRoutesCollector {
private final RegistryRoutesLoader registryRoutesLoader;
@@ -40,6 +43,23 @@ public class CamelMainRoutesCollector extends
DefaultRoutesCollector {
String excludePattern,
String includePattern) {
- return registryRoutesLoader.collectRoutesFromRegistry(camelContext,
excludePattern, includePattern);
+ List<RoutesBuilder> routes =
registryRoutesLoader.collectRoutesFromRegistry(camelContext, excludePattern,
+ includePattern);
+ for (RoutesBuilder route : routes) {
+ if (route instanceof ResourceAware ra) {
+ configureSourceResource(camelContext, route, ra);
+ }
+ }
+ return routes;
+ }
+
+ private static void configureSourceResource(CamelContext camelContext,
RoutesBuilder route, ResourceAware ra) {
+ if (ra.getResource() == null) {
+ String uri = "source:" +
route.getClass().getName().replace("_ClientProxy", "");
+ Resource r = ResourceHelper.resolveResource(camelContext, uri);
+ if (r != null && r.exists()) {
+ ra.setResource(r);
+ }
+ }
}
}
diff --git
a/integration-tests/main/src/main/java/org/apache/camel/quarkus/main/CamelCdiBeanRoute.java
b/integration-tests/main/src/main/java/org/apache/camel/quarkus/main/CamelCdiBeanRoute.java
new file mode 100644
index 0000000000..bea8393fb8
--- /dev/null
+++
b/integration-tests/main/src/main/java/org/apache/camel/quarkus/main/CamelCdiBeanRoute.java
@@ -0,0 +1,29 @@
+/*
+ * 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.main;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import org.apache.camel.builder.RouteBuilder;
+
+@ApplicationScoped
+public class CamelCdiBeanRoute extends RouteBuilder {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").routeId("camel-cdi-bean-route")
+ .log("Hello World");
+ }
+}
diff --git
a/integration-tests/main/src/main/java/org/apache/camel/quarkus/main/CoreMainResource.java
b/integration-tests/main/src/main/java/org/apache/camel/quarkus/main/CoreMainResource.java
index 3c9eb0c381..bef64d7055 100644
---
a/integration-tests/main/src/main/java/org/apache/camel/quarkus/main/CoreMainResource.java
+++
b/integration-tests/main/src/main/java/org/apache/camel/quarkus/main/CoreMainResource.java
@@ -19,6 +19,7 @@ package org.apache.camel.quarkus.main;
import java.io.IOException;
import java.net.ConnectException;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -37,6 +38,7 @@ import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import org.apache.camel.CamelContext;
import org.apache.camel.Component;
+import org.apache.camel.Route;
import org.apache.camel.ServiceStatus;
import org.apache.camel.component.log.LogComponent;
import org.apache.camel.impl.debugger.DebuggerJmxConnectorService;
@@ -52,6 +54,7 @@ import org.apache.camel.spi.DataFormat;
import org.apache.camel.spi.FactoryFinderResolver;
import org.apache.camel.spi.Language;
import org.apache.camel.spi.ReactiveExecutor;
+import org.apache.camel.spi.Resource;
import org.apache.camel.spi.ThreadPoolFactory;
import org.apache.camel.support.DefaultRegistry;
import org.apache.camel.support.LRUCacheFactory;
@@ -324,4 +327,16 @@ public class CoreMainResource {
public void runtimeStart() {
camelRuntime.start();
}
+
+ @Path("/context/route/source/resource")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String contextRouteSourceResource() throws IOException {
+ Route route = main.getCamelContext().getRoute("camel-cdi-bean-route");
+ Resource sourceResource = route.getSourceResource();
+ if (sourceResource != null && sourceResource.exists()) {
+ return new String(sourceResource.getInputStream().readAllBytes(),
StandardCharsets.UTF_8);
+ }
+ return null;
+ }
}
diff --git
a/integration-tests/main/src/test/java/org/apache/camel/quarkus/main/CoreMainTest.java
b/integration-tests/main/src/test/java/org/apache/camel/quarkus/main/CoreMainTest.java
index 2c597580ff..ae35559794 100644
---
a/integration-tests/main/src/test/java/org/apache/camel/quarkus/main/CoreMainTest.java
+++
b/integration-tests/main/src/test/java/org/apache/camel/quarkus/main/CoreMainTest.java
@@ -17,7 +17,10 @@
package org.apache.camel.quarkus.main;
import java.net.HttpURLConnection;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.Map;
+import java.util.function.BooleanSupplier;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
@@ -28,6 +31,7 @@ import jakarta.ws.rs.core.MediaType;
import org.apache.camel.ServiceStatus;
import org.apache.camel.quarkus.core.DisabledModelToXMLDumper;
import org.apache.camel.quarkus.core.RegistryRoutesLoaders;
+import org.apache.camel.quarkus.test.EnabledIf;
import org.apache.camel.reactive.vertx.VertXReactiveExecutor;
import org.apache.camel.reactive.vertx.VertXThreadPoolFactory;
import org.apache.camel.support.DefaultLRUCacheFactory;
@@ -38,6 +42,7 @@ import static org.apache.camel.quarkus.test.Conditions.entry;
import static org.apache.camel.quarkus.test.Conditions.startsWith;
import static org.apache.camel.util.CollectionHelper.mapOf;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -221,4 +226,22 @@ public class CoreMainTest {
.statusCode(200)
.body(is("true"));
}
+
+ // Avoid running in the Quarkus Platform where there are no .java source
files
+ @EnabledIf(SrcDirectoryExists.class)
+ @Test
+ public void routeSourceResource() {
+ RestAssured.given()
+ .get("/test/context/route/source/resource")
+ .then()
+ .statusCode(200)
+ .body(containsString("public class " +
CamelCdiBeanRoute.class.getSimpleName()));
+ }
+
+ public static class SrcDirectoryExists implements BooleanSupplier {
+ @Override
+ public boolean getAsBoolean() {
+ return Files.exists(Paths.get("src/main/java"));
+ }
+ }
}