Skip to content

Polish #42192

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

Closed
wants to merge 2 commits into from
Closed

Polish #42192

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,6 @@ private void setDriverClass(ComboPooledDataSource dataSource, String driverClass
*/
private static class SimpleDataSourceProperties extends MappedDataSourceProperties<SimpleDriverDataSource> {

@SuppressWarnings("unchecked")
SimpleDataSourceProperties() {
add(DataSourceProperty.URL, SimpleDriverDataSource::getUrl, SimpleDriverDataSource::setUrl);
add(DataSourceProperty.DRIVER_CLASS_NAME, Class.class, (dataSource) -> dataSource.getDriver().getClass(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ else if (value instanceof Map<?, ?> map) {
else if (value instanceof Number) {
append(value.toString());
}
else if (value instanceof Boolean) {
append(Boolean.TRUE.equals(value) ? "true" : "false");
else if (value instanceof Boolean bool) {
append(bool ? "true" : "false");
}
else {
writeString(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,7 @@ protected void loadConfiguration(LoggingInitializationContext initializationCont

private void load(LoggingInitializationContext initializationContext, String location, LogFile logFile) {
List<String> overrides = getOverrides(initializationContext);
if (initializationContext != null) {
applySystemProperties(initializationContext.getEnvironment(), logFile);
}
applySystemProperties(initializationContext.getEnvironment(), logFile);
loadConfiguration(location, logFile, overrides);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,49 +51,43 @@ public void initialize(ConfigurableApplicationContext applicationContext) {
applicationContext.addApplicationListener(new Listener(applicationContext));
}

private static class Listener implements ApplicationListener<RSocketServerInitializedEvent> {
private record Listener(ConfigurableApplicationContext applicationContext) implements ApplicationListener<RSocketServerInitializedEvent> {

private static final String PROPERTY_NAME = "local.rsocket.server.port";
private static final String PROPERTY_NAME = "local.rsocket.server.port";

private static final String PROPERTY_SOURCE_NAME = "server.ports";

private final ConfigurableApplicationContext applicationContext;

Listener(ConfigurableApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
private static final String PROPERTY_SOURCE_NAME = "server.ports";

@Override
public void onApplicationEvent(RSocketServerInitializedEvent event) {
if (event.getServer().address() != null) {
setPortProperty(this.applicationContext, event.getServer().address().getPort());
public void onApplicationEvent(RSocketServerInitializedEvent event) {
if (event.getServer().address() != null) {
setPortProperty(this.applicationContext, event.getServer().address().getPort());
}
}
}

private void setPortProperty(ApplicationContext context, int port) {
if (context instanceof ConfigurableApplicationContext configurableContext) {
setPortProperty(configurableContext.getEnvironment(), port);
private void setPortProperty(ApplicationContext context, int port) {
if (context instanceof ConfigurableApplicationContext configurableContext) {
setPortProperty(configurableContext.getEnvironment(), port);
}
if (context.getParent() != null) {
setPortProperty(context.getParent(), port);
}
}
if (context.getParent() != null) {
setPortProperty(context.getParent(), port);

private void setPortProperty(ConfigurableEnvironment environment, int port) {
MutablePropertySources sources = environment.getPropertySources();
PropertySource<?> source = sources.get(PROPERTY_SOURCE_NAME);
if (source == null) {
source = new MapPropertySource(PROPERTY_SOURCE_NAME, new HashMap<>());
sources.addFirst(source);
}
setPortProperty(port, source);
}
}

private void setPortProperty(ConfigurableEnvironment environment, int port) {
MutablePropertySources sources = environment.getPropertySources();
PropertySource<?> source = sources.get(PROPERTY_SOURCE_NAME);
if (source == null) {
source = new MapPropertySource(PROPERTY_SOURCE_NAME, new HashMap<>());
sources.addFirst(source);
@SuppressWarnings("unchecked")
private void setPortProperty(int port, PropertySource<?> source) {
((Map<String, Object>) source.getSource()).put(PROPERTY_NAME, port);
}
setPortProperty(port, source);
}

@SuppressWarnings("unchecked")
private void setPortProperty(int port, PropertySource<?> source) {
((Map<String, Object>) source.getSource()).put(PROPERTY_NAME, port);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/**
* {@link ApplicationContext} backed {@link ServerWebExchangeMatcher}. Can work directly
* with the {@link ApplicationContext}, obtain an existing bean or
* {@link AutowireCapableBeanFactory#createBean(Class, int, boolean) create a new bean}
* {@link AutowireCapableBeanFactory#createBean(Class) create a new bean}
* that is autowired in the usual way.
*
* @param <C> the type of the context that the match method actually needs to use. Can be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* {@link ApplicationContext} backed {@link RequestMatcher}. Can work directly with the
* {@link ApplicationContext}, obtain an existing bean or
* {@link AutowireCapableBeanFactory#createBean(Class, int, boolean) create a new bean}
* {@link AutowireCapableBeanFactory#createBean(Class) create a new bean}
* that is autowired in the usual way.
*
* @param <C> the type of the context that the match method actually needs to use. Can be
Expand Down
Loading