Skip to content

Commit

Permalink
Adapt to changes in Logback include processing
Browse files Browse the repository at this point in the history
Fixes gh-40491
  • Loading branch information
scottfrederick committed Apr 26, 2024
1 parent 86a3099 commit 3c00bf3
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 0 deletions.
Expand Up @@ -107,6 +107,16 @@ public void addElementSelectorAndActionAssociations(RuleStore ruleStore) {
ruleStore.addTransparentPathPart("springProfile");
}

@Override
public void buildModelInterpretationContext() {
super.buildModelInterpretationContext();
this.modelInterpretationContext.setConfiguratorSupplier(() -> {
SpringBootJoranConfigurator configurator = new SpringBootJoranConfigurator(this.initializationContext);
configurator.setContext(this.context);
return configurator;
});
}

boolean configureUsingAotGeneratedArtifacts() {
if (!new PatternRules(getContext()).load()) {
return false;
Expand Down
Expand Up @@ -83,6 +83,14 @@ void profileActive() throws Exception {
assertThat(this.output).contains("Hello");
}

@Test
void profileInIncludeActive() throws Exception {
this.environment.setActiveProfiles("production");
initialize("profile-in-include.xml");
this.logger.trace("Hello");
assertThat(this.output).contains("Hello");
}

@Test
void multipleNamesFirstProfileActive() throws Exception {
this.environment.setActiveProfiles("production");
Expand Down Expand Up @@ -203,6 +211,13 @@ void springPropertyInIfWhenFalse() throws Exception {
assertThat(this.context.getProperty("MYCHECK")).isNull();
}

@Test
void springPropertyInInclude() throws Exception {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "my.example-property=test");
initialize("property-in-include.xml");
assertThat(this.context.getProperty("MINE")).isEqualTo("test");
}

@Test
void addsAotContributionToContextDuringAotProcessing() throws Exception {
withSystemProperty("spring.aot.processing", "true", () -> {
Expand Down
@@ -0,0 +1,5 @@
<included>
<springProfile name="production">
<logger name="org.springframework.boot.logging.logback" level="TRACE" />
</springProfile>
</included>
@@ -0,0 +1,3 @@
<included>
<springProperty scope="context" name="MINE" source="my.example-property" defaultValue="default-test" />
</included>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<include resource="org/springframework/boot/logging/logback/include-with-profile.xml" />
</configuration>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<include resource="org/springframework/boot/logging/logback/include-with-property.xml" />
</configuration>

0 comments on commit 3c00bf3

Please sign in to comment.