Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Banner placeholders use default values too soon #34713

Closed
Saucistophe opened this issue Mar 22, 2023 · 4 comments
Closed

Banner placeholders use default values too soon #34713

Saucistophe opened this issue Mar 22, 2023 · 4 comments
Assignees
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: bug A general bug

Comments

@Saucistophe
Copy link

Saucistophe commented Mar 22, 2023

The ResourceBanner uses placeholders with the regular syntax ${variable.name} syntax.

There are only a few variables supported, which is fine; and some of them, such as the application version, is not resolved when starting the project from IDE (as opposed from the jar).

I wanted to use default values, for instance ${application.version:dev}; when I do that, the printed version becomes dev regardless of whether it's defined.

I reproduced the issue in unit tests in ResourceBannerTests, and I think it is due to the way we handle resolvers:

for (PropertyResolver resolver : getPropertyResolvers(environment, sourceClass)) {
    banner = resolver.resolvePlaceholders(banner);
}

If the first resolver fails to find the value, it outputs the default value and it's final.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 22, 2023
@philwebb philwebb added type: bug A general bug status: ideal-for-contribution An issue that a contributor can help us with and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 22, 2023
@philwebb philwebb added this to the 2.7.x milestone Mar 22, 2023
@krzyk
Copy link
Contributor

krzyk commented Mar 23, 2023

@philwebb Can I work on this one?

@wilkinsona
Copy link
Member

It's all yours, @krzyk. Thank you.

@Saucistophe
Copy link
Author

If that can help, here is the test I wrote:

	@Test
	void renderDefaultValues() {
		Resource resource = new ByteArrayResource(
				"banner ${a}${spring-boot.formatted-version:default-value}".getBytes());
		String banner = printBanner(resource, "10.2", "2.0", null);
		assertThat(banner).startsWith("banner 1 (v10.2)");
	}

..Which yields:

java.lang.AssertionError: 
Expecting actual:
  "banner 1default-value
"
to start with:
  "banner 1 (v10.2)"

@wilkinsona
Copy link
Member

Closing in favor of #34764. Thanks for the PR, @krzyk.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Mar 28, 2023
@wilkinsona wilkinsona changed the title Banner placeholders do not support default values Banner placeholders use default values too soon Mar 28, 2023
@wilkinsona wilkinsona removed this from the 2.7.x milestone Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants