From 45bf38d65343a37fc83120cd68d2210820f2ce92 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Aug 2023 07:10:26 +0000 Subject: [PATCH 01/17] Bump org.openapi.generator from 6.6.0 to 7.0.0 Bumps org.openapi.generator from 6.6.0 to 7.0.0. --- updated-dependencies: - dependency-name: org.openapi.generator dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 66080f6..d8885a6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ group = "com.gradle.enterprise.api" description = "Gradle Enterprise API sample" plugins { - id("org.openapi.generator") version "6.6.0" + id("org.openapi.generator") version "7.0.0" kotlin("jvm") version embeddedKotlinVersion apply false `java-library` application From f845ed013f864c208a8006abc884a20dab3272c7 Mon Sep 17 00:00:00 2001 From: Szava Maczika Date: Tue, 29 Aug 2023 13:54:12 +0200 Subject: [PATCH 02/17] Enforce java 11 due to openapi generator compatibility https://github.com/OpenAPITools/openapi-generator/pull/15553 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index d8885a6..db24864 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,7 @@ application { java { toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) + languageVersion.set(JavaLanguageVersion.of(11)) } } From 5ff2b2016da84c3df2e95ab513c184cf285a72b4 Mon Sep 17 00:00:00 2001 From: Szava Maczika Date: Wed, 6 Sep 2023 10:43:42 +0200 Subject: [PATCH 03/17] Add test to verify java 8 compatibility --- build.gradle.kts | 27 ++++++++-- .../com/gradle/enterprise/api/MockServer.java | 49 +++++++++++++++++++ 2 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/gradle/enterprise/api/MockServer.java diff --git a/build.gradle.kts b/build.gradle.kts index db24864..cfa817f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.distsDirectory + group = "com.gradle.enterprise.api" description = "Gradle Enterprise API sample" @@ -32,18 +34,25 @@ dependencies { implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.2") implementation("com.google.code.findbugs:jsr305:3.0.2") implementation("org.apache.httpcomponents.client5:httpclient5:5.2.1") + + testImplementation("org.mock-server:mockserver-netty:5.15.0") + testImplementation("org.junit.jupiter:junit-jupiter:5.7.1") + testRuntimeOnly("org.junit.platform:junit-platform-launcher") + } val gradleEnterpriseVersion = "2023.2" // Must be later than 2022.1 val baseApiUrl = providers.gradleProperty("apiManualUrl").orElse("https://docs.gradle.com/enterprise/api-manual/ref/") val apiSpecificationFileGradleProperty = providers.gradleProperty("apiSpecificationFile") +val apiSpecificationURL = "${baseApiUrl.get()}gradle-enterprise-${gradleEnterpriseVersion}-api.yaml" val apiSpecificationFile = apiSpecificationFileGradleProperty .map { s -> file(s) } - .orElse(objects.property(File::class) - .convention(provider { - resources.text.fromUri("${baseApiUrl.get()}gradle-enterprise-${gradleEnterpriseVersion}-api.yaml").asFile() - }) + .orElse( + objects.property(File::class) + .convention(provider { + resources.text.fromUri(apiSpecificationURL).asFile() + }) ).map { file -> file.absolutePath } val basePackageName = "com.gradle.enterprise.api" @@ -73,6 +82,16 @@ openApiGenerate { )) } +tasks.named("test") { + useJUnitPlatform() + + systemProperties["ge.api.url"] = apiSpecificationURL + + java { + sourceCompatibility = JavaVersion.VERSION_1_8 + } +} + sourceSets { main { java { diff --git a/src/test/java/com/gradle/enterprise/api/MockServer.java b/src/test/java/com/gradle/enterprise/api/MockServer.java new file mode 100644 index 0000000..eea5f8b --- /dev/null +++ b/src/test/java/com/gradle/enterprise/api/MockServer.java @@ -0,0 +1,49 @@ +package com.gradle.enterprise.api; + +import com.gradle.enterprise.api.client.ApiClient; +import com.gradle.enterprise.api.client.ApiException; +import com.gradle.enterprise.api.client.ServerConfiguration; +import com.gradle.enterprise.api.model.Build; +import com.gradle.enterprise.api.model.BuildsQuery; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockserver.configuration.Configuration; +import org.mockserver.integration.ClientAndServer; +import org.mockserver.logging.MockServerLogger; +import org.mockserver.mock.Expectation; +import org.mockserver.openapi.OpenAPIConverter; + +import java.net.InetSocketAddress; +import java.util.Collections; +import java.util.List; + +public class MockServer { + + private static final String gradleEnterpriseAPIYamlUrl = System.getProperty("ge.api.url"); + + private ClientAndServer mockServer; + + @BeforeEach + public void setup() { + Configuration configuration = Configuration.configuration(); + List openApiExpectations = new OpenAPIConverter(new MockServerLogger()).buildExpectations(gradleEnterpriseAPIYamlUrl, null); + mockServer = ClientAndServer.startClientAndServer(configuration, Collections.singletonList(19234)); + mockServer.upsert(openApiExpectations.toArray(new Expectation[0])); + } + + @Test + public void testSimpleAPICall() throws ApiException { + InetSocketAddress remoteAddress = mockServer.remoteAddress(); + + ApiClient apiClient = new ApiClient(); + apiClient.setServers(Collections.singletonList(new ServerConfiguration( + "http://" + remoteAddress.getHostName() + ":" + remoteAddress.getPort(), "mockServer", Collections.emptyMap() + ))); + BuildsApi buildsApi = new BuildsApi(apiClient); + apiClient.addDefaultHeader("Authorization", "Bearer XYZ"); + + List builds = buildsApi.getBuilds(new BuildsQuery()); + + assert !builds.isEmpty(); + } +} From 5523688c45cedb7744550236aa0ee6bf93a254f3 Mon Sep 17 00:00:00 2001 From: Szava Maczika Date: Wed, 6 Sep 2023 10:53:48 +0200 Subject: [PATCH 04/17] Rename test --- .../api/{MockServer.java => SimpleApiClientTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/test/java/com/gradle/enterprise/api/{MockServer.java => SimpleApiClientTest.java} (98%) diff --git a/src/test/java/com/gradle/enterprise/api/MockServer.java b/src/test/java/com/gradle/enterprise/api/SimpleApiClientTest.java similarity index 98% rename from src/test/java/com/gradle/enterprise/api/MockServer.java rename to src/test/java/com/gradle/enterprise/api/SimpleApiClientTest.java index eea5f8b..bf2de09 100644 --- a/src/test/java/com/gradle/enterprise/api/MockServer.java +++ b/src/test/java/com/gradle/enterprise/api/SimpleApiClientTest.java @@ -17,7 +17,7 @@ import java.util.Collections; import java.util.List; -public class MockServer { +public class SimpleApiClientTest { private static final String gradleEnterpriseAPIYamlUrl = System.getProperty("ge.api.url"); From d17db04a98f5fafb8e854aacf62b210499043265 Mon Sep 17 00:00:00 2001 From: Szava Maczika Date: Wed, 6 Sep 2023 11:00:12 +0200 Subject: [PATCH 05/17] Add info to readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 303f260..5222d35 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,9 @@ $ ./gradlew install This builds and installs the program into `build/install/gradle-enterprise-api-samples`. You can use the `build/install/gradle-enterprise-api-samples/bin/gradle-enterprise-api-samples` script to run the sample. +### Note on JDK11 + +Due to a change in the [openapi generator project](https://github.com/gradle/gradle-enterprise-api-samples/pull/74) JDK 11 is required to build the samples. The clients still work using java 8 ## How to run A Gradle Enterprise access key with the “Export build data via the API” permission is required. @@ -55,7 +58,6 @@ The sample code can be found [here](https://github.com/gradle/gradle-enterprise- The Gradle Enterprise API manual and reference documentation for each version of the API can be found [here](https://docs.gradle.com/enterprise/api-manual). - ## License The Gradle Enterprise API Samples project is open-source software released under the [Apache 2.0 License][apache-license]. From 6fc41794710d6fcc0eaaafb9c3276f0ee9984e6a Mon Sep 17 00:00:00 2001 From: Szava Maczika Date: Wed, 6 Sep 2023 16:14:56 +0200 Subject: [PATCH 06/17] Update build.gradle.kts Co-authored-by: Alexey Venderov Signed-off-by: Szava Maczika --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index cfa817f..b782494 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -82,7 +82,7 @@ openApiGenerate { )) } -tasks.named("test") { +tasks.test { useJUnitPlatform() systemProperties["ge.api.url"] = apiSpecificationURL From 06d4a78359a9b8c9d3f52da9bb5b8baf87d05bd2 Mon Sep 17 00:00:00 2001 From: Szava Maczika Date: Wed, 6 Sep 2023 16:15:55 +0200 Subject: [PATCH 07/17] Use proper assertion --- .../java/com/gradle/enterprise/api/SimpleApiClientTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/gradle/enterprise/api/SimpleApiClientTest.java b/src/test/java/com/gradle/enterprise/api/SimpleApiClientTest.java index bf2de09..366d125 100644 --- a/src/test/java/com/gradle/enterprise/api/SimpleApiClientTest.java +++ b/src/test/java/com/gradle/enterprise/api/SimpleApiClientTest.java @@ -5,6 +5,7 @@ import com.gradle.enterprise.api.client.ServerConfiguration; import com.gradle.enterprise.api.model.Build; import com.gradle.enterprise.api.model.BuildsQuery; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockserver.configuration.Configuration; @@ -17,6 +18,8 @@ import java.util.Collections; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertFalse; + public class SimpleApiClientTest { private static final String gradleEnterpriseAPIYamlUrl = System.getProperty("ge.api.url"); @@ -44,6 +47,6 @@ public void testSimpleAPICall() throws ApiException { List builds = buildsApi.getBuilds(new BuildsQuery()); - assert !builds.isEmpty(); + assertFalse(builds.isEmpty()); } } From 73cf4b7f370b272171e98ee1d49be33d494ecbf8 Mon Sep 17 00:00:00 2001 From: Szava Maczika Date: Thu, 7 Sep 2023 09:22:30 +0200 Subject: [PATCH 08/17] Update README.md Signed-off-by: Szava Maczika --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5222d35..4214423 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ You can use the `build/install/gradle-enterprise-api-samples/bin/gradle-enterpri ### Note on JDK11 -Due to a change in the [openapi generator project](https://github.com/gradle/gradle-enterprise-api-samples/pull/74) JDK 11 is required to build the samples. The clients still work using java 8 +Due to a change in the [openapi generator project](https://github.com/gradle/gradle-enterprise-api-samples/pull/74), JDK 11 is required to build the samples. The clients still work using java 8 ## How to run A Gradle Enterprise access key with the “Export build data via the API” permission is required. From 9957e577042a1313fa37cc529003067dc5358386 Mon Sep 17 00:00:00 2001 From: Szava Maczika Date: Thu, 7 Sep 2023 13:53:22 +0200 Subject: [PATCH 09/17] Use provider API and toolchain --- build.gradle.kts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b782494..1e2c437 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -45,7 +45,7 @@ val gradleEnterpriseVersion = "2023.2" // Must be later than 2022.1 val baseApiUrl = providers.gradleProperty("apiManualUrl").orElse("https://docs.gradle.com/enterprise/api-manual/ref/") val apiSpecificationFileGradleProperty = providers.gradleProperty("apiSpecificationFile") -val apiSpecificationURL = "${baseApiUrl.get()}gradle-enterprise-${gradleEnterpriseVersion}-api.yaml" +val apiSpecificationURL = baseApiUrl.map { "${it}gradle-enterprise-${gradleEnterpriseVersion}-api.yaml" } val apiSpecificationFile = apiSpecificationFileGradleProperty .map { s -> file(s) } .orElse( @@ -85,10 +85,12 @@ openApiGenerate { tasks.test { useJUnitPlatform() - systemProperties["ge.api.url"] = apiSpecificationURL + apiSpecificationURL.orNull.let { systemProperties["ge.api.url"] = it } java { - sourceCompatibility = JavaVersion.VERSION_1_8 + toolchain { + languageVersion.set(JavaLanguageVersion.of(8)) + } } } From a1bd80aa8299e04be7455e7ce0bef037129eff15 Mon Sep 17 00:00:00 2001 From: Szava Maczika Date: Thu, 7 Sep 2023 15:15:27 +0200 Subject: [PATCH 10/17] Update workflow with jdk11 and test --- .github/workflows/gradle-build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/gradle-build.yml b/.github/workflows/gradle-build.yml index 8be8d8d..370bb33 100644 --- a/.github/workflows/gradle-build.yml +++ b/.github/workflows/gradle-build.yml @@ -14,12 +14,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - - name: Set up JDK 8 + - name: Set up JDK 11 uses: actions/setup-java@v3 with: - java-version: '8' + java-version: '11' distribution: 'temurin' - name: Set up Gradle Build Action uses: gradle/gradle-build-action@v2 - - name: Build with Gradle - run: ./gradlew build + - name: Build and test with Gradle + run: ./gradlew build test From b0a214b9d11da319d9541551add808bb11586e8f Mon Sep 17 00:00:00 2001 From: Szava Maczika Date: Thu, 7 Sep 2023 22:09:07 +0200 Subject: [PATCH 11/17] Remove superflous build goal --- .github/workflows/gradle-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle-build.yml b/.github/workflows/gradle-build.yml index 370bb33..7344861 100644 --- a/.github/workflows/gradle-build.yml +++ b/.github/workflows/gradle-build.yml @@ -22,4 +22,4 @@ jobs: - name: Set up Gradle Build Action uses: gradle/gradle-build-action@v2 - name: Build and test with Gradle - run: ./gradlew build test + run: ./gradlew build From ed38b0b127243f5ab080ac1cdb78a18a39de9e37 Mon Sep 17 00:00:00 2001 From: Szava Maczika Date: Thu, 7 Sep 2023 22:19:40 +0200 Subject: [PATCH 12/17] Use source compatibility to compile not language version --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 1e2c437..8df270a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -89,7 +89,7 @@ tasks.test { java { toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) + sourceCompatibility = JavaVersion.VERSION_1_8 } } } From 91d7a799b05cc16d045aff0f292d6c420baef0bb Mon Sep 17 00:00:00 2001 From: Szava Maczika Date: Fri, 8 Sep 2023 09:28:08 +0200 Subject: [PATCH 13/17] Use toolchains properly --- build.gradle.kts | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8df270a..cf39269 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,6 +19,7 @@ application { } java { + sourceCompatibility = JavaVersion.VERSION_1_8 toolchain { languageVersion.set(JavaLanguageVersion.of(11)) } @@ -69,17 +70,19 @@ openApiGenerate { cleanupOutput.set(true) openapiNormalizer.set(mapOf("REF_AS_PARENT_IN_ALLOF" to "true")) // see https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/java.md for a description of each configuration option - configOptions.set(mapOf( - "library" to "apache-httpclient", - "dateLibrary" to "java8", - "hideGenerationTimestamp" to "true", - "openApiNullable" to "false", - "useBeanValidation" to "false", - "disallowAdditionalPropertiesIfNotPresent" to "false", - "additionalModelTypeAnnotations" to "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)", - "sourceFolder" to "", // makes IDEs like IntelliJ more reliably interpret the class packages. - "containerDefaultToNull" to "true" - )) + configOptions.set( + mapOf( + "library" to "apache-httpclient", + "dateLibrary" to "java8", + "hideGenerationTimestamp" to "true", + "openApiNullable" to "false", + "useBeanValidation" to "false", + "disallowAdditionalPropertiesIfNotPresent" to "false", + "additionalModelTypeAnnotations" to "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)", + "sourceFolder" to "", // makes IDEs like IntelliJ more reliably interpret the class packages. + "containerDefaultToNull" to "true" + ) + ) } tasks.test { @@ -87,11 +90,10 @@ tasks.test { apiSpecificationURL.orNull.let { systemProperties["ge.api.url"] = it } - java { - toolchain { - sourceCompatibility = JavaVersion.VERSION_1_8 - } - } + + javaLauncher.set(javaToolchains.launcherFor { + languageVersion.set(JavaLanguageVersion.of(8)) + }) } sourceSets { From 31ac51817816d7cb278ce281d70e2b5054a35af5 Mon Sep 17 00:00:00 2001 From: Szava Maczika Date: Fri, 8 Sep 2023 09:34:35 +0200 Subject: [PATCH 14/17] Revert accidental reformat --- build.gradle.kts | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index cf39269..8a183fd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -70,19 +70,17 @@ openApiGenerate { cleanupOutput.set(true) openapiNormalizer.set(mapOf("REF_AS_PARENT_IN_ALLOF" to "true")) // see https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/java.md for a description of each configuration option - configOptions.set( - mapOf( - "library" to "apache-httpclient", - "dateLibrary" to "java8", - "hideGenerationTimestamp" to "true", - "openApiNullable" to "false", - "useBeanValidation" to "false", - "disallowAdditionalPropertiesIfNotPresent" to "false", - "additionalModelTypeAnnotations" to "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)", - "sourceFolder" to "", // makes IDEs like IntelliJ more reliably interpret the class packages. - "containerDefaultToNull" to "true" - ) - ) + configOptions.set(mapOf( + "library" to "apache-httpclient", + "dateLibrary" to "java8", + "hideGenerationTimestamp" to "true", + "openApiNullable" to "false", + "useBeanValidation" to "false", + "disallowAdditionalPropertiesIfNotPresent" to "false", + "additionalModelTypeAnnotations" to "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)", + "sourceFolder" to "", // makes IDEs like IntelliJ more reliably interpret the class packages. + "containerDefaultToNull" to "true" + )) } tasks.test { From dd5b2e82cd005315f2ec20a428329ac1a4fd6ff7 Mon Sep 17 00:00:00 2001 From: Szava Maczika Date: Fri, 8 Sep 2023 09:45:45 +0200 Subject: [PATCH 15/17] Update README.md Signed-off-by: Szava Maczika --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4214423..d66a3dc 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ You can use the `build/install/gradle-enterprise-api-samples/bin/gradle-enterpri ### Note on JDK11 -Due to a change in the [openapi generator project](https://github.com/gradle/gradle-enterprise-api-samples/pull/74), JDK 11 is required to build the samples. The clients still work using java 8 +Due to a change in the [openapi generator project](https://github.com/gradle/gradle-enterprise-api-samples/pull/74), JDK 11 is required to build the samples. The clients still work using Java 8 ## How to run A Gradle Enterprise access key with the “Export build data via the API” permission is required. From 79630b42db593a57ae0b0fa40d193128fd2e3b99 Mon Sep 17 00:00:00 2001 From: Szava Maczika Date: Fri, 8 Sep 2023 10:34:40 +0200 Subject: [PATCH 16/17] Adapt readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d66a3dc..2dbc72c 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,9 @@ You can use the `build/install/gradle-enterprise-api-samples/bin/gradle-enterpri ### Note on JDK11 -Due to a change in the [openapi generator project](https://github.com/gradle/gradle-enterprise-api-samples/pull/74), JDK 11 is required to build the samples. The clients still work using Java 8 +The current version of the OpenAPI generator requires Java 11 to generate the client code. Even though this sample uses Java 11 to generate the client, but the generated **client code is based on Java 8**. +Therefore, the generated client is still compatible with Java 8 based projects. + ## How to run A Gradle Enterprise access key with the “Export build data via the API” permission is required. From 76afb2af6ff99d374f577c083586a9a3aaadf288 Mon Sep 17 00:00:00 2001 From: Szava Maczika Date: Fri, 8 Sep 2023 10:49:16 +0200 Subject: [PATCH 17/17] Adapt readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2dbc72c..6cca642 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ $ ./gradlew install This builds and installs the program into `build/install/gradle-enterprise-api-samples`. You can use the `build/install/gradle-enterprise-api-samples/bin/gradle-enterprise-api-samples` script to run the sample. -### Note on JDK11 +### Note on Java 11 The current version of the OpenAPI generator requires Java 11 to generate the client code. Even though this sample uses Java 11 to generate the client, but the generated **client code is based on Java 8**. Therefore, the generated client is still compatible with Java 8 based projects.