Skip to content

Commit

Permalink
refactor: deprecate EdcSetting, add Setting
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Oct 14, 2022
1 parent fa7b759 commit b4a3fca
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Inject;
import org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Provider;
import org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Provides;
import org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Setting;
import org.eclipse.dataspaceconnector.runtime.metamodel.annotation.SettingContext;
import org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Spi;
import org.eclipse.dataspaceconnector.runtime.metamodel.domain.ConfigurationSetting;
import org.eclipse.dataspaceconnector.runtime.metamodel.domain.Service;
Expand Down Expand Up @@ -98,10 +100,11 @@ public List<Service> resolveProvidedServices(Element element) {
}

/**
* Resolves configuration points declared with {@link EdcSetting}.
* Resolves configuration points declared with {@link Setting}.
*/
public List<ConfigurationSetting> resolveConfigurationSettings(Element element) {
return getEnclosedElementsAnnotatedWith(element, EdcSetting.class)
return Stream.concat(getEnclosedElementsAnnotatedWith(element, EdcSetting.class),
getEnclosedElementsAnnotatedWith(element, Setting.class))
.filter(VariableElement.class::isInstance)
.map(VariableElement.class::cast)
.map(this::createConfigurationSetting)
Expand Down Expand Up @@ -129,15 +132,18 @@ private Stream<? extends Element> getEnclosedElementsAnnotatedWith(Element exten
}

/**
* Maps a {@link ConfigurationSetting} from an {@link EdcSetting} annotation.
* Maps a {@link ConfigurationSetting} from an {@link Setting} annotation.
*/
private ConfigurationSetting createConfigurationSetting(VariableElement settingElement) {
var prefix = resolveConfigurationPrefix(settingElement);
var keyValue = prefix + settingElement.getConstantValue().toString();

var settingBuilder = ConfigurationSetting.Builder.newInstance().key(keyValue);

var settingMirror = mirrorFor(EdcSetting.class, settingElement);
var settingMirror = mirrorFor(Setting.class, settingElement);
if (settingMirror == null) { //todo: compatibility
settingMirror = mirrorFor(EdcSetting.class, settingElement);
}

var description = attributeValue(String.class, "value", settingMirror, elementUtils);
settingBuilder.description(description);
Expand Down Expand Up @@ -166,7 +172,10 @@ private String resolveConfigurationPrefix(VariableElement edcSettingElement) {
if (enclosingElement == null) {
return "";
}
var contextMirror = mirrorFor(EdcSettingContext.class, enclosingElement);
var contextMirror = mirrorFor(SettingContext.class, enclosingElement);
if (contextMirror == null) {
contextMirror = mirrorFor(EdcSettingContext.class, enclosingElement);
}
return contextMirror != null ? attributeValue(String.class, "value", contextMirror, elementUtils) : "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Provider;
import org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Provides;
import org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Requires;
import org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Setting;
import org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Spi;
import org.eclipse.dataspaceconnector.runtime.metamodel.domain.Service;

Expand Down Expand Up @@ -91,13 +92,14 @@ public String getModuleName(RoundEnvironment environment) {
*/
public Set<Element> getExtensionElements(RoundEnvironment environment) {
var extensionClasses = environment.getElementsAnnotatedWith(Extension.class);
var settingsSymbols = environment.getElementsAnnotatedWith(EdcSetting.class);
var settingsSymbolsDeprecated = environment.getElementsAnnotatedWith(EdcSetting.class);
var settingsSymbols = environment.getElementsAnnotatedWith(Setting.class);
var injectSymbols = environment.getElementsAnnotatedWith(Inject.class);
var providerSymbols = environment.getElementsAnnotatedWith(Provider.class);
var providesClasses = environment.getElementsAnnotatedWith(Provides.class);
var requiresClasses = environment.getElementsAnnotatedWith(Requires.class);

var symbols = settingsSymbols.stream();
var symbols = Stream.concat(settingsSymbols.stream(), settingsSymbolsDeprecated.stream());
symbols = Stream.concat(symbols, injectSymbols.stream());
symbols = Stream.concat(symbols, providerSymbols.stream());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@

/**
* Denotes a runtime configuration setting.
*
* @deprecated Please use {@link Setting}
*/
@Target({ ElementType.TYPE, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Deprecated
public @interface EdcSetting {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@

/**
* Defines a context for setting keys.
*
* @deprecated please use {@link SettingContext}
*/
@Target({ ElementType.TYPE, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Deprecated
public @interface EdcSettingContext {
String value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2022 Microsoft Corporation
*
* 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:
* Microsoft Corporation - initial API and implementation
*
*/

package org.eclipse.dataspaceconnector.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 a runtime configuration setting.
*/
@Target({ ElementType.TYPE, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Setting {

/**
* The setting description.
*/
String value() default "";

String type() default "string";

long min() default Long.MIN_VALUE;

long max() default Long.MAX_VALUE;

/**
* Returns true if the setting is required.
*/
boolean required() default false;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2022 Microsoft Corporation
*
* 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:
* Microsoft Corporation - initial API and implementation
*
*/

package org.eclipse.dataspaceconnector.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;

/**
* Defines a context for setting keys.
*/
@Target({ ElementType.TYPE, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface SettingContext {
String value();
}

0 comments on commit b4a3fca

Please sign in to comment.