Skip to content

Commit

Permalink
Merge pull request #49 from Automattic/warn_about_not_set_listener
Browse files Browse the repository at this point in the history
Do not crash if `buildMetricsPreparedAction` null
  • Loading branch information
wzieba authored Sep 24, 2024
2 parents e663dd9 + 6db8f2b commit bdbaad5
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package com.automattic.android.measure.reporters

import com.automattic.android.measure.InMemoryReport
import org.gradle.api.Action
import org.gradle.api.logging.Logging
import org.gradle.api.provider.Property

object InMemoryMetricsReporter {

lateinit var buildMetricsPreparedAction: Property<Action<MetricsReport>>
var buildMetricsPreparedAction: Property<Action<MetricsReport>>? = null

fun report(
report: InMemoryReport,
Expand All @@ -18,6 +19,11 @@ object InMemoryMetricsReporter {
override val gradleScanId: String?
get() = gradleScanId
}
buildMetricsPreparedAction.get().execute(result)
if (buildMetricsPreparedAction == null) {
Logging.getLogger(InMemoryMetricsReporter::class.java).warn(
"buildMetricsPreparedAction is not set. Metrics will not be reported."
)
}
buildMetricsPreparedAction?.get()?.execute(result)
}
}

0 comments on commit bdbaad5

Please sign in to comment.