Skip to content

Commit

Permalink
Add missing APIs to GradleEnterpriseApi (#174)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gabrielfeo authored Apr 2, 2024
1 parent a0e4e6f commit 62764ec
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ testing {
register<JvmTestSuite>("integrationTest") {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
implementation("com.google.guava:guava:33.1.0-jre")
}
}
withType<JvmTestSuite>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<String> {
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 }
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ interface GradleEnterpriseApi {

val buildsApi: BuildsApi
val buildCacheApi: BuildCacheApi
val projectsApi: ProjectsApi
val testsApi: TestsApi
val metaApi: MetaApi
val testDistributionApi: TestDistributionApi

Expand Down Expand Up @@ -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() }

Expand Down

0 comments on commit 62764ec

Please sign in to comment.