You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/08/25 16:45:30 UTC

[camel] 01/02: camel-package-maven-plugin - Ignore if no jandex.id file

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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 0e049ed8a313daf99c92d63d0c6cd1feca36197e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Aug 25 17:13:01 2021 +0200

    camel-package-maven-plugin - Ignore if no jandex.id file
---
 .../packaging/AbstractGenerateConfigurerMojo.java  | 47 +++++++++++++---------
 1 file changed, 27 insertions(+), 20 deletions(-)

diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGenerateConfigurerMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGenerateConfigurerMojo.java
index 77302af..a157bb1 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGenerateConfigurerMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGenerateConfigurerMojo.java
@@ -27,6 +27,7 @@ import java.lang.reflect.Modifier;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -136,30 +137,36 @@ public abstract class AbstractGenerateConfigurerMojo extends AbstractGeneratorMo
             Index index;
             try (InputStream is = Files.newInputStream(output.resolve("META-INF/jandex.idx"))) {
                 index = new IndexReader(is).read();
+            } catch (NoSuchFileException e) {
+                // ignore if no jandex index
+                index = null;
+                ;
             } catch (IOException e) {
                 throw new MojoExecutionException("IOException: " + e.getMessage(), e);
             }
 
-            // discover all classes annotated with @Configurer
-            List<AnnotationInstance> annotations = index.getAnnotations(CONFIGURER);
-            annotations.stream()
-                    .filter(annotation -> annotation.target().kind() == AnnotationTarget.Kind.CLASS)
-                    .filter(annotation -> annotation.target().asClass().nestingType() == ClassInfo.NestingType.TOP_LEVEL)
-                    .filter(annotation -> asBooleanDefaultTrue(annotation, "generateConfigurer"))
-                    .forEach(annotation -> {
-                        String currentClass = annotation.target().asClass().name().toString();
-                        boolean bootstrap = asBooleanDefaultFalse(annotation, "bootstrap");
-                        boolean extended = asBooleanDefaultFalse(annotation, "extended");
-                        if (bootstrap && extended) {
-                            bootstrapAndExtendedSet.add(currentClass);
-                        } else if (bootstrap) {
-                            bootstrapSet.add(currentClass);
-                        } else if (extended) {
-                            extendedSet.add(currentClass);
-                        } else {
-                            set.add(currentClass);
-                        }
-                    });
+            if (index != null) {
+                // discover all classes annotated with @Configurer
+                List<AnnotationInstance> annotations = index.getAnnotations(CONFIGURER);
+                annotations.stream()
+                        .filter(annotation -> annotation.target().kind() == AnnotationTarget.Kind.CLASS)
+                        .filter(annotation -> annotation.target().asClass().nestingType() == ClassInfo.NestingType.TOP_LEVEL)
+                        .filter(annotation -> asBooleanDefaultTrue(annotation, "generateConfigurer"))
+                        .forEach(annotation -> {
+                            String currentClass = annotation.target().asClass().name().toString();
+                            boolean bootstrap = asBooleanDefaultFalse(annotation, "bootstrap");
+                            boolean extended = asBooleanDefaultFalse(annotation, "extended");
+                            if (bootstrap && extended) {
+                                bootstrapAndExtendedSet.add(currentClass);
+                            } else if (bootstrap) {
+                                bootstrapSet.add(currentClass);
+                            } else if (extended) {
+                                extendedSet.add(currentClass);
+                            } else {
+                                set.add(currentClass);
+                            }
+                        });
+            }
         }
 
         // additional classes