Croway commented on code in PR #1907:
URL: 
https://github.com/apache/camel-spring-boot/pull/1907#discussion_r3880628166


##########
core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/EarlyResolutionPropertySources.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.spring.boot;
+
+import java.util.Properties;
+
+import org.springframework.boot.origin.OriginTrackedValue;
+
+/**
+ * Helpers for early property resolution listeners that inject a flat {@link 
Properties} override via
+ * {@code PropertySources.addFirst}.
+ * <p/>
+ * Spring iterates property sources in precedence order (highest first). When 
the same key appears in multiple
+ * sources, callers must retain the first resolved value so the override map 
reflects Spring's normal precedence
+ * after it is added with {@code addFirst}.
+ */
+public final class EarlyResolutionPropertySources {
+
+    private EarlyResolutionPropertySources() {
+    }
+
+    /**
+     * Returns the string value from a property source entry, including {@link 
OriginTrackedValue} wrappers.
+     */
+    public static String asString(Object value) {
+        if (value instanceof OriginTrackedValue originTrackedValue
+                && originTrackedValue.getValue() instanceof String 
stringValue) {
+            return stringValue;
+        }
+        if (value instanceof String stringValue) {
+            return stringValue;
+        }
+        return null;
+    }
+
+    /**
+     * Stores a resolved value only when the key is not already present, 
preserving highest-precedence values
+     * collected while iterating property sources.
+     */
+    public static void putIfAbsent(Properties props, Object key, String 
resolvedValue) {
+        props.putIfAbsent(key.toString(), resolvedValue);
+    }
+}

Review Comment:
   ```suggestion
       /**
        * Returns whether a property source with higher precedence defines the 
same key.
        */
       public static boolean hasHigherPrecedenceProperty(
               Iterable<PropertySource<?>> propertySources, PropertySource<?> 
currentPropertySource, Object key) {
           for (PropertySource<?> propertySource : propertySources) {
               if (propertySource == currentPropertySource) {
                   return false;
               }
               if (propertySource instanceof MapPropertySource && 
propertySource.containsProperty(key.toString())) {
                   return true;
               }
           }
           return false;
       }
   }
   ```



##########
core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/EarlyResolutionPropertySources.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.spring.boot;
+
+import java.util.Properties;
+
+import org.springframework.boot.origin.OriginTrackedValue;

Review Comment:
   ```suggestion
   import org.springframework.boot.origin.OriginTrackedValue;
   import org.springframework.core.env.MapPropertySource;
   import org.springframework.core.env.PropertySource;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to