This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 5250bf76bd5c337ca4cf83ac0de89327c0e3e5e4 Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Tue Apr 16 11:12:44 2024 +0100 Prevent xml-jaxb extension producing CamelModelToXMLDumperBuildItem if xml-io-dsl is present --- .../xml/jaxb/deployment/XmlJaxbProcessor.java | 20 ++++++++++- integration-tests/main-xml-jaxb/pom.xml | 8 ++--- .../quarkus/main/CoreMainXmlJaxbResource.java | 5 --- .../src/main/resources/application.properties | 2 +- .../src/main/resources/rests/my-rests.xml | 26 -------------- .../src/main/resources/rests/my-rests.yaml | 23 ++++++++++++ .../src/main/resources/routes/my-routes.xml | 41 ---------------------- .../src/main/resources/routes/my-routes.yaml | 34 ++++++++++++++++++ .../src/main/resources/templates/my-templates.xml | 29 --------------- .../src/main/resources/templates/my-templates.yaml | 27 ++++++++++++++ .../camel/quarkus/main/CoreMainXmlJaxbTest.java | 11 ++---- 11 files changed, 109 insertions(+), 117 deletions(-) diff --git a/extensions-core/xml-jaxb/deployment/src/main/java/org/apache/camel/quarkus/component/xml/jaxb/deployment/XmlJaxbProcessor.java b/extensions-core/xml-jaxb/deployment/src/main/java/org/apache/camel/quarkus/component/xml/jaxb/deployment/XmlJaxbProcessor.java index fe4cce2773..1d6732872a 100644 --- a/extensions-core/xml-jaxb/deployment/src/main/java/org/apache/camel/quarkus/component/xml/jaxb/deployment/XmlJaxbProcessor.java +++ b/extensions-core/xml-jaxb/deployment/src/main/java/org/apache/camel/quarkus/component/xml/jaxb/deployment/XmlJaxbProcessor.java @@ -16,6 +16,8 @@ */ package org.apache.camel.quarkus.component.xml.jaxb.deployment; +import java.util.function.BooleanSupplier; + import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Record; @@ -46,9 +48,25 @@ class XmlJaxbProcessor { return new CamelModelJAXBContextFactoryBuildItem(recorder.newContextFactory()); } - @BuildStep + @BuildStep(onlyIfNot = XmlIoPresent.class) @Record(value = ExecutionTime.STATIC_INIT, optional = true) CamelModelToXMLDumperBuildItem xmlModelDumper(XmlJaxbRecorder recorder) { return new CamelModelToXMLDumperBuildItem(recorder.newJaxbModelToXMLDumper()); } + + /** + * Normally we'd use Capabilities to detect xml-io-dsl, but in this case we must suppress the xmlModelDumper + * build step running. Since we can't have multiple active producers of CamelModelToXMLDumperBuildItem. + */ + static class XmlIoPresent implements BooleanSupplier { + @Override + public boolean getAsBoolean() { + try { + Thread.currentThread().getContextClassLoader().loadClass("org.apache.camel.xml.LwModelToXMLDumper"); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } + } } diff --git a/integration-tests/main-xml-jaxb/pom.xml b/integration-tests/main-xml-jaxb/pom.xml index f9dc20e568..46a57d88a1 100644 --- a/integration-tests/main-xml-jaxb/pom.xml +++ b/integration-tests/main-xml-jaxb/pom.xml @@ -35,14 +35,10 @@ <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-xml-jaxb</artifactId> </dependency> - <!-- JAXP is required for route dumping --> + <!-- YAML is used as the DSL since xml-io-dsl brings its own ModelXMLDumper that overrides the one from xml-jaxb --> <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-xml-jaxp</artifactId> - </dependency> - <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-xml-io-dsl</artifactId> + <artifactId>camel-quarkus-yaml-dsl</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> diff --git a/integration-tests/main-xml-jaxb/src/main/java/org/apache/camel/quarkus/main/CoreMainXmlJaxbResource.java b/integration-tests/main-xml-jaxb/src/main/java/org/apache/camel/quarkus/main/CoreMainXmlJaxbResource.java index 31192bda6b..6e80bcde73 100644 --- a/integration-tests/main-xml-jaxb/src/main/java/org/apache/camel/quarkus/main/CoreMainXmlJaxbResource.java +++ b/integration-tests/main-xml-jaxb/src/main/java/org/apache/camel/quarkus/main/CoreMainXmlJaxbResource.java @@ -27,8 +27,6 @@ import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; import org.apache.camel.ExtendedCamelContext; import org.apache.camel.builder.TemplatedRouteBuilder; -import org.apache.camel.dsl.xml.io.XmlRoutesBuilderLoader; -import org.apache.camel.spi.RoutesBuilderLoader; import org.apache.camel.support.PluginHelper; @Path("/test") @@ -59,9 +57,6 @@ public class CoreMainXmlJaxbResource { main.getCamelContext().getRoutes().forEach(route -> routes.add(route.getId())); return Json.createObjectBuilder() - .add("xml-routes-builder-loader", - camelContext.getBootstrapFactoryFinder(RoutesBuilderLoader.FACTORY_PATH) - .findClass(XmlRoutesBuilderLoader.EXTENSION).get().getName()) .add("xml-model-dumper", PluginHelper.getModelToXMLDumper(camelContext).getClass().getName()) .add("xml-model-factory", PluginHelper.getModelJAXBContextFactory(camelContext).getClass().getName()) .add("routeBuilders", routeBuilders) diff --git a/integration-tests/main-xml-jaxb/src/main/resources/application.properties b/integration-tests/main-xml-jaxb/src/main/resources/application.properties index eb47245419..6afcd39ef7 100644 --- a/integration-tests/main-xml-jaxb/src/main/resources/application.properties +++ b/integration-tests/main-xml-jaxb/src/main/resources/application.properties @@ -31,5 +31,5 @@ camel.main.dumpRoutesInclude = all # # Main # -camel.main.routes-include-pattern = classpath:routes/my-routes.xml,classpath:rests/my-rests.xml,classpath:templates/my-templates.xml +camel.main.routes-include-pattern = classpath:routes/my-routes.yaml,classpath:rests/my-rests.yaml,classpath:templates/my-templates.yaml camel.main.dump-routes = xml diff --git a/integration-tests/main-xml-jaxb/src/main/resources/rests/my-rests.xml b/integration-tests/main-xml-jaxb/src/main/resources/rests/my-rests.xml deleted file mode 100644 index 24f641fa35..0000000000 --- a/integration-tests/main-xml-jaxb/src/main/resources/rests/my-rests.xml +++ /dev/null @@ -1,26 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - 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. - ---> -<rests xmlns="http://camel.apache.org/schema/spring"> - <rest id="greet" path="/greeting"> - <get path="/hello"> - <to uri="direct:greet"/> - </get> - </rest> -</rests> diff --git a/integration-tests/main-xml-jaxb/src/main/resources/rests/my-rests.yaml b/integration-tests/main-xml-jaxb/src/main/resources/rests/my-rests.yaml new file mode 100644 index 0000000000..3a8680664f --- /dev/null +++ b/integration-tests/main-xml-jaxb/src/main/resources/rests/my-rests.yaml @@ -0,0 +1,23 @@ +# +# 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. +# + +- rest: + id: "greet" + path: "/greeting" + get: + - path: "/hello" + to: "direct:greet" diff --git a/integration-tests/main-xml-jaxb/src/main/resources/routes/my-routes.xml b/integration-tests/main-xml-jaxb/src/main/resources/routes/my-routes.xml deleted file mode 100644 index c3763c0d5f..0000000000 --- a/integration-tests/main-xml-jaxb/src/main/resources/routes/my-routes.xml +++ /dev/null @@ -1,41 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - 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. - ---> -<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="http://camel.apache.org/schema/spring" - xsi:schemaLocation=" - http://camel.apache.org/schema/spring - http://camel.apache.org/schema/spring/camel-spring.xsd"> - - <route id="rest-route"> - <from uri="direct:greet"/> - <setBody> - <constant>Hello World!</constant> - </setBody> - </route> - - <route id="my-xml-route"> - <from uri="timer:from-xml?period=3000"/> - <setBody> - <constant>Hello World!!!</constant> - </setBody> - <to uri="log:from-xml"/> - </route> - -</routes> \ No newline at end of file diff --git a/integration-tests/main-xml-jaxb/src/main/resources/routes/my-routes.yaml b/integration-tests/main-xml-jaxb/src/main/resources/routes/my-routes.yaml new file mode 100644 index 0000000000..3a67be7118 --- /dev/null +++ b/integration-tests/main-xml-jaxb/src/main/resources/routes/my-routes.yaml @@ -0,0 +1,34 @@ +# +# 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. +# + +- route: + id: "rest-route" + from: + uri: "direct:greet" + steps: + - setBody: + constant: "Hello World!" + +- route: + id: "my-yaml-route" + from: + uri: "timer:from-xml?period=3000" + steps: + - setBody: + constant: "Hello World!" + - to: + uri: "log:from-yaml" diff --git a/integration-tests/main-xml-jaxb/src/main/resources/templates/my-templates.xml b/integration-tests/main-xml-jaxb/src/main/resources/templates/my-templates.xml deleted file mode 100644 index 10416ab690..0000000000 --- a/integration-tests/main-xml-jaxb/src/main/resources/templates/my-templates.xml +++ /dev/null @@ -1,29 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - 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. - ---> -<routeTemplates xmlns="http://camel.apache.org/schema/spring"> - <routeTemplate id="myTemplate"> - <templateParameter name="name"/> - <templateParameter name="greeting"/> - <route> - <from uri="direct:template"/> - <setBody><simple>{{greeting}} ${body}</simple></setBody> - </route> - </routeTemplate> -</routeTemplates> diff --git a/integration-tests/main-xml-jaxb/src/main/resources/templates/my-templates.yaml b/integration-tests/main-xml-jaxb/src/main/resources/templates/my-templates.yaml new file mode 100644 index 0000000000..f0cd7d7525 --- /dev/null +++ b/integration-tests/main-xml-jaxb/src/main/resources/templates/my-templates.yaml @@ -0,0 +1,27 @@ +# +# 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. +# + +- routeTemplate: + id: "myTemplate" + parameters: + - name: "name" + - name: "greeting" + from: + uri: "direct:template" + steps: + - setBody: + simple: "{{greeting}} ${body}" diff --git a/integration-tests/main-xml-jaxb/src/test/java/org/apache/camel/quarkus/main/CoreMainXmlJaxbTest.java b/integration-tests/main-xml-jaxb/src/test/java/org/apache/camel/quarkus/main/CoreMainXmlJaxbTest.java index 6838b5f3a4..c58adc082a 100644 --- a/integration-tests/main-xml-jaxb/src/test/java/org/apache/camel/quarkus/main/CoreMainXmlJaxbTest.java +++ b/integration-tests/main-xml-jaxb/src/test/java/org/apache/camel/quarkus/main/CoreMainXmlJaxbTest.java @@ -16,7 +16,6 @@ */ package org.apache.camel.quarkus.main; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; @@ -26,7 +25,6 @@ import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import io.restassured.path.json.JsonPath; import jakarta.ws.rs.core.MediaType; -import org.apache.camel.dsl.xml.io.XmlRoutesBuilderLoader; import org.apache.camel.xml.jaxb.DefaultModelJAXBContextFactory; import org.apache.camel.xml.jaxb.JaxbModelToXMLDumper; import org.junit.jupiter.api.Test; @@ -51,15 +49,12 @@ public class CoreMainXmlJaxbTest { assertThat(p.getString("xml-model-dumper")).isEqualTo(JaxbModelToXMLDumper.class.getName()); assertThat(p.getString("xml-model-factory")).isEqualTo(DefaultModelJAXBContextFactory.class.getName()); - assertThat(p.getString("xml-routes-builder-loader")) - .isEqualTo(XmlRoutesBuilderLoader.class.getName()); - assertThat(p.getList("routeBuilders", String.class)) .isEmpty(); List<String> routes = p.getList("routes", String.class); assertThat(routes) - .contains("my-xml-route"); + .contains("my-yaml-route"); assertThat(routes) .contains("templated-route"); assertThat(routes) @@ -69,13 +64,13 @@ public class CoreMainXmlJaxbTest { @Test public void testDumpRoutes() { await().atMost(10L, TimeUnit.SECONDS).pollDelay(100, TimeUnit.MILLISECONDS).until(() -> { - String log = new String(Files.readAllBytes(Paths.get("target/quarkus.log")), StandardCharsets.UTF_8); + String log = Files.readString(Paths.get("target/quarkus.log")); return logContainsDumpedRoutes(log); }); } private boolean logContainsDumpedRoutes(String log) { - return log.contains("<route id=\"my-xml-route\">") && + return log.contains("<route id=\"my-yaml-route\">") && log.contains("<rest id=\"greet\" path=\"/greeting\">") && log.contains("<routeTemplate id=\"myTemplate\">"); }