Skip to content

Commit

Permalink
GradleVersion is comparable (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdsap authored Nov 10, 2024
1 parent dcdfcff commit 1a2d1f1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.github.cdsap.talaiot
import io.github.cdsap.talaiot.configuration.BuildFilterConfiguration
import io.github.cdsap.talaiot.configuration.MetricsConfiguration
import io.github.cdsap.talaiot.entities.ExecutionReport
import io.github.cdsap.talaiot.extensions.gradleVersionCompatibleWithIsolatedProjects
import io.github.cdsap.talaiot.extensions.isCompatibleWithIsolatedProjects
import io.github.cdsap.talaiot.filter.BuildFilterProcessor
import io.github.cdsap.talaiot.filter.TaskFilterProcessor
import io.github.cdsap.talaiot.logger.LogTracker
Expand Down Expand Up @@ -51,7 +51,7 @@ class Talaiot<T : TalaiotExtension>(
val executionReport = ExecutionReport()
val startTime = System.currentTimeMillis()
target.gradle.taskGraph.whenReady {
val dictionary = if (GradleVersion.current().version.gradleVersionCompatibleWithIsolatedProjects() && target.serviceOf<BuildFeatures>().isolatedProjects.active.getOrElse(false)) emptyMap<String, String>() else it.allTasks.associate { it.path to it.javaClass.toString().replace("class ", "").replace("_Decorated", "") }
val dictionary = if (GradleVersion.current().isCompatibleWithIsolatedProjects() && target.serviceOf<BuildFeatures>().isolatedProjects.active.getOrElse(false)) emptyMap<String, String>() else it.allTasks.associate { it.path to it.javaClass.toString().replace("class ", "").replace("_Decorated", "") }

val parameters = target.gradle.startParameter.taskRequests.flatMap {
it.args.flatMap { task ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.github.cdsap.talaiot.extensions

import org.gradle.util.GradleVersion

fun GradleVersion.isCompatibleWithIsolatedProjects(): Boolean = GradleVersion.version("8.5") <= this.baseVersion
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,3 @@ fun String.toBytes(): String? {
}
return null
}

fun String.gradleVersionCompatibleWithIsolatedProjects(): Boolean {
fun parseVersion(version: String): List<Int> {
return version.split(Regex("[^\\d]+")).filter { it.isNotEmpty() }.map { it.toInt() }
}

val versionParts = parseVersion(this)
val targetVersionParts = parseVersion("8.5")
val maxLength = maxOf(versionParts.size, targetVersionParts.size)
for (i in 0 until maxLength) {
val vPart = versionParts.getOrElse(i) { 0 }

val tPart = targetVersionParts.getOrElse(i) { 0 }
if (vPart > tPart) {
return true
}
if (vPart < tPart) {
return false
}
}
return true
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.cdsap.talaiot.metrics

import io.github.cdsap.talaiot.extensions.gradleVersionCompatibleWithIsolatedProjects
import io.github.cdsap.talaiot.extensions.isCompatibleWithIsolatedProjects
import io.github.cdsap.talaiot.extensions.toBytes
import io.github.cdsap.talaiot.metrics.base.GradleMetric
import io.github.cdsap.talaiot.metrics.base.JvmArgsMetric
Expand Down Expand Up @@ -129,7 +129,7 @@ class LocaleMetric : GradleMetric<String>(

private fun Gradle.findRequestedTasks(): List<String> {
val taskNames = startParameter.taskNames
return if (GradleVersion.current().version.gradleVersionCompatibleWithIsolatedProjects() && rootProject.serviceOf<BuildFeatures>().isolatedProjects.active.getOrElse(false)) {
return if (GradleVersion.current().isCompatibleWithIsolatedProjects() && rootProject.serviceOf<BuildFeatures>().isolatedProjects.active.getOrElse(false)) {
taskNames
} else {
val executedTasks = taskGraph.allTasks.map { TaskName(name = it.name, path = it.path) }
Expand Down

0 comments on commit 1a2d1f1

Please sign in to comment.