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 cfc6d1d  CAMEL-13346: Camel main - Allow to add extra properties to 
property component
cfc6d1d is described below

commit cfc6d1d2905b44a97841e22b5bc4fc2275276f65
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Wed Mar 20 10:31:15 2019 +0100

    CAMEL-13346: Camel main - Allow to add extra properties to property 
component
---
 .../org/apache/camel/spi/PropertiesComponent.java  | 11 +++++++
 .../java/org/apache/camel/main/MainSupport.java    | 38 ++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git 
a/core/camel-api/src/main/java/org/apache/camel/spi/PropertiesComponent.java 
b/core/camel-api/src/main/java/org/apache/camel/spi/PropertiesComponent.java
index 019de06..07dc1a8 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/PropertiesComponent.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/PropertiesComponent.java
@@ -95,4 +95,15 @@ public interface PropertiesComponent extends Component {
      */
     void setIgnoreMissingLocation(boolean ignoreMissingLocation);
 
+    /**
+     * Sets initial properties which will be added before any property 
locations are loaded.
+     */
+    void setInitialProperties(Properties initialProperties);
+
+    /**
+     * Sets a special list of override properties that take precedence
+     * and will use first, if a property exist.
+     */
+    void setOverrideProperties(Properties overrideProperties);
+
 }
diff --git 
a/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java 
b/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
index 0d5ca62..9f5ced9 100644
--- a/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
+++ b/core/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
@@ -89,6 +89,8 @@ public abstract class MainSupport extends ServiceSupport {
     protected ReloadStrategy reloadStrategy;
     protected String propertyPlaceholderLocations;
     protected boolean autoConfigurationEnabled = true;
+    protected Properties initialProperties;
+    protected Properties overrideProperties;
 
     /**
      * A class for intercepting the hang up signal and do a graceful shutdown 
of the Camel.
@@ -544,6 +546,30 @@ public abstract class MainSupport extends ServiceSupport {
         this.autoConfigurationEnabled = autoConfigurationEnabled;
     }
 
+    public Properties getInitialProperties() {
+        return initialProperties;
+    }
+
+    /**
+     * Sets initial properties for the properties component,
+     * which will be used before any locations are resolved.
+     */
+    public void setInitialProperties(Properties initialProperties) {
+        this.initialProperties = initialProperties;
+    }
+
+    public Properties getOverrideProperties() {
+        return overrideProperties;
+    }
+
+    /**
+     * Sets a special list of override properties that take precedence
+     * and will use first, if a property exist.
+     */
+    public void setOverrideProperties(Properties overrideProperties) {
+        this.overrideProperties = overrideProperties;
+    }
+
     public boolean isTrace() {
         return trace;
     }
@@ -707,12 +733,24 @@ public abstract class MainSupport extends ServiceSupport {
         if (propertyPlaceholderLocations != null) {
             PropertiesComponent pc = camelContext.getPropertiesComponent();
             pc.addLocation(propertyPlaceholderLocations);
+            if (initialProperties != null) {
+                pc.setInitialProperties(initialProperties);
+            }
+            if (overrideProperties != null) {
+                pc.setOverrideProperties(overrideProperties);
+            }
             LOG.info("Using properties from: {}", 
propertyPlaceholderLocations);
         } else {
             // lets default to application.properties and ignore if its missing
             PropertiesComponent pc = camelContext.getPropertiesComponent();
             pc.addLocation("classpath:application.properties");
             pc.setIgnoreMissingLocation(true);
+            if (initialProperties != null) {
+                pc.setInitialProperties(initialProperties);
+            }
+            if (overrideProperties != null) {
+                pc.setOverrideProperties(overrideProperties);
+            }
             LOG.info("Using optional properties from 
classpath:application.properties");
         }
         if (trace) {

Reply via email to