-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JSON output type for build reports
#KT-65792 Fixed
- Loading branch information
1 parent
666a2f2
commit 2f19d2e
Showing
20 changed files
with
772 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...n-build-statistics/src/org/jetbrains/kotlin/build/report/statistics/BuildReportService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.kotlin.build.report.statistics | ||
|
||
import org.jetbrains.kotlin.buildtools.api.KotlinLogger | ||
import java.io.Serializable | ||
|
||
interface BuildReportService<T> : Serializable { | ||
fun process(data: T, log: KotlinLogger) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...in-build-statistics/src/org/jetbrains/kotlin/build/report/statistics/FileReportService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.kotlin.build.report.statistics | ||
|
||
import org.jetbrains.kotlin.buildtools.api.KotlinLogger | ||
import java.io.File | ||
import java.text.SimpleDateFormat | ||
import java.util.* | ||
|
||
abstract class FileReportService<T>( | ||
buildReportDir: File, | ||
projectName: String, | ||
fileSuffix: String, | ||
) : BuildReportService<T> { | ||
companion object { | ||
internal val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").also { it.timeZone = TimeZone.getTimeZone("UTC") } | ||
} | ||
|
||
private val ts = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(Calendar.getInstance().time) | ||
private val outputFile = buildReportDir.resolve("$projectName-build-$ts.$fileSuffix") | ||
|
||
abstract fun printBuildReport(data: T, outputFile: File) | ||
|
||
override fun process(data: T, log: KotlinLogger) { | ||
val buildReportPath = outputFile.toPath().toUri().toString() | ||
try { | ||
outputFile.parentFile.mkdirs() | ||
if (!(outputFile.parentFile.exists() && outputFile.parentFile.isDirectory)) { | ||
log.error("Kotlin build report cannot be created: '${outputFile.parentFile}' is a file or do not have permissions to create") | ||
return | ||
} | ||
printBuildReport(data, outputFile) | ||
|
||
log.lifecycle("Kotlin build report is written to $buildReportPath") | ||
} catch (e: Exception) { | ||
log.error("Could not write Kotlin build report to $buildReportPath", e) | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...in-build-statistics/src/org/jetbrains/kotlin/build/report/statistics/JsonReportService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.kotlin.build.report.statistics | ||
|
||
import com.google.gson.Gson | ||
import java.io.File | ||
|
||
class JsonReportService( | ||
buildReportDir: File, | ||
projectName: String, | ||
) : FileReportService<Any>(buildReportDir, projectName, "json") { | ||
|
||
/** | ||
* Prints general build information and task/transform build metrics | ||
*/ | ||
override fun printBuildReport(data: Any, outputFile: File) { | ||
outputFile.bufferedWriter().use { | ||
it.write(Gson().toJson(data)) | ||
} | ||
} | ||
} |
Oops, something went wrong.