"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedYamlLoader.java" between
spring-boot-2.7.3.tar.gz and spring-boot-2.7.4.tar.gz

About: Spring Boot helps to create Spring-powered, production-grade applications and services.

OriginTrackedYamlLoader.java  (spring-boot-2.7.3):OriginTrackedYamlLoader.java  (spring-boot-2.7.4)
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
skipping to change at line 48 skipping to change at line 48
import org.yaml.snakeyaml.nodes.Tag; import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.representer.Representer; import org.yaml.snakeyaml.representer.Representer;
import org.yaml.snakeyaml.resolver.Resolver; import org.yaml.snakeyaml.resolver.Resolver;
import org.springframework.beans.factory.config.YamlProcessor; import org.springframework.beans.factory.config.YamlProcessor;
import org.springframework.boot.origin.Origin; import org.springframework.boot.origin.Origin;
import org.springframework.boot.origin.OriginTrackedValue; import org.springframework.boot.origin.OriginTrackedValue;
import org.springframework.boot.origin.TextResourceOrigin; import org.springframework.boot.origin.TextResourceOrigin;
import org.springframework.boot.origin.TextResourceOrigin.Location; import org.springframework.boot.origin.TextResourceOrigin.Location;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.util.ReflectionUtils;
/** /**
* Class to load {@code .yml} files into a map of {@code String} to * Class to load {@code .yml} files into a map of {@code String} to
* {@link OriginTrackedValue}. * {@link OriginTrackedValue}.
* *
* @author Madhura Bhave * @author Madhura Bhave
* @author Phillip Webb * @author Phillip Webb
*/ */
class OriginTrackedYamlLoader extends YamlProcessor { class OriginTrackedYamlLoader extends YamlProcessor {
private static final boolean HAS_RESOLVER_LIMIT = ReflectionUtils.findMet
hod(Resolver.class, "addImplicitResolver",
Tag.class, Pattern.class, String.class, int.class) != nul
l;
private final Resource resource; private final Resource resource;
OriginTrackedYamlLoader(Resource resource) { OriginTrackedYamlLoader(Resource resource) {
this.resource = resource; this.resource = resource;
setResources(resource); setResources(resource);
} }
@Override @Override
protected Yaml createYaml() { protected Yaml createYaml() {
LoaderOptions loaderOptions = new LoaderOptions(); LoaderOptions loaderOptions = new LoaderOptions();
loaderOptions.setAllowDuplicateKeys(false); loaderOptions.setAllowDuplicateKeys(false);
loaderOptions.setMaxAliasesForCollections(Integer.MAX_VALUE); loaderOptions.setMaxAliasesForCollections(Integer.MAX_VALUE);
loaderOptions.setAllowRecursiveKeys(true); loaderOptions.setAllowRecursiveKeys(true);
return createYaml(loaderOptions); return createYaml(loaderOptions);
} }
private Yaml createYaml(LoaderOptions loaderOptions) { private Yaml createYaml(LoaderOptions loaderOptions) {
BaseConstructor constructor = new OriginTrackingConstructor(loade rOptions); BaseConstructor constructor = new OriginTrackingConstructor(loade rOptions);
Representer representer = new Representer(); Representer representer = new Representer();
DumperOptions dumperOptions = new DumperOptions(); DumperOptions dumperOptions = new DumperOptions();
LimitedResolver resolver = new LimitedResolver(); Resolver resolver = HAS_RESOLVER_LIMIT ? new NoTimestampResolverW ithLimit() : new NoTimestampResolver();
return new Yaml(constructor, representer, dumperOptions, loaderOp tions, resolver); return new Yaml(constructor, representer, dumperOptions, loaderOp tions, resolver);
} }
List<Map<String, Object>> load() { List<Map<String, Object>> load() {
final List<Map<String, Object>> result = new ArrayList<>(); final List<Map<String, Object>> result = new ArrayList<>();
process((properties, map) -> result.add(getFlattenedMap(map))); process((properties, map) -> result.add(getFlattenedMap(map)));
return result; return result;
} }
/** /**
skipping to change at line 170 skipping to change at line 174
return new KeyScalarNode((ScalarNode) node); return new KeyScalarNode((ScalarNode) node);
} }
return node; return node;
} }
} }
/** /**
* {@link Resolver} that limits {@link Tag#TIMESTAMP} tags. * {@link Resolver} that limits {@link Tag#TIMESTAMP} tags.
*/ */
private static class LimitedResolver extends Resolver { private static class NoTimestampResolver extends Resolver {
@Override @Override
public void addImplicitResolver(Tag tag, Pattern regexp, String f irst) { public void addImplicitResolver(Tag tag, Pattern regexp, String f irst) {
if (tag == Tag.TIMESTAMP) { if (tag == Tag.TIMESTAMP) {
return; return;
} }
super.addImplicitResolver(tag, regexp, first); super.addImplicitResolver(tag, regexp, first);
} }
} }
/**
* {@link Resolver} that limits {@link Tag#TIMESTAMP} tags.
*/
private static class NoTimestampResolverWithLimit extends Resolver {
@Override
public void addImplicitResolver(Tag tag, Pattern regexp, String f
irst, int limit) {
if (tag == Tag.TIMESTAMP) {
return;
}
super.addImplicitResolver(tag, regexp, first, limit);
}
}
} }
 End of changes. 6 change blocks. 
3 lines changed or deleted 25 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)