Skip to content

Commit

Permalink
feat: permit @setting in ConfigurationExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt committed Mar 19, 2024
1 parent 46a48d0 commit 193ad23
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 20 deletions.
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mockito = "5.11.0"
assertj-core = { module = "org.assertj:assertj-core", version.ref = "assertj" }
checkstyle = { module = "com.puppycrawl.tools:checkstyle", version.ref = "checkstyle" }
edc-runtime-metamodel = { module = "org.eclipse.edc:runtime-metamodel", version.ref = "edc" }
edc-core-spi = { module = "org.eclipse.edc:core-spi", version.ref = "edc" }
jackson-annotations = { module = "com.fasterxml.jackson.core:jackson-annotations", version.ref = "jackson" }
jackson-core = { module = "com.fasterxml.jackson.core:jackson-core", version.ref = "jackson" }
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
Expand Down
2 changes: 2 additions & 0 deletions plugins/autodoc/autodoc-processor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ plugins {

dependencies {
api(libs.edc.runtime.metamodel)

testImplementation(libs.edc.core.spi)
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
*/
public class ModuleIntrospector {
private static final String SERVICE_EXTENSION_NAME = "org.eclipse.edc.spi.system.ServiceExtension";
private static final String SYSTEM_EXTENSION_NAME = "org.eclipse.edc.spi.system.SystemExtension";
private final Elements elementUtils;
private final Types typeUtils;
private final ProcessingEnvironment processingEnv;
Expand All @@ -56,7 +57,6 @@ public ModuleIntrospector(ProcessingEnvironment processingEnv) {
this.typeUtils = processingEnv.getTypeUtils();
}


public List<String> getCategories(RoundEnvironment environment) {
var extensionElement = environment.getElementsAnnotatedWith(Spi.class).iterator().next();
return attributeStringValues("categories", mirrorFor(Spi.class, extensionElement), elementUtils);
Expand Down Expand Up @@ -96,7 +96,7 @@ public Set<Element> getExtensionElements(RoundEnvironment environment) {
var settingsSymbols = environment.getElementsAnnotatedWith(Setting.class).stream()
.peek(setting -> {
var enclosingElement = setting.getEnclosingElement().asType();
var serviceExtensionType = typeUtils.erasure(elementUtils.getTypeElement(SERVICE_EXTENSION_NAME).asType());
var serviceExtensionType = typeUtils.erasure(elementUtils.getTypeElement(SYSTEM_EXTENSION_NAME).asType());
if (!typeUtils.isAssignable(enclosingElement, serviceExtensionType)) {
var message = "@Setting annotation must be used inside a ServiceExtension implementation, the " +
"ones defined in %s will be excluded from the autodoc manifest".formatted(enclosingElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ void shouldFail_whenSettingIsDefinedInClassNotExtension() {
});
}

@Test
void shouldPass_whenSettingIsDefinedInExtensionSubclass() {
var task = createTask("test/ConfigurationExtensionWithSetting.java");

assertThat(task.call()).isTrue();
}

private JavaCompiler.@NotNull CompilationTask createTask(String classPath) {
try {
var classes = getFiles(classPath);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.plugins.autodoc.core.processor.test;

import org.eclipse.edc.runtime.metamodel.annotation.Setting;
import org.eclipse.edc.spi.system.ConfigurationExtension;
import org.eclipse.edc.spi.system.configuration.Config;

public class ConfigurationExtensionWithSetting implements ConfigurationExtension {

@Setting("Valid because this is an extension of ServiceExtension")
private static final String VALID_SETTING = "any";

@Override
public Config getConfig() {
return null;
}
}

This file was deleted.

0 comments on commit 193ad23

Please sign in to comment.