diff --git a/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/actions/integration/CreateIntegrationAction.java b/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/actions/integration/CreateIntegrationAction.java index 849efe6f..f7ffb21f 100644 --- a/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/actions/integration/CreateIntegrationAction.java +++ b/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/actions/integration/CreateIntegrationAction.java @@ -75,6 +75,7 @@ public class CreateIntegrationAction extends AbstractCamelKAction { private final List propertyFiles; private final List traits; private final List openApis; + private final List resources; private final boolean supportVariables; /** @@ -95,6 +96,7 @@ public CreateIntegrationAction(Builder builder) { this.propertyFiles = builder.propertyFiles; this.traits = builder.traits; this.openApis = builder.openApis; + this.resources = builder.resources; this.supportVariables = builder.supportVariables; } @@ -124,8 +126,9 @@ public void doExecute(TestContext context) { specBuilder.addAllToDependencies(resolvedDependencies); } Map> traitConfigMap = new HashMap<>(); - addPropertyConfigurationSpec(specBuilder, context); + addPropertyConfigurationSpec(specBuilder, resolvedSource, context); addRuntimeConfigurationSpec(specBuilder, resolvedSource, context); + addResourcesSpec(traitConfigMap, resolvedSource, context); addBuildPropertyConfigurationSpec(traitConfigMap, resolvedSource, context); addEnvVarConfigurationSpec(traitConfigMap, resolvedSource, context); addOpenApiSpec(traitConfigMap, resolvedSource, context); @@ -145,6 +148,20 @@ public void doExecute(TestContext context) { LOG.info(String.format("Successfully created Camel K integration '%s'", integration.getMetadata().getName())); } + private void addResourcesSpec(Map> traitConfigMap, String source, TestContext context) { + String traitName = "mount.resources"; + Pattern pattern = getModelinePattern("resource"); + Matcher matcher = pattern.matcher(source); + while (matcher.find()) { + String resource = matcher.group(1); + addTraitSpec("%s=%s".formatted(traitName, context.replaceDynamicContentInString(resource)), traitConfigMap); + } + + for (String resource : resources) { + addTraitSpec("%s=%s".formatted(traitName, context.replaceDynamicContentInString(resource)), traitConfigMap); + } + } + /** * Creates the Camel K integration as a custom resource in given namespace. * @param k8sClient @@ -230,9 +247,9 @@ private static String[] camelRunArgs(Integration integration) { private void addOpenApiSpec(Map> traitConfigMap, String source, TestContext context) { String traitName = "openapi.configmaps"; Pattern pattern = getModelinePattern("open-api"); - Matcher depMatcher = pattern.matcher(source); - while (depMatcher.find()) { - String openApiSpecFile = depMatcher.group(1); + Matcher matcher = pattern.matcher(source); + while (matcher.find()) { + String openApiSpecFile = matcher.group(1); addTraitSpec("%s=%s".formatted(traitName, context.replaceDynamicContentInString(openApiSpecFile)), traitConfigMap); } @@ -249,9 +266,9 @@ private void addTraitSpec(Map> traitConfigMap, Strin } Pattern pattern = getModelinePattern("trait"); - Matcher depMatcher = pattern.matcher(source); - while (depMatcher.find()) { - addTraitSpec(depMatcher.group(1), traitConfigMap); + Matcher matcher = pattern.matcher(source); + while (matcher.find()) { + addTraitSpec(matcher.group(1), traitConfigMap); } } @@ -321,7 +338,15 @@ private Object resolveTraitValue(String traitKey, String value) { } } - private void addPropertyConfigurationSpec(IntegrationSpecBuilder specBuilder, TestContext context) { + private void addPropertyConfigurationSpec(IntegrationSpecBuilder specBuilder, String source, TestContext context) { + Pattern pattern = getModelinePattern("property"); + Matcher matcher = pattern.matcher(source); + while (matcher.find()) { + final String[] property = matcher.group(1).split("=",2); + specBuilder.addToConfiguration( + new ConfigurationBuilder().withType("property").withValue(createPropertySpec(property[0], property[1], context)).build()); + } + if (properties != null && !properties.isEmpty()) { for (String p : context.resolveDynamicValuesInList(properties)){ //key=value @@ -379,9 +404,9 @@ private void addBuildPropertyConfigurationSpec(Map> } Pattern pattern = getModelinePattern("build-property"); - Matcher depMatcher = pattern.matcher(source); - while (depMatcher.find()) { - addTraitSpec(String.format("%s=%s", traitName, depMatcher.group(1)), traitConfigMap); + Matcher matcher = pattern.matcher(source); + while (matcher.find()) { + addTraitSpec(String.format("%s=%s", traitName, matcher.group(1)), traitConfigMap); } } @@ -415,21 +440,21 @@ private void addEnvVarConfigurationSpec(Map> traitCo } Pattern pattern = getModelinePattern("env"); - Matcher depMatcher = pattern.matcher(source); - while (depMatcher.find()) { - addTraitSpec(String.format("%s=%s", traitName, depMatcher.group(1)), traitConfigMap); + Matcher matcher = pattern.matcher(source); + while (matcher.find()) { + addTraitSpec(String.format("%s=%s", traitName, matcher.group(1)), traitConfigMap); } } private void addRuntimeConfigurationSpec(IntegrationSpecBuilder specBuilder, String source, TestContext context) { Pattern pattern = getModelinePattern("config"); - Matcher depMatcher = pattern.matcher(source); - while (depMatcher.find()) { - String[] config = depMatcher.group(1).split(":", 2); + Matcher matcher = pattern.matcher(source); + while (matcher.find()) { + String[] config = matcher.group(1).split(":", 2); if (config.length == 2) { specBuilder.addToConfiguration(new ConfigurationBuilder().withType(config[0]).withValue(context.replaceDynamicContentInString(config[1])).build()); } else { - specBuilder.addToConfiguration(new ConfigurationBuilder().withType("property").withValue(context.replaceDynamicContentInString(depMatcher.group(1))).build()); + specBuilder.addToConfiguration(new ConfigurationBuilder().withType("property").withValue(context.replaceDynamicContentInString(matcher.group(1))).build()); } } } @@ -466,9 +491,9 @@ private static List resolveDependencies(String source, List depe List resolved = new ArrayList<>(dependencies); Pattern pattern = getModelinePattern("dependency"); - Matcher depMatcher = pattern.matcher(source); - while (depMatcher.find()) { - String dependency = depMatcher.group(1); + Matcher matcher = pattern.matcher(source); + while (matcher.find()) { + String dependency = matcher.group(1); if (dependency.startsWith("camel-quarkus-")) { dependency = "camel:" + dependency.substring("camel-quarkus-".length()); @@ -528,6 +553,7 @@ public static final class Builder extends AbstractCamelKAction.Builder propertyFiles = new ArrayList<>(); private final List traits = new ArrayList<>(); private final List openApis = new ArrayList<>(); + private final List resources = new ArrayList<>(); private boolean supportVariables = true; public Builder integration(String integrationName) { @@ -566,8 +592,13 @@ public Builder openApi(String configMap) { return this; } + public Builder resource(String resource) { + this.resources.add(resource); + return this; + } + public Builder dependencies(String dependencies) { - if (dependencies != null && dependencies.length() > 0) { + if (dependencies != null && !dependencies.isEmpty()) { dependencies(Arrays.asList(dependencies.split(","))); } @@ -585,7 +616,7 @@ public Builder propertyFiles(List propertyFiles) { } public Builder properties(String properties) { - if (properties != null && properties.length() > 0) { + if (properties != null && !properties.isEmpty()) { properties(Arrays.asList(properties.split(","))); } @@ -684,7 +715,7 @@ public Builder envVar(String name, String value) { } public Builder traits(String traits) { - if (traits != null && traits.length() > 0) { + if (traits != null && !traits.isEmpty()) { traits(Arrays.asList(traits.split(","))); }