Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
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
6 changes: 0 additions & 6 deletions configuration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@
<artifactId>byte-buddy</artifactId>
</dependency>

<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value-annotations</artifactId>
<optional>true</optional>
</dependency>

<!-- for testing -->
<dependency>
<groupId>org.testng</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@Beta
public class ConditionalModule<T>
extends AbstractConfigurationAwareModule
extends AbstractConfigurationAwareModule
{
public static <T> Module installModuleIf(Class<T> config, Predicate<T> predicate, Module module)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,46 +30,45 @@
*
* <pre>
* configBinder(binder).bind(FooConfig.class);</pre>
*
* <p>
* Binds the configuration class {@code FooConfig} to instances that are
* created by the configuration subsystem (specifically its
* {@link ConfigurationFactory}).
*
* <p>
* As configuration classes are mutable, the binding is with default scope
* so each injection point gets a separate instance.
*
* <p>
* Does not work with private binders.
*
* <pre>
* configBinder(binder)
* .bind(FooConfig.class)
* .annotatedWith(Red.class);</pre>
*
* <p>
* Binds the configuration class {@code Key.get(FooConfig.class, Red.class)}
* to instances that are created by the configuration subsystem.
*
* <pre>
* configBinder(binder)
* .bind(FooConfig.class)
* .annotatedWith(Names.named("red"));</pre>
*
* <p>
* Binds the configuration class {@code Key.get(FooConfig.class, Names.named("red"))}
* to instances that are created by the configuration subsystem.
*
* <pre>
* configBinder(binder)
* .bind(FooConfig.class)
* .prefixedWith("prefix");</pre>
*
* <p>
* The {@code .prefixedWith()} method causes the configuration properties that
* the bound configuration instances consume from to be prefixed by the
* specified parameter, followed by a ".". For example, if an attribute of the
* configuration class consumes the "size" configuration property, that
* attribute of the bound instance will instead consume the "prefix.size"
* configuration property.
*
* <p>
* May be combined with {@code .annotatedWith()}.
*
*/
public final class ConfigBinder
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* A provider with access to the Platform {@link ConfigurationFactory}.
*
* <p>
* Implementing this interface ensures that the provider gets access to the
* {@link ConfigurationFactory} before the first
* call to {@link Provider#get()}.
Expand All @@ -28,9 +28,9 @@ public interface ConfigurationAwareProvider<T> extends Provider<T>
* objects that this provider will need
*
* @param modules The application modules. The provider may inspect these
* in order to determine which config objects to build.
* in order to determine which config objects to build.
* @throws ConfigurationException when a programming error prevents
* this building.
* this building.
*/
default void buildConfigObjects(Iterable<? extends Module> modules)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import static com.google.common.base.CaseFormat.LOWER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_CAMEL;
import static com.google.common.collect.Sets.newConcurrentHashSet;
import static com.proofpoint.configuration.ConfigurationIdentity.configurationIdentity;
import static com.proofpoint.configuration.ConfigurationMetadata.getConfigurationMetadata;
import static com.proofpoint.configuration.ConfigurationMetadata.isConfigClass;
import static com.proofpoint.configuration.Problems.exceptionFor;
Expand Down Expand Up @@ -142,9 +141,9 @@ public <T> T build(Class<T> configClass, @Nullable String prefix)
* This is used by the configuration provider
*/
<T> T build(Class<T> configClass, @Nullable String prefix, Key<T> key)
{
{
Problems problems;
if (registeredConfigs.add(configurationIdentity(configClass, prefix, key))) {
if (registeredConfigs.add(new ConfigurationIdentity(configClass, prefix, key))) {
problems = new Problems(monitor);
}
else {
Expand Down Expand Up @@ -455,7 +454,7 @@ private Object getInjectedValue(AttributeMetadata attribute, InjectionPointMetaD
return finalValue;
}

private <K,V> Map<K, V> getInjectedMap(AttributeMetadata attribute, InjectionPointMetaData injectionPoint, String name, Problems problems, Class<K> keyClass, Class<V> valueClass)
private <K, V> Map<K, V> getInjectedMap(AttributeMetadata attribute, InjectionPointMetaData injectionPoint, String name, Problems problems, Class<K> keyClass, Class<V> valueClass)
{
final boolean valueIsConfigClass = isConfigClass(valueClass);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public final class ConfigurationFactoryBuilder
private PropertiesBuilder propertiesBuilder = new PropertiesBuilder();
private final Set<String> expectToUse = new HashSet<>();
private Monitor monitor = Problems.NULL_MONITOR;
private Map<String,String> applicationDefaults = ImmutableMap.of();
private Map<String,String> moduleDefaults = ImmutableMap.of();
private Map<String, String> applicationDefaults = ImmutableMap.of();
private Map<String, String> moduleDefaults = ImmutableMap.of();
private Map<String, ConfigurationDefaultingModule> moduleDefaultSource = ImmutableMap.of();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,42 @@
*/
package com.proofpoint.configuration;

import com.google.auto.value.AutoValue;
import com.google.inject.Key;
import jakarta.annotation.Nullable;

@AutoValue
abstract class ConfigurationIdentity<T>
{
private Key<T> key;
import java.util.Objects;

import static java.util.Objects.requireNonNull;

record ConfigurationIdentity<T>(
Class<T> configClass,

@Nullable
String prefix,

static <T> ConfigurationIdentity<T> configurationIdentity(Class<T> clazz, @Nullable String prefix, @Nullable Key<T> key)
// Must not participate in equals()
@Nullable
Key<T> key
)
{
ConfigurationIdentity
{
ConfigurationIdentity<T> identity = new AutoValue_ConfigurationIdentity<>(clazz, prefix);
identity.key = key;
return identity;
requireNonNull(configClass, "configClass is null");
}

abstract Class<T> getConfigClass();

@Nullable
abstract String getPrefix();
@Override
public boolean equals(Object o)
{
if (o == null || getClass() != o.getClass()) {
return false;
}
ConfigurationIdentity<?> that = (ConfigurationIdentity<?>) o;
return Objects.equals(prefix, that.prefix) && Objects.equals(configClass, that.configClass);
}

// Must not participate in equals()
Key<T> getKey()
@Override
public int hashCode()
{
return key;
return Objects.hash(configClass, prefix);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static class ConfigRecord<T> implements Comparable<ConfigRecord<?>>

static <T> ConfigRecord<T> createConfigRecord(ConfigurationFactory configurationFactory, ConfigurationIdentity<T> configurationIdentity)
{
return new ConfigRecord<>(configurationFactory, configurationIdentity.getConfigClass(), configurationIdentity.getPrefix(), configurationIdentity.getKey());
return new ConfigRecord<>(configurationFactory, configurationIdentity.configClass(), configurationIdentity.prefix(), configurationIdentity.key());
}

private ConfigRecord(ConfigurationFactory configurationFactory, Class<T> configClass, @Nullable String prefix, @Nullable Key<T> key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ else if (!this.defunctConfig.add(defunct)) {
try {
constructor = configClass.getDeclaredConstructor();
constructor.setAccessible(true);
} catch (Exception e) {
}
catch (Exception e) {
problems.addError("Configuration class [%s] does not have a no-arg constructor", configClass.getName());
}
this.constructor = constructor;
Expand All @@ -127,7 +128,8 @@ else if (!this.defunctConfig.add(defunct)) {
}
}

public static boolean isConfigClass(Class<?> classz) {
public static boolean isConfigClass(Class<?> classz)
{
for (Method method : classz.getDeclaredMethods()) {
if (method.isAnnotationPresent(Config.class)) {
return true;
Expand Down Expand Up @@ -188,7 +190,8 @@ private boolean validateAnnotations(Method configMethod)
if (arrayEntry == null || arrayEntry.isEmpty()) {
problems.addError("@LegacyConfig method [%s] annotation contains null or empty value", configMethod.toGenericString());
isValid = false;
} else if (arrayEntry.equals(config.value())) {
}
else if (arrayEntry.equals(config.value())) {
problems.addError("@Config property name '%s' appears in @LegacyConfig annotation for method [%s]", config.value(), configMethod.toGenericString());
isValid = false;
}
Expand Down Expand Up @@ -343,7 +346,7 @@ private AttributeMetadata buildAttributeMetadata(Class<T> configClass, Method co
}

if (defunctConfig.contains(propertyName)) {
problems.addError("@Config property '%s' on method [%s] is defunct on class [%s]", propertyName, configMethod, configClass);
problems.addError("@Config property '%s' on method [%s] is defunct on class [%s]", propertyName, configMethod, configClass);
}

// Add the injection point for the current setter/property
Expand All @@ -364,12 +367,18 @@ private AttributeMetadata buildAttributeMetadata(Class<T> configClass, Method co
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

ConfigurationMetadata<?> that = (ConfigurationMetadata<?>) o;

if (!configClass.equals(that.configClass)) return false;
if (!configClass.equals(that.configClass)) {
return false;
}

return true;
}
Expand Down Expand Up @@ -453,13 +462,21 @@ public boolean isLegacy()
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

InjectionPointMetaData that = (InjectionPointMetaData) o;

if (!configClass.equals(that.configClass)) return false;
if (!property.equals(that.property)) return false;
if (!configClass.equals(that.configClass)) {
return false;
}
if (!property.equals(that.property)) {
return false;
}

return true;
}
Expand Down Expand Up @@ -497,7 +514,7 @@ public static class AttributeMetadata
private final MapClasses mapClasses;

private AttributeMetadata(Class<?> configClass, String name, String description, boolean securitySensitive, @Nullable MapClasses mapClasses, Method getter,
InjectionPointMetaData injectionPoint, Set<InjectionPointMetaData> legacyInjectionPoints)
InjectionPointMetaData injectionPoint, Set<InjectionPointMetaData> legacyInjectionPoints)
{
requireNonNull(configClass);
requireNonNull(name);
Expand Down Expand Up @@ -559,13 +576,21 @@ public Set<InjectionPointMetaData> getLegacyInjectionPoints()
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

AttributeMetadata that = (AttributeMetadata) o;

if (!configClass.equals(that.configClass)) return false;
if (!name.equals(that.name)) return false;
if (!configClass.equals(that.configClass)) {
return false;
}
if (!name.equals(that.name)) {
return false;
}

return true;
}
Expand Down Expand Up @@ -675,7 +700,7 @@ private static Collection<Method> findSensitiveConfigMethods(Class<?> configClas
*
* @param configClass the class to analyze
* @return a map that associates a concrete method to the actual method tagged
* (which may belong to a different class in class hierarchy)
* (which may belong to a different class in class hierarchy)
*/
private static Collection<Method> findAnnotatedMethods(Class<?> configClass, Class<? extends java.lang.annotation.Annotation> annotation)
{
Expand Down Expand Up @@ -711,7 +736,8 @@ public static Method findAnnotatedMethod(Class<?> configClass, Class<? extends j
if (method != null && method.isAnnotationPresent(annotation)) {
return method;
}
} catch (NoSuchMethodException e) {
}
catch (NoSuchMethodException e) {
// ignore
}

Expand Down Expand Up @@ -747,29 +773,32 @@ private Set<InjectionPointMetaData> findLegacySetters(Class<?> configClass, Stri
if (validateSetter(method)) {
for (String property : method.getAnnotation(LegacyConfig.class).value()) {
if (defunctConfig.contains(property)) {
problems.addError("@LegacyConfig property '%s' on method [%s] is defunct on class [%s]", property, method, configClass);
problems.addError("@LegacyConfig property '%s' on method [%s] is defunct on class [%s]", property, method, configClass);
}

if (!property.equals(propertyName)) {
setters.add(InjectionPointMetaData.newLegacy(configClass, property, method));
} else {
}
else {
problems.addError("@LegacyConfig property '%s' on method [%s] is replaced by @Config property of same name on method [%s]",
property, method.toGenericString(), setterName);
}
}
}
} else if (method.isAnnotationPresent(LegacyConfig.class)
}
else if (method.isAnnotationPresent(LegacyConfig.class)
&& method.getAnnotation(LegacyConfig.class).replacedBy().equals(propertyName)) {
// Found @LegacyConfig setter linked by replacedBy() property
if (validateSetter(method)) {
for (String property : method.getAnnotation(LegacyConfig.class).value()) {
if (defunctConfig.contains(property)) {
problems.addError("@LegacyConfig property '%s' on method [%s] is defunct on class [%s]", property, method, configClass);
problems.addError("@LegacyConfig property '%s' on method [%s] is defunct on class [%s]", property, method, configClass);
}

if (!property.equals(propertyName)) {
setters.add(InjectionPointMetaData.newLegacy(configClass, property, method));
} else {
}
else {
problems.addError("@LegacyConfig property '%s' on method [%s] is replaced by @Config property of same name on method [%s]",
property, method.toGenericString(), setterName);
}
Expand All @@ -795,7 +824,8 @@ private Method findGetter(Class<?> configClass, Method configMethod, String attr
if (method.getName().equals(getterName) || method.getName().equals(isName)) {
if (isUsableMethod(method) && !method.getReturnType().equals(Void.TYPE) && method.getParameterTypes().length == 0) {
getters.add(method);
} else {
}
else {
unusableGetters.add(method);
}
}
Expand Down
Loading
Loading