Skip to content

Commit

Permalink
Fix ClassCastException in JPS statistics ad update log messages
Browse files Browse the repository at this point in the history
#KT-63594 Fixed
  • Loading branch information
nav-nav authored and Space Team committed Nov 22, 2023
1 parent 68f2618 commit 120c99d
Showing 1 changed file with 26 additions and 13 deletions.
Expand Up @@ -145,24 +145,16 @@ class KotlinBuildStatHandler {
// log?
}
}
val taskNames = project.tasks.names.toList()

configurationTimeMetrics.put(NumericalMetrics.NUMBER_OF_SUBPROJECTS, 1)


configurationTimeMetrics.put(
BooleanMetrics.KOTLIN_KTS_USED,
project.buildscript.sourceFile?.name?.endsWith(".kts") ?: false
)
configurationTimeMetrics.put(NumericalMetrics.GRADLE_NUMBER_OF_TASKS, taskNames.size.toLong())
configurationTimeMetrics.put(
NumericalMetrics.GRADLE_NUMBER_OF_UNCONFIGURED_TASKS,
taskNames.count { name ->
try {
project.tasks.named(name).javaClass.name.contains("TaskCreatingProvider")
} catch (_: Exception) {
true
}
}.toLong()
)

addTaskMetrics(project, configurationTimeMetrics)

if (project.name == "buildSrc") {
configurationTimeMetrics.put(NumericalMetrics.BUILD_SRC_COUNT, 1)
Expand All @@ -171,10 +163,31 @@ class KotlinBuildStatHandler {
}
}
sessionLogger.report(NumericalMetrics.STATISTICS_VISIT_ALL_PROJECTS_OVERHEAD, statisticOverhead)

return configurationTimeMetrics
}

private fun addTaskMetrics(
project: Project,
configurationTimeMetrics: MetricContainer,
) {
try {
val taskNames = project.tasks.names.toList()
configurationTimeMetrics.put(NumericalMetrics.GRADLE_NUMBER_OF_TASKS, taskNames.size.toLong())
configurationTimeMetrics.put(
NumericalMetrics.GRADLE_NUMBER_OF_UNCONFIGURED_TASKS,
taskNames.count { name ->
try {
project.tasks.named(name).javaClass.name.contains("TaskCreatingProvider")
} catch (_: Exception) {
true
}
}.toLong()
)
} catch (e: Exception) {
//ignore exceptions for KT-62131.
}
}

private fun collectAppliedPluginsStatistics(
project: Project,
configurationTimeMetrics: MetricContainer,
Expand Down

0 comments on commit 120c99d

Please sign in to comment.