Add workaround for Javadoc generation issues on JDK 9 b181
The javadoc tool on JDK 9 has issues with the combination of anonymous classes and varargs parameters. This commit simply refactors a few anonymous classes to private inner classes.
This commit is contained in:
parent
6ab4b6b0ac
commit
73dff6d21f
|
@ -118,19 +118,7 @@ public abstract class SecureSetting<T> extends Setting<T> {
|
||||||
*/
|
*/
|
||||||
public static Setting<SecureString> secureString(String name, Setting<SecureString> fallback,
|
public static Setting<SecureString> secureString(String name, Setting<SecureString> fallback,
|
||||||
Property... properties) {
|
Property... properties) {
|
||||||
return new SecureSetting<SecureString>(name, properties) {
|
return new SecureStringSetting(name, fallback, properties);
|
||||||
@Override
|
|
||||||
protected SecureString getSecret(SecureSettings secureSettings) throws GeneralSecurityException {
|
|
||||||
return secureSettings.getString(getKey());
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
SecureString getFallback(Settings settings) {
|
|
||||||
if (fallback != null) {
|
|
||||||
return fallback.get(settings);
|
|
||||||
}
|
|
||||||
return new SecureString(new char[0]); // this means "setting does not exist"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -138,16 +126,7 @@ public abstract class SecureSetting<T> extends Setting<T> {
|
||||||
* @see #secureString(String, Setting, Property...)
|
* @see #secureString(String, Setting, Property...)
|
||||||
*/
|
*/
|
||||||
public static Setting<SecureString> insecureString(String name) {
|
public static Setting<SecureString> insecureString(String name) {
|
||||||
return new Setting<SecureString>(name, "", SecureString::new, Property.Deprecated, Property.Filtered, Property.NodeScope) {
|
return new InsecureStringSetting(name);
|
||||||
@Override
|
|
||||||
public SecureString get(Settings settings) {
|
|
||||||
if (ALLOW_INSECURE_SETTINGS == false && exists(settings)) {
|
|
||||||
throw new IllegalArgumentException("Setting [" + name + "] is insecure, " +
|
|
||||||
"but property [allow_insecure_settings] is not set");
|
|
||||||
}
|
|
||||||
return super.get(settings);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -157,19 +136,68 @@ public abstract class SecureSetting<T> extends Setting<T> {
|
||||||
*/
|
*/
|
||||||
public static Setting<InputStream> secureFile(String name, Setting<InputStream> fallback,
|
public static Setting<InputStream> secureFile(String name, Setting<InputStream> fallback,
|
||||||
Property... properties) {
|
Property... properties) {
|
||||||
return new SecureSetting<InputStream>(name, properties) {
|
return new SecureFileSetting(name, fallback, properties);
|
||||||
@Override
|
|
||||||
protected InputStream getSecret(SecureSettings secureSettings) throws GeneralSecurityException {
|
|
||||||
return secureSettings.getFile(getKey());
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
InputStream getFallback(Settings settings) {
|
|
||||||
if (fallback != null) {
|
|
||||||
return fallback.get(settings);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class SecureStringSetting extends SecureSetting<SecureString> {
|
||||||
|
private final Setting<SecureString> fallback;
|
||||||
|
|
||||||
|
private SecureStringSetting(String name, Setting<SecureString> fallback, Property... properties) {
|
||||||
|
super(name, properties);
|
||||||
|
this.fallback = fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SecureString getSecret(SecureSettings secureSettings) throws GeneralSecurityException {
|
||||||
|
return secureSettings.getString(getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
SecureString getFallback(Settings settings) {
|
||||||
|
if (fallback != null) {
|
||||||
|
return fallback.get(settings);
|
||||||
|
}
|
||||||
|
return new SecureString(new char[0]); // this means "setting does not exist"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class InsecureStringSetting extends Setting<SecureString> {
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
private InsecureStringSetting(String name) {
|
||||||
|
super(name, "", SecureString::new, Property.Deprecated, Property.Filtered, Property.NodeScope);
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SecureString get(Settings settings) {
|
||||||
|
if (ALLOW_INSECURE_SETTINGS == false && exists(settings)) {
|
||||||
|
throw new IllegalArgumentException("Setting [" + name + "] is insecure, " +
|
||||||
|
"but property [allow_insecure_settings] is not set");
|
||||||
|
}
|
||||||
|
return super.get(settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SecureFileSetting extends SecureSetting<InputStream> {
|
||||||
|
private final Setting<InputStream> fallback;
|
||||||
|
|
||||||
|
private SecureFileSetting(String name, Setting<InputStream> fallback, Property... properties) {
|
||||||
|
super(name, properties);
|
||||||
|
this.fallback = fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected InputStream getSecret(SecureSettings secureSettings) throws GeneralSecurityException {
|
||||||
|
return secureSettings.getFile(getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
InputStream getFallback(Settings settings) {
|
||||||
|
if (fallback != null) {
|
||||||
|
return fallback.get(settings);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -640,6 +640,148 @@ public class Setting<T> extends ToXContentToBytes {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class GroupSetting extends Setting<Settings> {
|
||||||
|
private final String key;
|
||||||
|
private final Consumer<Settings> validator;
|
||||||
|
|
||||||
|
private GroupSetting(String key, Consumer<Settings> validator, Property... properties) {
|
||||||
|
super(new GroupKey(key), (s) -> "", (s) -> null, properties);
|
||||||
|
this.key = key;
|
||||||
|
this.validator = validator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isGroupSetting() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRaw(Settings settings) {
|
||||||
|
Settings subSettings = get(settings);
|
||||||
|
try {
|
||||||
|
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||||
|
builder.startObject();
|
||||||
|
subSettings.toXContent(builder, EMPTY_PARAMS);
|
||||||
|
builder.endObject();
|
||||||
|
return builder.string();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Settings get(Settings settings) {
|
||||||
|
Settings byPrefix = settings.getByPrefix(getKey());
|
||||||
|
validator.accept(byPrefix);
|
||||||
|
return byPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean exists(Settings settings) {
|
||||||
|
for (Map.Entry<String, String> entry : settings.getAsMap().entrySet()) {
|
||||||
|
if (entry.getKey().startsWith(key)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void diff(Settings.Builder builder, Settings source, Settings defaultSettings) {
|
||||||
|
Map<String, String> leftGroup = get(source).getAsMap();
|
||||||
|
Settings defaultGroup = get(defaultSettings);
|
||||||
|
for (Map.Entry<String, String> entry : defaultGroup.getAsMap().entrySet()) {
|
||||||
|
if (leftGroup.containsKey(entry.getKey()) == false) {
|
||||||
|
builder.put(getKey() + entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractScopedSettings.SettingUpdater<Settings> newUpdater(Consumer<Settings> consumer, Logger logger,
|
||||||
|
Consumer<Settings> validator) {
|
||||||
|
if (isDynamic() == false) {
|
||||||
|
throw new IllegalStateException("setting [" + getKey() + "] is not dynamic");
|
||||||
|
}
|
||||||
|
final Setting<?> setting = this;
|
||||||
|
return new AbstractScopedSettings.SettingUpdater<Settings>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasChanged(Settings current, Settings previous) {
|
||||||
|
Settings currentSettings = get(current);
|
||||||
|
Settings previousSettings = get(previous);
|
||||||
|
return currentSettings.equals(previousSettings) == false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Settings getValue(Settings current, Settings previous) {
|
||||||
|
Settings currentSettings = get(current);
|
||||||
|
Settings previousSettings = get(previous);
|
||||||
|
try {
|
||||||
|
validator.accept(currentSettings);
|
||||||
|
} catch (Exception | AssertionError e) {
|
||||||
|
throw new IllegalArgumentException("illegal value can't update [" + key + "] from ["
|
||||||
|
+ previousSettings.getAsMap() + "] to [" + currentSettings.getAsMap() + "]", e);
|
||||||
|
}
|
||||||
|
return currentSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Settings value, Settings current, Settings previous) {
|
||||||
|
if (logger.isInfoEnabled()) { // getRaw can create quite some objects
|
||||||
|
logger.info("updating [{}] from [{}] to [{}]", key, getRaw(previous), getRaw(current));
|
||||||
|
}
|
||||||
|
consumer.accept(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Updater for: " + setting.toString();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ListSetting<T> extends Setting<List<T>> {
|
||||||
|
private final Function<Settings, List<String>> defaultStringValue;
|
||||||
|
|
||||||
|
private ListSetting(String key, Function<Settings, List<String>> defaultStringValue, Function<String, List<T>> parser,
|
||||||
|
Property... properties) {
|
||||||
|
super(new ListKey(key), (s) -> Setting.arrayToParsableString(defaultStringValue.apply(s).toArray(Strings.EMPTY_ARRAY)), parser,
|
||||||
|
properties);
|
||||||
|
this.defaultStringValue = defaultStringValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRaw(Settings settings) {
|
||||||
|
String[] array = settings.getAsArray(getKey(), null);
|
||||||
|
return array == null ? defaultValue.apply(settings) : arrayToParsableString(array);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean hasComplexMatcher() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean exists(Settings settings) {
|
||||||
|
boolean exists = super.exists(settings);
|
||||||
|
return exists || settings.get(getKey() + ".0") != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void diff(Settings.Builder builder, Settings source, Settings defaultSettings) {
|
||||||
|
if (exists(source) == false) {
|
||||||
|
String[] asArray = defaultSettings.getAsArray(getKey(), null);
|
||||||
|
if (asArray == null) {
|
||||||
|
builder.putArray(getKey(), defaultStringValue.apply(defaultSettings));
|
||||||
|
} else {
|
||||||
|
builder.putArray(getKey(), asArray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final class Updater implements AbstractScopedSettings.SettingUpdater<T> {
|
private final class Updater implements AbstractScopedSettings.SettingUpdater<T> {
|
||||||
private final Consumer<T> consumer;
|
private final Consumer<T> consumer;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
@ -867,37 +1009,7 @@ public class Setting<T> extends ToXContentToBytes {
|
||||||
Function<String, List<T>> parser = (s) ->
|
Function<String, List<T>> parser = (s) ->
|
||||||
parseableStringToList(s).stream().map(singleValueParser).collect(Collectors.toList());
|
parseableStringToList(s).stream().map(singleValueParser).collect(Collectors.toList());
|
||||||
|
|
||||||
return new Setting<List<T>>(new ListKey(key),
|
return new ListSetting<>(key, defaultStringValue, parser, properties);
|
||||||
(s) -> arrayToParsableString(defaultStringValue.apply(s).toArray(Strings.EMPTY_ARRAY)), parser, properties) {
|
|
||||||
@Override
|
|
||||||
public String getRaw(Settings settings) {
|
|
||||||
String[] array = settings.getAsArray(getKey(), null);
|
|
||||||
return array == null ? defaultValue.apply(settings) : arrayToParsableString(array);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
boolean hasComplexMatcher() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean exists(Settings settings) {
|
|
||||||
boolean exists = super.exists(settings);
|
|
||||||
return exists || settings.get(getKey() + ".0") != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void diff(Settings.Builder builder, Settings source, Settings defaultSettings) {
|
|
||||||
if (exists(source) == false) {
|
|
||||||
String[] asArray = defaultSettings.getAsArray(getKey(), null);
|
|
||||||
if (asArray == null) {
|
|
||||||
builder.putArray(getKey(), defaultStringValue.apply(defaultSettings));
|
|
||||||
} else {
|
|
||||||
builder.putArray(getKey(), asArray);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> parseableStringToList(String parsableString) {
|
private static List<String> parseableStringToList(String parsableString) {
|
||||||
|
@ -939,98 +1051,7 @@ public class Setting<T> extends ToXContentToBytes {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Setting<Settings> groupSetting(String key, Consumer<Settings> validator, Property... properties) {
|
public static Setting<Settings> groupSetting(String key, Consumer<Settings> validator, Property... properties) {
|
||||||
return new Setting<Settings>(new GroupKey(key), (s) -> "", (s) -> null, properties) {
|
return new GroupSetting(key, validator, properties);
|
||||||
@Override
|
|
||||||
public boolean isGroupSetting() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRaw(Settings settings) {
|
|
||||||
Settings subSettings = get(settings);
|
|
||||||
try {
|
|
||||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
|
||||||
builder.startObject();
|
|
||||||
subSettings.toXContent(builder, EMPTY_PARAMS);
|
|
||||||
builder.endObject();
|
|
||||||
return builder.string();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Settings get(Settings settings) {
|
|
||||||
Settings byPrefix = settings.getByPrefix(getKey());
|
|
||||||
validator.accept(byPrefix);
|
|
||||||
return byPrefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean exists(Settings settings) {
|
|
||||||
for (Map.Entry<String, String> entry : settings.getAsMap().entrySet()) {
|
|
||||||
if (entry.getKey().startsWith(key)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void diff(Settings.Builder builder, Settings source, Settings defaultSettings) {
|
|
||||||
Map<String, String> leftGroup = get(source).getAsMap();
|
|
||||||
Settings defaultGroup = get(defaultSettings);
|
|
||||||
for (Map.Entry<String, String> entry : defaultGroup.getAsMap().entrySet()) {
|
|
||||||
if (leftGroup.containsKey(entry.getKey()) == false) {
|
|
||||||
builder.put(getKey() + entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AbstractScopedSettings.SettingUpdater<Settings> newUpdater(Consumer<Settings> consumer, Logger logger,
|
|
||||||
Consumer<Settings> validator) {
|
|
||||||
if (isDynamic() == false) {
|
|
||||||
throw new IllegalStateException("setting [" + getKey() + "] is not dynamic");
|
|
||||||
}
|
|
||||||
final Setting<?> setting = this;
|
|
||||||
return new AbstractScopedSettings.SettingUpdater<Settings>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasChanged(Settings current, Settings previous) {
|
|
||||||
Settings currentSettings = get(current);
|
|
||||||
Settings previousSettings = get(previous);
|
|
||||||
return currentSettings.equals(previousSettings) == false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Settings getValue(Settings current, Settings previous) {
|
|
||||||
Settings currentSettings = get(current);
|
|
||||||
Settings previousSettings = get(previous);
|
|
||||||
try {
|
|
||||||
validator.accept(currentSettings);
|
|
||||||
} catch (Exception | AssertionError e) {
|
|
||||||
throw new IllegalArgumentException("illegal value can't update [" + key + "] from ["
|
|
||||||
+ previousSettings.getAsMap() + "] to [" + currentSettings.getAsMap() + "]", e);
|
|
||||||
}
|
|
||||||
return currentSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply(Settings value, Settings current, Settings previous) {
|
|
||||||
if (logger.isInfoEnabled()) { // getRaw can create quite some objects
|
|
||||||
logger.info("updating [{}] from [{}] to [{}]", key, getRaw(previous), getRaw(current));
|
|
||||||
}
|
|
||||||
consumer.accept(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Updater for: " + setting.toString();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Setting<TimeValue> timeSetting(String key, Function<Settings, TimeValue> defaultValue, TimeValue minValue,
|
public static Setting<TimeValue> timeSetting(String key, Function<Settings, TimeValue> defaultValue, TimeValue minValue,
|
||||||
|
|
Loading…
Reference in New Issue