Skip to content

Commit

Permalink
Consistent collection type for profiles (#1149)
Browse files Browse the repository at this point in the history
radcortez authored Apr 19, 2024
1 parent 2327fb8 commit d863731
Showing 3 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ private void matchPropertiesWithEnv(final SmallRyeConfig config) {
// TODO - We shouldn't be mutating the EnvSource.
// We should do the calculation when creating the EnvSource, but right now mappings and sources are not well integrated.

String[] profiles = config.getProfiles().toArray(new String[0]);
List<String> profiles = config.getProfiles();
boolean all = roots.containsKey("");
StringBuilder sb = new StringBuilder();

Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
@Priority(Priorities.LIBRARY + 200)
public class ProfileConfigSourceInterceptor implements ConfigSourceInterceptor {
private static final long serialVersionUID = -6305289277993917313L;
private final String[] profiles;
private final List<String> profiles;

public ProfileConfigSourceInterceptor(final String profile) {
this(profile != null ? convertProfile(profile) : new ArrayList<>());
@@ -26,12 +26,12 @@ public ProfileConfigSourceInterceptor(final String profile) {
public ProfileConfigSourceInterceptor(final List<String> profiles) {
List<String> reverseProfiles = new ArrayList<>(profiles);
Collections.reverse(reverseProfiles);
this.profiles = reverseProfiles.toArray(new String[0]);
this.profiles = reverseProfiles;
}

@Override
public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) {
if (profiles.length > 0) {
if (profiles.size() > 0) {
final String normalizeName = activeName(name, profiles);
final ConfigValue profileValue = getProfileValue(context, normalizeName);
if (profileValue != null) {
@@ -67,11 +67,11 @@ public Iterator<String> iterateNames(final ConfigSourceInterceptorContext contex
return names.iterator();
}

public String[] getProfiles() {
public List<String> getProfiles() {
return profiles;
}

public static String activeName(final String name, final String[] profiles) {
public static String activeName(final String name, final List<String> profiles) {
if (!name.isEmpty() && name.charAt(0) == '%') {
int profilesEnd = name.indexOf('.', 1);
int multipleSplit = -1;
Original file line number Diff line number Diff line change
@@ -28,7 +28,6 @@
import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
@@ -361,18 +360,18 @@ public <T> T convertValue(ConfigValue configValue, Converter<T> converter) {
// See if the Converter is designed to handle a missing (null) value i.e. Optional Converters
converted = converter.convert("");
} catch (IllegalArgumentException ignored) {
throw new NoSuchElementException(ConfigMessages.msg.propertyNotFound(configValue.getNameProfiled())); // 2
throw new NoSuchElementException(ConfigMessages.msg.propertyNotFound(configValue.getNameProfiled()));
}
}

if (converted == null) {
if (configValue.getValue() == null) {
throw new NoSuchElementException(ConfigMessages.msg.propertyNotFound(configValue.getNameProfiled())); // 2
throw new NoSuchElementException(ConfigMessages.msg.propertyNotFound(configValue.getNameProfiled()));
} else if (configValue.getValue().isEmpty()) {
throw ConfigMessages.msg.propertyEmptyString(configValue.getNameProfiled(), converter.getClass().getTypeName()); // 3
throw ConfigMessages.msg.propertyEmptyString(configValue.getNameProfiled(), converter.getClass().getTypeName());
} else {
throw ConfigMessages.msg.converterReturnedNull(configValue.getNameProfiled(), configValue.getValue(),
converter.getClass().getTypeName()); // 4
converter.getClass().getTypeName());
}
}

@@ -807,7 +806,7 @@ private static List<ConfigSourceWithPriority> mapSources(final List<ConfigSource
private static List<String> getProfiles(final List<ConfigSourceInterceptor> interceptors) {
for (ConfigSourceInterceptor interceptor : interceptors) {
if (interceptor instanceof ProfileConfigSourceInterceptor) {
return Arrays.asList(((ProfileConfigSourceInterceptor) interceptor).getProfiles());
return ((ProfileConfigSourceInterceptor) interceptor).getProfiles();
}
}
return Collections.emptyList();

0 comments on commit d863731

Please sign in to comment.