Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Consistent collection type for profiles #1149

Merged
merged 1 commit into from
Apr 19, 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 @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<>());
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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();
Expand Down