From ee2d252118aea634e57cd8099106def44b6f7192 Mon Sep 17 00:00:00 2001 From: lburgazzoli Date: Wed, 29 Jan 2020 14:21:14 +0100 Subject: [PATCH] remove support for multiple camel versions #229 --- camel-k-loader-groovy/pom.xml | 9 +- camel-k-loader-java/pom.xml | 6 +- camel-k-loader-js/pom.xml | 7 +- camel-k-loader-knative/pom.xml | 5 +- camel-k-loader-kotlin/pom.xml | 6 +- camel-k-loader-xml/pom.xml | 5 +- .../camel-k-loader-yaml-common/pom.xml | 5 +- .../camel-k-loader-yaml/pom.xml | 5 +- camel-k-runtime-core/pom.xml | 1 - camel-k-runtime-cron/pom.xml | 1 - camel-k-runtime-health/pom.xml | 1 - camel-k-runtime-knative/pom.xml | 2 +- camel-k-runtime-main/pom.xml | 2 - camel-k-runtime-servlet/pom.xml | 2 - camel-k-runtime-webhook/pom.xml | 1 - camel-knative/camel-knative-api/pom.xml | 2 - camel-knative/camel-knative-http/pom.xml | 2 - camel-knative/camel-knative/pom.xml | 2 - .../camel-k-runtime-example-health/pom.xml | 28 +- .../camel-k-runtime-example-knative/pom.xml | 35 +- .../pom.xml | 5 - .../camel-k-runtime-example-servlet/pom.xml | 21 - examples/camel-k-runtime-example-yaml/pom.xml | 31 +- tooling/camel-k-maven-plugin/pom.xml | 9 +- .../pom.xml | 13 +- .../verify.groovy | 10 +- .../src/it/generate-catalog-quarkus/pom.xml | 104 +++++ .../generate-catalog-quarkus/verify.groovy} | 21 +- .../k/tooling/maven/GenerateCatalogMojo.java | 237 +++------- .../camel/k/tooling/maven/model/Artifact.java | 53 +-- .../k/tooling/maven/model/CamelArtifact.java | 187 ++------ .../k/tooling/maven/model/CamelLoader.java | 60 +++ .../k/tooling/maven/model/CamelScheme.java | 60 +-- .../model/CatalogComponentDefinition.java | 29 +- .../model/CatalogDataFormatDefinition.java | 29 +- ...meProvider.java => CatalogDefinition.java} | 37 +- .../model/CatalogLanguageDefinition.java | 29 +- .../tooling/maven/model/CatalogProcessor.java | 5 +- .../k/tooling/maven/model/MavenArtifact.java | 50 ++ .../maven/model/crd/CamelCatalogSpec.java | 27 +- .../tooling/maven/model/crd/RuntimeSpec.java | 53 +++ .../maven/processors/CatalogProcessor3x.java | 440 ++++++++++-------- .../processors/CatalogProcessor3Test.java | 75 ++- 43 files changed, 771 insertions(+), 941 deletions(-) rename tooling/camel-k-maven-plugin/src/it/{generate-catalog => generate-catalog-main}/pom.xml (89%) rename tooling/camel-k-maven-plugin/src/it/{generate-catalog => generate-catalog-main}/verify.groovy (74%) create mode 100644 tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/pom.xml rename tooling/camel-k-maven-plugin/src/{main/java/org/apache/camel/k/tooling/maven/model/crd/RuntimeProvider.java => it/generate-catalog-quarkus/verify.groovy} (61%) create mode 100644 tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelLoader.java rename tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/{crd/QuarkusRuntimeProvider.java => CatalogDefinition.java} (56%) create mode 100644 tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/MavenArtifact.java create mode 100644 tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/RuntimeSpec.java diff --git a/camel-k-loader-groovy/pom.xml b/camel-k-loader-groovy/pom.xml index 118ed2ffc..c9d6052a6 100644 --- a/camel-k-loader-groovy/pom.xml +++ b/camel-k-loader-groovy/pom.xml @@ -35,17 +35,14 @@ org.apache.camel camel-core-engine - provided org.apache.camel camel-log - provided org.apache.camel camel-endpointdsl - provided org.apache.camel @@ -56,24 +53,22 @@ * - provided org.codehaus.groovy groovy ${groovy.version} - provided org.apache.camel.k camel-k-apt - true + provided org.apache.camel.k camel-k-annotations - true + provided diff --git a/camel-k-loader-java/pom.xml b/camel-k-loader-java/pom.xml index 153890190..f0636656c 100644 --- a/camel-k-loader-java/pom.xml +++ b/camel-k-loader-java/pom.xml @@ -35,12 +35,10 @@ org.apache.camel camel-core-engine - provided org.apache.camel camel-endpointdsl - provided org.jooq @@ -51,12 +49,12 @@ org.apache.camel.k camel-k-apt - true + provided org.apache.camel.k camel-k-annotations - true + provided diff --git a/camel-k-loader-js/pom.xml b/camel-k-loader-js/pom.xml index 7dbc524d9..dc9f1745b 100644 --- a/camel-k-loader-js/pom.xml +++ b/camel-k-loader-js/pom.xml @@ -35,13 +35,12 @@ org.apache.camel camel-core-engine - provided org.apache.camel camel-endpointdsl - provided + org.graalvm.js js @@ -51,12 +50,12 @@ org.apache.camel.k camel-k-apt - true + provided org.apache.camel.k camel-k-annotations - true + provided diff --git a/camel-k-loader-knative/pom.xml b/camel-k-loader-knative/pom.xml index d01149d80..425e0b7ce 100644 --- a/camel-k-loader-knative/pom.xml +++ b/camel-k-loader-knative/pom.xml @@ -35,18 +35,17 @@ org.apache.camel camel-core-engine - provided org.apache.camel.k camel-k-apt - true + provided org.apache.camel.k camel-k-annotations - true + provided diff --git a/camel-k-loader-kotlin/pom.xml b/camel-k-loader-kotlin/pom.xml index 9295b340e..161bb923a 100644 --- a/camel-k-loader-kotlin/pom.xml +++ b/camel-k-loader-kotlin/pom.xml @@ -35,17 +35,15 @@ org.apache.camel camel-core-engine - provided org.apache.camel camel-endpointdsl - provided org.apache.camel camel-log - provided + true org.jetbrains.kotlin @@ -76,7 +74,7 @@ org.apache.camel.k camel-k-annotations - true + provided diff --git a/camel-k-loader-xml/pom.xml b/camel-k-loader-xml/pom.xml index 4a285bc9b..700053785 100644 --- a/camel-k-loader-xml/pom.xml +++ b/camel-k-loader-xml/pom.xml @@ -43,18 +43,17 @@ org.apache.camel camel-core-engine - provided org.apache.camel.k camel-k-apt - true + provided org.apache.camel.k camel-k-annotations - true + provided diff --git a/camel-k-loader-yaml/camel-k-loader-yaml-common/pom.xml b/camel-k-loader-yaml/camel-k-loader-yaml-common/pom.xml index b1d1112d9..76f78eb1f 100644 --- a/camel-k-loader-yaml/camel-k-loader-yaml-common/pom.xml +++ b/camel-k-loader-yaml/camel-k-loader-yaml-common/pom.xml @@ -43,7 +43,6 @@ org.apache.camel camel-core-engine - provided @@ -58,12 +57,12 @@ org.apache.camel.k camel-k-apt - true + provided org.apache.camel.k camel-k-annotations - true + provided 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 20dd73b5c..da9f7ebce 100644 --- a/camel-k-loader-yaml/camel-k-loader-yaml/pom.xml +++ b/camel-k-loader-yaml/camel-k-loader-yaml/pom.xml @@ -47,7 +47,6 @@ org.apache.camel camel-core-engine - provided @@ -62,12 +61,12 @@ org.apache.camel.k camel-k-apt - true + provided org.apache.camel.k camel-k-annotations - true + provided diff --git a/camel-k-runtime-core/pom.xml b/camel-k-runtime-core/pom.xml index 83316076d..f4e133326 100644 --- a/camel-k-runtime-core/pom.xml +++ b/camel-k-runtime-core/pom.xml @@ -44,7 +44,6 @@ org.apache.camel camel-core-engine - provided diff --git a/camel-k-runtime-cron/pom.xml b/camel-k-runtime-cron/pom.xml index 5ee94b7d3..915809893 100644 --- a/camel-k-runtime-cron/pom.xml +++ b/camel-k-runtime-cron/pom.xml @@ -38,7 +38,6 @@ org.apache.camel camel-core-engine - provided org.apache.camel diff --git a/camel-k-runtime-health/pom.xml b/camel-k-runtime-health/pom.xml index 8386621dd..3eb0e2dc0 100644 --- a/camel-k-runtime-health/pom.xml +++ b/camel-k-runtime-health/pom.xml @@ -38,7 +38,6 @@ org.apache.camel camel-core-engine - provided org.apache.camel.k diff --git a/camel-k-runtime-knative/pom.xml b/camel-k-runtime-knative/pom.xml index 5ea6be0e2..843bb0547 100644 --- a/camel-k-runtime-knative/pom.xml +++ b/camel-k-runtime-knative/pom.xml @@ -36,6 +36,7 @@ org.apache.camel.k camel-knative-http + org.apache.camel.k camel-k-loader-yaml @@ -50,7 +51,6 @@ org.apache.camel camel-core-engine - provided diff --git a/camel-k-runtime-main/pom.xml b/camel-k-runtime-main/pom.xml index c37af825e..456d2b85d 100644 --- a/camel-k-runtime-main/pom.xml +++ b/camel-k-runtime-main/pom.xml @@ -43,12 +43,10 @@ org.apache.camel camel-core-engine - provided org.apache.camel camel-main - provided diff --git a/camel-k-runtime-servlet/pom.xml b/camel-k-runtime-servlet/pom.xml index 43c95bb0d..948297deb 100644 --- a/camel-k-runtime-servlet/pom.xml +++ b/camel-k-runtime-servlet/pom.xml @@ -38,12 +38,10 @@ org.apache.camel camel-core-engine - provided org.apache.camel camel-servlet - provided org.apache.camel.k diff --git a/camel-k-runtime-webhook/pom.xml b/camel-k-runtime-webhook/pom.xml index 42e151d07..86f04e26a 100644 --- a/camel-k-runtime-webhook/pom.xml +++ b/camel-k-runtime-webhook/pom.xml @@ -38,7 +38,6 @@ org.apache.camel camel-core-engine - provided org.apache.camel diff --git a/camel-knative/camel-knative-api/pom.xml b/camel-knative/camel-knative-api/pom.xml index d36f40a31..b8261e3a1 100644 --- a/camel-knative/camel-knative-api/pom.xml +++ b/camel-knative/camel-knative-api/pom.xml @@ -44,12 +44,10 @@ org.apache.camel camel-core-engine - provided org.apache.camel camel-cloud - provided diff --git a/camel-knative/camel-knative-http/pom.xml b/camel-knative/camel-knative-http/pom.xml index a200c8da0..c3c51f294 100644 --- a/camel-knative/camel-knative-http/pom.xml +++ b/camel-knative/camel-knative-http/pom.xml @@ -44,12 +44,10 @@ org.apache.camel camel-core-engine - provided org.apache.camel camel-cloud - provided diff --git a/camel-knative/camel-knative/pom.xml b/camel-knative/camel-knative/pom.xml index af22d8da0..6db1cb933 100644 --- a/camel-knative/camel-knative/pom.xml +++ b/camel-knative/camel-knative/pom.xml @@ -44,12 +44,10 @@ org.apache.camel camel-core-engine - provided org.apache.camel camel-cloud - provided org.apache.camel.k diff --git a/examples/camel-k-runtime-example-health/pom.xml b/examples/camel-k-runtime-example-health/pom.xml index 5e40bf539..83c34cb22 100644 --- a/examples/camel-k-runtime-example-health/pom.xml +++ b/examples/camel-k-runtime-example-health/pom.xml @@ -28,29 +28,6 @@ camel-k-runtime-example-health - - - - - - - - - org.apache.camel - camel-core-engine - - - org.apache.camel - camel-main - - - org.apache.camel - camel-log - - - org.apache.camel - camel-servlet - org.apache.camel.k camel-k-runtime-main @@ -68,9 +45,8 @@ camel-k-runtime-health - org.codehaus.groovy - groovy - ${groovy.version} + org.apache.camel + camel-log diff --git a/examples/camel-k-runtime-example-knative/pom.xml b/examples/camel-k-runtime-example-knative/pom.xml index 3db32708b..5c4e99d31 100644 --- a/examples/camel-k-runtime-example-knative/pom.xml +++ b/examples/camel-k-runtime-example-knative/pom.xml @@ -28,33 +28,6 @@ - - - - - - - - - org.apache.camel - camel-core-engine - - - org.apache.camel - camel-main - - - org.apache.camel - camel-log - - - org.apache.camel - camel-jackson - - - org.apache.camel - camel-cloud - org.apache.camel.k camel-k-runtime-main @@ -67,6 +40,14 @@ org.apache.camel.k camel-k-loader-yaml + + org.apache.camel + camel-log + + + org.apache.camel + camel-jackson + diff --git a/examples/camel-k-runtime-example-quarkus-yaml/pom.xml b/examples/camel-k-runtime-example-quarkus-yaml/pom.xml index 94b4184a7..75aba803b 100644 --- a/examples/camel-k-runtime-example-quarkus-yaml/pom.xml +++ b/examples/camel-k-runtime-example-quarkus-yaml/pom.xml @@ -67,11 +67,6 @@ org.apache.camel.quarkus camel-quarkus-timer - - - io.quarkus - quarkus-netty - diff --git a/examples/camel-k-runtime-example-servlet/pom.xml b/examples/camel-k-runtime-example-servlet/pom.xml index 0ae914add..20e1acd39 100644 --- a/examples/camel-k-runtime-example-servlet/pom.xml +++ b/examples/camel-k-runtime-example-servlet/pom.xml @@ -35,22 +35,6 @@ - - org.apache.camel - camel-core-engine - - - org.apache.camel - camel-main - - - org.apache.camel - camel-log - - - org.apache.camel - camel-servlet - org.apache.camel.k camel-k-runtime-main @@ -63,11 +47,6 @@ org.apache.camel.k camel-k-runtime-servlet - - org.codehaus.groovy - groovy - ${groovy.version} - diff --git a/examples/camel-k-runtime-example-yaml/pom.xml b/examples/camel-k-runtime-example-yaml/pom.xml index fb981bef9..bc8848655 100644 --- a/examples/camel-k-runtime-example-yaml/pom.xml +++ b/examples/camel-k-runtime-example-yaml/pom.xml @@ -28,20 +28,17 @@ camel-k-runtime-example-yaml - - - - - - - - org.apache.camel - camel-core-engine + org.apache.camel.k + camel-k-runtime-main - org.apache.camel - camel-main + org.apache.camel.k + camel-k-runtime-servlet + + + org.apache.camel.k + camel-k-loader-yaml org.apache.camel @@ -59,18 +56,6 @@ org.apache.camel camel-jackson - - org.apache.camel.k - camel-k-runtime-main - - - org.apache.camel.k - camel-k-runtime-servlet - - - org.apache.camel.k - camel-k-loader-yaml - diff --git a/tooling/camel-k-maven-plugin/pom.xml b/tooling/camel-k-maven-plugin/pom.xml index d4a391804..85668345d 100644 --- a/tooling/camel-k-maven-plugin/pom.xml +++ b/tooling/camel-k-maven-plugin/pom.xml @@ -84,23 +84,26 @@ + org.apache.camel camel-swagger-rest-dsl-generator ${camel.version} - provided org.apache.camel camel-catalog ${camel.version} - provided org.apache.camel.quarkus camel-catalog-quarkus ${camel-quarkus.version} - provided + + + org.apache.camel.quarkus + camel-quarkus-core + ${camel-quarkus.version} org.yaml diff --git a/tooling/camel-k-maven-plugin/src/it/generate-catalog/pom.xml b/tooling/camel-k-maven-plugin/src/it/generate-catalog-main/pom.xml similarity index 89% rename from tooling/camel-k-maven-plugin/src/it/generate-catalog/pom.xml rename to tooling/camel-k-maven-plugin/src/it/generate-catalog-main/pom.xml index 7dbd03290..bbdc7baab 100644 --- a/tooling/camel-k-maven-plugin/src/it/generate-catalog/pom.xml +++ b/tooling/camel-k-maven-plugin/src/it/generate-catalog-main/pom.xml @@ -29,8 +29,10 @@ ${project.basedir} - 3.0.0-RC3 - 1.0.5 + main + catalog.yaml + + 1.0.11-SNAPSHOT @@ -47,13 +49,6 @@ - - - org.apache.camel - camel-catalog - ${camel.version} - - diff --git a/tooling/camel-k-maven-plugin/src/it/generate-catalog/verify.groovy b/tooling/camel-k-maven-plugin/src/it/generate-catalog-main/verify.groovy similarity index 74% rename from tooling/camel-k-maven-plugin/src/it/generate-catalog/verify.groovy rename to tooling/camel-k-maven-plugin/src/it/generate-catalog-main/verify.groovy index 00d99b1bf..7ca710bd4 100644 --- a/tooling/camel-k-maven-plugin/src/it/generate-catalog/verify.groovy +++ b/tooling/camel-k-maven-plugin/src/it/generate-catalog-main/verify.groovy @@ -14,13 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -def catalogVersion = '3.0.0-RC3' -def runtimeVersion = '1.0.5' +def runtimeVersion = '1.0.11-SNAPSHOT' -def source = new File(basedir, "camel-catalog-${catalogVersion}-${runtimeVersion}.yaml") +def source = new File(basedir, "catalog.yaml") def catalog = new org.yaml.snakeyaml.Yaml().load(new FileInputStream(source)) -assert catalog.spec.version == catalogVersion -assert catalog.spec.runtimeVersion == runtimeVersion -assert catalog.metadata.labels['camel.apache.org/catalog.version'] == catalogVersion +assert catalog.spec.runtime.version == runtimeVersion +assert catalog.spec.runtime.applicationClass == 'org.apache.camel.k.main.Application' assert catalog.metadata.labels['camel.apache.org/runtime.version'] == runtimeVersion \ No newline at end of file diff --git a/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/pom.xml b/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/pom.xml new file mode 100644 index 000000000..63e6f7726 --- /dev/null +++ b/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/pom.xml @@ -0,0 +1,104 @@ + + + + + + 4.0.0 + org.apache.camel.k + camel-k-catalog-generator + 1.0.0 + + + ${project.basedir} + quarkus + catalog.yaml + + 1.0.11-SNAPSHOT + + + + + + org.apache.camel.k + camel-k-maven-plugin + ${runtime.version} + + + generate-catalog + + generate-catalog + + + + + + + + + + apache.snapshots + Apache Development Snapshot Repository + https://repository.apache.org/content/repositories/snapshots/ + + false + + + true + + + + oss.snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + + + + apache.snapshots + Apache Development Snapshot Repository + https://repository.apache.org/content/repositories/snapshots/ + + false + + + true + + + + oss.snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + + diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/RuntimeProvider.java b/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/verify.groovy similarity index 61% rename from tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/RuntimeProvider.java rename to tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/verify.groovy index 192022981..a2f8d2d0a 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/RuntimeProvider.java +++ b/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/verify.groovy @@ -14,20 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.k.tooling.maven.model.crd; +def runtimeVersion = '1.0.11-SNAPSHOT' -import java.util.Optional; +def source = new File(basedir, "catalog.yaml") +def catalog = new org.yaml.snakeyaml.Yaml().load(new FileInputStream(source)) -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import org.immutables.value.Value; - -@Value.Immutable -@JsonDeserialize(builder = RuntimeProvider.Builder.class) -@JsonPropertyOrder({ "quarkus" }) -public interface RuntimeProvider { - Optional getQuarkus(); - - class Builder extends ImmutableRuntimeProvider.Builder { - } -} +assert catalog.spec.runtime.version == runtimeVersion +assert catalog.spec.runtime.applicationClass == 'io.quarkus.runner.GeneratedMain' +assert catalog.metadata.labels['camel.apache.org/runtime.version'] == runtimeVersion \ No newline at end of file diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateCatalogMojo.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateCatalogMojo.java index 39a452c21..cd62f2e9e 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateCatalogMojo.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateCatalogMojo.java @@ -24,13 +24,9 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Comparator; -import java.util.Map; -import java.util.Objects; import java.util.Properties; import java.util.ServiceLoader; -import java.util.SortedMap; -import java.util.TreeMap; -import java.util.regex.Pattern; +import java.util.function.Consumer; import java.util.stream.StreamSupport; import com.fasterxml.jackson.annotation.JsonInclude; @@ -39,18 +35,15 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import org.apache.camel.catalog.DefaultCamelCatalog; -import org.apache.camel.k.tooling.maven.model.CamelArtifact; -import org.apache.camel.k.tooling.maven.model.CatalogComponentDefinition; -import org.apache.camel.k.tooling.maven.model.CatalogDataFormatDefinition; -import org.apache.camel.k.tooling.maven.model.CatalogLanguageDefinition; +import org.apache.camel.catalog.DefaultRuntimeProvider; +import org.apache.camel.catalog.quarkus.QuarkusRuntimeProvider; +import org.apache.camel.impl.engine.AbstractCamelContext; import org.apache.camel.k.tooling.maven.model.CatalogProcessor; -import org.apache.camel.k.tooling.maven.model.CatalogSupport; import org.apache.camel.k.tooling.maven.model.crd.CamelCatalog; import org.apache.camel.k.tooling.maven.model.crd.CamelCatalogSpec; -import org.apache.camel.k.tooling.maven.model.crd.QuarkusRuntimeProvider; -import org.apache.camel.k.tooling.maven.model.crd.RuntimeProvider; +import org.apache.camel.k.tooling.maven.model.crd.RuntimeSpec; import org.apache.camel.k.tooling.maven.model.k8s.ObjectMeta; -import org.apache.commons.lang3.StringUtils; +import org.apache.camel.quarkus.core.FastCamelContext; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -74,10 +67,10 @@ public class GenerateCatalogMojo extends AbstractMojo { @Parameter(property = "catalog.path", defaultValue = "${project.build.directory}") private String outputPath; - @Parameter(property = "catalog.file", defaultValue = "camel-catalog-${camel.version}-${runtime.version}.yaml") + @Parameter(property = "catalog.file", defaultValue = "camel-catalog-${runtime.version}.yaml") private String outputFile; - @Parameter(property = "catalog.runtime", defaultValue = "") + @Parameter(property = "catalog.runtime", defaultValue = "main") private String runtime; // ******************** @@ -100,48 +93,79 @@ public void execute() throws MojoExecutionException, MojoFailureException { throw new MojoExecutionException("Exception while generating camel catalog", e); } - final SortedMap artifacts = new TreeMap<>(); final org.apache.camel.catalog.CamelCatalog catalog = new DefaultCamelCatalog(); - if (runtime == null) { - runtime = ""; - } - switch (runtime) { - case "quarkus": - catalog.setRuntimeProvider(new org.apache.camel.catalog.quarkus.QuarkusRuntimeProvider()); - break; - case "": - break; - default: - throw new IllegalArgumentException("catalog.runtime parameter value [" + runtime + "] is not supported!"); - } + final String runtimeVersion = getVersion(getClass(), "/META-INF/maven/org.apache.camel.k/camel-k-maven-plugin/pom.properties"); + final String catalogName = String.format("camel-catalog-%s-%s", runtimeVersion.toLowerCase(), runtime); try { - processComponents(catalog, artifacts); - processLanguages(catalog, artifacts); - processDataFormats(catalog, artifacts); - ServiceLoader processors = ServiceLoader.load(CatalogProcessor.class); Comparator comparator = Comparator.comparingInt(CatalogProcessor::getOrder); - // - // post process catalog - // + RuntimeSpec.Builder runtimeSpec = new RuntimeSpec.Builder() + .version(runtimeVersion) + .provider(runtime); + + getVersion( + AbstractCamelContext.class, + "org.apache.camel", "camel-base", + version -> runtimeSpec.putMetadata("camel.version", version)); + getVersion( + FastCamelContext.class, + "io.quarkus", "quarkus-core", + version -> runtimeSpec.putMetadata("quarkus.version", version)); + getVersion( + QuarkusRuntimeProvider.class, + "org.apache.camel.quarkus", "camel-catalog-quarkus", + version -> runtimeSpec.putMetadata("camel-quarkus.version", version)); + + switch (runtime) { + case "main": + catalog.setRuntimeProvider(new DefaultRuntimeProvider()); + runtimeSpec.applicationClass("org.apache.camel.k.main.Application"); + runtimeSpec.addDependency("org.apache.camel.k", "camel-k-runtime-main"); + break; + case "quarkus": + catalog.setRuntimeProvider(new QuarkusRuntimeProvider()); + runtimeSpec.applicationClass("io.quarkus.runner.GeneratedMain"); + runtimeSpec.addDependency("org.apache.camel.k", "camel-k-runtime-quarkus"); + break; + default: + throw new IllegalArgumentException("catalog.runtime parameter value [" + runtime + "] is not supported!"); + } + + CamelCatalogSpec.Builder catalogSpec = new CamelCatalogSpec.Builder() + .runtime(runtimeSpec.build()); + StreamSupport.stream(processors.spliterator(), false).sorted(comparator).filter(p -> p.accepts(catalog)).forEach(p -> { getLog().info("Executing processor: " + p.getClass().getName()); - p.process(project, catalog, artifacts); + p.process(project, catalog, catalogSpec); }); + ObjectMeta.Builder metadata = new ObjectMeta.Builder() + .name(catalogName) + .putLabels("app", "camel-k") + .putLabels("camel.apache.org/catalog.version", catalog.getCatalogVersion()) + .putLabels("camel.apache.org/catalog.loader.version", catalog.getLoadedVersion()) + .putLabels("camel.apache.org/runtime.version", runtimeVersion) + .putLabels("camel.apache.org/runtime.provider", runtime); + + CamelCatalog cr = new CamelCatalog.Builder() + .metadata(metadata.build()) + .spec(catalogSpec.build()) + .build(); + // // apiVersion: camel.apache.org/v1 // kind: CamelCatalog // metadata: - // name: catalog-x.y.z-a.b.c + // name: catalog-x.y.z-main // labels: // app: "camel-k" // camel.apache.org/catalog.version: x.y.x // camel.apache.org/catalog.loader.version: x.y.z // camel.apache.org/runtime.version: x.y.x + // camel.apache.org/runtime.provider: main // spec: // version: // runtimeVersion: @@ -149,50 +173,6 @@ public void execute() throws MojoExecutionException, MojoFailureException { // artifacts: // try (Writer writer = Files.newBufferedWriter(output, StandardCharsets.UTF_8)) { - String catalogName; - if ("quarkus".equals(runtime)) { - catalogName = String.format("camel-catalog-%s-%s-%s", - runtime, - getVersionFor("/META-INF/maven/org.apache.camel.quarkus/camel-catalog-quarkus/pom.properties").toLowerCase(), - getRuntimeVersion().toLowerCase() - ); - } else { - catalogName = String.format("camel-catalog-%s-%s", - catalog.getCatalogVersion().toLowerCase(), - getRuntimeVersion().toLowerCase() - ); - } - - ObjectMeta.Builder labels = new ObjectMeta.Builder() - .name(catalogName) - .putLabels("app", "camel-k") - .putLabels("camel.apache.org/catalog.version", catalog.getCatalogVersion()) - .putLabels("camel.apache.org/catalog.loader.version", catalog.getLoadedVersion()) - .putLabels("camel.apache.org/runtime.version", getRuntimeVersion()); - if (!"".equals(runtime)) { - labels.putLabels("camel.apache.org/runtime.provider", runtime); - } - - CamelCatalogSpec.Builder catalogSpec = new CamelCatalogSpec.Builder() - .version(catalog.getCatalogVersion()) - .runtimeVersion(getRuntimeVersion()) - .artifacts(artifacts); - - if ("quarkus".equals(runtime)) { - String camelQuarkusVersion = getVersionFor("/META-INF/maven/org.apache.camel.quarkus/camel-catalog-quarkus/pom.properties"); - String quarkusVersion = getVersionFor("/META-INF/maven/io.quarkus/quarkus-core/pom.properties"); - catalogSpec.runtimeProvider(new RuntimeProvider.Builder() - .quarkus(new QuarkusRuntimeProvider.Builder() - .camelQuarkusVersion(camelQuarkusVersion) - .quarkusVersion(quarkusVersion) - .build()) - .build()); - } - - CamelCatalog cr = new CamelCatalog.Builder() - .metadata(labels.build()) - .spec(catalogSpec.build()) - .build(); YAMLFactory factory = new YAMLFactory() .configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true) @@ -200,7 +180,6 @@ public void execute() throws MojoExecutionException, MojoFailureException { .configure(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID, false) .configure(YAMLGenerator.Feature.WRITE_DOC_START_MARKER, false); - // write license header writer.write( GenerateSupport.getResourceAsString("/catalog-license.txt") @@ -220,95 +199,29 @@ public void execute() throws MojoExecutionException, MojoFailureException { } } - private void processComponents(org.apache.camel.catalog.CamelCatalog catalog, Map artifacts) { - for (String name : catalog.findComponentNames()) { - String json = catalog.componentJSonSchema(name); - - if ("rest-swagger".equalsIgnoreCase(name)) { - // TODO: workaround for https://issues.apache.org/jira/browse/CAMEL-13588 - json = json.replaceAll(Pattern.quote("\\h"), "h"); - } - - CatalogComponentDefinition definition = CatalogSupport.unmarshallComponent(json); - - artifacts.compute(definition.getArtifactId(), (key, artifact) -> { - if (artifact == null) { - artifact = new CamelArtifact(); - artifact.setGroupId(definition.getGroupId()); - artifact.setArtifactId(definition.getArtifactId()); - - Objects.requireNonNull(artifact.getGroupId()); - Objects.requireNonNull(artifact.getArtifactId()); - } - - definition.getSchemes() - .map(StringUtils::trimToNull) - .filter(Objects::nonNull) - .forEach(artifact::createScheme); - - artifact.addJavaType(definition.getJavaType()); - - return artifact; - }); - } - } - - private void processLanguages(org.apache.camel.catalog.CamelCatalog catalog, Map artifacts) { - for (String name : catalog.findLanguageNames()) { - String json = catalog.languageJSonSchema(name); - CatalogLanguageDefinition definition = CatalogSupport.unmarshallLanguage(json); - - artifacts.compute(definition.getArtifactId(), (key, artifact) -> { - if (artifact == null) { - artifact = new CamelArtifact(); - artifact.setGroupId(definition.getGroupId()); - artifact.setArtifactId(definition.getArtifactId()); - - Objects.requireNonNull(artifact.getGroupId()); - Objects.requireNonNull(artifact.getArtifactId()); - } - - artifact.addLanguage(definition.getName()); - artifact.addJavaType(definition.getJavaType()); - - return artifact; - }); - } + private static void getVersion(Class clazz, String path, Consumer consumer) { + consumer.accept(getVersion(clazz, path)); } - private void processDataFormats(org.apache.camel.catalog.CamelCatalog catalog, Map artifacts) { - for (String name : catalog.findDataFormatNames()) { - String json = catalog.dataFormatJSonSchema(name); - CatalogDataFormatDefinition definition = CatalogSupport.unmarshallDataFormat(json); - - artifacts.compute(definition.getArtifactId(), (key, artifact) -> { - if (artifact == null) { - artifact = new CamelArtifact(); - artifact.setGroupId(definition.getGroupId()); - artifact.setArtifactId(definition.getArtifactId()); - - Objects.requireNonNull(artifact.getGroupId()); - Objects.requireNonNull(artifact.getArtifactId()); - } - - artifact.addDataformats(definition.getName()); - artifact.addJavaType(definition.getJavaType()); - - return artifact; - }); - } + private static void getVersion(Class clazz, String groupId, String artifactId, Consumer consumer) { + getVersion( + clazz, + String.format("/META-INF/maven/%s/%s/pom.properties", groupId, artifactId), + consumer); } - private String getRuntimeVersion() { - return getVersionFor("/META-INF/maven/org.apache.camel.k/camel-k-maven-plugin/pom.properties"); + private static synchronized String getVersion(Class clazz, String groupId, String artifactId) { + return getVersion( + clazz, + String.format("/META-INF/maven/%s/%s/pom.properties", groupId, artifactId)); } - private synchronized String getVersionFor(String path) { + private static synchronized String getVersion(Class clazz, String path) { String version = null; // try to load from maven properties first try { - InputStream is = getClass().getResourceAsStream(path); + InputStream is = clazz.getResourceAsStream(path); if (is != null) { Properties p = new Properties(); @@ -321,7 +234,7 @@ private synchronized String getVersionFor(String path) { // fallback to using Java API if (version == null) { - Package aPackage = getClass().getPackage(); + Package aPackage = clazz.getPackage(); if (aPackage != null) { version = aPackage.getImplementationVersion(); if (version == null) { diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/Artifact.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/Artifact.java index 86ce6eb1b..d378ab00e 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/Artifact.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/Artifact.java @@ -16,53 +16,10 @@ */ package org.apache.camel.k.tooling.maven.model; -import java.util.Objects; +import java.util.Optional; -public class Artifact { - private String groupId; - private String artifactId; - private String version; - - public String getGroupId() { - return groupId; - } - - public void setGroupId(String groupId) { - this.groupId = groupId; - } - - public String getArtifactId() { - return artifactId; - } - - public void setArtifactId(String artifactId) { - this.artifactId = artifactId; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Artifact artifact = (Artifact) o; - - return Objects.equals(groupId, artifact.groupId) - && Objects.equals(artifactId, artifact.artifactId); - } - - @Override - public int hashCode() { - return Objects.hash(groupId, artifactId); - } +public interface Artifact { + String getGroupId();; + String getArtifactId(); + Optional getVersion(); } diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelArtifact.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelArtifact.java index 7c2b16f1f..d03191973 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelArtifact.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelArtifact.java @@ -16,171 +16,54 @@ */ package org.apache.camel.k.tooling.maven.model; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.Collections; +import java.util.Set; -public class CamelArtifact extends Artifact { - private List schemes; - private List languages; - private List dataformats; - private List dependencies; - private List exclusions; - private List javaTypes; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; - public CamelArtifact() { - this.schemes = new ArrayList<>(); - this.languages = new ArrayList<>(); - this.dataformats = new ArrayList<>(); - this.dependencies = new ArrayList<>(); - this.exclusions = new ArrayList<>(); - this.javaTypes = new ArrayList<>(); +@Value.Immutable +@Value.Style(depluralize = true) +@JsonDeserialize(builder = CamelArtifact.Builder.class) +@JsonPropertyOrder({"groupId", "artifactId", "version"}) +public interface CamelArtifact extends Artifact { + @Value.Auxiliary + @Value.Default + default Set getSchemes() { + return Collections.emptySet(); } - public void setSchemes(List schemes) { - this.schemes = schemes; + @Value.Auxiliary + @Value.Default + default Set getLanguages() { + return Collections.emptySet(); } - public void addScheme(CamelScheme scheme) { - if (!this.schemes.contains(scheme)) { - this.schemes.add(scheme); - } + @Value.Auxiliary + @Value.Default + default Set getDataformats() { + return Collections.emptySet(); } - public List getLanguages() { - return languages; + @Value.Auxiliary + @Value.Default + default Set getDependencies() { + return Collections.emptySet(); } - public void setLanguages(List languages) { - this.languages = languages; + @Value.Auxiliary + @Value.Default + default Set getExclusions() { + return Collections.emptySet(); } - public void addLanguage(String language) { - if (!this.languages.contains(language)) { - this.languages.add(language); - } + @Value.Auxiliary + @Value.Default + default Set getJavaTypes() { + return Collections.emptySet(); } - public List getDataformats() { - return dataformats; - } - - public void setDataformats(List dataformats) { - this.dataformats = dataformats; - } - - public void addDataformats(String dataformat) { - if (!this.dataformats.contains(dataformat)) { - this.dataformats.add(dataformat); - } - } - - public List getSchemes() { - return schemes; - } - - public Optional getScheme(String id) { - return schemes.stream().filter(s -> Objects.equals(s.getId(), id)).findFirst(); - } - - public CamelScheme createScheme(String id) { - for (CamelScheme scheme: schemes) { - if (scheme.getId().equals(id)) { - return scheme; - } - } - - - CamelScheme answer = new CamelScheme(); - answer.setId(id); - - schemes.add(answer); - - return answer; - } - - public List getDependencies() { - return dependencies; - } - - public void setDependencies(List dependencies) { - this.dependencies = dependencies; - } - - public void addDependency(Artifact dependency) { - if (!this.dependencies.contains(dependency)) { - this.dependencies.add(dependency); - } - } - - public void addDependency(String groupId, String artifactId) { - Artifact artifact = new Artifact(); - artifact.setGroupId(groupId); - artifact.setArtifactId(artifactId); - - addDependency(artifact); - } - - public void addDependency(String groupId, String artifactId, String version) { - Artifact artifact = new Artifact(); - artifact.setGroupId(groupId); - artifact.setArtifactId(artifactId); - artifact.setVersion(version); - - addDependency(artifact); - } - - public List getExclusions() { - return exclusions; - } - - public void setExclusions(List exclusions) { - this.exclusions = exclusions; - } - - public void addExclusion(Artifact exclusion) { - if (!this.exclusions.contains(exclusion)) { - this.exclusions.add(exclusion); - } - } - - public void addExclusion(String groupId, String artifactId) { - Artifact artifact = new Artifact(); - artifact.setGroupId(groupId); - artifact.setArtifactId(artifactId); - - addExclusion(artifact); - } - - public List getJavaTypes() { - return javaTypes; - } - - public void setJavaTypes(List javaTypes) { - this.javaTypes = javaTypes; - } - - public void addJavaType(String javaType) { - if (!this.javaTypes.contains(javaType)) { - this.javaTypes.add(javaType); - } - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - CamelArtifact artifact = (CamelArtifact) o; - return Objects.equals(getArtifactId(), artifact.getArtifactId()); - } - - @Override - public int hashCode() { - return Objects.hash(getArtifactId()); + class Builder extends ImmutableCamelArtifact.Builder { } } diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelLoader.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelLoader.java new file mode 100644 index 000000000..b051ddb48 --- /dev/null +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelLoader.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.k.tooling.maven.model; + +import java.util.Collections; +import java.util.Map; +import java.util.Set; + +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +@Value.Immutable +@Value.Style(depluralize = true) +@JsonDeserialize(builder = CamelLoader.Builder.class) +@JsonPropertyOrder({"groupId", "artifactId", "version"}) +public interface CamelLoader extends Artifact { + @Value.Auxiliary + @Value.Default + default Set getLanguages() { + return Collections.emptySet(); + } + + @Value.Auxiliary + @Value.Default + default Set getDependencies() { + return Collections.emptySet(); + } + + @Value.Auxiliary + @Value.Default + default Map getMetadata() { + return Collections.emptyMap(); + } + + static Builder fromArtifact(String groupId, String artifactId) { + return new Builder().groupId(groupId).artifactId(artifactId); + } + + class Builder extends ImmutableCamelLoader.Builder { + public Builder addDependency(String groupId, String artifactId) { + addDependencies(MavenArtifact.from(groupId, artifactId)); + return this; + } + } +} diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelScheme.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelScheme.java index 51c022707..6edcb8a17 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelScheme.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelScheme.java @@ -16,56 +16,26 @@ */ package org.apache.camel.k.tooling.maven.model; -import java.util.Objects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; -public class CamelScheme { - private String id; - private boolean http; - private boolean passive; +@Value.Immutable +@JsonDeserialize(builder = CamelScheme.Builder.class) +public interface CamelScheme { + String getId(); - public CamelScheme() { + @Value.Auxiliary + @Value.Default + default boolean http() { + return false; } - public String getId() { - return id; + @Value.Auxiliary + @Value.Default + default boolean passive() { + return false; } - public void setId(String id) { - this.id = id; - } - - public boolean isHttp() { - return http; - } - - public void setHttp(boolean http) { - this.http = http; - } - - public boolean isPassive() { - return passive; - } - - public void setPassive(boolean passive) { - this.passive = passive; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - CamelScheme scheme = (CamelScheme) o; - return isHttp() == scheme.isHttp() - && isPassive() == scheme.isPassive() - && Objects.equals(getId(), scheme.getId()); - } - - @Override - public int hashCode() { - return Objects.hash(getId(), isHttp(), isPassive()); + class Builder extends ImmutableCamelScheme.Builder { } } diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogComponentDefinition.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogComponentDefinition.java index 7cb656656..929f7725e 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogComponentDefinition.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogComponentDefinition.java @@ -24,11 +24,8 @@ import org.apache.commons.lang3.StringUtils; @JsonIgnoreProperties(ignoreUnknown = true) -public final class CatalogComponentDefinition { +public final class CatalogComponentDefinition extends CatalogDefinition { private String scheme; - private String groupId; - private String artifactId; - private String version; private String alternativeSchemes; private String javaType; @@ -49,30 +46,6 @@ public void setScheme(String scheme) { this.scheme = scheme; } - public String getGroupId() { - return groupId; - } - - public void setGroupId(String groupId) { - this.groupId = groupId; - } - - public String getArtifactId() { - return artifactId; - } - - public void setArtifactId(String artifactId) { - this.artifactId = artifactId; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - public String getAlternativeSchemes() { return alternativeSchemes; } diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogDataFormatDefinition.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogDataFormatDefinition.java index 01b43cd7a..1ade47c4c 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogDataFormatDefinition.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogDataFormatDefinition.java @@ -21,11 +21,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) -public final class CatalogDataFormatDefinition { +public final class CatalogDataFormatDefinition extends CatalogDefinition { private String name; - private String groupId; - private String artifactId; - private String version; private String javaType; public String getName() { @@ -36,30 +33,6 @@ public void setName(String name) { this.name = name; } - public String getGroupId() { - return groupId; - } - - public void setGroupId(String groupId) { - this.groupId = groupId; - } - - public String getArtifactId() { - return artifactId; - } - - public void setArtifactId(String artifactId) { - this.artifactId = artifactId; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - public String getJavaType() { return javaType; } diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/QuarkusRuntimeProvider.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogDefinition.java similarity index 56% rename from tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/QuarkusRuntimeProvider.java rename to tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogDefinition.java index 6858f3c21..a42389428 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/QuarkusRuntimeProvider.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogDefinition.java @@ -14,19 +14,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.k.tooling.maven.model.crd; +package org.apache.camel.k.tooling.maven.model; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import org.immutables.value.Value; +public class CatalogDefinition { + private String groupId; + private String artifactId; + private String version; -@Value.Immutable -@JsonDeserialize(builder = QuarkusRuntimeProvider.Builder.class) -@JsonPropertyOrder({ "camelQuarkusVersion", "quarkusVersion" }) -public interface QuarkusRuntimeProvider { - String getCamelQuarkusVersion(); - String getQuarkusVersion(); + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getArtifactId() { + return artifactId; + } + + public void setArtifactId(String artifactId) { + this.artifactId = artifactId; + } + + public String getVersion() { + return version; + } - class Builder extends ImmutableQuarkusRuntimeProvider.Builder { + public void setVersion(String version) { + this.version = version; } } diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogLanguageDefinition.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogLanguageDefinition.java index 7c9134b6a..d2d0f204b 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogLanguageDefinition.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogLanguageDefinition.java @@ -21,11 +21,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) -public final class CatalogLanguageDefinition { +public final class CatalogLanguageDefinition extends CatalogDefinition { private String name; - private String groupId; - private String artifactId; - private String version; private String javaType; public String getName() { @@ -36,30 +33,6 @@ public void setName(String name) { this.name = name; } - public String getGroupId() { - return groupId; - } - - public void setGroupId(String groupId) { - this.groupId = groupId; - } - - public String getArtifactId() { - return artifactId; - } - - public void setArtifactId(String artifactId) { - this.artifactId = artifactId; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - public String getJavaType() { return javaType; } diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogProcessor.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogProcessor.java index 95ceb3106..999aa99bd 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogProcessor.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CatalogProcessor.java @@ -16,9 +16,8 @@ */ package org.apache.camel.k.tooling.maven.model; -import java.util.Map; - import org.apache.camel.catalog.CamelCatalog; +import org.apache.camel.k.tooling.maven.model.crd.CamelCatalogSpec; import org.apache.maven.project.MavenProject; public interface CatalogProcessor { @@ -34,7 +33,7 @@ public interface CatalogProcessor { boolean accepts(CamelCatalog catalog); - void process(MavenProject project, CamelCatalog catalog, Map artifacts); + void process(MavenProject project, CamelCatalog catalog, CamelCatalogSpec.Builder specBuilder); default int getOrder() { return LOWEST; diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/MavenArtifact.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/MavenArtifact.java new file mode 100644 index 000000000..b864ce1aa --- /dev/null +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/MavenArtifact.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.k.tooling.maven.model; + +import java.util.Optional; + +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +@Value.Immutable +@JsonDeserialize(builder = MavenArtifact.Builder.class) +@JsonPropertyOrder({"groupId", "artifactId", "version"}) +public interface MavenArtifact extends Artifact { + static MavenArtifact from(String groupId, String artifactId) { + return new MavenArtifact() { + @Override + public String getGroupId() { + return groupId; + } + + @Override + public String getArtifactId() { + return artifactId; + } + + @Override + public Optional getVersion() { + return Optional.empty(); + } + }; + } + + class Builder extends ImmutableMavenArtifact.Builder { + } +} diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/CamelCatalogSpec.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/CamelCatalogSpec.java index f41d2e7d6..f0960562b 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/CamelCatalogSpec.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/CamelCatalogSpec.java @@ -17,28 +17,39 @@ package org.apache.camel.k.tooling.maven.model.crd; import java.util.Collections; -import java.util.Optional; -import java.util.SortedMap; +import java.util.Map; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.apache.camel.k.tooling.maven.model.CamelArtifact; +import org.apache.camel.k.tooling.maven.model.CamelLoader; import org.immutables.value.Value; @Value.Immutable +@Value.Style(depluralize = true) @JsonDeserialize(builder = CamelCatalogSpec.Builder.class) -@JsonPropertyOrder({ "version", "runtimeVersion", "runtimeProvider", "artifacts" }) +@JsonPropertyOrder({ "runtime", "artifacts" }) public interface CamelCatalogSpec { - String getVersion(); - String getRuntimeVersion(); + RuntimeSpec getRuntime(); - Optional getRuntimeProvider(); + @Value.Default + default Map getArtifacts() { + return Collections.emptyMap(); + } @Value.Default - default SortedMap getArtifacts() { - return Collections.emptySortedMap(); + default Map getLoaders() { + return Collections.emptyMap(); } class Builder extends ImmutableCamelCatalogSpec.Builder { + public Builder putArtifact(CamelArtifact artifact) { + putArtifact(artifact.getArtifactId(), artifact); + return this; + } + public Builder putArtifact(String groupId, String artifactId) { + putArtifact(new CamelArtifact.Builder().groupId(groupId).artifactId(artifactId).build()); + return this; + } } } diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/RuntimeSpec.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/RuntimeSpec.java new file mode 100644 index 000000000..ee1b3f752 --- /dev/null +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/RuntimeSpec.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.k.tooling.maven.model.crd; + +import java.util.Collections; +import java.util.Map; +import java.util.Set; + +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.apache.camel.k.tooling.maven.model.MavenArtifact; +import org.immutables.value.Value; + +@Value.Immutable +@Value.Style(depluralize = true) +@JsonDeserialize(builder = RuntimeSpec.Builder.class) +@JsonPropertyOrder({ "version", "runtimeVersion", "artifacts" }) +public interface RuntimeSpec { + String getVersion(); + String getProvider(); + String getApplicationClass(); + + @Value.Default + default Map getMetadata() { + return Collections.emptyMap(); + } + + @Value.Default + default Set getDependencies() { + return Collections.emptySet(); + } + + class Builder extends ImmutableRuntimeSpec.Builder { + public Builder addDependency(String groupId, String artifactId) { + addDependencies(MavenArtifact.from(groupId, artifactId)); + return this; + } + } +} diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java index 3d26b5dbb..0fe6453fe 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java @@ -17,13 +17,26 @@ package org.apache.camel.k.tooling.maven.processors; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import com.vdurmont.semver4j.Semver; import org.apache.camel.catalog.CamelCatalog; +import org.apache.camel.catalog.quarkus.QuarkusRuntimeProvider; import org.apache.camel.k.tooling.maven.model.CamelArtifact; +import org.apache.camel.k.tooling.maven.model.CamelLoader; +import org.apache.camel.k.tooling.maven.model.CamelScheme; +import org.apache.camel.k.tooling.maven.model.CatalogComponentDefinition; +import org.apache.camel.k.tooling.maven.model.CatalogDataFormatDefinition; +import org.apache.camel.k.tooling.maven.model.CatalogDefinition; +import org.apache.camel.k.tooling.maven.model.CatalogLanguageDefinition; import org.apache.camel.k.tooling.maven.model.CatalogProcessor; +import org.apache.camel.k.tooling.maven.model.CatalogSupport; +import org.apache.camel.k.tooling.maven.model.MavenArtifact; +import org.apache.camel.k.tooling.maven.model.crd.CamelCatalogSpec; +import org.apache.commons.lang3.StringUtils; import org.apache.maven.project.MavenProject; public class CatalogProcessor3x implements CatalogProcessor { @@ -79,220 +92,251 @@ public boolean accepts(CamelCatalog catalog) { } @Override - public void process(MavenProject project, CamelCatalog catalog, Map artifacts) { - - // ************************ - // - // camel-k-runtime-main - // - // ************************ - - { - CamelArtifact artifact = new CamelArtifact(); - artifact.setGroupId("org.apache.camel.k"); - artifact.setArtifactId("camel-k-runtime-main"); - artifact.addDependency("org.apache.camel", "camel-core-engine"); - artifact.addDependency("org.apache.camel", "camel-main"); - - artifacts.put(artifact.getArtifactId(), artifact); - } - - // ************************ - // - // camel-k-loader-groovy - // - // ************************ - - { - CamelArtifact artifact = new CamelArtifact(); - artifact.setGroupId("org.apache.camel.k"); - artifact.setArtifactId("camel-k-loader-groovy"); - artifact.addDependency("org.apache.camel", "camel-endpointdsl"); - artifact.addDependency("org.apache.camel", "camel-groovy"); - - artifacts.put(artifact.getArtifactId(), artifact); - } - - // ************************ - // - // camel-k-loader-kotlin - // - // ************************ - - { - CamelArtifact artifact = new CamelArtifact(); - artifact.setGroupId("org.apache.camel.k"); - artifact.setArtifactId("camel-k-loader-kotlin"); - artifact.addDependency("org.apache.camel", "camel-endpointdsl"); - - artifacts.put(artifact.getArtifactId(), artifact); - } - - // ************************ - // - // camel-k-loader-js - // - // ************************ - - { - CamelArtifact artifact = new CamelArtifact(); - artifact.setGroupId("org.apache.camel.k"); - artifact.setArtifactId("camel-k-loader-js"); - artifact.addDependency("org.apache.camel", "camel-endpointdsl"); - - artifacts.put(artifact.getArtifactId(), artifact); - } - - // ************************ - // - // camel-k-loader-xml - // - // ************************ - - { - CamelArtifact artifact = new CamelArtifact(); - artifact.setGroupId("org.apache.camel.k"); - artifact.setArtifactId("camel-k-loader-xml"); - - artifacts.put(artifact.getArtifactId(), artifact); - } - - // ************************ - // - // camel-k-loader-java - // - // ************************ - - { - CamelArtifact artifact = new CamelArtifact(); - artifact.setGroupId("org.apache.camel.k"); - artifact.setArtifactId("camel-k-loader-java"); - artifact.addDependency("org.apache.camel", "camel-endpointdsl"); - - artifacts.put(artifact.getArtifactId(), artifact); - } - - // ************************ - // - // camel-k-loader-knative - // - // ************************ - - { - CamelArtifact artifact = new CamelArtifact(); - artifact.setGroupId("org.apache.camel.k"); - artifact.setArtifactId("camel-k-loader-knative"); - - artifacts.put(artifact.getArtifactId(), artifact); - } - - // ************************ - // - // camel-knative - // - // ************************ + public void process(MavenProject project, CamelCatalog catalog, CamelCatalogSpec.Builder specBuilder) { + Map artifacts = new HashMap<>(); + + processComponents(catalog, artifacts); + processLanguages(catalog, artifacts); + processDataFormats(catalog, artifacts); + processLoaders(catalog, specBuilder); + + artifacts.computeIfPresent("camel-http", + (key, artifact) -> new CamelArtifact.Builder() + .from(artifact) + .addDependencies(MavenArtifact.from("org.apache.camel", "camel-file")) + .build() + ); + + specBuilder.putAllArtifacts(artifacts); + + specBuilder.putArtifact("org.apache.camel.k", "camel-k-loader-yaml"); + specBuilder.putArtifact("org.apache.camel.k", "camel-k-loader-groovy"); + specBuilder.putArtifact("org.apache.camel.k", "camel-k-loader-kotlin"); + specBuilder.putArtifact("org.apache.camel.k", "camel-k-loader-js"); + specBuilder.putArtifact("org.apache.camel.k", "camel-k-loader-xml"); + specBuilder.putArtifact("org.apache.camel.k", "camel-k-loader-java"); + specBuilder.putArtifact("org.apache.camel.k", "camel-k-loader-knative"); + + specBuilder.putArtifact( + new CamelArtifact.Builder() + .groupId("org.apache.camel.k") + .artifactId("camel-k-runtime-main") + .build() + ); + specBuilder.putArtifact( + new CamelArtifact.Builder() + .groupId("org.apache.camel.k") + .artifactId("camel-k-runtime-health") + .build() + ); + specBuilder.putArtifact( + new CamelArtifact.Builder() + .groupId("org.apache.camel.k") + .artifactId("camel-k-runtime-servlet") + .build() + ); + specBuilder.putArtifact( + new CamelArtifact.Builder() + .groupId("org.apache.camel.k") + .artifactId("camel-k-runtime-webhook") + .build() + ); + specBuilder.putArtifact( + new CamelArtifact.Builder() + .groupId("org.apache.camel.k") + .artifactId("camel-k-runtime-cron") + .build() + ); + + specBuilder.putArtifact( + new CamelArtifact.Builder() + .groupId("org.apache.camel.k") + .artifactId("camel-k-runtime-knative") + .addDependencies(MavenArtifact.from("org.apache.camel.k", "camel-k-loader-yaml")) + .addDependencies(MavenArtifact.from("org.apache.camel.k", "camel-k-loader-knative")) + .addDependencies(MavenArtifact.from("org.apache.camel.k", "camel-knative-api")) + .addDependencies(MavenArtifact.from("org.apache.camel.k", "camel-knative")) + .addDependencies(MavenArtifact.from("org.apache.camel.k", "camel-knative-http")) + .build() + ); + + specBuilder.putArtifact( + new CamelArtifact.Builder() + .groupId("org.apache.camel.k") + .artifactId("camel-knative") + .addScheme(new CamelScheme.Builder() + .id("knative") + .http(true) + .build()) + .addDependencies(MavenArtifact.from("org.apache.camel.k", "camel-knative-api")) + .addDependencies(MavenArtifact.from("org.apache.camel.k", "camel-knative-http")) + .build() + ); + } - { - CamelArtifact artifact = new CamelArtifact(); - artifact.setGroupId("org.apache.camel.k"); - artifact.setArtifactId("camel-knative"); - artifact.createScheme("knative").setHttp(true); - artifact.addDependency("org.apache.camel", "camel-cloud"); - artifact.addDependency("org.apache.camel.k", "camel-knative-api"); - artifact.addDependency("org.apache.camel.k", "camel-knative-http"); + private static void processLoaders(CamelCatalog catalog, CamelCatalogSpec.Builder specBuilder) { + if (catalog.getRuntimeProvider() instanceof QuarkusRuntimeProvider) { + specBuilder.putLoader( + "yaml", + CamelLoader.fromArtifact("org.apache.camel.k", "camel-k-quarkus-loader-yaml") + .addLanguage("yaml") + .putMetadata("native", "true") + .build() + ); + specBuilder.putLoader( + "groovy", + CamelLoader.fromArtifact("org.apache.camel.k", "camel-k-quarkus-loader-groovy") + .addLanguage("groovy") + .putMetadata("native", "false") + .build() + ); + specBuilder.putLoader( + "kts", + CamelLoader.fromArtifact("org.apache.camel.k", "camel-k-quarkus-loader-kotlin") + .addLanguage("kts") + .putMetadata("native", "false") + .build() + ); + specBuilder.putLoader( + "js", + CamelLoader.fromArtifact("org.apache.camel.k", "camel-k-quarkus-loader-js") + .addLanguage("js") + .putMetadata("native", "true") + .build() + ); + specBuilder.putLoader( + "xml", + CamelLoader.fromArtifact("org.apache.camel.k", "camel-k-quarkus-loader-xml") + .addLanguage("xml") + .putMetadata("native", "true") + .build() + ); + specBuilder.putLoader( + "java", + CamelLoader.fromArtifact("org.apache.camel.k", "camel-k-quarkus-loader-java") + .addLanguage("java") + .putMetadata("native", "false") + .build() + ); + specBuilder.putLoader( + "knative-source", + CamelLoader.fromArtifact("org.apache.camel.k", "camel-k-quarkus-loader-knative") + .addDependency("org.apache.camel.k", "camel-k-quarkus-knative") + .putMetadata("native", "true") + .build() + ); + } else { + specBuilder.putLoader( + "yaml", + CamelLoader.fromArtifact("org.apache.camel.k", "camel-k-loader-yaml") + .addLanguage("yaml") + .build() + ); + specBuilder.putLoader( + "groovy", + CamelLoader.fromArtifact("org.apache.camel.k", "camel-k-loader-groovy") + .addLanguage("groovy") + .build() + ); + specBuilder.putLoader( + "kts", + CamelLoader.fromArtifact("org.apache.camel.k", "camel-k-loader-kotlin") + .addLanguage("kts") + .build() + ); + specBuilder.putLoader( + "js", + CamelLoader.fromArtifact("org.apache.camel.k", "camel-k-loader-js") + .addLanguage("js") + .build() + ); + specBuilder.putLoader( + "xml", + CamelLoader.fromArtifact("org.apache.camel.k", "camel-k-loader-xml") + .addLanguage("xml") + .build() + ); + specBuilder.putLoader( + "java", + CamelLoader.fromArtifact("org.apache.camel.k", "camel-k-loader-java") + .addLanguage("java") + .build() + ); + specBuilder.putLoader( + "knative-source", + CamelLoader.fromArtifact("org.apache.camel.k", "camel-k-loader-knative") + .addDependency("org.apache.camel.k", "camel-k-runtime-knative") + .build() + ); - artifacts.put(artifact.getArtifactId(), artifact); } - - // ************************ - // - // camel-k-runtime-health - // - // ************************ - - { - CamelArtifact artifact = new CamelArtifact(); - artifact.setGroupId("org.apache.camel.k"); - artifact.setArtifactId("camel-k-runtime-health"); - artifact.addDependency("org.apache.camel", "camel-servlet"); - artifact.addDependency("org.apache.camel.k", "camel-k-runtime-servlet"); - - - artifacts.put(artifact.getArtifactId(), artifact); + } + private static void processComponents(org.apache.camel.catalog.CamelCatalog catalog, Map artifacts) { + for (String name : catalog.findComponentNames()) { + String json = catalog.componentJSonSchema(name); + CatalogComponentDefinition definition = CatalogSupport.unmarshallComponent(json); + + artifacts.compute(definition.getArtifactId(), (key, artifact) -> { + CamelArtifact.Builder builder = artifactBuilder(artifact, definition); + builder.addJavaType(definition.getJavaType()); + + definition.getSchemes().map(StringUtils::trimToNull).filter(Objects::nonNull).forEach(scheme -> { + builder.addScheme( + new CamelScheme.Builder() + .id(scheme) + .http(KNOWN_HTTP_URIS.contains(scheme)) + .passive(KNOWN_PASSIVE_URIS.contains(scheme)) + .build()); + }); + + return builder.build(); + }); } + } - // ************************ - // - // camel-k-runtime-servlet - // - // ************************ + private static void processLanguages(org.apache.camel.catalog.CamelCatalog catalog, Map artifacts) { + for (String name : catalog.findLanguageNames()) { + String json = catalog.languageJSonSchema(name); + CatalogLanguageDefinition definition = CatalogSupport.unmarshallLanguage(json); - { - CamelArtifact artifact = new CamelArtifact(); - artifact.setGroupId("org.apache.camel.k"); - artifact.setArtifactId("camel-k-runtime-servlet"); - artifact.addDependency("org.apache.camel", "camel-servlet"); + artifacts.compute(definition.getArtifactId(), (key, artifact) -> { + CamelArtifact.Builder builder = artifactBuilder(artifact, definition); + builder.addLanguage(definition.getName()); + builder.addJavaType(definition.getJavaType()); - artifacts.put(artifact.getArtifactId(), artifact); + return builder.build(); + }); } + } - // ************************ - // - // camel-k-runtime-webhook - // - // ************************ + private static void processDataFormats(org.apache.camel.catalog.CamelCatalog catalog, Map artifacts) { + for (String name : catalog.findDataFormatNames()) { + String json = catalog.dataFormatJSonSchema(name); + CatalogDataFormatDefinition definition = CatalogSupport.unmarshallDataFormat(json); - { - CamelArtifact artifact = new CamelArtifact(); - artifact.setGroupId("org.apache.camel.k"); - artifact.setArtifactId("camel-k-runtime-webhook"); - artifact.addDependency("org.apache.camel", "camel-webhook"); + artifacts.compute(definition.getArtifactId(), (key, artifact) -> { + CamelArtifact.Builder builder = artifactBuilder(artifact, definition); + builder.addDataformat(definition.getName()); + builder.addJavaType(definition.getJavaType()); - artifacts.put(artifact.getArtifactId(), artifact); + return builder.build(); + }); } + } - // ************************ - // - // camel-k-runtime-knative - // - // ************************ - - { - CamelArtifact artifact = new CamelArtifact(); - artifact.setGroupId("org.apache.camel.k"); - artifact.setArtifactId("camel-k-runtime-knative"); - artifact.addDependency("org.apache.camel", "camel-cloud"); - artifact.addDependency("org.apache.camel.k", "camel-k-loader-yaml"); - artifact.addDependency("org.apache.camel.k", "camel-k-loader-knative"); - artifact.addDependency("org.apache.camel.k", "camel-knative-api"); - artifact.addDependency("org.apache.camel.k", "camel-knative"); - artifact.addDependency("org.apache.camel.k", "camel-knative-http"); - - artifacts.put(artifact.getArtifactId(), artifact); - } + private static CamelArtifact.Builder artifactBuilder(CamelArtifact artifact, CatalogDefinition definition) { + CamelArtifact.Builder builder = new CamelArtifact.Builder(); - // ************************ - // - // - // - // ************************ + if (artifact != null) { + builder.from(artifact); + } else { + Objects.requireNonNull(definition.getGroupId()); + Objects.requireNonNull(definition.getArtifactId()); - for (String scheme: KNOWN_HTTP_URIS) { - artifacts.values().forEach(artifact -> artifact.getScheme(scheme).ifPresent(s -> s.setHttp(true))); + builder.groupId(definition.getGroupId()); + builder.artifactId(definition.getArtifactId()); } - for (String scheme: KNOWN_PASSIVE_URIS) { - artifacts.values().forEach(artifact -> artifact.getScheme(scheme).ifPresent(s -> s.setPassive(true))); - } - - // ************************ - // - // - // - // ************************ - artifacts.computeIfPresent("camel-http", (key, artifact) -> { - artifact.addDependency("org.apache.camel", "camel-file"); - return artifact; - }); + return builder; } } diff --git a/tooling/camel-k-maven-plugin/src/test/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3Test.java b/tooling/camel-k-maven-plugin/src/test/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3Test.java index 6f581bb72..18e9388dc 100644 --- a/tooling/camel-k-maven-plugin/src/test/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3Test.java +++ b/tooling/camel-k-maven-plugin/src/test/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3Test.java @@ -16,13 +16,14 @@ */ package org.apache.camel.k.tooling.maven.processors; -import java.util.HashMap; import java.util.Map; import org.apache.camel.catalog.CamelCatalog; import org.apache.camel.k.tooling.maven.model.Artifact; import org.apache.camel.k.tooling.maven.model.CamelArtifact; import org.apache.camel.k.tooling.maven.model.CatalogProcessor; +import org.apache.camel.k.tooling.maven.model.crd.CamelCatalogSpec; +import org.apache.camel.k.tooling.maven.model.crd.RuntimeSpec; import org.apache.maven.project.MavenProject; import org.junit.jupiter.api.Test; @@ -31,29 +32,23 @@ public class CatalogProcessor3Test extends AbstractCatalogProcessorTest { @Test public void testAcceptHyphen() { - CatalogProcessor3x cp3 = new CatalogProcessor3x(); - CamelCatalog catalog = versionCamelCatalog("3.0.0.acme-123456"); - assertThat(cp3.accepts(catalog)).isTrue(); + assertThat(new CatalogProcessor3x().accepts(catalog)).isTrue(); } @Test public void testAcceptEqualToLower() { - CatalogProcessor3x cp3 = new CatalogProcessor3x(); - CamelCatalog catalog = versionCamelCatalog("3.0.0"); - assertThat(cp3.accepts(catalog)).isTrue(); + assertThat(new CatalogProcessor3x().accepts(catalog)).isTrue(); } @Test public void testAcceptLessThanLower() { - CatalogProcessor3x cp3 = new CatalogProcessor3x(); - CamelCatalog catalog = versionCamelCatalog("2.17.0"); - assertThat(cp3.accepts(catalog)).isFalse(); + assertThat(new CatalogProcessor3x().accepts(catalog)).isFalse(); } @Test @@ -62,46 +57,33 @@ public void testAcceptEqualToHigher() { CamelCatalog catalog = versionCamelCatalog("4.0.0"); - assertThat(cp3.accepts(catalog)).isFalse(); + assertThat(new CatalogProcessor3x().accepts(catalog)).isFalse(); } @Test public void testAcceptMoreThanHigher() { - CatalogProcessor3x cp3 = new CatalogProcessor3x(); - CamelCatalog catalog = versionCamelCatalog("5.0.0"); - assertThat(cp3.accepts(catalog)).isFalse(); + assertThat(new CatalogProcessor3x().accepts(catalog)).isFalse(); } @Test public void testArtifactsEnrichment() { CatalogProcessor processor = new CatalogProcessor3x(); CamelCatalog catalog = versionCamelCatalog("3.0.0"); - Map artifactMap = new HashMap<>(); - artifactMap.put("camel-http", new CamelArtifact()); + + RuntimeSpec runtime = new RuntimeSpec.Builder().version("1.0.0").provider("main").applicationClass("unknown").build(); + CamelCatalogSpec.Builder builder = new CamelCatalogSpec.Builder().runtime(runtime); assertThat(processor.accepts(catalog)).isTrue(); - processor.process(new MavenProject(), catalog, artifactMap); + processor.process(new MavenProject(), catalog, builder); - assertThat(artifactMap.get("camel-k-runtime-health")).satisfies(a -> { - assertThat(a.getDependencies()).anyMatch( - d -> d.getGroupId().equals("org.apache.camel") && d.getArtifactId().equals("camel-servlet") - ); - assertThat(a.getDependencies()).anyMatch( - d -> d.getGroupId().equals("org.apache.camel.k") && d.getArtifactId().equals("camel-k-runtime-servlet") - ); - }); - assertThat(artifactMap.get("camel-k-runtime-servlet")).satisfies(a -> { - assertThat(a.getDependencies()).anyMatch( - d -> d.getGroupId().equals("org.apache.camel") && d.getArtifactId().equals("camel-servlet") - ); - }); - assertThat(artifactMap.get("camel-k-runtime-webhook")).satisfies(a -> { - assertThat(a.getDependencies()).anyMatch( - d -> d.getGroupId().equals("org.apache.camel") && d.getArtifactId().equals("camel-webhook") - ); - }); + CamelCatalogSpec spec = builder.build(); + Map artifactMap = spec.getArtifacts(); + + assertThat(artifactMap).containsKeys("camel-k-runtime-health"); + assertThat(artifactMap).containsKeys("camel-k-runtime-servlet"); + assertThat(artifactMap).containsKeys("camel-k-runtime-webhook"); assertThat(artifactMap.get("camel-k-runtime-knative")).satisfies(a -> { assertThat(a.getDependencies()).anyMatch( @@ -116,15 +98,6 @@ public void testArtifactsEnrichment() { assertThat(a.getDependencies()).anyMatch( d -> d.getGroupId().equals("org.apache.camel.k") && d.getArtifactId().equals("camel-k-loader-yaml") ); - assertThat(a.getDependencies()).anyMatch( - d -> d.getGroupId().equals("org.apache.camel") && d.getArtifactId().equals("camel-cloud") - ); - }); - - assertThat(artifactMap.get("camel-knative")).satisfies(a -> { - assertThat(a.getDependencies()).anyMatch( - d -> d.getGroupId().equals("org.apache.camel") && d.getArtifactId().equals("camel-cloud") - ); }); assertThat(artifactMap.get("camel-http")).satisfies(a -> { @@ -138,17 +111,21 @@ public void testArtifactsEnrichment() { public void testArtifactsDoNotContainVersion() { CatalogProcessor processor = new CatalogProcessor3x(); CamelCatalog catalog = versionCamelCatalog("3.0.0"); - Map artifactMap = new HashMap<>(); - artifactMap.put("camel-http", new CamelArtifact()); + + RuntimeSpec runtime = new RuntimeSpec.Builder().version("1.0.0").provider("main").applicationClass("unknown").build(); + CamelCatalogSpec.Builder builder = new CamelCatalogSpec.Builder().runtime(runtime); assertThat(processor.accepts(catalog)).isTrue(); - processor.process(new MavenProject(), catalog, artifactMap); + processor.process(new MavenProject(), catalog, builder); + + CamelCatalogSpec spec = builder.build(); + Map artifactMap = spec.getArtifacts(); for (Map.Entry artifact: artifactMap.entrySet()) { - assertThat(artifact.getValue().getVersion()).isNull(); + assertThat(artifact.getValue().getVersion()).isNotPresent(); for (Artifact dependency: artifact.getValue().getDependencies()) { - assertThat(dependency.getVersion()).isNull(); + assertThat(dependency.getVersion()).isNotPresent(); } } }