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
The following commit(s) were added to refs/heads/main by this push: new 882faa3b96 Deprecated parameters in several annotations are ignored - inconsistent with other annotations. 882faa3b96 is described below commit 882faa3b96ccab8a6b477db7d6c4dbc76772be23 Author: JiriOndrusek <ondrusek.j...@gmail.com> AuthorDate: Mon Sep 26 13:47:08 2022 +0200 Deprecated parameters in several annotations are ignored - inconsistent with other annotations. --- .../quarkus/core/deployment/ConsumeProcessor.java | 3 ++ .../core/deployment/InjectionPointsProcessor.java | 25 ++++++++--- .../main/CamelMainDeprecatedConsumeTest.java | 40 ++++++++++++++++++ .../CamelMainDeprecatedEndpointInjectTest.java | 48 ++++++++++++++++++++++ .../main/CamelMainDeprecatedProduceTest.java | 48 ++++++++++++++++++++++ 5 files changed, 158 insertions(+), 6 deletions(-) diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/ConsumeProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/ConsumeProcessor.java index 0e3d029c42..caa397c872 100644 --- a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/ConsumeProcessor.java +++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/ConsumeProcessor.java @@ -173,6 +173,9 @@ public class ConsumeProcessor { uri = annot.value().asString(); } else if (annot.value("uri") != null) { uri = annot.value("uri").asString(); + throw new IllegalArgumentException(String.format("@%s(uri = \"%s\") is not supported on Camel" + + " Quarkus. Please replace it with just @%s(\"%s\").", annot.name().toString(), uri, + annot.name().toString(), uri)); } else if (annot.value("property") != null) { runtimeUriOrEndpoint = recorder.getEndpointUri( camelContext.getCamelContext(), diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/InjectionPointsProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/InjectionPointsProcessor.java index 2e15c9c8e1..e37c6a9399 100644 --- a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/InjectionPointsProcessor.java +++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/InjectionPointsProcessor.java @@ -328,7 +328,7 @@ public class InjectionPointsProcessor { .configure(fieldType) .setRuntimeInit().scope(Singleton.class) .supplier( - recorder.createProducerTemplate(annot.valueWithDefault(index).asString())) + recorder.createProducerTemplate(resolveAnnotValue(index, annot))) .addQualifier(annot) .done()); /* @@ -341,7 +341,7 @@ public class InjectionPointsProcessor { .configure(fieldType) .setRuntimeInit().scope(Singleton.class) .supplier( - recorder.createFluentProducerTemplate(annot.valueWithDefault(index).asString())) + recorder.createFluentProducerTemplate(resolveAnnotValue(index, annot))) .addQualifier(annot) .done()); /* @@ -369,7 +369,7 @@ public class InjectionPointsProcessor { .configure(fieldType) .setRuntimeInit().scope(Singleton.class) .supplier( - recorder.produceProxy(clazz, annot.valueWithDefault(index).asString())) + recorder.produceProxy(clazz, resolveAnnotValue(index, annot))) .addQualifier(annot) .done()); } @@ -388,7 +388,7 @@ public class InjectionPointsProcessor { .configure(fieldType) .setRuntimeInit().scope(Singleton.class) .supplier( - recorder.createEndpoint(annot.valueWithDefault(index).asString(), + recorder.createEndpoint(resolveAnnotValue(index, annot), (Class<? extends Endpoint>) clazz)) .addQualifier(annot) .done()); @@ -398,7 +398,7 @@ public class InjectionPointsProcessor { .configure(fieldType) .setRuntimeInit().scope(Singleton.class) .supplier( - recorder.createProducerTemplate(annot.valueWithDefault(index).asString())) + recorder.createProducerTemplate(resolveAnnotValue(index, annot))) .addQualifier(annot) .done()); /* @@ -411,7 +411,7 @@ public class InjectionPointsProcessor { .configure(fieldType) .setRuntimeInit().scope(Singleton.class) .supplier( - recorder.createFluentProducerTemplate(annot.valueWithDefault(index).asString())) + recorder.createFluentProducerTemplate(resolveAnnotValue(index, annot))) .addQualifier(annot) .done()); /* @@ -424,4 +424,17 @@ public class InjectionPointsProcessor { } } + private String resolveAnnotValue(IndexView index, AnnotationInstance annot) { + //consider also parameter 'uri', which is deprecated but can be still supported + String uri = annot.valueWithDefault(index).asString(); + + String deprecatedUri = annot.valueWithDefault(index, "uri").asString(); + if (uri.isEmpty() && !deprecatedUri.isEmpty()) { + throw new IllegalArgumentException(String.format("@%s(uri = \"%s\") is not supported on Camel" + + " Quarkus. Please replace it with just @%s(\"%s\").", annot.name().toString(), deprecatedUri, + annot.name().toString(), deprecatedUri)); + } + return uri; + } + } diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainDeprecatedConsumeTest.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainDeprecatedConsumeTest.java new file mode 100644 index 0000000000..31aaf5e076 --- /dev/null +++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainDeprecatedConsumeTest.java @@ -0,0 +1,40 @@ +/* + * 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.quarkus.core.deployment.main; + +import io.quarkus.test.QuarkusUnitTest; +import org.apache.camel.Consume; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +public class CamelMainDeprecatedConsumeTest { + @RegisterExtension + static final QuarkusUnitTest CONFIG = new QuarkusUnitTest().setExpectedException(IllegalArgumentException.class) + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); + + @Consume(uri = "direct:consumeAnnotation") + public String consumeAnnotation(String name) { + return "Consumed " + name; + } + + @Test + public void consumeAnnotationWithDeprecatedParamsThrowsIllegalArgumentException() { + // Noop - we expect IllegalArgumentException to be thrown on application startup + } +} diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainDeprecatedEndpointInjectTest.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainDeprecatedEndpointInjectTest.java new file mode 100644 index 0000000000..7be4aebea6 --- /dev/null +++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainDeprecatedEndpointInjectTest.java @@ -0,0 +1,48 @@ +/* + * 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.quarkus.core.deployment.main; + +import io.quarkus.test.QuarkusUnitTest; +import org.apache.camel.EndpointInject; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.direct.DirectEndpoint; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +public class CamelMainDeprecatedEndpointInjectTest { + @RegisterExtension + static final QuarkusUnitTest CONFIG = new QuarkusUnitTest().setExpectedException(IllegalArgumentException.class) + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); + + @EndpointInject(uri = "direct:start") + DirectEndpoint start; + + @Test + public void endpointAnnotationWithDeprecatedParamsThrowsIllegalArgumentException() { + // Noop - we expect IllegalArgumentException to be thrown on application startup + } + + public static class MyRoutes extends RouteBuilder { + + @Override + public void configure() throws Exception { + from("direct:start").to("direct:end"); + } + } +} diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainDeprecatedProduceTest.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainDeprecatedProduceTest.java new file mode 100644 index 0000000000..986477e05e --- /dev/null +++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainDeprecatedProduceTest.java @@ -0,0 +1,48 @@ +/* + * 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.quarkus.core.deployment.main; + +import io.quarkus.test.QuarkusUnitTest; +import org.apache.camel.FluentProducerTemplate; +import org.apache.camel.Produce; +import org.apache.camel.builder.RouteBuilder; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +public class CamelMainDeprecatedProduceTest { + @RegisterExtension + static final QuarkusUnitTest CONFIG = new QuarkusUnitTest().setExpectedException(IllegalArgumentException.class) + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); + + @Produce(uri = "direct:start") + FluentProducerTemplate produceProducerFluent; + + @Test + public void produceAnnotationWithDeprecatedParamsThrowsIllegalArgumentException() { + // Noop - we expect IllegalArgumentException to be thrown on application startup + } + + public static class MyRoutes extends RouteBuilder { + + @Override + public void configure() throws Exception { + from("direct:start").to("direct:end"); + } + } +}