This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 820c4d1f4f6 CAMEL-17972: camel-main - Property placeholder kamelets
summary
820c4d1f4f6 is described below
commit 820c4d1f4f6fd30f56f512f7d156db13ec060e97
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Apr 15 18:17:29 2022 +0200
CAMEL-17972: camel-main - Property placeholder kamelets summary
---
.../org/apache/camel/component/kamelet/Kamelet.java | 2 ++
.../properties/DefaultPropertiesLookup.java | 20 +++++++++++++++++---
.../properties/DefaultPropertiesParser.java | 15 ++++++++++++++-
.../org/apache/camel/impl/DefaultCamelContext.java | 10 +++++-----
.../java/org/apache/camel/main/BaseMainSupport.java | 3 +++
5 files changed, 41 insertions(+), 9 deletions(-)
diff --git
a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java
b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java
index e68a06d8b7b..3d207645483 100644
---
a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java
+++
b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java
@@ -127,6 +127,8 @@ public final class Kamelet {
ObjectHelper.notNull(rid, PARAM_ROUTE_ID);
RouteDefinition def = in.asRouteDefinition();
+ def.setLocation(in.getLocation());
+ def.setLineNumber(in.getLineNumber());
def.setId(rid);
if (def.getInput() == null) {
diff --git
a/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesLookup.java
b/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesLookup.java
index c20e9df3909..f912b62021c 100644
---
a/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesLookup.java
+++
b/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesLookup.java
@@ -56,7 +56,8 @@ public class DefaultPropertiesLookup implements
PropertiesLookup {
Object value = local.get(name);
if (value != null) {
answer =
component.getCamelContext().getTypeConverter().mandatoryConvertTo(String.class,
value);
- onLookup(name, answer, "LocalProperties");
+ String loc = location(local, name, "LocalProperties");
+ onLookup(name, answer, loc);
}
}
@@ -66,7 +67,8 @@ public class DefaultPropertiesLookup implements
PropertiesLookup {
Object value = component.getOverrideProperties().get(name);
if (value != null) {
answer =
component.getCamelContext().getTypeConverter().mandatoryConvertTo(String.class,
value);
- onLookup(name, answer, "OverrideProperties");
+ String loc = location(local, name, "OverrideProperties");
+ onLookup(name, answer, loc);
}
}
if (answer == null) {
@@ -101,7 +103,8 @@ public class DefaultPropertiesLookup implements
PropertiesLookup {
Object value = component.getInitialProperties().get(name);
if (value != null) {
answer =
component.getCamelContext().getTypeConverter().mandatoryConvertTo(String.class,
value);
- onLookup(name, answer, "InitialProperties");
+ String loc = location(local, name, "InitialProperties");
+ onLookup(name, answer, loc);
}
}
@@ -118,4 +121,15 @@ public class DefaultPropertiesLookup implements
PropertiesLookup {
}
}
+ private static String location(Properties prop, String name, String
defaultLocation) {
+ String loc = null;
+ if (prop instanceof OrderedLocationProperties) {
+ loc = ((OrderedLocationProperties) prop).getLocation(name);
+ }
+ if (loc == null) {
+ loc = defaultLocation;
+ }
+ return loc;
+ }
+
}
diff --git
a/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
b/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
index ef2f75bbd08..aed9f3c6ebc 100644
---
a/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
+++
b/core/camel-base/src/main/java/org/apache/camel/component/properties/DefaultPropertiesParser.java
@@ -23,6 +23,7 @@ import java.util.Set;
import org.apache.camel.PropertiesLookupListener;
import org.apache.camel.spi.PropertiesFunction;
import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.OrderedLocationProperties;
import org.apache.camel.util.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -314,7 +315,8 @@ public class DefaultPropertiesParser implements
PropertiesParser {
if (local != null) {
value = local.getProperty(key);
if (value != null) {
- onLookup(key, value, "LocalProperties");
+ String loc = location(local, key, "LocalProperties");
+ onLookup(key, value, loc);
log.debug("Found local property: {} with value: {} to be
used.", key, value);
}
}
@@ -383,6 +385,17 @@ public class DefaultPropertiesParser implements
PropertiesParser {
}
}
+ private static String location(Properties prop, String name, String
defaultLocation) {
+ String loc = null;
+ if (prop instanceof OrderedLocationProperties) {
+ loc = ((OrderedLocationProperties) prop).getLocation(name);
+ }
+ if (loc == null) {
+ loc = defaultLocation;
+ }
+ return loc;
+ }
+
/**
* This inner class is the definition of a property used in a string
*/
diff --git
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 7e96ea6640c..1a02fe0c44b 100644
---
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -22,7 +22,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.Set;
import java.util.function.Function;
@@ -87,6 +86,7 @@ import org.apache.camel.support.DefaultRegistry;
import org.apache.camel.support.LocalBeanRegistry;
import org.apache.camel.support.SimpleUuidGenerator;
import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.OrderedLocationProperties;
import org.apache.camel.util.StopWatch;
import org.apache.camel.util.StringHelper;
import org.apache.camel.util.concurrent.NamedThreadLocal;
@@ -793,7 +793,7 @@ public class DefaultCamelContext extends SimpleCamelContext
implements ModelCame
}
// copy parameters/bean repository to not cause side-effect
- Map<String, Object> params = new
HashMap<>(routeDefinition.getTemplateParameters());
+ Map<Object, Object> params = new
HashMap<>(routeDefinition.getTemplateParameters());
LocalBeanRegistry bbr
= (LocalBeanRegistry)
routeDefinition.getRouteTemplateContext().getLocalBeanRepository();
LocalBeanRegistry bbrCopy = new LocalBeanRegistry();
@@ -803,7 +803,7 @@ public class DefaultCamelContext extends SimpleCamelContext
implements ModelCame
// no side-effect from previously used values that Camel
may use in its endpoint
// registry and elsewhere
if (bbr != null && !bbr.isEmpty()) {
- for (Map.Entry<String, Object> param :
params.entrySet()) {
+ for (Map.Entry<Object, Object> param :
params.entrySet()) {
Object value = param.getValue();
if (value instanceof String) {
String oldKey = (String) value;
@@ -836,8 +836,8 @@ public class DefaultCamelContext extends SimpleCamelContext
implements ModelCame
}
}
- Properties prop = new Properties();
- prop.putAll(params);
+ OrderedLocationProperties prop = new
OrderedLocationProperties();
+ prop.putAll(routeDefinition.getLocation(), params);
pc.setLocalProperties(prop);
// we need to shadow the bean registry on the CamelContext
with the local beans from the route template context
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 9cc72fb8cd8..39b0e50542f 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
@@ -1651,6 +1651,9 @@ public abstract class BaseMainSupport extends BaseService
{
if (loc.contains(":")) {
loc = StringHelper.after(loc, ":");
}
+ // strip paths so location is only the name
+ loc = FileUtil.stripPath(loc);
+ // clip long name
if (loc.length() > 28) {
int pos = loc.length() - 28;
loc = loc.substring(pos);