diff --git a/autodoc/build.gradle.kts b/autodoc/build.gradle.kts index 8831782a..65ab3cfc 100644 --- a/autodoc/build.gradle.kts +++ b/autodoc/build.gradle.kts @@ -6,7 +6,7 @@ val jupiterVersion: String by project val assertj: String by project dependencies { - implementation(project(":autodoc-model")) + implementation(project(":runtime-metamodel")) // Use JUnit test framework for unit tests testImplementation("org.junit.jupiter:junit-jupiter-api:${jupiterVersion}") testImplementation("org.junit.jupiter:junit-jupiter-params:${jupiterVersion}") diff --git a/autodoc/build/tmp/compileJava/previous-compilation-data.bin b/autodoc/build/tmp/compileJava/previous-compilation-data.bin deleted file mode 100644 index 9f89f9fe..00000000 Binary files a/autodoc/build/tmp/compileJava/previous-compilation-data.bin and /dev/null differ diff --git a/autodoc/src/test/java/org/eclipse/dataspaceconnector/plugins/AutodocPluginTest.java b/autodoc/src/test/java/org/eclipse/dataspaceconnector/plugins/AutodocPluginTest.java index 45352708..0985a36c 100644 --- a/autodoc/src/test/java/org/eclipse/dataspaceconnector/plugins/AutodocPluginTest.java +++ b/autodoc/src/test/java/org/eclipse/dataspaceconnector/plugins/AutodocPluginTest.java @@ -1,14 +1,14 @@ /* - * Copyright (c) 2022 Microsoft Corporation + * 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 + * 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 + * SPDX-License-Identifier: Apache-2.0 * - * Contributors: - * Microsoft Corporation - initial API and implementation + * Contributors: + * Microsoft Corporation - initial API and implementation * */ diff --git a/build.gradle.kts b/build.gradle.kts index 18ca6b55..1343c77e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,12 +1,13 @@ plugins { // Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins - id("com.gradle.plugin-publish") version "1.0.0" apply false checkstyle + `maven-publish` + signing + `java-library` // for publishing to nexus/ossrh/mavencentral id("org.gradle.crypto.checksum") version "1.4.0" id("io.github.gradle-nexus.publish-plugin") version "1.1.0" - `maven-publish` - signing + id("com.gradle.plugin-publish") version "1.0.0" apply false } val groupId: String by project; @@ -53,6 +54,18 @@ subprojects { } } } + + java { + val javaVersion = 11 + toolchain { + languageVersion.set(JavaLanguageVersion.of(javaVersion)) + } + tasks.withType(JavaCompile::class.java) { + // making sure the code does not use any APIs from a more recent version. + // Ref: https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation + options.release.set(javaVersion.toInt()) + } + } } // configure checkstyle version @@ -65,6 +78,7 @@ subprojects { mavenCentral() } + // let's not generate any reports because that is done from within the Github Actions workflow tasks.withType { reports { @@ -76,7 +90,6 @@ subprojects { } - repositories { // Use Maven Central for resolving dependencies mavenCentral() diff --git a/gradle.properties b/gradle.properties index 57866df5..9714d73c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,6 @@ assertj=3.23.1 jupiterVersion=5.9.0 groupId=org.eclipse.dataspaceconnector -projectVersion=0.0.1 \ No newline at end of file +projectVersion=0.0.1 +jacksonVersion=2.13.3 +jetBrainsAnnotationsVersion=15.0 \ No newline at end of file diff --git a/autodoc-model/build.gradle.kts b/runtime-metamodel/build.gradle.kts similarity index 58% rename from autodoc-model/build.gradle.kts rename to runtime-metamodel/build.gradle.kts index 93805c42..9fbf07e0 100644 --- a/autodoc-model/build.gradle.kts +++ b/runtime-metamodel/build.gradle.kts @@ -4,8 +4,17 @@ plugins { val jupiterVersion: String by project val assertj: String by project +val jetBrainsAnnotationsVersion: String by project +val jacksonVersion: String by project dependencies { + + api("org.jetbrains:annotations:${jetBrainsAnnotationsVersion}") + api("com.fasterxml.jackson.core:jackson-core:${jacksonVersion}") + api("com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}") + api("com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}") + api("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jacksonVersion}") + // Use JUnit test framework for unit tests testImplementation("org.junit.jupiter:junit-jupiter-api:${jupiterVersion}") testImplementation("org.junit.jupiter:junit-jupiter-params:${jupiterVersion}") @@ -24,8 +33,8 @@ tasks.test { publishing { publications { - create("autodoc-model") { - artifactId = "autodoc-model" + create("runtime-metamodel") { + artifactId = "runtime-metamodel" from(components["java"]) } } diff --git a/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/BaseExtension.java b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/BaseExtension.java new file mode 100644 index 00000000..40468be6 --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/BaseExtension.java @@ -0,0 +1,28 @@ +/* + * 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.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Indicates that an extension belongs to the runtime core and should always be loaded first. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface BaseExtension { +} diff --git a/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/CoreExtension.java b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/CoreExtension.java new file mode 100644 index 00000000..84bead09 --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/CoreExtension.java @@ -0,0 +1,30 @@ +/* + * 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.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Indicates that an extension pertains to the core:transfer module, which will cause it to receive special treatment + * upon extension loading. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface CoreExtension { + +} diff --git a/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/EdcSetting.java b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/EdcSetting.java new file mode 100644 index 00000000..fb80285f --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/EdcSetting.java @@ -0,0 +1,45 @@ +/* + * 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.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) +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; + +} diff --git a/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/EdcSettingContext.java b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/EdcSettingContext.java new file mode 100644 index 00000000..f02278e6 --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/EdcSettingContext.java @@ -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 EdcSettingContext { + String value(); +} diff --git a/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Extension.java b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Extension.java new file mode 100644 index 00000000..de423687 --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Extension.java @@ -0,0 +1,41 @@ +/* + * 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 an extension module. + */ +@Target({ ElementType.TYPE }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface Extension { + + /** + * The readable module name. + */ + String value(); + + /** + * Optional categories used to classify this module. + */ + String[] categories() default ""; + +} diff --git a/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/ExtensionPoint.java b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/ExtensionPoint.java new file mode 100644 index 00000000..bb37e1be --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/ExtensionPoint.java @@ -0,0 +1,32 @@ +/* + * 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.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Denotes a service extension point. + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Inherited +@Documented +public @interface ExtensionPoint { +} diff --git a/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Inject.java b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Inject.java new file mode 100644 index 00000000..9163ed1c --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Inject.java @@ -0,0 +1,33 @@ +/* + * 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.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation to be used on a {@code ServiceExtension}'s fields, so that they can be automatically set during + * the extension load phase. + * This annotation has no effect on any class other than a {@code ServiceExtension}. + *

+ * do NOT @Inherited it, because that complicates things + */ +@Target({ ElementType.FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Inject { + boolean required() default true; +} diff --git a/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Provider.java b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Provider.java new file mode 100644 index 00000000..ce5bd2fb --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Provider.java @@ -0,0 +1,39 @@ +/* + * 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.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation on the method level, that designates that method to be a factory for a particular type. + * The type is determined by the methods return type. + *

+ *

+ * Methods annotated with {@code @Provider} must : + *

    + *
  • be declared on an implementor of a {@code ServiceExtension}
  • + *
  • have a non-void return type
  • + *
  • be public
  • + *
  • either have no parameters or accept a single {@code ServiceExtensionContext}
  • + *
+ */ +@Target({ ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Provider { + boolean isDefault() default false; +} diff --git a/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Provides.java b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Provides.java new file mode 100644 index 00000000..9a450330 --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Provides.java @@ -0,0 +1,32 @@ +/* + * 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.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation, that specifies on the type level which feature a certain class provides. + *

+ *

+ * All fields that are marked with {@link Inject} must be @Provides-ed by at least one extension. + */ +@Target({ ElementType.TYPE, ElementType.PACKAGE, ElementType.MODULE }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Provides { + Class[] value(); +} diff --git a/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Requires.java b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Requires.java new file mode 100644 index 00000000..a38d7540 --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Requires.java @@ -0,0 +1,35 @@ +/* + * 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.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Specifies which feature a certain class, package or modules provides. + * Feature must be namespaced in the form "edc:XXX:YYY:ZZZ". + *

+ * If a referenced feature class is not annotated, the dependency injection mechanism will use the feature's fully + * qualified class name by default. + *

+ * All fields that are marked with {@link Inject} must be @Provided by at least one extension. + */ +@Target({ ElementType.TYPE, ElementType.PACKAGE, ElementType.MODULE }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Requires { + Class[] value(); +} diff --git a/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Spi.java b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Spi.java new file mode 100644 index 00000000..53ec6259 --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/annotation/Spi.java @@ -0,0 +1,38 @@ +/* + * 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.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Denotes an SPI module. + */ +@Target({ ElementType.PACKAGE }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Spi { + + /** + * The readable module name. + */ + String value(); + + /** + * Optional categories used to classify this module. + */ + String[] categories() default ""; +} diff --git a/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/domain/ConfigurationSetting.java b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/domain/ConfigurationSetting.java new file mode 100644 index 00000000..a3d3bae7 --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/domain/ConfigurationSetting.java @@ -0,0 +1,162 @@ +/* + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; + +import java.util.Objects; + +import static java.util.Objects.requireNonNull; + +/** + * A configuration point that can be set for an {@link EdcModule}. + */ +@JsonDeserialize(builder = ConfigurationSetting.Builder.class) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ConfigurationSetting { + private String key; + private boolean required = true; + private String type = "string"; + private String pattern; + private Long minimum; + private Long maximum; + private String description; + + private ConfigurationSetting() { + } + + /** + * Returns the normalized configuration key. + */ + public String getKey() { + return key; + } + + /** + * Returns true if this configuration must be supplied or false if it is optional. + */ + public boolean isRequired() { + return required; + } + + /** + * Returns the value type corresponding to Json schema types. + */ + public String getType() { + return type; + } + + /** + * Returns a REGEX expressing the pattern required by the configuration value or null if not specififed. + */ + public String getPattern() { + return pattern; + } + + /** + * Returns a minimum valid value for numeric configuration or null if not specified. + */ + public Long getMinimum() { + return minimum; + } + + /** + * Returns a maximum valid value for numeric configuration or null if not specified. + */ + public Long getMaximum() { + return maximum; + } + + /** + * Returns a description of this configuration element. + */ + public String getDescription() { + return description; + } + + @Override + public int hashCode() { + return Objects.hash(key); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + var that = (ConfigurationSetting) o; + return key.equals(that.key); + } + + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + private final ConfigurationSetting setting; + + private Builder() { + setting = new ConfigurationSetting(); + } + + @JsonCreator + public static Builder newInstance() { + return new Builder(); + } + + public Builder required(boolean required) { + setting.required = required; + return this; + } + + public Builder key(String key) { + setting.key = key; + return this; + } + + public Builder type(String type) { + setting.type = type; + return this; + } + + public Builder pattern(String pattern) { + setting.pattern = pattern; + return this; + } + + public Builder minimum(Long minimum) { + setting.minimum = minimum; + return this; + } + + public Builder maximum(Long maximum) { + setting.maximum = maximum; + return this; + } + + public Builder description(String description) { + setting.description = description; + return this; + } + + public ConfigurationSetting build() { + requireNonNull(setting.key, "key"); + return setting; + } + } +} diff --git a/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/domain/EdcModule.java b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/domain/EdcModule.java new file mode 100644 index 00000000..74e166fc --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/domain/EdcModule.java @@ -0,0 +1,201 @@ +/* + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import static java.util.Objects.requireNonNull; + +/** + * An EDC module. + */ +@JsonDeserialize(builder = EdcModule.Builder.class) +public class EdcModule { + private final List categories = new ArrayList<>(); + private final List extensionPoints = new ArrayList<>(); + private final List provides = new ArrayList<>(); + private final List references = new ArrayList<>(); + private final List configuration = new ArrayList<>(); + private String id; + private String version; + private String name; + private ModuleType type = ModuleType.EXTENSION; + private String overview; + + /** + * Returns the module id, which corresponds to Maven-style group:artifact coordinates. + */ + public String getId() { + return id; + } + + /** + * Returns the module version. + */ + public String getVersion() { + return version; + } + + /** + * Returns the module readable name. + */ + public String getName() { + return name; + } + + /** + * Returns the module type. + */ + public ModuleType getType() { + return type; + } + + /** + * Returns categories assigned to the module, or an empty collection. + */ + public List getCategories() { + return categories; + } + + /** + * Returns services provided by this extension module, or an empty collection. + */ + public List getProvides() { + return provides; + } + + /** + * Returns services extension points defined in this SPI module, or an empty collection. + */ + public List getExtensionPoints() { + return extensionPoints; + } + + /** + * Returns services that are provided by other modules and referenced in the current module, or an empty collection. + */ + public List getReferences() { + return references; + } + + /** + * Returns the configuration settings for this module. + */ + public List getConfiguration() { + return configuration; + } + + /** + * Returns a Markdown-formatted description of this module. + */ + public String getOverview() { + return overview; + } + + @Override + public int hashCode() { + return Objects.hash(id, version); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + var edcModule = (EdcModule) o; + return id.equals(edcModule.id) && version.equals(edcModule.version); + } + + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + private final EdcModule module; + + private Builder() { + module = new EdcModule(); + } + + @JsonCreator + public static Builder newInstance() { + return new Builder(); + } + + public Builder id(String id) { + module.id = id; + return this; + } + + public Builder version(String version) { + module.version = version; + return this; + } + + public Builder name(String name) { + module.name = name; + return this; + } + + public Builder type(ModuleType type) { + module.type = type; + return this; + } + + public Builder categories(List categories) { + module.categories.addAll(categories); + return this; + } + + public Builder provides(List provides) { + module.provides.addAll(provides); + return this; + } + + public Builder extensionPoints(List provides) { + module.extensionPoints.addAll(provides); + return this; + } + + public Builder references(List requires) { + module.references.addAll(requires); + return this; + } + + public Builder configuration(List configuration) { + module.configuration.addAll(configuration); + return this; + } + + public Builder overview(String overview) { + module.overview = overview; + return this; + } + + public EdcModule build() { + requireNonNull(module.id, "id"); + requireNonNull(module.version, "version"); + requireNonNull(module.name, "name"); + return module; + } + + } +} diff --git a/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/domain/ModuleType.java b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/domain/ModuleType.java new file mode 100644 index 00000000..61dedcdf --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/domain/ModuleType.java @@ -0,0 +1,43 @@ +/* + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Enumerates {@link EdcModule} types. SPI modules define extension points and extension modules contribute capabilities to a runtime. + */ +public enum ModuleType { + SPI("spi"), + EXTENSION("extension"); + + private final String key; + + ModuleType(String key) { + this.key = key; + } + + @JsonCreator + public static ModuleType fromString(String key) { + return key == null ? null : ModuleType.valueOf(key.toUpperCase()); + } + + @JsonValue + public String getKey() { + return key; + } + +} diff --git a/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/domain/Service.java b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/domain/Service.java new file mode 100644 index 00000000..b337165e --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/domain/Service.java @@ -0,0 +1,56 @@ +/* + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Objects; + +import static java.util.Objects.requireNonNull; + +/** + * An extension point defined in an SPI module or a service provided an extension module. + */ +public class Service { + private final String service; + + public Service(@JsonProperty("service") String service) { + this.service = requireNonNull(service, "service"); + } + + /** + * Returns the service class name. + */ + public String getService() { + return service; + } + + @Override + public int hashCode() { + return Objects.hash(service); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + var service1 = (Service) o; + return service.equals(service1.service); + } +} diff --git a/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/domain/ServiceReference.java b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/domain/ServiceReference.java new file mode 100644 index 00000000..8ca0b850 --- /dev/null +++ b/runtime-metamodel/src/main/java/org/eclipse/dataspaceconnector/runtime/metamodel/domain/ServiceReference.java @@ -0,0 +1,65 @@ +/* + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Objects; + +import static java.util.Objects.requireNonNull; + +/** + * A service required by an {@link EdcModule}. + */ +public class ServiceReference { + private final String service; + private final boolean required; + + public ServiceReference(@JsonProperty("service") String service, @JsonProperty("required") boolean required) { + this.service = requireNonNull(service, "service"); + this.required = required; + } + + /** + * Returns the service class name. + */ + public String getService() { + return service; + } + + /** + * Returns true if the service must be provided. + */ + public boolean isRequired() { + return required; + } + + @Override + public int hashCode() { + return Objects.hash(service, required); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + var that = (ServiceReference) o; + return required == that.required && service.equals(that.service); + } +} diff --git a/runtime-metamodel/src/test/java/org/eclipse/dataspaceconnector/tooling/autodoc/domain/ConfigurationSettingTest.java b/runtime-metamodel/src/test/java/org/eclipse/dataspaceconnector/tooling/autodoc/domain/ConfigurationSettingTest.java new file mode 100644 index 00000000..591db513 --- /dev/null +++ b/runtime-metamodel/src/test/java/org/eclipse/dataspaceconnector/tooling/autodoc/domain/ConfigurationSettingTest.java @@ -0,0 +1,39 @@ +/* + * 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.tooling.autodoc.domain; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.dataspaceconnector.runtime.metamodel.domain.ConfigurationSetting; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class ConfigurationSettingTest { + + @Test + void verifySerializeDeserialize() throws JsonProcessingException { + var mapper = new ObjectMapper(); + var configuration = ConfigurationSetting.Builder.newInstance().key("key1").build(); + + var serialized = mapper.writeValueAsString(configuration); + var deserialized = mapper.readValue(serialized, ConfigurationSetting.class); + + assertThat(deserialized).isNotNull(); + assertThat(deserialized.isRequired()).isTrue(); + assertThat(deserialized.getKey()).isEqualTo("key1"); + } + +} diff --git a/runtime-metamodel/src/test/java/org/eclipse/dataspaceconnector/tooling/autodoc/domain/EdcModuleTest.java b/runtime-metamodel/src/test/java/org/eclipse/dataspaceconnector/tooling/autodoc/domain/EdcModuleTest.java new file mode 100644 index 00000000..4e7b6673 --- /dev/null +++ b/runtime-metamodel/src/test/java/org/eclipse/dataspaceconnector/tooling/autodoc/domain/EdcModuleTest.java @@ -0,0 +1,56 @@ +/* + * 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.tooling.autodoc.domain; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.dataspaceconnector.runtime.metamodel.domain.ConfigurationSetting; +import org.eclipse.dataspaceconnector.runtime.metamodel.domain.EdcModule; +import org.eclipse.dataspaceconnector.runtime.metamodel.domain.Service; +import org.eclipse.dataspaceconnector.runtime.metamodel.domain.ServiceReference; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class EdcModuleTest { + + @Test + void verifySerializeDeserialize() throws JsonProcessingException { + var mapper = new ObjectMapper(); + var module = EdcModule.Builder.newInstance() + .id("foo:bar") + .version("1.0.0") + .name("test") + .overview("overview") + .categories(List.of("category")) + .extensionPoints(List.of(new Service("com.bar.BarService"))) + .provides(List.of(new Service("com.bar.BazService"))) + .references(List.of(new ServiceReference("com.bar.QuuxService", false))) + .configuration(List.of(ConfigurationSetting.Builder.newInstance().key("key1").build())) + .build(); + + var serialized = mapper.writeValueAsString(module); + var deserialized = mapper.readValue(serialized, EdcModule.class); + + assertThat(deserialized).isNotNull(); + assertThat(deserialized.getCategories().size()).isEqualTo(1); + assertThat(deserialized.getExtensionPoints().size()).isEqualTo(1); + assertThat(deserialized.getProvides().size()).isEqualTo(1); + assertThat(deserialized.getReferences().size()).isEqualTo(1); + assertThat(deserialized.getConfiguration().size()).isEqualTo(1); + } +} diff --git a/runtime-metamodel/src/test/java/org/eclipse/dataspaceconnector/tooling/autodoc/domain/ServiceReferenceTest.java b/runtime-metamodel/src/test/java/org/eclipse/dataspaceconnector/tooling/autodoc/domain/ServiceReferenceTest.java new file mode 100644 index 00000000..6bb334c9 --- /dev/null +++ b/runtime-metamodel/src/test/java/org/eclipse/dataspaceconnector/tooling/autodoc/domain/ServiceReferenceTest.java @@ -0,0 +1,36 @@ +/* + * 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.tooling.autodoc.domain; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.dataspaceconnector.runtime.metamodel.domain.ServiceReference; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class ServiceReferenceTest { + + @Test + void verifySerializeDeserialize() throws JsonProcessingException { + var mapper = new ObjectMapper(); + var service = new ServiceReference("foo.bar.BarService", false); + + var serialized = mapper.writeValueAsString(service); + var deserialized = mapper.readValue(serialized, ServiceReference.class); + + assertThat(deserialized).isNotNull(); + } +} diff --git a/runtime-metamodel/src/test/java/org/eclipse/dataspaceconnector/tooling/autodoc/domain/ServiceTest.java b/runtime-metamodel/src/test/java/org/eclipse/dataspaceconnector/tooling/autodoc/domain/ServiceTest.java new file mode 100644 index 00000000..853efeac --- /dev/null +++ b/runtime-metamodel/src/test/java/org/eclipse/dataspaceconnector/tooling/autodoc/domain/ServiceTest.java @@ -0,0 +1,36 @@ +/* + * 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.tooling.autodoc.domain; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.dataspaceconnector.runtime.metamodel.domain.Service; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class ServiceTest { + + @Test + void verifySerializeDeserialize() throws JsonProcessingException { + var mapper = new ObjectMapper(); + var service = new Service("foo.bar.BarService"); + + var serialized = mapper.writeValueAsString(service); + var deserialized = mapper.readValue(serialized, Service.class); + + assertThat(deserialized).isNotNull(); + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 66a15a66..49cba700 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,4 +1,4 @@ rootProject.name = "edcPlugins" include("autodoc") -include("autodoc-model") \ No newline at end of file +include("runtime-metamodel")