All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.boot.env.ConfigTreePropertySource Maven / Gradle / Ivy

There is a newer version: 3.2.5
Show newest version
/*
 * Copyright 2012-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.boot.env;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import org.springframework.boot.convert.ApplicationConversionService;
import org.springframework.boot.origin.Origin;
import org.springframework.boot.origin.OriginLookup;
import org.springframework.boot.origin.OriginProvider;
import org.springframework.boot.origin.TextResourceOrigin;
import org.springframework.boot.origin.TextResourceOrigin.Location;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.InputStreamSource;
import org.springframework.core.io.PathResource;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils;

/**
 * {@link PropertySource} backed by a directory tree that contains files for each value.
 * The {@link PropertySource} will recursively scan a given source directory and expose a
 * property for each file found. The property name will be the filename, and the property
 * value will be the contents of the file.
 * 

* Directories are only scanned when the source is first created. The directory is not * monitored for updates, so files should not be added or removed. However, the contents * of a file can be updated as long as the property source was created with a * {@link Option#ALWAYS_READ} option. Nested directories are included in the source, but * with a {@code '.'} rather than {@code '/'} used as the path separator. *

* Property values are returned as {@link Value} instances which allows them to be treated * either as an {@link InputStreamSource} or as a {@link CharSequence}. In addition, if * used with an {@link Environment} configured with an * {@link ApplicationConversionService}, property values can be converted to a * {@code String} or {@code byte[]}. *

* This property source is typically used to read Kubernetes {@code configMap} volume * mounts. * * @author Phillip Webb * @since 2.4.0 */ public class ConfigTreePropertySource extends EnumerablePropertySource implements OriginLookup { private static final int MAX_DEPTH = 100; private final Map propertyFiles; private final String[] names; private final Set





© 2015 - 2024 Weber Informatics LLC | Privacy Policy