From 62764ecd9dfa20a46c9bed84b3286bbe2d08a9ad Mon Sep 17 00:00:00 2001 From: Gabriel Feo Date: Tue, 2 Apr 2024 18:49:11 +0100 Subject: [PATCH] Add missing APIs to GradleEnterpriseApi (#174) The beta `ProjectsApi` (added in 2023.3) and `TestsApi` (added in 2023.4) weren't accessible from `GradleEnterpriseApi`. Fix and an integration test to prevent it from happening again. --- library/build.gradle.kts | 1 + .../api/GradleEnterpriseApiIntegrationTest.kt | 27 +++++++++++++++++++ .../enterprise/api/GradleEnterpriseApi.kt | 4 +++ 3 files changed, 32 insertions(+) diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 76a30146..c30f00b3 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -201,6 +201,7 @@ testing { register("integrationTest") { dependencies { implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3") + implementation("com.google.guava:guava:33.1.0-jre") } } withType().configureEach { diff --git a/library/src/integrationTest/kotlin/com/gabrielfeo/gradle/enterprise/api/GradleEnterpriseApiIntegrationTest.kt b/library/src/integrationTest/kotlin/com/gabrielfeo/gradle/enterprise/api/GradleEnterpriseApiIntegrationTest.kt index f9e52a41..d689ae09 100644 --- a/library/src/integrationTest/kotlin/com/gabrielfeo/gradle/enterprise/api/GradleEnterpriseApiIntegrationTest.kt +++ b/library/src/integrationTest/kotlin/com/gabrielfeo/gradle/enterprise/api/GradleEnterpriseApiIntegrationTest.kt @@ -1,10 +1,15 @@ package com.gabrielfeo.gradle.enterprise.api import com.gabrielfeo.gradle.enterprise.api.internal.* +import com.google.common.reflect.ClassPath import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.assertDoesNotThrow +import kotlin.reflect.KVisibility.PUBLIC +import kotlin.reflect.full.memberProperties +import kotlin.reflect.javaType import kotlin.test.* +@OptIn(ExperimentalStdlibApi::class) class GradleEnterpriseApiIntegrationTest { @Test @@ -33,4 +38,26 @@ class GradleEnterpriseApiIntegrationTest { GradleEnterpriseApi.newInstance(config) } } + + @Test + fun mainApiInterfaceExposesAllGeneratedApiClasses() = runTest { + val generatedApiTypes = getGeneratedApiTypes() + val mainApiInterfaceProperties = getMainApiInterfaceProperties() + generatedApiTypes.forEach { + mainApiInterfaceProperties.singleOrNull { type -> type == it } + ?: fail("No property in GradleEnterpriseApi for $it") + } + } + + private fun getGeneratedApiTypes(): List { + val cp = ClassPath.from(this::class.java.classLoader) + return cp.getTopLevelClasses("com.gabrielfeo.gradle.enterprise.api") + .filter { it.simpleName.endsWith("Api") } + .filter { !it.simpleName.endsWith("GradleEnterpriseApi") } + .map { it.name } + } + + private fun getMainApiInterfaceProperties() = GradleEnterpriseApi::class.memberProperties + .filter { it.visibility == PUBLIC } + .map { it.returnType.javaType.typeName } } \ No newline at end of file diff --git a/library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/GradleEnterpriseApi.kt b/library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/GradleEnterpriseApi.kt index 1bbb1f16..a8c5648f 100644 --- a/library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/GradleEnterpriseApi.kt +++ b/library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/GradleEnterpriseApi.kt @@ -35,6 +35,8 @@ interface GradleEnterpriseApi { val buildsApi: BuildsApi val buildCacheApi: BuildCacheApi + val projectsApi: ProjectsApi + val testsApi: TestsApi val metaApi: MetaApi val testDistributionApi: TestDistributionApi @@ -78,6 +80,8 @@ internal class RealGradleEnterpriseApi( override val buildsApi: BuildsApi by lazy { retrofit.create() } override val buildCacheApi: BuildCacheApi by lazy { retrofit.create() } + override val projectsApi: ProjectsApi by lazy { retrofit.create() } + override val testsApi: TestsApi by lazy { retrofit.create() } override val metaApi: MetaApi by lazy { retrofit.create() } override val testDistributionApi: TestDistributionApi by lazy { retrofit.create() }