Skip to content

Commit

Permalink
Support gradle 7.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Doron Gold committed Dec 31, 2022
1 parent d11352e commit c1d913f
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 24 deletions.
15 changes: 6 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ java {
}
}



group = 'com.dorongold.plugins'
version = '2.1.0'
description = "Gradle plugin that adds a 'taskTree' task that prints task dependency tree"
Expand All @@ -44,16 +42,15 @@ task createClasspathManifest {
}

dependencies {
compile localGroovy()
compile gradleApi()
compile 'org.apache.commons:commons-lang3:3.5'
implementation localGroovy()
implementation 'org.apache.commons:commons-lang3:3.5'

testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
testImplementation('org.spockframework:spock-core:1.0-groovy-2.4') {
exclude module: 'groovy-all'
}
testCompile 'com.netflix.nebula:nebula-test:5.0.1'
testCompile 'commons-io:commons-io:2.5'
testRuntime files(createClasspathManifest)
testImplementation 'com.netflix.nebula:nebula-test:5.0.1'
testImplementation 'commons-io:commons-io:2.5'
testRuntimeOnly files(createClasspathManifest)
}

pluginBundle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.gradle.initialization.BuildClientMetaData
import org.gradle.internal.graph.GraphRenderer
import org.gradle.internal.logging.text.StyledTextOutput
import org.gradle.util.CollectionUtils
import utils.GradleUtils

