Skip to content

Commit

Permalink
Add lazy init for build scan statistic
Browse files Browse the repository at this point in the history
#KT-51501 Fixed
  • Loading branch information
nav-nav committed Mar 22, 2022
1 parent 699641a commit 92a8ebc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
Expand Up @@ -960,6 +960,31 @@ class KotlinGradleIT : BaseGradleIT() {
}
}

@Test //KT-51501
fun testWithGradleInit() = with(Project("simpleProject")) {
setupWorkingDir()
val initGradleFile = projectDir.resolve("init.gradle")
initGradleFile.createNewFile()
initGradleFile.modify {
"""initscript {
repositories {
maven { url = 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'com.gradle:gradle-enterprise-gradle-plugin:3.8.1'
}
}
beforeSettings {
it.pluginManager.apply(com.gradle.enterprise.gradleplugin.GradleEnterprisePlugin)
}"""
}

build("-I", "init.gradle") {
assertSuccessful()
}
}


@Test
fun testKt29971() = with(Project("kt-29971", GradleVersionRequired.FOR_MPP_SUPPORT)) {
Expand Down
Expand Up @@ -58,7 +58,7 @@ internal abstract class KotlinGradleBuildServices : BuildService<KotlinGradleBui
) { service ->
service.parameters.rootDir = project.rootProject.rootDir
service.parameters.buildDir = project.rootProject.buildDir
if (!kotlinStatisticEnabled) {
if (kotlinStatisticEnabled) {
addListeners(project)
}
}
Expand All @@ -67,13 +67,14 @@ internal abstract class KotlinGradleBuildServices : BuildService<KotlinGradleBui
fun addListeners(project: Project) {
project.rootProject.extensions.findByName("buildScan")
?.also {
val listeners = project.rootProject.objects.listProperty(ReportStatistics::class.java)
.value(listOf<ReportStatistics>(ReportStatisticsToElasticSearch))
listeners.add(ReportStatisticsToBuildScan(it as BuildScanExtension))
val statListener = KotlinBuildStatListener(project.rootProject.name, listeners.get())
val listenerRegistryHolder = BuildEventsListenerRegistryHolder.getInstance(project)

listenerRegistryHolder.listenerRegistry.onTaskCompletion(project.provider { statListener })
listenerRegistryHolder.listenerRegistry.onTaskCompletion(project.provider {
val listeners = project.rootProject.objects.listProperty(ReportStatistics::class.java)
.value(listOf<ReportStatistics>(ReportStatisticsToElasticSearch))
listeners.add(ReportStatisticsToBuildScan(it as BuildScanExtension))
KotlinBuildStatListener(project.rootProject.name, listeners.get())
})
}
}

Expand Down

0 comments on commit 92a8ebc

Please sign in to comment.