
net.rdrei.android.buildtimetracker.reporters.CSVSummaryReporter.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-plugin Show documentation
Show all versions of gradle-plugin Show documentation
Gradle plugin which tracks your build times.
The newest version!
package net.rdrei.android.buildtimetracker.reporters
import au.com.bytecode.opencsv.CSVReader
import net.rdrei.android.buildtimetracker.Timing
import org.gradle.api.logging.Logger
import org.ocpsoft.prettytime.PrettyTime
class CSVSummaryReporter extends AbstractBuildTimeTrackerReporter {
DateUtils dateUtils
CSVSummaryReporter(Map options, Logger logger) {
super(options, logger)
dateUtils = new DateUtils()
}
@Override
def run(List timings) {
def csv = getOption("csv", "")
def csvFile = new File(csv)
if (csv.isEmpty()) {
throw new ReporterConfigurationError(
ReporterConfigurationError.ErrorType.REQUIRED,
this.getClass().getSimpleName(),
"csv"
)
}
if (!csvFile.exists() || !csvFile.isFile()) {
throw new ReporterConfigurationError(
ReporterConfigurationError.ErrorType.INVALID,
this.getClass().getSimpleName(),
"csv",
"$csv either doesn't exist or is not a valid file"
)
}
printReport(new CSVReader(new BufferedReader(new FileReader(csvFile))))
}
void printReport(CSVReader reader) {
def lines = reader.readAll()
if (lines.size() == 0) return
logger.quiet "== CSV Build Time Summary =="
Map times = lines.groupBy { it[0] }.collectEntries {
k, v -> [Long.valueOf(k), v.collect { Long.valueOf(it[6]) }.sum()]
}
printToday(times)
printTotal(times)
}
void printTotal(Map times) {
long total = times.collect { it.value }.sum()
def prettyTime = new PrettyTime()
def first = new Date((Long) times.keySet().min())
logger.quiet "Total build time: " + FormattingUtils.formatDuration(total)
logger.quiet "(measured since " + prettyTime.format(first) + ")"
}
void printToday(Map times) {
def midnight = dateUtils.localMidnightUTCTimestamp
long today = times.collect { it.key >= midnight ? it.value : 0 }.sum()
logger.quiet "Build time today: " + FormattingUtils.formatDuration(today)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy