You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2023/10/31 15:43:37 UTC

(camel-quarkus) 02/03: Add capability to log potentially missing service pattern includes

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

commit 376f1a11eb776048c224a53e7636f480636da7c6
Author: James Netherton <ja...@gmail.com>
AuthorDate: Tue Oct 31 09:38:11 2023 +0000

    Add capability to log potentially missing service pattern includes
---
 .../quarkus/core/deployment/CamelProcessor.java    | 47 ++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java
index aa5be329f0..1a6e446233 100644
--- a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java
+++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java
@@ -220,6 +220,10 @@ class CamelProcessor {
                 .build();
         CamelSupport.services(applicationArchives, pathFilter)
                 .forEach(camelServices::produce);
+
+        if (LOGGER.isDebugEnabled()) {
+            debugCamelServiceInclusion(applicationArchives, servicePatterns);
+        }
     }
 
     /*
@@ -438,4 +442,47 @@ class CamelProcessor {
                 "META-INF/services/org/apache/camel/bean-processor-factory",
                 "META-INF/services/org/apache/camel/rest-registry-factory");
     }
+
+    /**
+     * Useful for identifying Camel services that are potentially not covered by inclusion patterns
+     */
+    private void debugCamelServiceInclusion(ApplicationArchivesBuildItem applicationArchives,
+            List<CamelServicePatternBuildItem> servicePatterns) {
+        PathFilter.Builder pathBuilder = new PathFilter.Builder();
+        servicePatterns.forEach(camelServicePatternBuildItem -> {
+            camelServicePatternBuildItem.getPatterns().forEach(pathBuilder::include);
+        });
+
+        PathFilter filter = pathBuilder.build();
+        HashSet<String> missingServiceIncludes = new HashSet<>();
+
+        for (ApplicationArchive archive : applicationArchives.getAllApplicationArchives()) {
+            for (Path root : archive.getRootDirectories()) {
+                final Path resourcePath = root.resolve("META-INF/services/org/apache/camel");
+
+                if (!Files.isDirectory(resourcePath)) {
+                    continue;
+                }
+
+                try (Stream<Path> files = Files.walk(resourcePath)) {
+                    files.filter(Files::isRegularFile).forEach(file -> {
+                        Path key = root.relativize(file);
+                        if (!filter.asPathPredicate().test(key)) {
+                            missingServiceIncludes.add(key.toString());
+                        }
+                    });
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        }
+
+        if (!missingServiceIncludes.isEmpty()) {
+            // Note this is only partly reliable info as some include patterns are provided elsewhere independently of camel-quarkus-core
+            LOGGER.debug("Found potential missing service include patterns for the following paths:");
+            missingServiceIncludes.forEach(path -> {
+                LOGGER.debug("Missing service include path: {}", path);
+            });
+        }
+    }
 }