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 2024/03/13 16:40:04 UTC
(camel) branch main-profile updated: CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main-profile
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main-profile by this push:
new da4b2a07ae9 CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test
da4b2a07ae9 is described below
commit da4b2a07ae987794a73e338cccdd11441be9c701
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Mar 13 17:39:45 2024 +0100
CAMEL-18090: camel-main - Loading properties with profiles for prod/dev/test
---
.../component/properties/PropertiesComponent.java | 4 +---
.../src/test/java/org/apache/camel/main/MainTest.java | 15 +++++++++++++++
.../src/test/resources/application-prod.properties | 19 +++++++++++++++++++
3 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java b/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index d7acf6218b9..bf708f58a22 100644
--- a/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ b/core/camel-base/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -353,7 +353,7 @@ public class PropertiesComponent extends ServiceSupport
// we need to re-create the property sources which may have already been created from locations
this.sources.removeIf(s -> s instanceof LocationPropertiesSource);
- // ensure order we want as given in the locations
+ // ensure the locations are in the same order as here, and therefore we provide the order number
int order = 100;
for (PropertiesLocation loc : locations) {
addPropertiesLocationsAsPropertiesSource(loc, order++);
@@ -388,8 +388,6 @@ public class PropertiesComponent extends ServiceSupport
public void addLocation(String location) {
if (location != null) {
List<PropertiesLocation> newLocations = new ArrayList<>();
- // add in reverse order as
-
for (String loc : location.split(",")) {
newLocations.add(new PropertiesLocation(loc));
}
diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainTest.java b/core/camel-main/src/test/java/org/apache/camel/main/MainTest.java
index fb9935da4eb..3b4d5de4578 100644
--- a/core/camel-main/src/test/java/org/apache/camel/main/MainTest.java
+++ b/core/camel-main/src/test/java/org/apache/camel/main/MainTest.java
@@ -140,6 +140,21 @@ public class MainTest {
main.stop();
}
+ @Test
+ public void testProfile() throws Exception {
+ // lets make a simple route
+ Main main = new Main();
+ main.configure().addRoutesBuilder(new MyRouteBuilder());
+ main.configure().withProfile("prod");
+ main.start();
+
+ CamelContext camelContext = main.getCamelContext();
+ // should load application-prod.properties from classpath
+ assertEquals("Production World", camelContext.resolvePropertyPlaceholders("{{hello}}"));
+
+ main.stop();
+ }
+
@Test
public void testDisableTracing() throws Exception {
Main main = new Main();
diff --git a/core/camel-main/src/test/resources/application-prod.properties b/core/camel-main/src/test/resources/application-prod.properties
new file mode 100644
index 00000000000..7be4cfa5d50
--- /dev/null
+++ b/core/camel-main/src/test/resources/application-prod.properties
@@ -0,0 +1,19 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+# this should override the value from application.properties
+hello=Production World