Skip to content

Commit

Permalink
yaml-loader: allow to blacklist definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed May 7, 2020
1 parent ec05e8f commit b866293
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
14 changes: 14 additions & 0 deletions camel-k-loader-yaml/camel-k-loader-yaml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,20 @@
<goals>
<goal>generate-yaml-loader-support-classes</goal>
</goals>
<configuration>
<blacklistedDefinitions>
<blacklistedDefinition>org.apache.camel.model.Resilience4jConfigurationDefinition</blacklistedDefinition>
<blacklistedDefinition>org.apache.camel.model.HystrixConfigurationDefinition</blacklistedDefinition>
<blacklistedDefinition>org.apache.camel.model.OnFallbackDefinition</blacklistedDefinition>
<blacklistedDefinition>org.apache.camel.model.InOnlyDefinition</blacklistedDefinition>
<blacklistedDefinition>org.apache.camel.model.InOutDefinition</blacklistedDefinition>
<blacklistedDefinition>org.apache.camel.model.OtherwiseDefinition</blacklistedDefinition>
<blacklistedDefinition>org.apache.camel.model.WhenDefinition</blacklistedDefinition>
<blacklistedDefinition>org.apache.camel.model.config.StreamResequencerConfig</blacklistedDefinition>
<blacklistedDefinition>org.apache.camel.model.config.BatchResequencerConfig</blacklistedDefinition>
<blacklistedDefinition>org.apache.camel.model.loadbalancer/**</blacklistedDefinition>
</blacklistedDefinitions>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -49,6 +52,9 @@
threadSafe = true,
requiresProject = false)
public class GenerateYamlLoaderSupportClasses extends GenerateYamlSupport {
@Parameter
protected List<String> blacklistedDefinitions;

@Override
public void execute() throws MojoFailureException {
try {
Expand Down Expand Up @@ -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<String> labels = Set.of(label.asString().split(",", -1));
Expand Down

0 comments on commit b866293

Please sign in to comment.