diff --git a/.github/workflows/publish-plugins.yml b/.github/workflows/publish-plugins.yml deleted file mode 100644 index 1c66880..0000000 --- a/.github/workflows/publish-plugins.yml +++ /dev/null @@ -1,66 +0,0 @@ -# -# 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 -# - ---- -name: "Publish Gradle Plugins" - -on: - workflow_dispatch: - inputs: - tck_version: - description: 'Version string that is used for publishing (e.g. "1.0.0", NOT "v1.0.0"). -SNAPSHOT builds are not supported!' - required: true - type: string - workflow_call: - inputs: - tck_version: - description: 'Version string that is used for publishing (e.g. "1.0.0", NOT "v1.0.0"). -SNAPSHOT builds are not supported!' - required: true - type: string - - -jobs: - Secrets-Presence: - name: "Check for required credentials" - runs-on: ubuntu-latest - outputs: - HAS_GRADLE_CREDENTIALS: ${{ steps.secret-presence.outputs.HAS_GRADLE_CREDENTIALS }} - steps: - - name: Check whether secrets exist - id: secret-presence - run: | - [ ! -z "${{ secrets.GRADLE_PUBLISH_KEY }}" ] && - [ ! -z "${{ secrets.GRADLE_PUBLISH_SECRET }}" ] && echo "HAS_GRADLE_CREDENTIALS=true" >> $GITHUB_OUTPUT - exit 0 - - Publish-Plugins: - name: "Publish artefacts to Gradle Plugin Portal" - runs-on: ubuntu-latest - needs: [ Secrets-Presence ] - if: | - needs.Secrets-Presence.outputs.HAS_GRADLE_CREDENTIALS - steps: - - uses: actions/checkout@v4 - - name: Publish Gradle Plugins (validate) - run: | - ./gradlew publishPlugins -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} --validate-only - - name: Publish Gradle Plugins - run: | - ./gradlew publishPlugins -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} - - Create-Github-Release: - name: "Create Github Release" - needs: [ Publish-Plugins] - uses: ./.github/workflows/create-github-release.yml - with: - tck_version: ${{ github.event.inputs.tck_version || inputs.tck_version }} \ No newline at end of file diff --git a/.github/workflows/publish-snapshot.yml b/.github/workflows/publish-snapshot.yml new file mode 100644 index 0000000..2a509f6 --- /dev/null +++ b/.github/workflows/publish-snapshot.yml @@ -0,0 +1,50 @@ +# +# 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 +# + +--- +name: "Publish Snapshot Build" + +on: + workflow_dispatch: + workflow_call: + +jobs: + secrets-presence: + name: "Check for required credentials" + runs-on: ubuntu-latest + outputs: + HAS_OSSRH: ${{ steps.secret-presence.outputs.HAS_OSSRH }} + steps: + - name: Check whether secrets exist + id: secret-presence + run: | + [ ! -z "${{ secrets.GPG_PASSPHRASE }}" ] && + [ ! -z "${{ secrets.GPG_PRIVATE_KEY }}" ] && + [ ! -z "${{ secrets.OSSRH_PASSWORD }}" ] && + [ ! -z "${{ secrets.OSSRH_USERNAME }}" ] && echo "HAS_OSSRH=true" >> $GITHUB_OUTPUT + exit 0 + + Publish-Snapshot: + name: "Publish artefacts to OSSRH Snapshots" + runs-on: ubuntu-latest + needs: [ secrets-presence ] + if: | + needs.secrets-presence.outputs.HAS_OSSRH + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/publish-maven-artifacts + with: + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} + osshr-username: ${{ secrets.OSSRH_USERNAME }} + osshr-password: ${{ secrets.OSSRH_PASSWORD }} diff --git a/.github/workflows/create-github-release.yml b/.github/workflows/release-tck-build.yml similarity index 90% rename from .github/workflows/create-github-release.yml rename to .github/workflows/release-tck-build.yml index cdac6c1..a999649 100644 --- a/.github/workflows/create-github-release.yml +++ b/.github/workflows/release-tck-build.yml @@ -12,7 +12,7 @@ # --- -name: Create Github Release +name: Create CVF Release on: workflow_dispatch: inputs: @@ -32,7 +32,7 @@ env: TCK_VERSION: ${{ github.event.inputs.tck_version || inputs.tck_version }} jobs: - Create-Tag: + Prepare-Release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -56,7 +56,7 @@ jobs: # cannot use the workflow-level env yet as it does not yet exist, must take output from previous job if: ${{ !endsWith( needs.Prepare-Release.outputs.tck-version, '-SNAPSHOT') }} needs: - - Create-Tag + - Prepare-Release runs-on: ubuntu-latest permissions: contents: write @@ -75,12 +75,12 @@ jobs: Bump-Version: name: 'Update release version' # cannot use the workflow-level env yet as it does not yet exist, must take output from previous job - if: ${{ !endsWith( needs.Create-Tag.outputs.tck-version, '-SNAPSHOT') }} - needs: [ Create-Tag, Github-Release ] + if: ${{ !endsWith( needs.Prepare-Release.outputs.tck-version, '-SNAPSHOT') }} + needs: [ Prepare-Release, Github-Release ] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ./.github/actions/bump-version with: target_branch: "main" - base_version: ${{ needs.Create-Tag.outputs.tck-version }} \ No newline at end of file + base_version: ${{ needs.Prepare-Release.outputs.tck-version }} \ No newline at end of file diff --git a/.github/workflows/trigger_snapshot.yml b/.github/workflows/trigger_snapshot.yml new file mode 100644 index 0000000..f224bab --- /dev/null +++ b/.github/workflows/trigger_snapshot.yml @@ -0,0 +1,31 @@ +# +# 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 +# + +--- +name: "Publish Snapshot Build" + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + Publish-Snapshot: + # This workflow will abort if the required secrets don't exist + uses: ./.github/workflows/publish-snapshot.yml + secrets: inherit + +# Publish-Dependencies: +# uses: eclipse-edc/.github/.github/workflows/publish-dependencies.yml@main +# secrets: inherit diff --git a/build.gradle.kts b/build.gradle.kts index 937f412..73d0752 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,5 @@ +import org.eclipse.dataspacetck.gradle.tckbuild.extensions.TckBuildExtension + /* * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * @@ -15,129 +17,40 @@ plugins { checkstyle `maven-publish` -} - -subprojects { - -// afterEvaluate { -// -// publishing { -// publications.forEach { i -> -// val mp = (i as MavenPublication) -// mp.pom { -// name.set(project.name) -// description.set("Compliance Verification Toolkit") -// url.set("https://projects.eclipse.org/projects/technology.dataspacetck") -// -// licenses { -// license { -// name.set("The Apache License, Version 2.0") -// url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") -// } -// developers { -// developer { -// id.set("JimMarino") -// name.set("Jim Marino") -// email.set("jmarino@metaformsystems.com") -// } -// developer { -// id.set("PaulLatzelsperger") -// name.set("Paul Latzelsperger") -// email.set("paul.latzelsperger@beardyinc.com") -// } -// developer { -// id.set("EnricoRisa") -// name.set("Enrico Risa") -// email.set("enrico.risa@gmail.com") -// } -// } -// scm { -// connection.set("scm:git:git@github.com:eclipse-dataspacetck/cvf.git") -// url.set("https://github.com/eclipse-dataspacetck/cvf.git") -// } -// } -// } -// } -// } -// -// } - + signing + `java-library` + `version-catalog` + alias(libs.plugins.gradle.publish) apply false } // needed for running the dash tool tasks.register("allDependencies", DependencyReportTask::class) -// disallow any errors -checkstyle { - maxErrors = 0 -} allprojects { - apply(plugin = "checkstyle") - apply(plugin = "maven-publish") - apply(plugin = "java-library") + apply(plugin = "org.eclipse.dataspacetck.tck-build") - configure { - toolchain.languageVersion.set(JavaLanguageVersion.of(17)) + // for all gradle plugins: + pluginManager.withPlugin("java-gradle-plugin") { + apply(plugin = "com.gradle.plugin-publish") } -} - -subprojects { - - publishing { - publications { - if (project.subprojects.isEmpty()) { - create(project.name) { - artifactId = project.name - from(components["java"]) - } - } + // configure POM + configure { + pom { + scmConnection = "https://github.com/eclipse-dataspacetck/dsp-tck.git" + scmUrl = "scm:git:git@github.com:eclipse-dataspacetck/dsp-tck.git" + groupId = "org.eclipse.dataspacetck.build" + projectName = project.name + description = "DSP Technology Compatibility Kit" + projectUrl = "https://projects.eclipse.org/projects/technology.dataspacetck" } } - afterEvaluate { - publishing { - publications.forEach { i -> - val mp = (i as MavenPublication) - mp.pom { - name.set(project.name) - description.set("Compliance Verification Toolkit") - url.set("https://projects.eclipse.org/projects/technology.dataspacetck") - - licenses { - license { - name.set("The Apache License, Version 2.0") - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") - } - developers { - developer { - id.set("JimMarino") - name.set("Jim Marino") - email.set("jmarino@metaformsystems.com") - } - developer { - id.set("PaulLatzelsperger") - name.set("Paul Latzelsperger") - email.set("paul.latzelsperger@beardyinc.com") - } - developer { - id.set("EnricoRisa") - name.set("Enrico Risa") - email.set("enrico.risa@gmail.com") - } - } - scm { - connection.set("scm:git:git@github.com:eclipse-dataspacetck/cvf.git") - url.set("https://github.com/eclipse-dataspacetck/cvf.git") - } - } - } - } - } + // FIXME - workaround for https://github.com/gradle/gradle/issues/26091 + val signingTasks = tasks.withType() + tasks.withType().configureEach { + mustRunAfter(signingTasks) } -} - - - +} \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..6f0a1c3 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,60 @@ +/* + * 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 + * + */ + +plugins { + `java-gradle-plugin` +} + +group = "org.eclipse.dataspacetck.build" + +repositories { + mavenCentral() + maven { + url = uri("https://oss.sonatype.org/content/repositories/snapshots/") + } + gradlePluginPortal() + mavenLocal() +} + +dependencies { + + implementation(libs.plugin.nexus.publish) + implementation(libs.plugin.docker.remoteapi) + implementation(libs.plugin.nexus.publish) + + api(libs.tck.common.api) +} + +gradlePlugin { + plugins { + create("tckBuild") { + id = "org.eclipse.dataspacetck.tck-build" + group = "org.eclipse.dataspacetck.build" + implementationClass = "org.eclipse.dataspacetck.gradle.tckbuild.plugins.TckBuildPlugin" + } + } +} + +val generatedSourcesFolder = layout.buildDirectory.asFile.get().resolve("generated").resolve("sources") + +sourceSets { + main { + java { + srcDirs( + generatedSourcesFolder, + "../plugins/tck-build-plugin/src/main" + ) + } + } +} diff --git a/buildSrc/gradle.properties b/buildSrc/gradle.properties new file mode 100644 index 0000000..15c08f9 --- /dev/null +++ b/buildSrc/gradle.properties @@ -0,0 +1,15 @@ +# +# 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 +# +# +group=org.eclipse.dataspacetck.build +version=0.0.1-SNAPSHOT diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 0000000..91e8fac --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,21 @@ +/* + * 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 + * + */ + +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} diff --git a/gradle.properties b/gradle.properties index 574a662..15c08f9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,5 +11,5 @@ # Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation # # -group=org.eclipse.dataspacetck -version=0.0.1 +group=org.eclipse.dataspacetck.build +version=0.0.1-SNAPSHOT diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 19e4a93..48d4938 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,8 +7,8 @@ jupiter = "5.10.3" tck = "0.0.1-SNAPSHOT" [libraries] -tck-common-api = { module = "org.eclipse.dataspacetck:core-api", version.ref = "tck" } -tck-common-testplan-gen = { module = "org.eclipse.dataspacetck:test-plan-generator", version.ref = "tck" } +tck-common-api = { module = "org.eclipse.dataspacetck.common:core-api", version.ref = "tck" } +tck-common-testplan-gen = { module = "org.eclipse.dataspacetck.common:test-plan-generator", version.ref = "tck" } junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "jupiter" } junit-platform-engine = { module = "org.junit.platform:junit-platform-suite-engine", version.ref = "junit" } plugin-docker-remoteapi = { module = "com.bmuschko.docker-remote-api:com.bmuschko.docker-remote-api.gradle.plugin", version = "9.4.0" } @@ -20,4 +20,4 @@ nexuspublishing = { id = "io.github.gradle-nexus.publish-plugin", version = "2.0 docker = { id = "com.bmuschko.docker-remote-api", version = "9.4.0" } # needed to build a fat JAR shadow = { id = "com.gradleup.shadow", version = "8.3.5" } -gradle-publish = { id = "com.gradle.plugin-publish", version = "1.2.1" } +gradle-publish = { id = "com.gradle.plugin-publish", version = "1.2.1" } \ No newline at end of file diff --git a/plugins/tck-build-plugin/build.gradle.kts b/plugins/tck-build-plugin/build.gradle.kts index 8b07c77..bf7d93d 100644 --- a/plugins/tck-build-plugin/build.gradle.kts +++ b/plugins/tck-build-plugin/build.gradle.kts @@ -33,7 +33,8 @@ gradlePlugin { plugins { create("tckBuild") { - id = "org.eclipse.dataspacetck.tck-build" + id = "org.eclipse.dataspacetck.build.tck-build" + group = "org.eclipse.dataspacetck.build" displayName = "TCK Build Plugin" description = "Gradle Plugin to customize the TCK build" tags = listOf("tags", "dataspace", "dsp", "dcp", "tck", "plugins", "build") diff --git a/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/Repositories.java b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/Repositories.java index 6fd8110..b3fc627 100644 --- a/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/Repositories.java +++ b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/Repositories.java @@ -17,6 +17,7 @@ import io.github.gradlenexus.publishplugin.NexusRepository; import io.github.gradlenexus.publishplugin.NexusRepositoryContainer; import org.gradle.api.Action; +import org.gradle.api.artifacts.repositories.MavenArtifactRepository; import java.net.URI; @@ -27,6 +28,12 @@ public class Repositories { private static final String OSSRH_PASSWORD = "OSSRH_PASSWORD"; private static final String OSSRH_USER = "OSSRH_USERNAME"; + public static Action mavenRepo(String repoUrl) { + return repo -> { + repo.setUrl(repoUrl); + }; + } + public static Action sonatypeRepo() { return c -> c.sonatype(nexusRepo(NEXUS_REPO_URL, SNAPSHOT_REPO_URL)); } diff --git a/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/conventions/JarConvention.java b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/conventions/JarConvention.java new file mode 100644 index 0000000..b4d0765 --- /dev/null +++ b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/conventions/JarConvention.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.dataspacetck.gradle.tckbuild.conventions; + +import org.gradle.api.Project; +import org.gradle.api.file.DuplicatesStrategy; +import org.gradle.jvm.tasks.Jar; + +import java.nio.file.Path; + +/** + * Adds the LICENSE and NOTICE.md file to every JAR + */ +public class JarConvention { + public void apply(Project target) { + var task = target.getTasks().named("jar"); + if (task.isPresent()) { + var jarTask = (Jar) task.get(); + var rootProjectPath = target.getRootProject().getProjectDir().getAbsolutePath(); + var licenseFile = Path.of(rootProjectPath, "LICENSE"); + var noticeFile = Path.of(rootProjectPath, "NOTICE.md"); + var dependenciesFile = Path.of(rootProjectPath, "DEPENDENCIES"); + jarTask.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE); + jarTask.metaInf(metaInf -> metaInf.from(licenseFile.toString(), noticeFile.toString(), dependenciesFile.toString())); + } + } +} diff --git a/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/conventions/JavaConvention.java b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/conventions/JavaConvention.java new file mode 100644 index 0000000..95ce4be --- /dev/null +++ b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/conventions/JavaConvention.java @@ -0,0 +1,54 @@ +/* + * 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.dataspacetck.gradle.tckbuild.conventions; + +import org.eclipse.dataspacetck.gradle.tckbuild.extensions.TckBuildExtension; +import org.gradle.api.Project; +import org.gradle.api.plugins.JavaPluginExtension; +import org.gradle.api.tasks.compile.JavaCompile; +import org.gradle.jvm.toolchain.JavaLanguageVersion; + +/** + * Enforces the Java version, generates Javadoc jar and Sources jar for publications + */ +public class JavaConvention { + + private static final int DEFAULT_JAVA_VERSION = 17; + + public void apply(Project target) { + var javaPluginExt = target.getExtensions().getByType(JavaPluginExtension.class); + var buildExt = target.getExtensions().getByType(TckBuildExtension.class); + var javaVersion = buildExt.getJavaLanguageVersion() + .getOrElse(JavaLanguageVersion.of(DEFAULT_JAVA_VERSION)); + + // set java version + javaPluginExt.toolchain(tc -> tc.getLanguageVersion().set(javaVersion)); + + // 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 + target.getTasks().withType(JavaCompile.class, compileTask -> { + var options = compileTask.getOptions(); + options.getRelease().set(javaVersion.asInt()); + options.setFork(true); + options.setIncremental(true); + }); + + + // needed for publishing to maven central + javaPluginExt.withJavadocJar(); + javaPluginExt.withSourcesJar(); + } + +} diff --git a/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/conventions/PomConvention.java b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/conventions/PomConvention.java new file mode 100644 index 0000000..471ddd5 --- /dev/null +++ b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/conventions/PomConvention.java @@ -0,0 +1,69 @@ +/* + * 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.dataspacetck.gradle.tckbuild.conventions; + +import org.eclipse.dataspacetck.gradle.tckbuild.extensions.PomExtension; +import org.eclipse.dataspacetck.gradle.tckbuild.extensions.TckBuildExtension; +import org.gradle.api.Project; +import org.gradle.api.publish.PublishingExtension; +import org.gradle.api.publish.maven.MavenPom; +import org.gradle.api.publish.maven.MavenPublication; + +public class PomConvention { + + private static final String PROJECT_URL = "https://projects.eclipse.org/projects/technology.dataspacetck"; + + public void apply(Project project) { + project.afterEvaluate(p -> { + var pomExtension = p.getExtensions().getByType(TckBuildExtension.class).getPom(); + var pubExtension = p.getExtensions().getByType(PublishingExtension.class); + + + pubExtension.getPublications().stream() + .filter(pub -> pub instanceof MavenPublication) + .map(pub -> (MavenPublication) pub) + .forEach(mp -> mp.pom(mavenPom -> setPomInformation(project, pomExtension, mavenPom))); + }); + } + + private void setPomInformation(Project project, PomExtension pomExtension, MavenPom pom) { + // these properties are mandatory! + var projectName = pomExtension.getProjectName().getOrElse(project.getName()); + var description = pomExtension.getDescription().getOrElse("Dataspace TCK :: " + project.getName()); + var projectUrl = pomExtension.getProjectUrl().getOrElse(PROJECT_URL); + pom.getName().set(projectName); + pom.getDescription().set(description); + pom.getUrl().set(projectUrl); + + // we'll provide a sane default for these properties + pom.licenses(l -> l.license(pl -> { + pl.getName().set(pomExtension.getLicenseName().getOrElse("The Apache License, Version 2.0")); + pl.getUrl().set(pomExtension.getLicenseUrl().getOrElse("http://www.apache.org/licenses/LICENSE-2.0.txt")); + })); + + pomExtension.getDeveloper().forEach(developer -> { + pom.developers(l -> l.developer(dev -> { + dev.getName().set(developer.name()); + dev.getId().set(developer.id()); + dev.getEmail().set(developer.email()); + })); + }); + + pom.scm(scm -> { + scm.getUrl().set(pomExtension.getScmUrl()); + scm.getConnection().set(pomExtension.getScmConnection()); + }); + } +} diff --git a/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/conventions/PublicationConvention.java b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/conventions/PublicationConvention.java index 5e0bf50..a3c087e 100644 --- a/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/conventions/PublicationConvention.java +++ b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/conventions/PublicationConvention.java @@ -48,7 +48,7 @@ public void apply(Project target) { pe.publications(publications -> publications.create(target.getName(), MavenPublication.class, mavenPublication -> { mavenPublication.from(target.getComponents().getByName("java")); - mavenPublication.setGroupId(buildExt.getPom().getGroupId()); + mavenPublication.setGroupId(buildExt.getPom().getGroupId().get()); mavenPublication.suppressPomMetadataWarningsFor("testFixturesApiElements"); mavenPublication.suppressPomMetadataWarningsFor("testFixturesRuntimeElements"); })); diff --git a/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/conventions/RootBuildScriptConvention.java b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/conventions/RootBuildScriptConvention.java new file mode 100644 index 0000000..2599e84 --- /dev/null +++ b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/conventions/RootBuildScriptConvention.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.dataspacetck.gradle.tckbuild.conventions; + +import org.gradle.api.Project; + +import static org.eclipse.dataspacetck.gradle.Repositories.SNAPSHOT_REPO_URL; +import static org.eclipse.dataspacetck.gradle.Repositories.mavenRepo; + +/** + * Configures the root buildscript, i.e. adds repos + */ +public class RootBuildScriptConvention { + public void apply(Project target) { + if (target == target.getRootProject()) { + // configure buildscript repos + target.getBuildscript().getRepositories().mavenLocal(); + target.getBuildscript().getRepositories().mavenCentral(); + target.getBuildscript().getRepositories().gradlePluginPortal(); + target.getBuildscript().getRepositories().maven(mavenRepo(SNAPSHOT_REPO_URL)); + } + } +} diff --git a/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/extensions/DeveloperContact.java b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/extensions/DeveloperContact.java new file mode 100644 index 0000000..044737f --- /dev/null +++ b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/extensions/DeveloperContact.java @@ -0,0 +1,23 @@ +/* + * 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.dataspacetck.gradle.tckbuild.extensions; + +import javax.inject.Inject; + +public record DeveloperContact(String id, String name, String email) { + @Inject + public DeveloperContact { + } +} diff --git a/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/extensions/PomExtension.java b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/extensions/PomExtension.java index 669b396..5e479b1 100644 --- a/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/extensions/PomExtension.java +++ b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/extensions/PomExtension.java @@ -16,8 +16,18 @@ import org.gradle.api.provider.Property; +import java.util.ArrayList; +import java.util.List; + public abstract class PomExtension { - private String groupId = "org.eclipse.dataspacetck"; + private List developerContacts; + + public PomExtension() { + developerContacts = new ArrayList<>(); + developerContacts.add(new DeveloperContact("jimmarino", "Jim Marino", "jmarino@metaformsystems.com")); + developerContacts.add(new DeveloperContact("paullatzelsperger", "Paul Latzelsperger", "paul.latzelsperger@beardyinc.com")); + developerContacts.add(new DeveloperContact("wolf4ood", "Enrico Risa", "enrico.risa@gmail.com")); + } public abstract Property getProjectName(); @@ -29,22 +39,19 @@ public abstract class PomExtension { public abstract Property getLicenseUrl(); - public abstract Property getDeveloperId(); - public abstract Property getDeveloperName(); + public List getDeveloper() { + return developerContacts; + } - public abstract Property getDeveloperEmail(); + public void setDeveloper(List developer) { + developerContacts = developer; + } public abstract Property getScmConnection(); public abstract Property getScmUrl(); - public String getGroupId() { - return groupId; - } - - public void setGroupId(String groupId) { - this.groupId = groupId; - } + public abstract Property getGroupId(); } diff --git a/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/plugins/TckBuildPlugin.java b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/plugins/TckBuildPlugin.java index 8e6de59..fa01f9b 100644 --- a/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/plugins/TckBuildPlugin.java +++ b/plugins/tck-build-plugin/src/main/java/org/eclipse/dataspacetck/gradle/tckbuild/plugins/TckBuildPlugin.java @@ -18,12 +18,20 @@ import com.bmuschko.gradle.docker.DockerRemoteApiPlugin; import io.github.gradlenexus.publishplugin.NexusPublishPlugin; import org.eclipse.dataspacetck.gradle.tckbuild.conventions.DockerConvention; +import org.eclipse.dataspacetck.gradle.tckbuild.conventions.JarConvention; +import org.eclipse.dataspacetck.gradle.tckbuild.conventions.JavaConvention; import org.eclipse.dataspacetck.gradle.tckbuild.conventions.NexusPublishingConvention; +import org.eclipse.dataspacetck.gradle.tckbuild.conventions.PomConvention; import org.eclipse.dataspacetck.gradle.tckbuild.conventions.PublicationConvention; +import org.eclipse.dataspacetck.gradle.tckbuild.conventions.RootBuildScriptConvention; import org.eclipse.dataspacetck.gradle.tckbuild.conventions.SigningConvention; import org.eclipse.dataspacetck.gradle.tckbuild.extensions.DockerExtension; import org.eclipse.dataspacetck.gradle.tckbuild.extensions.TckBuildExtension; import org.gradle.api.Project; +import org.gradle.api.plugins.JavaLibraryPlugin; +import org.gradle.api.plugins.JavaPlugin; +import org.gradle.api.plugins.quality.CheckstylePlugin; +import org.gradle.api.publish.maven.plugins.MavenPublishPlugin; import org.jetbrains.annotations.NotNull; /** @@ -34,21 +42,30 @@ public class TckBuildPlugin implements org.gradle.api.Plugin { @Override public void apply(@NotNull Project target) { - target.getExtensions().create("tckBuild", TckBuildExtension.class, target.getObjects()); - var ext = target.getExtensions().create("dockerExtension", DockerExtension.class); + target.getExtensions().create("tckBuild", TckBuildExtension.class, target.getObjects()); target.getPlugins().apply(DockerRemoteApiPlugin.class); if (target.getRootProject() == target) { target.getPlugins().apply(NexusPublishPlugin.class); } + target.getPlugins().apply(JavaLibraryPlugin.class); + target.getPlugins().apply(CheckstylePlugin.class); + target.getPlugins().apply(MavenPublishPlugin.class); + target.getPlugins().apply(JavaPlugin.class); + + new NexusPublishingConvention().apply(target); target.afterEvaluate(project -> { + new RootBuildScriptConvention().apply(project); new DockerConvention(ext).apply(project); new SigningConvention().apply(project); new PublicationConvention().apply(project); + new PomConvention().apply(project); + new JavaConvention().apply(project); + new JarConvention().apply(project); }); } diff --git a/plugins/tck-generator-plugin/build.gradle.kts b/plugins/tck-generator-plugin/build.gradle.kts index 0e88959..1e79a21 100644 --- a/plugins/tck-generator-plugin/build.gradle.kts +++ b/plugins/tck-generator-plugin/build.gradle.kts @@ -28,7 +28,8 @@ gradlePlugin { plugins { create("tckGen") { - id = "org.eclipse.dataspacetck.tck-generator" + id = "org.eclipse.dataspacetck.build.tck-generator" + group = "org.eclipse.dataspacetck.build" displayName = "TCK Test Plan Generator Plugin" description = "Gradle Plugin to generate a test plan document in Markdown format" tags = listOf("tags", "dataspace", "dsp", "dcp", "tck", "plugins", "test", "testplan", "markdown") diff --git a/plugins/tck-generator-plugin/src/main/java/org/eclipse/dataspacetck/gradle/plugins/tckgen/TckGeneratorPlugin.java b/plugins/tck-generator-plugin/src/main/java/org/eclipse/dataspacetck/gradle/plugins/tckgen/TckGeneratorPlugin.java index caf6cd5..21ef0df 100644 --- a/plugins/tck-generator-plugin/src/main/java/org/eclipse/dataspacetck/gradle/plugins/tckgen/TckGeneratorPlugin.java +++ b/plugins/tck-generator-plugin/src/main/java/org/eclipse/dataspacetck/gradle/plugins/tckgen/TckGeneratorPlugin.java @@ -29,7 +29,7 @@ */ public class TckGeneratorPlugin implements Plugin { - private static final String GENERATOR_GROUP_ARTIFACT = "org.eclipse.dataspacetck:test-plan-generator"; + private static final String GENERATOR_GROUP_ARTIFACT = "org.eclipse.dataspacetck.common:test-plan-generator"; @Override public void apply(@NotNull Project target) { @@ -52,31 +52,11 @@ public void apply(@NotNull Project target) { }); } - private @NotNull String getProcessorVersion(TckGeneratorExtension extension, Project project) { - var processorVersion = extension.getGeneratorVersion(); - - if (processorVersion.isPresent()) { - var version = processorVersion.get(); - project.getLogger().debug("{}: use configured version from AutodocExtension (override) [{}]", project.getName(), version); - return version; - } else { - var version = project.getVersion().toString(); - project.getLogger().info("No explicit configuration value for the annotationProcessor version was found. Project version {} will be used", version); - return version; - } - } /** * callback that is invoked before dependency resolution begins. We need this hook to add the "annotationProcessor" version */ - private class DependencyInjector implements DependencyResolutionListener { - private final Project target; - private final TckGeneratorExtension extension; - - private DependencyInjector(Project target, TckGeneratorExtension extension) { - this.target = target; - this.extension = extension; - } + private record DependencyInjector(Project target, TckGeneratorExtension extension) implements DependencyResolutionListener { @Override public void beforeResolve(@NotNull ResolvableDependencies dependencies) { @@ -91,5 +71,19 @@ public void beforeResolve(@NotNull ResolvableDependencies dependencies) { public void afterResolve(@NotNull ResolvableDependencies dependencies) { //noop } + + private @NotNull String getProcessorVersion(TckGeneratorExtension extension, Project project) { + var processorVersion = extension.getGeneratorVersion(); + + if (processorVersion.isPresent()) { + var version = processorVersion.get(); + project.getLogger().debug("{}: use configured version from AutodocExtension (override) [{}]", project.getName(), version); + return version; + } else { + var version = project.getVersion().toString(); + project.getLogger().info("No explicit configuration value for the annotationProcessor version was found. Project version {} will be used", version); + return version; + } + } } }