-
Notifications
You must be signed in to change notification settings - Fork 11
chore: moves all autdoc code here #4
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
Merged
paullatzelsperger
merged 6 commits into
eclipse-edc:main
from
paullatzelsperger:feature/move_autodoc_code_here
Sep 22, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c58875e
moved all code to sub-module
paullatzelsperger 5992f4d
adds code from EDC as -core
paullatzelsperger 2a91a8c
moved test deps to root build file
paullatzelsperger e77fd12
all plugins should be in 'plugins' folder
paullatzelsperger 949995f
add functional test module
paullatzelsperger 5c76ccd
moved over the spi-test module
paullatzelsperger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| This module contains the business logic code for the `autodoc` feature, i.e. the actual annotation processor. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * 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 | ||
| */ | ||
|
|
||
| plugins { | ||
| `java-library` | ||
| } | ||
|
|
||
| dependencies { | ||
| api(project(":runtime-metamodel")) | ||
| } | ||
|
|
||
| publishing { | ||
| publications { | ||
| create<MavenPublication>("autodoc-core") { | ||
| artifactId = "autodoc-core" | ||
| from(components["java"]) | ||
| } | ||
| } | ||
| } |
198 changes: 198 additions & 0 deletions
198
...ava/org/eclipse/dataspaceconnector/plugins/autodoc/core/processor/EdcModuleProcessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| /* | ||
| * 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.plugins.autodoc.core.processor; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.eclipse.dataspaceconnector.plugins.autodoc.core.processor.introspection.ModuleIntrospector; | ||
| import org.eclipse.dataspaceconnector.plugins.autodoc.core.processor.introspection.OverviewIntrospector; | ||
| import org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Extension; | ||
| import org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Spi; | ||
| import org.eclipse.dataspaceconnector.runtime.metamodel.domain.EdcModule; | ||
| import org.eclipse.dataspaceconnector.runtime.metamodel.domain.ModuleType; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import java.io.BufferedWriter; | ||
| import java.io.File; | ||
| import java.io.FileWriter; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
| import javax.annotation.processing.AbstractProcessor; | ||
| import javax.annotation.processing.ProcessingEnvironment; | ||
| import javax.annotation.processing.RoundEnvironment; | ||
| import javax.annotation.processing.SupportedAnnotationTypes; | ||
| import javax.annotation.processing.SupportedOptions; | ||
| import javax.annotation.processing.SupportedSourceVersion; | ||
| import javax.lang.model.SourceVersion; | ||
| import javax.lang.model.element.TypeElement; | ||
| import javax.tools.StandardLocation; | ||
|
|
||
| import static javax.tools.Diagnostic.Kind.ERROR; | ||
| import static javax.tools.Diagnostic.Kind.NOTE; | ||
|
|
||
| /** | ||
| * Generates an EDC module manifest by introspecting a set of bounded artifacts. | ||
| * <p> | ||
| * Two processor parameters must be set: {@link #ID} which by convention uses Maven group id an artifact id coordinates; | ||
| * and {@link #VERSION}. To Override the location where the manifest is generated, specify | ||
| * {@link #EDC_LOCATION_OVERRIDE} as a processor parameter. | ||
| */ | ||
| @SupportedAnnotationTypes({ | ||
| "org.eclipse.dataspaceconnector.runtime.metamodel.annotationEdcSetting", | ||
| "org.eclipse.dataspaceconnector.runtime.metamodel.annotationEdcSettingContext", | ||
| "org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Extension", | ||
| "org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Spi", | ||
| "org.eclipse.dataspaceconnector.runtime.metamodel.annotation.ExtensionPoint", | ||
| "org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Provider", | ||
| "org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Provides", | ||
| "org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Requires", | ||
| "org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Inject", | ||
| }) | ||
| @SupportedSourceVersion(SourceVersion.RELEASE_11) | ||
| @SupportedOptions({ EdcModuleProcessor.ID, EdcModuleProcessor.VERSION }) | ||
| public class EdcModuleProcessor extends AbstractProcessor { | ||
| static final String VERSION = "edc.version"; | ||
| static final String ID = "edc.id"; | ||
|
|
||
| private static final String MANIFEST_NAME = "edc.json"; | ||
| private static final String EDC_LOCATION_OVERRIDE = "edc.location"; | ||
|
|
||
| private final ObjectMapper mapper = new ObjectMapper(); | ||
|
|
||
| private ModuleIntrospector moduleIntrospector; | ||
|
|
||
| private OverviewIntrospector overviewIntrospector; | ||
|
|
||
| private EdcModule.Builder moduleBuilder; | ||
|
|
||
| private ModuleType moduleType; | ||
|
|
||
| @Override | ||
| public synchronized void init(ProcessingEnvironment processingEnv) { | ||
| super.init(processingEnv); | ||
| moduleIntrospector = new ModuleIntrospector(processingEnv.getElementUtils()); | ||
| //todo: replace this Noop converter with an actual JavadocConverter | ||
| overviewIntrospector = new OverviewIntrospector(javadoc -> javadoc, processingEnv.getElementUtils()); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment environment) { | ||
| if (!initializeModuleBuilder(environment)) { | ||
| return false; // error, do not continue processing | ||
| } | ||
|
|
||
| if (environment.processingOver()) { | ||
| if (moduleBuilder != null) { | ||
| writeManifest(); | ||
| } | ||
| return false; // processing rounds are complete, return | ||
| } | ||
|
|
||
| moduleBuilder.provides(moduleIntrospector.resolveProvidedServices(environment)); | ||
|
|
||
| moduleBuilder.extensionPoints(moduleIntrospector.resolveExtensionPoints(environment)); | ||
|
|
||
| moduleBuilder.references(moduleIntrospector.resolveReferencedServices(environment)); | ||
|
|
||
| moduleBuilder.configuration(moduleIntrospector.resolveConfigurationSettings(environment)); | ||
|
|
||
| moduleBuilder.overview(overviewIntrospector.generateModuleOverview(moduleType, environment)); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| private boolean initializeModuleBuilder(RoundEnvironment environment) { | ||
| if (moduleBuilder != null) { | ||
| // already initialized in a previous round | ||
| return true; | ||
| } | ||
|
|
||
| var id = processingEnv.getOptions().get(ID); | ||
| if (id == null) { | ||
| processingEnv.getMessager().printMessage(ERROR, "Value for '" + ID + "' not set on processor configuration. Skipping manifest generation."); | ||
| return false; | ||
| } | ||
|
|
||
| var version = processingEnv.getOptions().get(VERSION); | ||
| if (version == null) { | ||
| processingEnv.getMessager().printMessage(ERROR, "Value for '" + VERSION + "' not set on processor configuration. Skipping manifest generation."); | ||
| return false; | ||
| } | ||
|
|
||
| moduleType = determineAndValidateModuleType(environment); | ||
| if (moduleType == null) { | ||
| // error or not a module, return | ||
| return false; | ||
| } | ||
|
|
||
| var name = moduleIntrospector.getModuleName(moduleType, environment); | ||
|
|
||
| var categories = moduleIntrospector.getModuleCategories(moduleType, environment); | ||
|
|
||
| moduleBuilder = EdcModule.Builder.newInstance().id(id).version(version).type(moduleType).name(name).categories(categories); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| @Nullable | ||
| private ModuleType determineAndValidateModuleType(RoundEnvironment environment) { | ||
| var extensionElements = environment.getElementsAnnotatedWith(Extension.class); | ||
| if (extensionElements.isEmpty()) { | ||
| // check if it is an SPI | ||
| var spiElements = environment.getElementsAnnotatedWith(Spi.class); | ||
| if (spiElements.size() > 1) { | ||
| var types = spiElements.stream().map(e -> e.asType().toString()).collect(Collectors.joining(", ")); | ||
| processingEnv.getMessager().printMessage(ERROR, "Multiple SPI definitions found in module: " + types); | ||
| return null; | ||
| } else if (spiElements.isEmpty()) { | ||
| processingEnv.getMessager().printMessage(NOTE, "Note an EDC module. Skipping module processing."); | ||
| return null; | ||
| } | ||
| return ModuleType.SPI; | ||
|
|
||
| } else { | ||
| // an extension | ||
| if (extensionElements.size() > 1) { | ||
| var types = extensionElements.stream().map(e -> e.asType().toString()).collect(Collectors.joining(", ")); | ||
| processingEnv.getMessager().printMessage(ERROR, "Multiple extension types found in module: " + types); | ||
| return null; | ||
| } | ||
| return ModuleType.EXTENSION; | ||
| } | ||
| } | ||
|
|
||
| private void writeManifest() { | ||
| try { | ||
| var filer = processingEnv.getFiler(); | ||
| var location = processingEnv.getOptions().get(EDC_LOCATION_OVERRIDE); | ||
| if (location != null) { | ||
| new File(location).mkdirs(); | ||
| try (var writer = new BufferedWriter(new FileWriter(location + File.separator + MANIFEST_NAME))) { | ||
| mapper.writeValue(writer, List.of(moduleBuilder.build())); | ||
| } | ||
| } else { | ||
| var resource = filer.createResource(StandardLocation.SOURCE_OUTPUT, "", MANIFEST_NAME); | ||
| try (var writer = resource.openWriter()) { | ||
| mapper.writeValue(writer, List.of(moduleBuilder.build())); | ||
| } | ||
| } | ||
| } catch (IOException ex) { | ||
| throw new RuntimeException(ex); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
29 changes: 29 additions & 0 deletions
29
...paceconnector/plugins/autodoc/core/processor/compiler/AnnotationBooleanValueResolver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * 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.plugins.autodoc.core.processor.compiler; | ||
|
|
||
| import javax.lang.model.util.SimpleAnnotationValueVisitor9; | ||
|
|
||
| /** | ||
| * Returns the value of an annotation attribute as a boolean. | ||
| */ | ||
| class AnnotationBooleanValueResolver extends SimpleAnnotationValueVisitor9<Boolean, Void> { | ||
|
|
||
| @Override | ||
| public Boolean visitBoolean(boolean b, Void o) { | ||
| return b; | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Dereferenced variable may be null