@@ -10,123 +10,123 @@ import kotlin.math.abs
1010
1111//  Set up activePartition property on all projects
1212allprojects {
13-      extra.set(" activePartition" true )
14-      
15-      val  shouldUseTaskPartitions =  rootProject.hasProperty(" taskPartitionCount" &&  rootProject.hasProperty(" taskPartition" 
16-      if  (shouldUseTaskPartitions) {
17-          val  taskPartitionCount =  rootProject.property(" taskPartitionCount" as  String 
18-          val  taskPartition =  rootProject.property(" taskPartition" as  String 
19-          val  currentTaskPartition =  abs(project.path.hashCode() %  taskPartitionCount.toInt())
20-          extra.set(" activePartition" ==  taskPartition.toInt())
21-      }
13+   extra.set(" activePartition" true )
14+   
15+   val  shouldUseTaskPartitions =  rootProject.hasProperty(" taskPartitionCount" &&  rootProject.hasProperty(" taskPartition" 
16+   if  (shouldUseTaskPartitions) {
17+     val  taskPartitionCount =  rootProject.property(" taskPartitionCount" as  String 
18+     val  taskPartition =  rootProject.property(" taskPartition" as  String 
19+     val  currentTaskPartition =  abs(project.path.hashCode() %  taskPartitionCount.toInt())
20+     extra.set(" activePartition" ==  taskPartition.toInt())
21+   }
2222}
2323
2424fun  relativeToGitRoot (f :  File ): File  {
25-      return  rootProject.projectDir.toPath().relativize(f.absoluteFile.toPath()).toFile()
25+   return  rootProject.projectDir.toPath().relativize(f.absoluteFile.toPath()).toFile()
2626}
2727
2828fun  getChangedFiles (baseRef :  String , newRef :  String ): List <File > {
29-      val  stdout =  StringBuilder ()
30-      val  stderr =  StringBuilder ()
29+   val  stdout =  StringBuilder ()
30+   val  stderr =  StringBuilder ()
3131
32-      val  proc =  Runtime .getRuntime().exec(arrayOf(" git" " diff" " --name-only" " $baseRef ..$newRef " 
33-      proc.inputStream.bufferedReader().use { stdout.append(it.readText()) }
34-      proc.errorStream.bufferedReader().use { stderr.append(it.readText()) }
35-      proc.waitFor()
36-      require(proc.exitValue() ==  0 ) { " git diff command failed, stderr: $stderr " 
32+   val  proc =  Runtime .getRuntime().exec(arrayOf(" git" " diff" " --name-only" " $baseRef ..$newRef " 
33+   proc.inputStream.bufferedReader().use { stdout.append(it.readText()) }
34+   proc.errorStream.bufferedReader().use { stderr.append(it.readText()) }
35+   proc.waitFor()
36+   require(proc.exitValue() ==  0 ) { " git diff command failed, stderr: $stderr " 
3737
38-      val  out  =  stdout.toString().trim()
39-      if  (out .isEmpty()) {
40-          return  emptyList()
41-      }
38+   val  out  =  stdout.toString().trim()
39+   if  (out .isEmpty()) {
40+     return  emptyList()
41+   }
4242
43-      logger.debug(" git diff output: $out " 
44-      return  out .split(" \n " File (rootProject.projectDir, it.trim()) }
43+   logger.debug(" git diff output: $out " 
44+   return  out .split(" \n " File (rootProject.projectDir, it.trim()) }
4545}
4646
4747//  Initialize git change tracking
4848rootProject.extra.set(" useGitChanges" false )
4949
5050if  (rootProject.hasProperty(" gitBaseRef" 
51-      val  baseRef =  rootProject.property(" gitBaseRef" as  String 
52-      val  newRef =  if  (rootProject.hasProperty(" gitNewRef" 
53-          rootProject.property(" gitNewRef" as  String 
54-      } else  {
55-          " HEAD" 
56-      }
57-      
58-      val  changedFiles =  getChangedFiles(baseRef, newRef)
59-      rootProject.extra.set(" changedFiles" 
60-      rootProject.extra.set(" useGitChanges" true )
61-      
62-      val  ignoredFiles =  fileTree(rootProject.projectDir) {
63-          include(" .gitignore" " .editorconfig" 
64-          include(" *.md" " **/*.md" 
65-          include(" gradlew" " gradlew.bat" " mvnw" " mvnw.cmd" 
66-          include(" NOTICE" 
67-          include(" static-analysis.datadog.yml" 
68-      }
51+   val  baseRef =  rootProject.property(" gitBaseRef" as  String 
52+   val  newRef =  if  (rootProject.hasProperty(" gitNewRef" 
53+     rootProject.property(" gitNewRef" as  String 
54+   } else  {
55+     " HEAD" 
56+   }
57+   
58+   val  changedFiles =  getChangedFiles(baseRef, newRef)
59+   rootProject.extra.set(" changedFiles" 
60+   rootProject.extra.set(" useGitChanges" true )
61+   
62+   val  ignoredFiles =  fileTree(rootProject.projectDir) {
63+     include(" .gitignore" " .editorconfig" 
64+     include(" *.md" " **/*.md" 
65+     include(" gradlew" " gradlew.bat" " mvnw" " mvnw.cmd" 
66+     include(" NOTICE" 
67+     include(" static-analysis.datadog.yml" 
68+   }
6969
70-     changedFiles.forEach { f -> 
71-         if  (ignoredFiles.contains(f)) {
72-             logger.warn(" Ignoring changed file: ${relativeToGitRoot(f)} " 
73-         }
70+   changedFiles.forEach { f -> 
71+     if  (ignoredFiles.contains(f)) {
72+       logger.warn(" Ignoring changed file: ${relativeToGitRoot(f)} " 
7473    }
74+   }
7575
76-     val  filteredChangedFiles =  changedFiles.filter { ! ignoredFiles.contains(it) }
77-     rootProject.extra.set(" changedFiles" 
78-     
79-     val  globalEffectFiles =  fileTree(rootProject.projectDir) {
80-         include(" .gitlab/**" 
81-         include(" build.gradle" 
82-         include(" gradle/**" 
83-     }
84-     
85-     for  (f in  filteredChangedFiles) {
86-         if  (globalEffectFiles.contains(f)) {
87-             logger.warn(" Global effect change: ${relativeToGitRoot(f)}  (no tasks will be skipped)" 
88-             rootProject.extra.set(" useGitChanges" false )
89-             break 
90-         }
76+   val  filteredChangedFiles =  changedFiles.filter { ! ignoredFiles.contains(it) }
77+   rootProject.extra.set(" changedFiles" 
78+   
79+   val  globalEffectFiles =  fileTree(rootProject.projectDir) {
80+     include(" .gitlab/**" 
81+     include(" build.gradle" 
82+     include(" gradle/**" 
83+   }
84+   
85+   for  (f in  filteredChangedFiles) {
86+     if  (globalEffectFiles.contains(f)) {
87+       logger.warn(" Global effect change: ${relativeToGitRoot(f)}  (no tasks will be skipped)" 
88+       rootProject.extra.set(" useGitChanges" false )
89+       break 
9190    }
91+   }
92+   
93+   if  (rootProject.extra.get(" useGitChanges" as  Boolean ) {
94+     logger.warn(" Git change tracking is enabled: $baseRef ..$newRef " 
9295
93-     if  (rootProject.extra.get(" useGitChanges" as  Boolean ) {
94-         logger.warn(" Git change tracking is enabled: $baseRef ..$newRef " 
95-         
96-         val  projects =  subprojects.sortedByDescending { it.projectDir.path.length }
97-         val  affectedProjects =  mutableMapOf<Project , MutableSet <String >>()
96+     val  projects =  subprojects.sortedByDescending { it.projectDir.path.length }
97+     val  affectedProjects =  mutableMapOf<Project , MutableSet <String >>()
9898
99-          //  Path prefixes mapped to affected task names. A file not matching any of these prefixes will affect all tasks in
100-          //  the project ("all" can be used a task name to explicitly state the same). Only the first matching prefix is used.
101-          val  matchers =  listOf (
102-              mapOf (" prefix" " src/testFixtures/" " task" " testFixturesClasses" 
103-              mapOf (" prefix" " src/test/" " task" " testClasses" 
104-              mapOf (" prefix" " src/jmh/" " task" " jmhCompileGeneratedClasses" 
105-          )
99+     //  Path prefixes mapped to affected task names. A file not matching any of these prefixes will affect all tasks in
100+     //  the project ("all" can be used a task name to explicitly state the same). Only the first matching prefix is used.
101+     val  matchers =  listOf (
102+       mapOf (" prefix" " src/testFixtures/" " task" " testFixturesClasses" 
103+       mapOf (" prefix" " src/test/" " task" " testClasses" 
104+       mapOf (" prefix" " src/jmh/" " task" " jmhCompileGeneratedClasses" 
105+     )
106106
107-          for  (f in  filteredChangedFiles) {
108-              val  p =  projects.find { f.toString().startsWith(it.projectDir.path +  " /" 
109-              if  (p ==  null ) {
110-                  logger.warn(" Changed file: ${relativeToGitRoot(f)}  at root project (no task will be skipped)" 
111-                  rootProject.extra.set(" useGitChanges" false )
112-                  break 
113-              }
107+     for  (f in  filteredChangedFiles) {
108+       val  p =  projects.find { f.toString().startsWith(it.projectDir.path +  " /" 
109+       if  (p ==  null ) {
110+         logger.warn(" Changed file: ${relativeToGitRoot(f)}  at root project (no task will be skipped)" 
111+         rootProject.extra.set(" useGitChanges" false )
112+         break 
113+       }
114114
115-             //  Make sure path separator is /
116-             val  relPath =  p.projectDir.toPath().relativize(f.toPath()).joinToString(" /" 
117-             val  task =  matchers.find { relPath.startsWith(it[" prefix" !! ) }?.get(" task" ? :  " all" 
118-             logger.warn(" Changed file: ${relativeToGitRoot(f)}  in project ${p.path}  ($task )" 
119-             affectedProjects.computeIfAbsent(p) { mutableSetOf () }.add(task)
120-         }
121-         
122-         rootProject.extra.set(" affectedProjects" 
115+       //  Make sure path separator is /
116+       val  relPath =  p.projectDir.toPath().relativize(f.toPath()).joinToString(" /" 
117+       val  task =  matchers.find { relPath.startsWith(it[" prefix" !! ) }?.get(" task" ? :  " all" 
118+       logger.warn(" Changed file: ${relativeToGitRoot(f)}  in project ${p.path}  ($task )" 
119+       affectedProjects.computeIfAbsent(p) { mutableSetOf () }.add(task)
123120    }
121+     
122+     rootProject.extra.set(" affectedProjects" 
123+   }
124124}
125125
126126tasks.register(" runMuzzle" 
127-      val  muzzleSubprojects =  subprojects.filter { p -> 
128-          val  activePartition =  p.extra.get(" activePartition" as  Boolean 
129-          activePartition &&  p.plugins.hasPlugin(" java" &&  p.plugins.hasPlugin(" muzzle" 
130-      }
131-      dependsOn(muzzleSubprojects.map { p ->  " ${p.path} :muzzle" 
127+   val  muzzleSubprojects =  subprojects.filter { p -> 
128+     val  activePartition =  p.extra.get(" activePartition" as  Boolean 
129+     activePartition &&  p.plugins.hasPlugin(" java" &&  p.plugins.hasPlugin(" muzzle" 
130+   }
131+   dependsOn(muzzleSubprojects.map { p ->  " ${p.path} :muzzle" 
132132}
0 commit comments