use of cn.taketoday.origin.Origin in project today-framework by TAKETODAY.
the class ConfigDataEnvironmentContributorPlaceholdersResolver method resolvePlaceholder.
@Nullable
private String resolvePlaceholder(String placeholder) {
Object result = null;
for (ConfigDataEnvironmentContributor contributor : this.contributors) {
PropertySource<?> propertySource = contributor.getPropertySource();
Object value = (propertySource != null) ? propertySource.getProperty(placeholder) : null;
if (value != null && !isActive(contributor)) {
if (this.failOnResolveFromInactiveContributor) {
ConfigDataResource resource = contributor.getResource();
Origin origin = OriginLookup.getOrigin(propertySource, placeholder);
throw new InactiveConfigDataAccessException(propertySource, resource, placeholder, origin);
}
value = null;
}
result = (result != null) ? result : value;
}
return (result != null) ? String.valueOf(result) : null;
}
use of cn.taketoday.origin.Origin in project today-framework by TAKETODAY.
the class ConfigDataNotFoundFailureAnalyzer method analyze.
@Override
protected FailureAnalysis analyze(Throwable rootFailure, ConfigDataNotFoundException cause) {
ConfigDataLocation location = getLocation(cause);
Origin origin = Origin.from(location);
String message = String.format("Config data %s does not exist", cause.getReferenceDescription());
StringBuilder action = new StringBuilder("Check that the value ");
if (location != null) {
action.append(String.format("'%s' ", location));
}
if (origin != null) {
action.append(String.format("at %s ", origin));
}
action.append("is correct");
if (location != null && !location.isOptional()) {
action.append(String.format(", or prefix it with '%s'", ConfigDataLocation.OPTIONAL_PREFIX));
}
return new FailureAnalysis(message, action.toString(), cause);
}
use of cn.taketoday.origin.Origin in project today-infrastructure by TAKETODAY.
the class ConfigDataEnvironmentContributorPlaceholdersResolver method resolvePlaceholder.
@Nullable
private String resolvePlaceholder(String placeholder) {
Object result = null;
for (ConfigDataEnvironmentContributor contributor : this.contributors) {
PropertySource<?> propertySource = contributor.getPropertySource();
Object value = (propertySource != null) ? propertySource.getProperty(placeholder) : null;
if (value != null && !isActive(contributor)) {
if (this.failOnResolveFromInactiveContributor) {
ConfigDataResource resource = contributor.getResource();
Origin origin = OriginLookup.getOrigin(propertySource, placeholder);
throw new InactiveConfigDataAccessException(propertySource, resource, placeholder, origin);
}
value = null;
}
result = (result != null) ? result : value;
}
return (result != null) ? String.valueOf(result) : null;
}
use of cn.taketoday.origin.Origin in project today-infrastructure by TAKETODAY.
the class ConfigDataEnvironmentPostProcessorIntegrationTests method runWhenImportingIncludesParentOrigin.
@Test
void runWhenImportingIncludesParentOrigin() {
ConfigurableApplicationContext context = this.application.run("--context.config.location=classpath:application-import-with-placeholder.properties");
Binder binder = Binder.get(context.getEnvironment());
List<ConfigurationProperty> properties = new ArrayList<>();
BindHandler bindHandler = new BindHandler() {
@Override
public Object onSuccess(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) {
properties.add(context.getConfigurationProperty());
return result;
}
};
binder.bind("my.value", Bindable.of(String.class), bindHandler);
assertThat(properties).hasSize(1);
Origin origin = properties.get(0).getOrigin();
assertThat(origin.toString()).contains("application-import-with-placeholder-imported");
assertThat(origin.getParent().toString()).contains("application-import-with-placeholder");
}
use of cn.taketoday.origin.Origin in project today-infrastructure by TAKETODAY.
the class ConfigDataLocationTests method withOriginSetsOrigin.
@Test
void withOriginSetsOrigin() {
Origin origin = mock(Origin.class);
ConfigDataLocation location = ConfigDataLocation.valueOf("test").withOrigin(origin);
assertThat(location.getOrigin()).isSameAs(origin);
}
Aggregations