Skip to content

Commit 5ff0857

Browse files
committed
sync
1 parent d0c170c commit 5ff0857

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

agent/agent/build.gradle.kts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,36 @@ tasks {
162162
delete(rootProject.file("licenses"))
163163
}
164164

165+
val removeLicenseDate by registering {
166+
// removing the license report date makes it idempotent
167+
doLast {
168+
val filePath = rootDir.toPath().resolve("licenses").resolve("licenses.md")
169+
if (Files.exists(filePath)) {
170+
val datePattern = Pattern.compile("^_[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} .*_$")
171+
val lines = Files.readAllLines(filePath)
172+
// 4th line contains the timestamp of when the license report was generated, replace it with
173+
// an empty line
174+
if (lines.size > 3 && datePattern.matcher(lines[3]).matches()) {
175+
lines[3] = ""
176+
Files.write(filePath, lines)
177+
}
178+
}
179+
}
180+
}
181+
182+
val generateLicenseReportEnabled =
183+
gradle.startParameter.taskNames.any { it.equals("generateLicenseReport") }
165184
named("generateLicenseReport").configure {
166185
dependsOn(cleanLicenses)
186+
finalizedBy(":spotlessApply")
187+
finalizedBy(removeLicenseDate)
188+
// disable licence report generation unless this task is explicitly run
189+
// the files produced by this task are used by other tasks without declaring them as dependency
190+
// which gradle considers an error
191+
enabled = enabled && generateLicenseReportEnabled
192+
}
193+
if (generateLicenseReportEnabled) {
194+
project.parent?.tasks?.getByName("spotlessMisc")?.dependsOn(named("generateLicenseReport"))
167195
}
168196
}
169197

0 commit comments

Comments
 (0)