Skip to content

Commit 31efcdf

Browse files
committed
Simplify code
1 parent 9c440f3 commit 31efcdf

File tree

1 file changed

+17
-32
lines changed

1 file changed

+17
-32
lines changed

gradle/ci_jobs.gradle

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,31 @@ allprojects { project ->
1818
}
1919
}
2020

21-
Set<Task> getTaskDependenciesRecursive(Task baseTask, Set<Task> visited = []) {
22-
if (visited.contains(baseTask)) {
23-
return []
24-
}
25-
Set<Task> dependencies = [baseTask]
26-
visited.add(baseTask)
27-
for (td in baseTask.taskDependencies) {
28-
for (t in td.getDependencies(baseTask)) {
29-
dependencies.add(t)
30-
dependencies.addAll(getTaskDependenciesRecursive(t, visited))
31-
}
32-
}
33-
return dependencies
34-
}
35-
3621
File relativeToGitRoot(File f) {
3722
return rootProject.projectDir.toPath().relativize(f.absoluteFile.toPath()).toFile()
3823
}
3924

4025
String isAffectedBy(Task baseTask, Map<Project, Set<String>> affectedProjects) {
41-
for (Task t in getTaskDependenciesRecursive(baseTask)) {
42-
if (!affectedProjects.containsKey(t.project)) {
26+
HashSet<Task> visited = []
27+
LinkedList<Task> queue = [baseTask]
28+
while (!queue.isEmpty()) {
29+
Task t = queue.poll()
30+
if (visited.contains(t)) {
4331
continue
4432
}
33+
visited.add(t)
34+
4535
final Set<String> affectedTasks = affectedProjects.get(t.project)
46-
if (affectedTasks.contains("all")) {
47-
return "${t.project.path}:${t.name}"
48-
}
49-
if (affectedTasks.contains(t.name)) {
50-
return "${t.project.path}:${t.name}"
36+
if (affectedTasks != null) {
37+
if (affectedTasks.contains("all")) {
38+
return "${t.project.path}:${t.name}"
39+
}
40+
if (affectedTasks.contains(t.name)) {
41+
return "${t.project.path}:${t.name}"
42+
}
5143
}
44+
45+
t.taskDependencies.each { queue.addAll(it.getDependencies(t)) }
5246
}
5347
return null
5448
}
@@ -75,19 +69,14 @@ rootProject.ext {
7569
}
7670

7771
if (rootProject.hasProperty("gitBaseRef")) {
78-
// -PgitBaseRef sets the base git reference to compare changes to. In CI, this should generally be set to the target
79-
// branch, usually master.
8072
final String baseRef = rootProject.property("gitBaseRef")
81-
// -PgitNewRef sets the new git new reference to compare changes to. This is useful for testing the test selection method
82-
// itself. Otherwise, comparing against current HEAD is what makes sense for CI.
8373
final String newRef = rootProject.hasProperty("gitNewRef") ? rootProject.property("gitNewRef") : "HEAD"
8474

8575
rootProject.ext {
8676
it.changedFiles = getChangedFiles(baseRef, newRef)
8777
useGitChanges = true
8878
}
8979

90-
// The ignoredFiles FileTree selects any file that should not trigger any tasks.
9180
final ignoredFiles = fileTree(rootProject.projectDir) {
9281
include '.gitignore', '.editorconfig'
9382
include '*.md', '**/*.md'
@@ -102,8 +91,6 @@ if (rootProject.hasProperty("gitBaseRef")) {
10291
}
10392
rootProject.changedFiles = rootProject.changedFiles.findAll { !ignoredFiles.contains(it) }
10493

105-
// The globalEffectsFile FileTree selects any file that should trigger all tasks, regardless of gradle dependency
106-
// tracking.
10794
final globalEffectFiles = fileTree(rootProject.projectDir) {
10895
include '.circleci/**'
10996
include 'build.gradle'
@@ -119,9 +106,8 @@ if (rootProject.hasProperty("gitBaseRef")) {
119106
}
120107

121108
if (rootProject.useGitChanges) {
122-
logger.warn("Git change tracking is enabled, base: ${baseRef}")
109+
logger.warn("Git change tracking is enabled: ${baseRef}..${newRef}")
123110

124-
// Get all projects, sorted by descending path length.
125111
final projects = subprojects.sort { a, b -> b.projectDir.path.length() <=> a.projectDir.path.length() }
126112
Map<Project, Set<String>> _affectedProjects = [:]
127113
final List<Map<String, String>> matchers = [
@@ -146,7 +132,6 @@ if (rootProject.hasProperty("gitBaseRef")) {
146132
it.affectedProjects = _affectedProjects
147133
}
148134
}
149-
150135
}
151136

152137
def testAggregate(String baseTaskName, includePrefixes, excludePrefixes, boolean forceCoverage = false) {

0 commit comments

Comments
 (0)