Skip to content

Commit

Permalink
fix: Revert "chore: remove @EdcSettng and @EdcSettingContext from the…
Browse files Browse the repository at this point in the history
… code base (#47)" (#55)

This reverts commit f190f7f.
  • Loading branch information
paullatzelsperger committed Nov 24, 2022
1 parent 4bb591b commit f7a3c18
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package org.eclipse.edc.plugins.autodoc.core.processor.introspection;

import org.eclipse.edc.plugins.autodoc.core.processor.compiler.AnnotationFunctions;
import org.eclipse.edc.runtime.metamodel.annotation.EdcSetting;
import org.eclipse.edc.runtime.metamodel.annotation.EdcSettingContext;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
Expand Down Expand Up @@ -101,7 +103,8 @@ public List<Service> resolveProvidedServices(Element element) {
* Resolves configuration points declared with {@link Setting}.
*/
public List<ConfigurationSetting> resolveConfigurationSettings(Element element) {
return getEnclosedElementsAnnotatedWith(element, Setting.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 @@ -138,6 +141,9 @@ private ConfigurationSetting createConfigurationSetting(VariableElement settingE
var settingBuilder = ConfigurationSetting.Builder.newInstance().key(keyValue);

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 All @@ -158,7 +164,7 @@ private ConfigurationSetting createConfigurationSetting(VariableElement settingE
}

/**
* Resolves a configuration prefix specified by {@link SettingContext} for a given EDC setting element or an empty string if there is none.
* Resolves a configuration prefix specified by {@link EdcSettingContext} for a given EDC setting element or an empty string if there is none.
*/
@NotNull
private String resolveConfigurationPrefix(VariableElement edcSettingElement) {
Expand All @@ -167,6 +173,9 @@ private String resolveConfigurationPrefix(VariableElement edcSettingElement) {
return "";
}
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 @@ -14,6 +14,7 @@

package org.eclipse.edc.plugins.autodoc.core.processor.introspection;

import org.eclipse.edc.runtime.metamodel.annotation.EdcSetting;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.ExtensionPoint;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
Expand Down Expand Up @@ -79,7 +80,7 @@ public String getModuleName(RoundEnvironment environment) {
* <li>Are annotated with {@link Provides}</li>
* <li>Are annotated with {@link Requires}</li>
* <li>Have one or more fields annotated with {@link Inject}</li>
* <li>Have one or more fields annotated with {@link Setting}</li>
* <li>Have one or more fields annotated with {@link EdcSetting}</li>
* <li>Have one or more methods annotated with {@link Provider}</li>
* </ul>
* <p>
Expand All @@ -91,13 +92,14 @@ public String getModuleName(RoundEnvironment environment) {
*/
public Set<Element> getExtensionElements(RoundEnvironment environment) {
var extensionClasses = environment.getElementsAnnotatedWith(Extension.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 @@ -15,15 +15,15 @@
package org.eclipse.edc.plugins.autodoc.core.processor.testextensions;

import org.eclipse.edc.plugins.autodoc.core.processor.Constants;
import org.eclipse.edc.runtime.metamodel.annotation.EdcSetting;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
import org.eclipse.edc.runtime.metamodel.annotation.Provides;
import org.eclipse.edc.runtime.metamodel.annotation.Setting;
import org.eclipse.edc.spi.system.ServiceExtension;

@Provides(SomeOtherService.class)
public class SampleExtensionWithoutAnnotation implements ServiceExtension {
@Setting(value = Constants.TEST_SETTING_NAME, required = true)
@EdcSetting(value = Constants.TEST_SETTING_NAME, required = true)
public static final String TEST_SETTING = Constants.TEST_SETTING_KEY;

@Inject
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.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 a runtime configuration setting.
*
* @deprecated Please use {@link Setting}
*/
@Target({ ElementType.TYPE, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Deprecated
public @interface EdcSetting {

/**
* 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,34 @@
/*
* 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.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;

/**
* 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();
}

0 comments on commit f7a3c18

Please sign in to comment.