import static org.gradle.internal.logging.text.StyledTextOutput.Style.Description
import static org.gradle.internal.logging.text.StyledTextOutput.Style.Failure
Expand Down Expand Up @@ -65,7 +66,7 @@ abstract class TaskTreeTaskBase extends ProjectBasedReportTask {

TaskExecutionGraph executionGraph = project.gradle.taskGraph
// Getting a private field is possible thanks to groovy not honoring the private modifier
DefaultExecutionPlan executionPlan = executionGraph.executionPlan
DefaultExecutionPlan executionPlan = getExecutionPlan(executionGraph)
Set<Node> tasksOfCurrentProject = executionPlan.entryNodes.findAll {
it.getTask().getProject() == project
}
Expand Down Expand Up @@ -202,10 +203,17 @@ abstract class TaskTreeTaskBase extends ProjectBasedReportTask {
textOutput.println()
}

private static void printNoTaskDependencies(StyledTextOutput textOutput) {
static void printNoTaskDependencies(StyledTextOutput textOutput) {
textOutput.withStyle(Info).text("No task dependencies")
textOutput.println()

}

static DefaultExecutionPlan getExecutionPlan(TaskExecutionGraph taskExecutionGraph) {
if (GradleUtils.IS_GRADLE_MIN_7_6) {
return taskExecutionGraph.executionPlan.contents
} else {
return taskExecutionGraph.executionPlan
}
}
}
7 changes: 7 additions & 0 deletions src/main/groovy/utils/GradleUtils.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package utils

import org.gradle.util.GradleVersion

class GradleUtils {
public static boolean IS_GRADLE_MIN_7_6 = GradleVersion.current().baseVersion >= GradleVersion.version("7.6")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.dorongold.gradle.integtests.fixtures.Sample
import com.dorongold.gradle.integtests.fixtures.UsesSample
import groovy.json.JsonSlurper
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.internal.feature.TestKitFeature
import org.gradle.util.GradleVersion
import org.junit.ClassRule
import org.junit.Rule
Expand Down Expand Up @@ -47,14 +46,14 @@ class TaskTreeTaskTest extends Specification {
}

@Unroll
def "test output of taskTree on the build task in gradle version #gradleVersion"() {
def "taskTree without repeat output on build task in gradle version #gradleVersion"() {
setup:
println "--------------------- Testing gradle version ${gradleVersion} ---------------------"

when:
def result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('build', 'taskTree', '--repeat')
.withArguments('build', 'taskTree')
.withGradleVersion(gradleVersion)
// running in debug mode as a workaround to prevent gradle from spawning new gradle daemons - which causes the build to fail on Travis CI
// debug mode runs "embedded" gradle
Expand All @@ -63,16 +62,28 @@ class TaskTreeTaskTest extends Specification {
.build()

then:
result.output.contains expectedOutputWithRepeat()
if (GradleVersion.version(gradleVersion) > TestKitFeature.CAPTURE_BUILD_RESULT_TASKS.getSince()) {
result.task(":taskTree").outcome == SUCCESS
result.task(":build").outcome == SKIPPED
if (GradleVersion.version(gradleVersion) >= GradleVersion.version("7.6")) {
result.output.contains(expectedOutputNoRepeatAfter76())
} else {
result.output.contains expectedOutputNoRepeat()

}
result.task(":taskTree").outcome == SUCCESS
result.task(":build").outcome == SKIPPED

where:
gradleVersion << testedGradleVersions
}

@Unroll
def "taskTree with repeat output on build task in gradle version #gradleVersion"() {
setup:
println "--------------------- Testing gradle version ${gradleVersion} ---------------------"

when:
result = GradleRunner.create()
def result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('build', 'taskTree')
.withArguments('build', 'taskTree', '--repeat')
.withGradleVersion(gradleVersion)
// running in debug mode as a workaround to prevent gradle from spawning new gradle daemons - which causes the build to fail on Travis CI
// debug mode runs "embedded" gradle
Expand All @@ -81,11 +92,13 @@ class TaskTreeTaskTest extends Specification {
.build()

then:
result.output.contains expectedOutputNoRepeat()
if (GradleVersion.version(gradleVersion) > TestKitFeature.CAPTURE_BUILD_RESULT_TASKS.getSince()) {
result.task(":taskTree").outcome == SUCCESS
result.task(":build").outcome == SKIPPED
if (GradleVersion.version(gradleVersion) >= GradleVersion.version("7.6")) {
result.output.contains expectedOutputWithRepeatAfter76()
} else {
result.output.contains expectedOutputWithRepeat()
}
result.task(":taskTree").outcome == SUCCESS
result.task(":build").outcome == SKIPPED

where:
gradleVersion << testedGradleVersions
Expand Down Expand Up @@ -156,6 +169,38 @@ class TaskTreeTaskTest extends Specification {
'''.stripIndent()
}

static String expectedOutputWithRepeatAfter76() {
'''
------------------------------------------------------------
:build
+--- :assemble
| \\--- :jar
| +--- :classes
| | +--- :compileJava
| | \\--- :processResources
| \\--- :compileJava
\\--- :check
\\--- :test
+--- :classes
| +--- :compileJava
| \\--- :processResources
+--- :compileJava
+--- :compileTestJava
| +--- :classes
| | +--- :compileJava
| | \\--- :processResources
| \\--- :compileJava
\\--- :testClasses
+--- :compileTestJava
| +--- :classes
| | +--- :compileJava
| | \\--- :processResources
| \\--- :compileJava
\\--- :processTestResources
'''.stripIndent()
}

static String expectedOutputNoRepeat() {
'''
------------------------------------------------------------
Expand All @@ -175,6 +220,34 @@ class TaskTreeTaskTest extends Specification {
\\--- :processTestResources
(*) - subtree omitted (printed previously)
'''.stripIndent()
}

static String expectedOutputNoRepeatAfter76() {
'''
------------------------------------------------------------
:build
+--- :assemble
| \\--- :jar
| +--- :classes
| | +--- :compileJava
| | \\--- :processResources
| \\--- :compileJava *
\\--- :check
\\--- :test
+--- :classes *
+--- :compileJava *
+--- :compileTestJava
| +--- :classes *
| \\--- :compileJava *
\\--- :testClasses
+--- :compileTestJava *
\\--- :processTestResources
(*) - subtree omitted (printed previously)
'''.stripIndent()
}
Expand Down

0 comments on commit c1d913f

Please sign in to comment.