Skip to content

Commit

Permalink
Prevent double-warning when using deprecated properties
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd authored and poldinik committed Apr 29, 2024
1 parent 3e52fc4 commit 3559c94
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,7 @@ public String getValue(final String propertyName) {
builder.getSources().clear();
builder.getSourceProviders().clear();
builder.setAddDefaultSources(false)
.withInterceptors(ConfigCompatibility.FrontEnd.nonLoggingInstance(), ConfigCompatibility.BackEnd.instance())
.addDiscoveredCustomizers()
.withProfiles(config.getProfiles())
.withSources(sourceProperties);
Expand All @@ -1099,6 +1100,7 @@ public String getValue(final String propertyName) {
builder.getSources().clear();
builder.getSourceProviders().clear();
builder.setAddDefaultSources(false)
.withInterceptors(ConfigCompatibility.FrontEnd.nonLoggingInstance(), ConfigCompatibility.BackEnd.instance())
.addDiscoveredCustomizers()
.withSources(sourceProperties)
.withSources(new MapBackedConfigSource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,13 @@ public static final class FrontEnd implements ConfigSourceInterceptor {
@Serial
private static final long serialVersionUID = -3438497970389074611L;

private static final FrontEnd instance = new FrontEnd();
private static final FrontEnd instance = new FrontEnd(true);
private static final FrontEnd nonLoggingInstance = new FrontEnd(false);

private FrontEnd() {
private final boolean logging;

private FrontEnd(final boolean logging) {
this.logging = logging;
}

public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) {
Expand Down Expand Up @@ -155,11 +159,13 @@ public boolean hasNext() {
// get the replacement names
List<String> list = fn.apply(context, new NameIterator(next));
subIter = list.iterator();
// todo: print these warnings when mapping the configuration so they cannot appear more than once
if (list.isEmpty()) {
log.warnf("Configuration property '%s' has been deprecated and will be ignored", next);
} else {
log.warnf("Configuration property '%s' has been deprecated and replaced by: %s", next, list);
if (logging) {
// todo: print these warnings when mapping the configuration so they cannot appear more than once
if (list.isEmpty()) {
log.warnf("Configuration property '%s' has been deprecated and will be ignored", next);
} else {
log.warnf("Configuration property '%s' has been deprecated and replaced by: %s", next, list);
}
}
}
return true;
Expand All @@ -179,6 +185,10 @@ public String next() {
public static FrontEnd instance() {
return instance;
}

public static FrontEnd nonLoggingInstance() {
return nonLoggingInstance;
}
}

/**
Expand Down

0 comments on commit 3559c94

Please sign in to comment.