Skip to content
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

Source names as constants #1268

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -9,12 +9,14 @@
public final class DefaultValuesConfigSource extends AbstractConfigSource {
private static final long serialVersionUID = -6386021034957868328L;

private final Map<String, String> properties;
public static final String NAME = "DefaultValuesConfigSource";
public static final int ORDINAL = Integer.MIN_VALUE;

private final Map<String, String> properties;
private final Map<PropertyName, String> wildcards;

public DefaultValuesConfigSource(final Map<String, String> properties) {
this(properties, "DefaultValuesConfigSource", Integer.MIN_VALUE);
this(properties, NAME, ORDINAL);
}

public DefaultValuesConfigSource(final Map<String, String> properties, final String name, final int ordinal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@
public class PropertiesConfigSource extends MapBackedConfigValueConfigSource {
private static final long serialVersionUID = 1866835565147832432L;

private static final String NAME_PREFIX = "PropertiesConfigSource[source=";
public static final String NAME = "PropertiesConfigSource[source=%s]";
public static final int ORDINAL = DEFAULT_ORDINAL;

public PropertiesConfigSource(URL url) throws IOException {
this(url, DEFAULT_ORDINAL);
}

public PropertiesConfigSource(URL url, int defaultOrdinal) throws IOException {
this(url, NAME_PREFIX + url.toString() + "]", defaultOrdinal);
this(url, String.format(NAME, url.toString()), defaultOrdinal);
}

private PropertiesConfigSource(URL url, String name, int defaultOrdinal) throws IOException {
Expand All @@ -57,7 +58,7 @@ public PropertiesConfigSource(Properties properties, String name) {
}

public PropertiesConfigSource(Map<String, String> properties, String name, int defaultOrdinal) {
this(NAME_PREFIX + name + "]", properties, defaultOrdinal);
this(String.format(NAME, name), properties, defaultOrdinal);
}

private PropertiesConfigSource(String name, Map<String, String> properties, int defaultOrdinal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
*/
public class SysPropConfigSource extends AbstractConfigSource {
private static final long serialVersionUID = 9167738611308785403L;
private static final int DEFAULT_ORDINAL = 400;

public static final String NAME = "SysPropConfigSource";
public static final int ORDINAL = 400;

public SysPropConfigSource() {
super("SysPropConfigSource", ConfigSourceUtil.getOrdinalFromMap(getSystemProperties(), DEFAULT_ORDINAL));
super(NAME, ConfigSourceUtil.getOrdinalFromMap(getSystemProperties(), ORDINAL));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,17 @@
public class FileSystemConfigSource extends MapBackedConfigSource {
private static final long serialVersionUID = 654034634846856045L;

public static final String NAME = "FileSystemConfigSource[dir=%s]";
public static final int ORDINAL = DEFAULT_ORDINAL;

private static final Pattern PATTERN = Pattern.compile("[^a-zA-Z0-9_]");

public FileSystemConfigSource(File dir) {
this(dir, DEFAULT_ORDINAL);
this(dir, ORDINAL);
}

public FileSystemConfigSource(String dir) {
this(new File(dir), DEFAULT_ORDINAL);
this(new File(dir), ORDINAL);
}

/**
Expand All @@ -75,7 +78,7 @@ public FileSystemConfigSource(String dir) {
* @param ordinal the ordinal value
*/
public FileSystemConfigSource(File dir, int ordinal) {
super("FileSystemConfigSource[dir=" + dir.getAbsolutePath() + "]", scan(dir), ordinal);
super(String.format(NAME, dir.getAbsolutePath()), scan(dir), ordinal);
}

private static Map<String, String> scan(File directory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import java.util.Set;
import java.util.TreeMap;

import org.eclipse.microprofile.config.spi.ConfigSource;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigList;
Expand All @@ -24,7 +22,8 @@
public class HoconConfigSource extends MapBackedConfigSource {
private static final long serialVersionUID = -458821383311704657L;

static final int ORDINAL = ConfigSource.DEFAULT_ORDINAL + 5;
public static final String NAME = "HoconConfigSource[source=%s]";
public static final int ORDINAL = DEFAULT_ORDINAL + 5;

public HoconConfigSource(String name, Map<String, String> source, int ordinal) {
super(name, source, ordinal, false);
Expand All @@ -35,7 +34,7 @@ public HoconConfigSource(URL url) throws IOException {
}

public HoconConfigSource(URL url, int ordinal) throws IOException {
this("HoconConfigSource[source=" + url.toString() + "]", ClassPathUtils.readStream(url, inputStream -> {
this(String.format(NAME, url.toString()), ClassPathUtils.readStream(url, inputStream -> {
try {
return streamToMap(inputStream);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.smallrye.config.source.keystore;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.microprofile.config.spi.ConfigSource.DEFAULT_ORDINAL;

import java.io.IOException;
import java.net.URL;
Expand Down Expand Up @@ -33,6 +34,9 @@
import io.smallrye.config.source.keystore.KeyStoreConfig.KeyStore.Alias;

public class KeyStoreConfigSourceFactory implements ConfigSourceFactory {
public static final String NAME = "KeyStoreConfigSource[source=%s]";
public static final int ORDINAL = DEFAULT_ORDINAL;

@Override
public Iterable<ConfigSource> getConfigSources(final ConfigSourceContext context) {
KeyStoreConfig keyStoreConfig = getKeyStoreConfig(context);
Expand Down Expand Up @@ -107,7 +111,7 @@ protected ConfigSource loadConfigSource(final URL url, final int ordinal) throws

@Override
public Iterable<ConfigSource> getConfigSources(final ConfigSourceContext context) {
return loadConfigSources(keyStore.path(), 100);
return loadConfigSources(keyStore.path(), ORDINAL);
}

}.getConfigSources(context);
Expand Down Expand Up @@ -195,7 +199,7 @@ public String getValue(final String propertyName) {

@Override
public String getName() {
return "KeyStoreConfigSource[source=" + url.toString() + "]";
return String.format(NAME, url.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import org.eclipse.microprofile.config.spi.ConfigSource;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
Expand All @@ -33,8 +32,8 @@
public class YamlConfigSource extends MapBackedConfigSource {
private static final long serialVersionUID = -418186029484956531L;

private static final String NAME_PREFIX = "YamlConfigSource[source=";
private static final int ORDINAL = ConfigSource.DEFAULT_ORDINAL + 10;
public static final String NAME = "YamlConfigSource[source=%s]";
public static final int ORDINAL = DEFAULT_ORDINAL + 10;

public YamlConfigSource(String name, Map<String, String> source, int ordinal) {
super(name, source, ordinal, false);
Expand All @@ -45,7 +44,7 @@ public YamlConfigSource(URL url) throws IOException {
}

public YamlConfigSource(URL url, int ordinal) throws IOException {
this(NAME_PREFIX + url.toString() + "]",
this(String.format(NAME, url.toString()),
ClassPathUtils.readStream(url, (Function<InputStream, Map<String, String>>) inputStream -> {
try {
return streamToMap(inputStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
public class ZooKeeperConfigSource extends AbstractConfigSource {
private static final long serialVersionUID = 3127679154588598693L;

public static final String NAME = "ZooKeeperConfigSource";
public static final int ORDINAL = 150;

//Property the URL of the Zookeeper instance will be read from
static final String ZOOKEEPER_URL_KEY = "io.smallrye.configsource.zookeeper.url";
//Property of the Application Id. This will be the root znode for an application's properties
static final String APPLICATION_ID_KEY = "io.smallrye.configsource.zookeeper.applicationId";

//Name of this ConfigSource
private static final String ZOOKEEPER_CONFIG_SOURCE_NAME = "io.smallrye.configsource.zookeeper";

//Apache Curator framework used to access Zookeeper
private final CuratorFramework curator;
//Root node of an application's configuration
private final String applicationId;

public ZooKeeperConfigSource(final String zookeeperUrl, final String applicationId) {
super(ZOOKEEPER_CONFIG_SOURCE_NAME, 150);
super(NAME, ORDINAL);

//Only create the ZK Client if the properties exist.
if (zookeeperUrl != null && applicationId != null) {
Expand Down
Loading