Skip to content

Commit

Permalink
feat: add config injection annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Nov 8, 2024
1 parent ceb0ad7 commit e0dc0ef
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ format.version = "1.1"

[versions]
jackson = "2.18.1"
edc-build = "0.10.1"
edc-build = "0.11.0-SNAPSHOT"
jetbrainsAnnotation = "26.0.1"

[libraries]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.eclipse.edc.runtime.metamodel.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* This annotation indicates that a certain field is a "configuration object", i.e. a POJO that contains fields annotated with
* {@link Setting}. These fields must be declared inside an extension class. Their respective class declaration must be annotated
* with {@link Settings}.
* Types annotated with this annotation will get instantiated by the EDC dependency injection mechanism using values from the config.
*/
@Target({ ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Configuration {
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,41 @@
import java.lang.annotation.Target;

/**
* Denotes a runtime configuration setting.
* Denotes a runtime configuration setting. This can be put on config value fields and the dependency injection mechanism will
* attempt to automatically resolve them.
*/
@Target({ ElementType.TYPE, ElementType.FIELD })
@Target({ ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Setting {
String NULL = "";

/**
* The setting description.
*
* @deprecated Please use {@link Setting#description()} to supply description. In future releases this property will hold the
* Setting's config key!
*/
String value() default "";
@Deprecated
String value() default NULL;

/**
* The setting context
*/
String context() default "";
String context() default NULL;

/**
* @deprecated this attribute is deprecated because it will be inferred from the field
*/
@Deprecated
String type() default "string";

/**
* The setting default value. Empty string if no default value is provided
*
* @return the setting's default value
*/
String defaultValue() default "";
String defaultValue() default NULL;

long min() default Long.MIN_VALUE;

Expand All @@ -55,6 +65,26 @@
/**
* Returns true if the setting is required.
*/
boolean required() default false;
boolean required() default true;

/**
* The key of the property, e.g. "edc.foo.bar.baz". If this attribute is present, the dependency injection mechanism
* will attempt to resolve the config value.
*/
String key() default NULL;

/**
* The Setting's description. This is equivalent to {@link Setting#value()} in the current release, but users should
* use this attribute.
*
* @return The setting's description.
*/
String description() default NULL;

/**
* Specify whether a warning should be issued when an optional config value is missing or when the default value is used.
* If set to false, a debug log is issued.
* Note that this is ignored on mandatory (non-optional) config values.
*/
boolean warnOnMissingConfig() default false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.eclipse.edc.runtime.metamodel.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Denotes that a certain class is a "configuration object", i.e. contains fields annotated with {@link Setting}. Note that
* if the configuration object is a record, it may ONLY contain fields annotated with {@link Setting}.
*/
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.CLASS)
@Documented
public @interface Settings {
}

0 comments on commit e0dc0ef

Please sign in to comment.