Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/0.0.6 #13

Merged
merged 22 commits into from
Aug 13, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/deploy_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ jobs:
if: ${{ always() }}
steps:
- uses: actions/checkout@v3
- name: set up JDK 11
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
Expand Down
4 changes: 2 additions & 2 deletions .run/diagonDAG.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>true</RunAsTest>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
24 changes: 24 additions & 0 deletions .run/publish local.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="publish local" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value=":tasktree:publishPluginMavenPublicationToMavenLocal" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
4 changes: 2 additions & 2 deletions .run/tasktree.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>true</RunAsTest>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
5 changes: 2 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.2.2")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.21")
classpath("org.jetbrains.kotlin:kotlin-serialization:1.7.21")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21")
classpath("org.jetbrains.kotlin:kotlin-serialization:1.8.21")
}
}
2 changes: 1 addition & 1 deletion example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tasktree {
outputs = false
printClassName = false
printPrice = true
printWeight = true
printImportance = true
printComplexPrice = true

}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jdk:
- openjdk11
- openjdk17
install:
- echo "publish crosscompile plugin"
- ./gradlew :tasktree:publishPluginMavenPublicationToMavenLocal
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![](https://img.shields.io/badge/license-GNU_GPLv3-blue.svg?style=flat-square)](./LICENSE)
[![](https://jitpack.io/v/klee0kai/tasktree.svg)](https://jitpack.io/#klee0kai/tasktree)

Print gradle build dependencies graph
Print gradle task dependencies graph

## Usage

Expand All @@ -15,7 +15,7 @@ buildscript {
maven(url = "https://jitpack.io")
}
dependencies {
classpath("com.github.klee0kai:tasktree:0.0.4")
classpath("com.github.klee0kai:tasktree:0.0.6")
}
}
```
Expand Down Expand Up @@ -52,7 +52,7 @@ initscript {
maven(url = "https://jitpack.io")
}
dependencies {
classpath("com.github.klee0kai:tasktree:0.0.4")
classpath("com.github.klee0kai:tasktree:0.0.6")
}
}

Expand Down
11 changes: 5 additions & 6 deletions tasktree/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
buildscript {
dependencies {
classpath("com.android.tools.build:gradle:7.2.2")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.21")
classpath("org.jetbrains.kotlin:kotlin-serialization:1.7.21")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21")
classpath("org.jetbrains.kotlin:kotlin-serialization:1.8.21")
}
}

Expand All @@ -13,16 +12,16 @@ plugins {
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}


gradlePlugin {
plugins.register("tasktree") {
id = "tasktree"
group = "com.github.klee0kai"
version = "0.0.4"
version = "0.0.6"
implementationClass = "com.github.klee0kai.tasktree.TaskTreePlugin"
displayName = "Task Tree"
description = "Print gradle build dependencies graph"
Expand Down
42 changes: 42 additions & 0 deletions tasktree/src/main/kotlin/com/github/klee0kai/tasktree/TaskStat.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.github.klee0kai.tasktree

import com.github.klee0kai.tasktree.utils.getAllDeps
import com.github.klee0kai.tasktree.utils.taskGraph
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.kotlin.dsl.provideDelegate

class TaskStat(
val task: Task,
val allTasks: Set<Task>,
val rootProject: Project,
) {

val allDepsCount by lazy { rootProject.taskGraph.getAllDeps(task).count() }
val allDependedOnCount by lazy {
allTasks.count {
rootProject.taskGraph
.getAllDeps(it)
.contains(task)
}
}
val price by lazy { allDepsCount }
val importance by lazy { allDependedOnCount }

val complexPrice by lazy {
(price * importance).toFloat() / allTasks.size
}


// ---- outside of project ------
val allDependedOnOutsideProjectCount by lazy {
allTasks.count {
it.project != task.project &&
rootProject.taskGraph
.getAllDeps(it)
.contains(task)
}
}
val importanceOutsideProject by lazy { allDependedOnOutsideProjectCount }
val complexPriceOutsideProject by lazy { (price * importanceOutsideProject).toFloat() / allTasks.size }
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,28 @@ open class TaskTreeExtension {
/**
* Print depended task count
*/
var printWeight: Boolean = false
var printImportance: Boolean = false

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


/**
* List sorted list of most expensive tasks
*/
var printMostExpensiveTasks: Boolean = false

/**
* List sorted list of most expensive modules
*/
var printMostExpensiveModules: Boolean = false

}


Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package com.github.klee0kai.tasktree

import com.github.klee0kai.tasktree.tasks.DiagonDagTask
import com.github.klee0kai.tasktree.tasks.TaskTreeTask
import com.github.klee0kai.tasktree.utils.*
import com.github.klee0kai.tasktree.utils.allRequestedTasks
import com.github.klee0kai.tasktree.utils.taskGraph
import org.gradle.api.Plugin
import org.gradle.api.Project

Expand All @@ -12,16 +13,15 @@ open class TaskTreePlugin : Plugin<Project> {

private fun Project.applyOnProject() {
val ext = extensions.create("tasktree", TaskTreeExtension::class.java)
tasks.register("tasktree", TaskTreeTask::class.java, ext)
tasks.register("diagonDAG", DiagonDagTask::class.java)
val taskTree = tasks.register("tasktree", TaskTreeTask::class.java, ext)
val taskDag = tasks.register("diagonDAG", DiagonDagTask::class.java)

taskGraph.whenReady {
if (isTaskTreeRequested || isDiagonGraphRequested) {
requestedTasks
?.flatMap { project.taskGraph.getAllDeps(it) }
?.forEach {
it.enabled = false
}
val isTaskTreeRequested = hasTask(taskTree.get()) || hasTask(taskDag.get())
if (isTaskTreeRequested) {
allRequestedTasks.forEach {
it.enabled = false
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.github.klee0kai.tasktree.tasks

import org.gradle.api.Project
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.diagnostics.ConventionReportTask
import org.gradle.api.tasks.diagnostics.internal.ReportGenerator
import org.gradle.api.tasks.diagnostics.internal.ReportRenderer
import org.gradle.api.tasks.diagnostics.internal.TextReportRenderer
import org.gradle.internal.graph.GraphRenderer

abstract class BaseReportTask : ConventionReportTask() {

@Internal
protected val renderer = TextReportRenderer()

@get:Internal
protected val graphRenderer: GraphRenderer? by lazy { GraphRenderer(renderer.textOutput) }

abstract fun generate(project: Project)

@TaskAction
fun generate() {
reportGenerator().generateReport(projects) {
generate(it)
}
}

override fun getRenderer(): ReportRenderer = renderer

private fun reportGenerator(): ReportGenerator {
return ReportGenerator(
getRenderer(),
clientMetaData,
outputFile,
textOutputFactory
)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.github.klee0kai.tasktree.tasks

import com.github.klee0kai.tasktree.utils.*
import com.github.klee0kai.tasktree.utils.allRequestedTasks
import com.github.klee0kai.tasktree.utils.fullName
import com.github.klee0kai.tasktree.utils.getDeps
import com.github.klee0kai.tasktree.utils.taskGraph
import org.apache.tools.ant.util.TeeOutputStream
import org.gradle.api.Project
import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.diagnostics.ProjectReportTask
import org.gradle.process.internal.ExecActionFactory
import org.gradle.process.internal.ExecException
import java.io.ByteArrayOutputStream
Expand All @@ -18,19 +20,16 @@ open class DiagonDagTask @Inject constructor(
val objectFactory: ObjectFactory,
@Input
val execAction: ExecActionFactory,
) : ProjectReportTask() {
) : BaseReportTask() {


@Internal
override fun getDescription(): String =
"Draw tasktree graph use Diagon. More: https://github.com/ArthurSonzogni/Diagon"


override fun generate(project: Project) {
super.generate(project)
val allTasks = project.requestedTasks?.flatMap {
setOf(it) + project.taskGraph.getAllDeps(it)
}?.toSet() ?: emptySet()

val allTasks = project.allRequestedTasks.toSet()

val depsCode = allTasks.joinToString("\n") { task ->
project.taskGraph.getDeps(task).joinToString("\n") { dep ->
Expand Down
Loading