Skip to content

Add missing APIs to GradleEnterpriseApi #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.8.0")
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