Skip to content

Commit

Permalink
Merge pull request #25 from asarkar/3.0.x
Browse files Browse the repository at this point in the history
closes #22; support for output to CSV file
  • Loading branch information
asarkar authored May 16, 2021
2 parents bcbd285 + 90d68d9 commit ad6b6f3
Show file tree
Hide file tree
Showing 17 changed files with 715 additions and 492 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: "Close stale issues and PRs"
on:
schedule:
- cron: "0 0 * * *"

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v3
with:
stale-issue-message: "This issue is stale and will be closed in 5 days."
stale-pr-message: "This PR is stale and will be closed in 5 days."
days-before-stale: 30
days-before-close: 5
any-of-labels: "waiting-feedback"
exempt-all-milestones: true
debug-only: false
enable-statistics: true
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# build-time-tracker

Like [passy/build-time-tracker-plugin](https://github.com/passy/build-time-tracker-plugin), but actively maintained.
Requires Java 8 or later.
Gradle plugin that prints the time taken by the tasks in a build. Requires Java 8 or later.

[![](https://github.com/asarkar/build-time-tracker/workflows/CI%20Pipeline/badge.svg)](https://github.com/asarkar/build-time-tracker/actions?query=workflow%3A%22CI+Pipeline%22)

Expand All @@ -16,35 +15,42 @@ Requires Java 8 or later.
:webapp:dockerPushImage | 4S | 14% | ████
```

See [Gradle Plugin Portal](https://plugins.gradle.org/plugin/com.asarkar.gradle.build-time-tracker) for usage
See [Gradle Plugin Portal](https://plugins.gradle.org/plugin/com.asarkar.gradle.build-time-tracker) for usage
instructions.

If you are the fiddling type, you can customize the plugin as follows:

```
import com.asarkar.gradle.BuildTimeTrackerPluginExtension
// bunch of code
configure<BuildTimeTrackerPluginExtension> { // or buildTimeTracker {...}, for Groovy
buildTimeTracker {
barPosition = TRAILING or LEADING, default is TRAILING
sort = false or true, default is false
output = CONSOLE, other options may be added in the future
maxWidth = 80, so that your build logs don't look like Craigslist
minTaskDuration = Duration.ofSeconds(1), don't worry about tasks that take less than a second to execute
output = CONSOLE or CSV, default is CONSOLE
maxWidth = 120, default is 80
minTaskDuration = Duration.ofSeconds(1), don't show tasks that take less than a second to execute
showBars = false or true, default is true
reportsDir = only relevant if output = CSV, default $buildDir/reports/buildTimeTracker
}
```

:information_source: Due to a [Gradle limitation](https://docs.gradle.org/6.5.1/userguide/upgrading_version_5.html#apis_buildlistener_buildstarted_and_gradle_buildstarted_have_been_deprecated),
the build duration can't be calculated precisely.
The bars and percentages are rounded off such that the output provides a good indication of how long individual
tasks took to complete relative to the build, but are not meant to be correct up to the milliseconds.
> If you are using Kotlin build script, set the configuration properties using `property.set()` method.
:information_source: It is sufficient to apply the plugin to the root project; applying to subprojects will result
in duplication of the report.
:information_source: Due to a
[Gradle limitation](https://docs.gradle.org/6.5.1/userguide/upgrading_version_5.html#apis_buildlistener_buildstarted_and_gradle_buildstarted_have_been_deprecated)
, the build duration can't be calculated precisely. The bars and percentages are rounded off such that the output
provides a good indication of how long individual tasks took to complete relative to the build, but are not meant to be
correct up to the milliseconds.

:warning: If the output console does not support UTF-8 encoding, the bars may appear as weird characters. If you are
:information_source: It is sufficient to apply the plugin to the root project; applying to subprojects will result in
duplication of the report.

:warning: If the output terminal does not support UTF-8 encoding, the bars may appear as weird characters. If you are
running Windows, make sure the terminal encoding is set to UTF-8, or turn off the bars as explained above.

:warning: If exporting to CSV, and bars are enabled, the resulting file must be imported as UTF-8 encoded CSV data in
Microsoft Excel. How to do this depends on the Operating System, and Excel version, but
[here](https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-mso_mac-mso_365hp/how-to-open-utf-8-csv-file-in-excel-without-mis/1eb15700-d235-441e-8b99-db10fafff3c2)
is one way.

## Contribute

This project is a volunteer effort. You are welcome to send pull requests, ask questions, or create issues. If you like
Expand Down
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ dependencies {
testImplementation("org.assertj:assertj-core:$assertjVersion")
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
freeCompilerArgs = listOf("-Xjsr305=strict", "-Xopt-in=kotlin.RequiresOptIn")
jvmTarget = "1.8"
}
}

plugins.withType<JavaPlugin> {
plugins.withType<JavaPlugin>().configureEach {
extensions.configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}

tasks.withType<Test> {
tasks.withType<Test>().configureEach {
useJUnitPlatform()
testLogging {
showStandardStreams = true
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ pluginTags = performance, build, metrics
pluginId = com.asarkar.gradle.build-time-tracker
pluginDisplayName = build-time-tracker
pluginDescription = Gradle plugin that prints the time taken by the tasks in a build
pluginImplementationClass = com.asarkar.gradle.BuildTimeTrackerPlugin
pluginImplementationClass = com.asarkar.gradle.buildtimetracker.BuildTimeTrackerPlugin
pluginDeclarationName = buildTimeTrackerPlugin

projectGroup = com.asarkar.gradle
projectVersion = 2.1.0
projectVersion = 3.0.0

junitVersion = latest.release
assertjVersion = latest.release
Expand Down
55 changes: 0 additions & 55 deletions src/main/kotlin/com/asarkar/gradle/ConsolePrinter.kt

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/kotlin/com/asarkar/gradle/Constants.kt

This file was deleted.

19 changes: 0 additions & 19 deletions src/main/kotlin/com/asarkar/gradle/Printer.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
package com.asarkar.gradle
package com.asarkar.gradle.buildtimetracker

import com.asarkar.gradle.Constants.EXTRA_EXTENSION_NAME
import com.asarkar.gradle.Constants.LOGGER_KEY
import com.asarkar.gradle.Constants.PLUGIN_EXTENSION_NAME
import com.asarkar.gradle.buildtimetracker.Constants.EXTRA_EXTENSION_NAME
import com.asarkar.gradle.buildtimetracker.Constants.LOGGER_KEY
import com.asarkar.gradle.buildtimetracker.Constants.PLUGIN_EXTENSION_NAME
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.ReportingBasePlugin
import org.gradle.api.reflect.TypeOf
import java.time.Duration

enum class BarPosition {
LEADING, TRAILING
}

enum class Output {
CONSOLE
}

open class BuildTimeTrackerPluginExtension {
var barPosition: BarPosition = BarPosition.TRAILING
var sort: Boolean = false
var output: Output = Output.CONSOLE
var maxWidth: Int = 80
var minTaskDuration: Duration = Duration.ofSeconds(1)
var showBars: Boolean = true
}

class BuildTimeTrackerPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.pluginManager.apply(ReportingBasePlugin::class.java)
val ext = project.extensions.create(
PLUGIN_EXTENSION_NAME, BuildTimeTrackerPluginExtension::class.java
PLUGIN_EXTENSION_NAME, BuildTimeTrackerPluginExtension::class.java, project
)
(ext as ExtensionAware).extensions.add(
object : TypeOf<Map<String, Any>>() {},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.asarkar.gradle.buildtimetracker

import org.gradle.api.Project
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property
import org.gradle.api.reporting.ReportingExtension
import java.time.Duration

enum class BarPosition {
LEADING, TRAILING
}

enum class Output {
CONSOLE, CSV
}

open class BuildTimeTrackerPluginExtension(private val project: Project) {
val barPosition: Property<BarPosition> = project.objects.property(BarPosition::class.java)
.convention(Constants.DEFAULT_BAR_POSITION)
val sort: Property<Boolean> = project.objects.property(Boolean::class.java)
.convention(Constants.DEFAULT_SORT)
val output: Property<Output> = project.objects.property(Output::class.java)
.convention(Constants.DEFAULT_OUTPUT)
val maxWidth: Property<Int> = project.objects.property(Int::class.java)
.convention(Constants.DEFAULT_MAX_WIDTH)
val minTaskDuration: Property<Duration> = project.objects.property(Duration::class.java)
.convention(Duration.ofSeconds(Constants.DEFAULT_MIN_TASK_DURATION))
val showBars: Property<Boolean> = project.objects.property(Boolean::class.java)
.convention(Constants.DEFAULT_SHOW_BARS)
val reportsDir: DirectoryProperty = project.objects.directoryProperty()
.convention(baseReportsDir.map { it.dir(Constants.PLUGIN_EXTENSION_NAME) })

private val baseReportsDir: DirectoryProperty
get() = project.extensions.getByType(ReportingExtension::class.java)
.baseDirectory
}
14 changes: 14 additions & 0 deletions src/main/kotlin/com/asarkar/gradle/buildtimetracker/Constants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.asarkar.gradle.buildtimetracker

object Constants {
const val PLUGIN_EXTENSION_NAME = "buildTimeTracker"
const val EXTRA_EXTENSION_NAME = "extra"
const val LOGGER_KEY = "logger"
val DEFAULT_BAR_POSITION = BarPosition.TRAILING
const val DEFAULT_SORT = false
val DEFAULT_OUTPUT = Output.CONSOLE
const val DEFAULT_MAX_WIDTH = 80
const val DEFAULT_MIN_TASK_DURATION = 1L
const val DEFAULT_SHOW_BARS = true
const val CSV_FILENAME = "build.csv"
}
Loading

0 comments on commit ad6b6f3

Please sign in to comment.