Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
buildscript {
repositories {
gradlePluginPortal()
mavenLocal()
mavenCentral()
google()
mavenCentral()
Expand Down
6 changes: 4 additions & 2 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ tasks.create("simple_first_task") {
tasks.getByName("assemble").dependsOn(this)
}


tasktree {

inputs = false
outputs = false
printClassName = true
printClassName = false
printPrice = true
printWeight = true
printComplexPrice = true

}

Expand Down
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ initscript {

rootProject{
pluginManager.apply(com.github.klee0kai.tasktree.TaskTreePlugin::class.java)

extensions.findByType(com.github.klee0kai.tasktree.TaskTreeExtension::class.java)
?.apply {
printComplexPrice = true
}
}
```

Expand Down
2 changes: 0 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pluginManagement {
google()
mavenCentral()
maven(url = "https://plugins.gradle.org/m2")
maven(url = "https://jitpack.io")
}
}

Expand All @@ -13,7 +12,6 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven(url = "https://jitpack.io")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,49 @@ package com.github.klee0kai.tasktree

open class TaskTreeExtension {

/**
* Print task inputs
*/
var inputs: Boolean = false

/**
* Print task outputs
*/
var outputs: Boolean = false

/**
* Graph max depth
*/
var maxDepth: Int = -1

/**
* print task's class type
*/
var printClassName: Boolean = false

/**
* Don't show doubles in graph
*/
var printDoubles: Boolean = false

/**
* Print dependency count for task
*/
var printPrice: Boolean = false

/**
* Print depended task count
*/
var printWeight: Boolean = false

/**
* Complex price
* ```
* ( dependencies count ) * (depended task count) / ( all task count )
* ```
* Show that task expensive to run and necessary for many others
*/
var printComplexPrice: Boolean = false

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.github.klee0kai.tasktree.tasks

import com.github.klee0kai.tasktree.TaskTreeExtension
import com.github.klee0kai.tasktree.utils.requestedTasks
import com.github.klee0kai.tasktree.utils.simpleClassName
import com.github.klee0kai.tasktree.utils.taskGraph
import com.github.klee0kai.tasktree.utils.*
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.tasks.diagnostics.ProjectBasedReportTask
Expand All @@ -19,23 +17,58 @@ open class TaskTreeTask @Inject constructor(

private val renderer = TextReportRenderer()
private val graphRenderer: GraphRenderer? by lazy { GraphRenderer(renderer.textOutput) }
private val renderedTasks = HashSet<Task>()
private val renderedTasks = mutableSetOf<Task>()
private val allTasks = mutableSetOf<Task>()

override fun getRenderer(): ReportRenderer = renderer

override fun generate(project: Project) {
project.requestedTasks?.flatMap {
setOf(it) + project.taskGraph.getAllDeps(it)
}?.let { allTasks.addAll(it) }

project.requestedTasks?.forEach { render(it) }


renderedTasks.clear()
allTasks.clear()
}

private fun render(task: Task, lastChild: Boolean = true, depth: Int = 0) {
graphRenderer?.visit({

val allDeps by lazy { project.taskGraph.getAllDeps(task) }
val dependedCount by lazy {
allTasks.count {
project.taskGraph
.getDeps(it)
.contains(task)
}
}
val complexPrice by lazy {
val depsCount = allDeps.size.toFloat()
val allTasksCount = allTasks.count().toFloat()
depsCount * (dependedCount / allTasksCount)
}

withStyle(Identifier)
.text(task.name)

if (ext.printPrice) {
withStyle(Description)
.text(" price: ${allDeps.size};")
}
if (ext.printWeight) {
withStyle(Description)
.text(" weight: $dependedCount;")
}
if (ext.printComplexPrice) {
withStyle(Description)
.text(" complexPrice: $complexPrice;")
}
if (ext.printClassName) {
withStyle(Description)
.text(" class: ${task.simpleClassName}")
.text(" class: ${task.simpleClassName};")
}

if (task.isIncludedBuild) {
Expand Down Expand Up @@ -67,15 +100,11 @@ open class TaskTreeTask @Inject constructor(
renderedTasks.add(task)

graphRenderer?.startChildren()
try {
val deps = project.taskGraph.getDependencies(task)
val depsSize = deps.size
deps.forEachIndexed { indx, it ->
val lastChild = indx >= depsSize - 1
render(it, lastChild = lastChild, depth = depth + 1)
}
} catch (ignore: Exception) {
//ignore non available info
val deps = project.taskGraph.getDeps(task)
val depsSize = deps.size
deps.forEachIndexed { indx, it ->
val lastChild = indx >= depsSize - 1
render(it, lastChild = lastChild, depth = depth + 1)
}
graphRenderer?.completeChildren()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,20 @@ val Project.executionPlan get() = taskGraph.executionPlan

val Project.isTaskTreeRequested get() = executionPlan?.requestedTasks?.any { it is TaskTreeTask } ?: false

val Project.requestedTasks get() = executionPlan?.requestedTasks?.filter { it !is TaskTreeTask }
val Project.requestedTasks get() = executionPlan?.requestedTasks?.filter { it !is TaskTreeTask }

fun DefaultTaskExecutionGraph.getAllDeps(task: Task): Set<Task> =
getDeps(task)
.flatMap {
setOf(it) + getAllDeps(it)
}
.toSet()


fun DefaultTaskExecutionGraph.getDeps(task: Task): Set<Task> =
try {
getDependencies(task)
} catch (ignore: Exception) {
//ignore non available info
setOf()
}