From b866293e5cffad8e10999f713af33b310ca5cfc9 Mon Sep 17 00:00:00 2001 From: lburgazzoli Date: Thu, 7 May 2020 16:40:53 +0200 Subject: [PATCH] yaml-loader: allow to blacklist definitions --- .../camel-k-loader-yaml/pom.xml | 14 ++++++++ .../GenerateYamlLoaderSupportClasses.java | 35 ++++++++----------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/camel-k-loader-yaml/camel-k-loader-yaml/pom.xml b/camel-k-loader-yaml/camel-k-loader-yaml/pom.xml index 1f8d67f5b..199a2d7f0 100644 --- a/camel-k-loader-yaml/camel-k-loader-yaml/pom.xml +++ b/camel-k-loader-yaml/camel-k-loader-yaml/pom.xml @@ -145,6 +145,20 @@ generate-yaml-loader-support-classes + + + org.apache.camel.model.Resilience4jConfigurationDefinition + org.apache.camel.model.HystrixConfigurationDefinition + org.apache.camel.model.OnFallbackDefinition + org.apache.camel.model.InOnlyDefinition + org.apache.camel.model.InOutDefinition + org.apache.camel.model.OtherwiseDefinition + org.apache.camel.model.WhenDefinition + org.apache.camel.model.config.StreamResequencerConfig + org.apache.camel.model.config.BatchResequencerConfig + org.apache.camel.model.loadbalancer/** + + diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateYamlLoaderSupportClasses.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateYamlLoaderSupportClasses.java index 39822573d..91d7cc5fd 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateYamlLoaderSupportClasses.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateYamlLoaderSupportClasses.java @@ -21,6 +21,7 @@ import java.nio.file.Paths; import java.util.Comparator; import java.util.HashSet; +import java.util.List; import java.util.Set; import javax.lang.model.element.Modifier; @@ -33,9 +34,11 @@ import com.squareup.javapoet.JavaFile; import com.squareup.javapoet.MethodSpec; import com.squareup.javapoet.TypeSpec; +import org.apache.camel.util.AntPathMatcher; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; @@ -49,6 +52,9 @@ threadSafe = true, requiresProject = false) public class GenerateYamlLoaderSupportClasses extends GenerateYamlSupport { + @Parameter + protected List blacklistedDefinitions; + @Override public void execute() throws MojoFailureException { try { @@ -195,27 +201,14 @@ public final TypeSpec generateResolver() { AnnotationValue label = meta.value("label"); if (name != null && label != null) { - // skip known definitions for which there is a custom - // implementation - switch (i.name().toString()) { - case "org.apache.camel.model.Resilience4jConfigurationDefinition": - case "org.apache.camel.model.HystrixConfigurationDefinition": - case "org.apache.camel.model.config.StreamResequencerConfig": - case "org.apache.camel.model.config.BatchResequencerConfig": - case "org.apache.camel.model.OnFallbackDefinition": - case "org.apache.camel.model.InOnlyDefinition": - case "org.apache.camel.model.InOutDefinition": - case "org.apache.camel.model.OtherwiseDefinition": - case "org.apache.camel.model.WhenDefinition": - return; - default: - break; - } - switch (i.name().prefix().toString()) { - case "org.apache.camel.model.loadbalancer": - return; - default: - break; + + if (blacklistedDefinitions != null) { + for (String blacklistedDefinition: blacklistedDefinitions) { + if (AntPathMatcher.INSTANCE.match(blacklistedDefinition.replace('.', '/'), i.name().toString('/'))) { + getLog().debug("Skipping definition: " + i.name().toString()); + return; + } + } } Set labels = Set.of(label.asString().split(",", -1));