You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pp...@apache.org on 2022/12/19 19:11:50 UTC

[camel-quarkus] branch main updated: Check extension pages with strict option

This is an automated email from the ASF dual-hosted git repository.

ppalaga 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 fbe2163e82 Check extension pages with strict option
fbe2163e82 is described below

commit fbe2163e82b1393fc59e73c812e34d6e8fd31ec0
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Mon Dec 19 16:15:24 2022 +0100

    Check extension pages with strict option
---
 pom.xml                                            |  3 +
 .../quarkus/maven/AbstractExtensionListMojo.java   | 64 +++++++++++++++++++++-
 .../quarkus/maven/CheckExtensionPagesMojo.java     | 12 +++-
 3 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index d8f8d03445..dd8abeca96 100644
--- a/pom.xml
+++ b/pom.xml
@@ -220,6 +220,9 @@
 
         <!-- maven-release-plugin -->
         <tagNameFormat>@{project.version}</tagNameFormat>
+
+        <!-- camel-quarkus-maven-plugin -->
+        <camel-quarkus.extension.finder.strict>true</camel-quarkus.extension.finder.strict>
     </properties>
 
     <modules>
diff --git a/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/AbstractExtensionListMojo.java b/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/AbstractExtensionListMojo.java
index 4fde01d781..7ded60b17c 100644
--- a/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/AbstractExtensionListMojo.java
+++ b/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/AbstractExtensionListMojo.java
@@ -17,13 +17,25 @@
 package org.apache.camel.quarkus.maven;
 
 import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
 import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 import java.nio.file.Path;
+import java.util.Collection;
+import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugins.annotations.Parameter;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 import org.l2x6.maven.utils.MavenSourceTree;
 
 public abstract class AbstractExtensionListMojo extends AbstractMojo {
@@ -73,11 +85,61 @@ public abstract class AbstractExtensionListMojo extends AbstractMojo {
     }
 
     Stream<ExtensionModule> findExtensions() {
+        return findExtensions(true);
+    }
+
+    /**
+     * @param  strict if {@code true} only Maven modules are considered that are reachable over a {@code <module>}
+     *                element from the root module; otherwise also unreachable modules will be returned.
+     * @return
+     */
+    Stream<ExtensionModule> findExtensions(boolean strict) {
         getSkipArtifactIdBases();
-        return CqUtils.findExtensions(
+        final Stream<ExtensionModule> strictModulesStream = CqUtils.findExtensions(
                 getRootModuleDirectory(),
                 getTree().getModulesByGa().values(),
                 artifactIdBase -> !skipArtifactIdBasePatterns.matchesAny(artifactIdBase));
+        if (strict) {
+            return strictModulesStream;
+        } else {
+            final Collection<ExtensionModule> strictModules = strictModulesStream
+                    .collect(Collectors.toCollection(LinkedHashSet::new));
+            final Set<ExtensionModule> result = new TreeSet<>();
+            strictModules.stream()
+                    .map(module -> module.getExtensionDir().getParent())
+                    .distinct()
+                    .forEach(extensionDir -> {
+
+                        try (Stream<Path> files = Files.list(extensionDir)) {
+                            files
+                                    .filter(Files::isDirectory)
+                                    .map(extensionDirectory -> extensionDirectory.resolve("runtime/pom.xml"))
+                                    .filter(Files::isRegularFile)
+                                    .forEach(runtimePomXmlPath -> {
+                                        String artifactId = null;
+                                        try (Reader r = Files.newBufferedReader(runtimePomXmlPath, StandardCharsets.UTF_8)) {
+                                            final MavenXpp3Reader rxppReader = new MavenXpp3Reader();
+                                            final Model model = rxppReader.read(r);
+                                            artifactId = model.getArtifactId();
+                                        } catch (IOException | XmlPullParserException e) {
+                                            throw new RuntimeException("Could not read " + runtimePomXmlPath);
+                                        }
+                                        if (!artifactId.startsWith("camel-quarkus-")) {
+                                            throw new IllegalStateException(
+                                                    "Should start with 'camel-quarkus-': " + artifactId);
+                                        }
+                                        final String artifactIdBase = artifactId.substring("camel-quarkus-".length());
+                                        if (!skipArtifactIdBasePatterns.matchesAny(artifactIdBase)) {
+                                            result.add(new ExtensionModule(runtimePomXmlPath.getParent().getParent(),
+                                                    artifactIdBase));
+                                        }
+                                    });
+                        } catch (IOException e) {
+                            throw new RuntimeException("Could not list " + extensionDir, e);
+                        }
+                    });
+            return result.stream();
+        }
     }
 
     PatternSet getSkipArtifactIdBases() {
diff --git a/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CheckExtensionPagesMojo.java b/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CheckExtensionPagesMojo.java
index 9e342bd354..c835153e9b 100644
--- a/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CheckExtensionPagesMojo.java
+++ b/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CheckExtensionPagesMojo.java
@@ -70,6 +70,16 @@ public class CheckExtensionPagesMojo extends AbstractDocGeneratorMojo {
     @Parameter(property = "camel.version")
     String camelVersion;
 
+    /**
+     * If {@code true} only extension Maven modules are considered to exist which are reachable through a chain of
+     * {@code <module>} elements from the root Maven module; otherwise it is enough for an extension to be considered
+     * existent if its {@code runtime/pom.xml} exists although it is not reachable through {@code <module>} elements.
+     *
+     * @since 2.16.0
+     */
+    @Parameter(property = "camel-quarkus.extension.finder.strict", defaultValue = "true")
+    boolean strict;
+
     /**
      * The path to the navigation document.
      */
@@ -145,7 +155,7 @@ public class CheckExtensionPagesMojo extends AbstractDocGeneratorMojo {
 
         final Set<String> artifactIdBases = new HashSet<>();
         final Set<CamelQuarkusExtension> extensions = new TreeSet<>(Comparator.comparing(e -> e.getName().get()));
-        findExtensions()
+        findExtensions(strict)
                 .forEach(ext -> {
                     final String artifactIdBase = ext.getArtifactIdBase();
                     artifactIdBases.add(artifactIdBase);