Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: add config injection annotations #75

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
@@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,42 @@
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";

/**
* 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 +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;
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Loading