diff --git a/runtime-metamodel/src/main/java/org/eclipse/edc/runtime/metamodel/annotation/Configuration.java b/runtime-metamodel/src/main/java/org/eclipse/edc/runtime/metamodel/annotation/Configuration.java new file mode 100644 index 0000000..b603090 --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/edc/runtime/metamodel/annotation/Configuration.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * + */ + +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; + +/** + * 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 { +} diff --git a/runtime-metamodel/src/main/java/org/eclipse/edc/runtime/metamodel/annotation/Setting.java b/runtime-metamodel/src/main/java/org/eclipse/edc/runtime/metamodel/annotation/Setting.java index 7f12fc3..33cc7b9 100644 --- a/runtime-metamodel/src/main/java/org/eclipse/edc/runtime/metamodel/annotation/Setting.java +++ b/runtime-metamodel/src/main/java/org/eclipse/edc/runtime/metamodel/annotation/Setting.java @@ -22,23 +22,34 @@ 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; + /** + * Type of the config value + * + * @deprecated this attribute is deprecated because it will be inferred from the field + */ + @Deprecated String type() default "string"; /** @@ -46,7 +57,7 @@ * * @return the setting's default value */ - String defaultValue() default ""; + String defaultValue() default NULL; long min() default Long.MIN_VALUE; @@ -55,6 +66,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; } diff --git a/runtime-metamodel/src/main/java/org/eclipse/edc/runtime/metamodel/annotation/Settings.java b/runtime-metamodel/src/main/java/org/eclipse/edc/runtime/metamodel/annotation/Settings.java new file mode 100644 index 0000000..22b55de --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/edc/runtime/metamodel/annotation/Settings.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * + */ + +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 { +}