Skip to content

Commit

Permalink
feat: permit @setting in ConfigurationExtension (#229)
Browse files Browse the repository at this point in the history
* feat: permit @setting in ConfigurationExtension

* dependencies
  • Loading branch information
ndr-brt committed Mar 19, 2024
1 parent 46a48d0 commit 830f9ca
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 20 deletions.
5 changes: 5 additions & 0 deletions DEPENDENCIES
Expand Up @@ -46,9 +46,12 @@ maven/mavencentral/commons-collections/commons-collections/3.2.2, Apache-2.0, ap
maven/mavencentral/commons-io/commons-io/2.4, Apache-1.1, approved, CQ9218
maven/mavencentral/commons-io/commons-io/2.6, Apache-2.0, approved, CQ19090
maven/mavencentral/commons-logging/commons-logging/1.2, Apache-2.0, approved, CQ10162
maven/mavencentral/dev.failsafe/failsafe/3.3.2, Apache-2.0, approved, #9268
maven/mavencentral/gradle.plugin.org.gradle.crypto/checksum/1.4.0, Apache-2.0, approved, #9667
maven/mavencentral/info.picocli/picocli/4.7.5, Apache-2.0, approved, #4365
maven/mavencentral/io.github.gradle-nexus/publish-plugin/1.3.0, Apache-2.0 AND (Apache-2.0 AND BSD-3-Clause AND CPL-1.0 AND LGPL-2.1-only AND LGPL-2.1-or-later AND MIT AND LicenseRef-Permission-Notice), approved, #10359
maven/mavencentral/io.opentelemetry/opentelemetry-api/1.32.0, Apache-2.0, approved, #11682
maven/mavencentral/io.opentelemetry/opentelemetry-context/1.32.0, Apache-2.0, approved, #11683
maven/mavencentral/io.swagger.core.v3/swagger-annotations/2.1.5, Apache-2.0, approved, clearlydefined
maven/mavencentral/io.swagger.core.v3/swagger-core/2.1.5, Apache-2.0, approved, clearlydefined
maven/mavencentral/io.swagger.core.v3/swagger-gradle-plugin/2.2.15, Apache-2.0 AND MIT, approved, #10356
Expand Down Expand Up @@ -110,6 +113,8 @@ maven/mavencentral/org.codehaus.plexus/plexus-container-default/2.1.0, Apache-2.
maven/mavencentral/org.codehaus.plexus/plexus-utils/3.1.1, , approved, CQ16492
maven/mavencentral/org.codehaus.plexus/plexus-utils/3.3.0, , approved, CQ21066
maven/mavencentral/org.eclipse.edc/autodoc-processor/0.5.2-SNAPSHOT, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/core-spi/0.5.2-SNAPSHOT, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/policy-model/0.5.2-SNAPSHOT, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/runtime-metamodel/0.5.2-SNAPSHOT, Apache-2.0, approved, technology.edc
maven/mavencentral/org.glassfish.web/javax.el/2.2.6, CDDL-1.0 OR GPL-2.0-only WITH Classpath-exception-2.0, approved, #1654
maven/mavencentral/org.hibernate.validator/hibernate-validator-annotation-processor/6.0.2.Final, Apache-2.0 AND LicenseRef-Public-Domain, approved, CQ20221
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
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
Expand Up @@ -17,4 +17,6 @@ plugins {

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

testImplementation(libs.edc.core.spi)
}
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
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
@@ -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 830f9ca

Please sign in to comment.