You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/09/10 07:04:47 UTC
[camel] branch master updated: Camel 15518 (#4181)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 54a892e Camel 15518 (#4181)
54a892e is described below
commit 54a892edab0aec4836fe14cb1ffaf75a6c47d8e8
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Sep 10 09:04:33 2020 +0200
Camel 15518 (#4181)
CAMEL-15518: CamelContext configurer should be handled specially and be loadable.
---
.../impl/engine/DefaultConfigurerResolver.java | 10 ++++--
...ntext => org.apache.camel.ExtendedCamelContext} | 0
...tion => org.apache.camel.spi.RestConfiguration} | 0
.../apache/camel/impl/ConfigurerResolverTest.java | 36 ++++++++++++++++++++++
.../org/apache/camel/main/BaseMainSupport.java | 13 --------
.../camel/support/PropertyConfigurerHelper.java | 10 ------
.../packaging/AbstractGenerateConfigurerMojo.java | 11 +++----
7 files changed, 49 insertions(+), 31 deletions(-)
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultConfigurerResolver.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultConfigurerResolver.java
index d4a9ebf..0196350 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultConfigurerResolver.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultConfigurerResolver.java
@@ -62,8 +62,14 @@ public class DefaultConfigurerResolver implements ConfigurerResolver {
try {
type = findConfigurer(name, context);
if (type == null) {
- // not found
- return null;
+ if (name.contains("CamelContext")) {
+ // fallback special for camel context itself as we have an extended configurer
+ type = findConfigurer(ExtendedCamelContext.class.getName(), context);
+ }
+ if (type == null) {
+ // not found
+ return null;
+ }
}
} catch (NoFactoryAvailableException e) {
return null;
diff --git a/core/camel-core-engine/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.impl.ExtendedCamelContext b/core/camel-core-engine/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.ExtendedCamelContext
similarity index 100%
rename from core/camel-core-engine/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.impl.ExtendedCamelContext
rename to core/camel-core-engine/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.ExtendedCamelContext
diff --git a/core/camel-core-engine/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.impl.RestConfiguration b/core/camel-core-engine/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.spi.RestConfiguration
similarity index 100%
rename from core/camel-core-engine/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.impl.RestConfiguration
rename to core/camel-core-engine/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.spi.RestConfiguration
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/ConfigurerResolverTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/ConfigurerResolverTest.java
new file mode 100644
index 0000000..dd20ff6
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/ConfigurerResolverTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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.impl;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class ConfigurerResolverTest extends ContextTestSupport {
+
+ @Test
+ public void testConfigurerResolver() throws Exception {
+ GeneratedPropertyConfigurer resolver = context.adapt(ExtendedCamelContext.class).getConfigurerResolver()
+ .resolvePropertyConfigurer(context.getClass().getName(), context);
+ Assertions.assertNotNull(resolver);
+
+ resolver.configure(context, context, "name", "foobar", true);
+ Assertions.assertEquals("foobar", context.getName());
+ }
+}
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 04625ef..3c0fea9 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -130,10 +130,6 @@ public abstract class BaseMainSupport extends BaseService {
}
if (targetConfigurer == null) {
String name = target.getClass().getName();
- if (target instanceof ExtendedCamelContext) {
- // special for camel context itself as we have an extended configurer
- name = ExtendedCamelContext.class.getName();
- }
// see if there is a configurer for it
targetConfigurer = context.adapt(ExtendedCamelContext.class)
.getConfigurerResolver().resolvePropertyConfigurer(name, context);
@@ -147,10 +143,6 @@ public abstract class BaseMainSupport extends BaseService {
}
if (sourceConfigurer == null) {
String name = source.getClass().getName();
- if (source instanceof ExtendedCamelContext) {
- // special for camel context itself as we have an extended configurer
- name = ExtendedCamelContext.class.getName();
- }
// see if there is a configurer for it
sourceConfigurer = context.adapt(ExtendedCamelContext.class)
.getConfigurerResolver().resolvePropertyConfigurer(name, context);
@@ -187,11 +179,6 @@ public abstract class BaseMainSupport extends BaseService {
if (configurer == null) {
String name = target.getClass().getName();
- if (target instanceof ExtendedCamelContext) {
- // special for camel context itself as we have an extended configurer
- name = ExtendedCamelContext.class.getName();
- }
-
// see if there is a configurer for it
configurer = context.adapt(ExtendedCamelContext.class)
.getConfigurerResolver().resolvePropertyConfigurer(name, context);
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyConfigurerHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyConfigurerHelper.java
index b04397c..f1b5959 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyConfigurerHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyConfigurerHelper.java
@@ -55,11 +55,6 @@ public final class PropertyConfigurerHelper {
if (configurer == null) {
String name = target.getClass().getName();
- if (target instanceof ExtendedCamelContext) {
- // special for camel context itself as we have an extended configurer
- name = ExtendedCamelContext.class.getName();
- }
-
// see if there is a configurer for it
configurer = context.adapt(ExtendedCamelContext.class)
.getConfigurerResolver()
@@ -81,11 +76,6 @@ public final class PropertyConfigurerHelper {
ObjectHelper.notNull(context, "context");
String name = targetType.getName();
- if (ExtendedCamelContext.class.isAssignableFrom(targetType)) {
- // special for camel context itself as we have an extended configurer
- name = ExtendedCamelContext.class.getName();
- }
-
// see if there is a configurer for it
return context.adapt(ExtendedCamelContext.class)
.getConfigurerResolver()
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGenerateConfigurerMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGenerateConfigurerMojo.java
index b6ad8ee..037dff1 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGenerateConfigurerMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGenerateConfigurerMojo.java
@@ -171,7 +171,7 @@ public abstract class AbstractGenerateConfigurerMojo extends AbstractGeneratorMo
}
List<ConfigurerOption> options = processClass(fqn);
generateConfigurer(fqn, targetFqn, options, sourcesOutputDir);
- generateMetaInfConfigurer(targetFqn, resourcesOutputDir);
+ generateMetaInfConfigurer(fqn, targetFqn, resourcesOutputDir);
} catch (Exception e) {
throw new MojoExecutionException("Error processing class: " + fqn, e);
}
@@ -390,11 +390,10 @@ public abstract class AbstractGenerateConfigurerMojo extends AbstractGeneratorMo
}
}
- private void generateMetaInfConfigurer(String name, File resourcesOutputDir) {
- int pos = name.lastIndexOf('.');
- String pn = name.substring(0, pos);
- String en = name.substring(pos + 1);
- String fqn = name;
+ private void generateMetaInfConfigurer(String fqn, String targetFqn, File resourcesOutputDir) {
+ int pos = targetFqn.lastIndexOf('.');
+ String pn = targetFqn.substring(0, pos);
+ String en = targetFqn.substring(pos + 1);
try (Writer w = new StringWriter()) {
w.append("# " + GENERATED_MSG + "\n");
w.append("class=").append(pn).append(".").append(en).append("Configurer").append("\n");