jdaugherty commented on code in PR #16547:
URL: https://github.com/apache/grails-core/pull/16547#discussion_r4221024911


##########
grails-core/src/main/groovy/org/grails/config/yaml/YamlPropertySourceLoader.java:
##########
@@ -58,9 +62,17 @@ public List<PropertySource<?>> load(String name, Resource 
resource) throws IOExc
 
     public List<PropertySource<?>> load(String name, Resource resource, 
List<String> filteredKeys) throws IOException {
         setResources(resource);
+        // Select source documents once; merging resolved configuration must 
not re-evaluate JVM profiles.

Review Comment:
   Fixed in b92b61d8df. Once documents are selected, the loader removes 
`spring.config.activate.on-profile` and `spring.profiles` (scalar and indexed 
keys) before merging, so Boot no longer evaluates them again.
   
   The new `GrailsAppYamlProfileSpec` starts `GrailsApp` against an 
`application.yml`. It covers `'!production'` with `grails.env=production`, 
`'!prod'` with `--spring.profiles.active=prod`, and selected legacy 
`spring.profiles` documents, both scalar and sequence. Before the change, the 
negated cases resolved `sample.base` to `null` and the legacy cases failed with 
`InvalidConfigDataPropertyException`.



##########
grails-core/src/main/groovy/org/grails/config/yaml/YamlPropertySourceLoader.java:
##########
@@ -58,9 +62,17 @@ public List<PropertySource<?>> load(String name, Resource 
resource) throws IOExc
 
     public List<PropertySource<?>> load(String name, Resource resource, 
List<String> filteredKeys) throws IOException {
         setResources(resource);
+        // Select source documents once; merging resolved configuration must 
not re-evaluate JVM profiles.
+        final List<String> activeProfiles = Arrays.asList(
+                
StringUtils.tokenizeToStringArray(System.getProperty("spring.profiles.active", 
""), ","));
         setDocumentMatchers((DocumentMatcher) properties -> {
-            final String profile = properties.getProperty("spring.profiles");
-            return profile == null || 
profile.equalsIgnoreCase(System.getProperty("spring.profiles.active")) ? 
MatchStatus.FOUND : MatchStatus.NOT_FOUND;
+            final String[] profiles = profileSelectors(properties, 
"spring.config.activate.on-profile");
+            final String[] legacyProfiles = profileSelectors(properties, 
"spring.profiles");
+            final boolean matchesProfile = profiles.length == 0 ||

Review Comment:
   Done in b92b61d8df. Scalar selectors are now split with 
`StringUtils.commaDelimitedListToStringArray`, and each entry is an 
alternative, as with a sequence. Blank entries are ignored. The `'dev,alpha'` 
rows now select the document, and I added rows such as `'beta, dev & alpha'` 
and `'!prod,!test'`. Sequence entries are not split further, which matches 
Boot's indexed binding. The guide paragraph now describes commas as 
alternatives.



##########
grails-doc/src/en/guide/conf/config.adoc:
##########
@@ -53,6 +53,35 @@ For example:
 my.tmp.dir = "${userHome}/.grails/tmp"
 ----
 
+=== Profile-specific YAML Documents
+
+Use `spring.config.activate.on-profile` to load a YAML document only when its 
profile condition matches. Grails evaluates these conditions against the 
comma-separated profiles in the JVM's `spring.profiles.active` system property. 
For example, `-Dspring.profiles.active=dev,alpha` activates both `dev` and 
`alpha`; whitespace around each name is ignored.

Review Comment:
   Added a NOTE in b92b61d8df. It says only the `spring.profiles.active` system 
property affects document selection, lists `SPRING_PROFILES_ACTIVE`, 
`--spring.profiles.active` and the Grails environment name as sources that are 
not considered, and includes the `'!prod'` example.



-- 
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