Skip to content

Commit 8e0637b

Browse files
committed
style: generate dynamic license header
1 parent 2bd38a5 commit 8e0637b

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

build.gradle.kts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import java.util.Calendar
2+
13
buildscript {
24
repositories {
35
mavenCentral()
@@ -134,7 +136,40 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
134136
spotless {
135137
kotlin {
136138
target("**/*.kt")
137-
licenseHeaderFile(file("LICENSE-HEADER.txt"))
139+
140+
val startYear = 2022
141+
val currentYear = Calendar.getInstance().get(Calendar.YEAR)
142+
val copyrightYears = if (startYear == currentYear) {
143+
"$startYear"
144+
} else {
145+
"$startYear-$currentYear"
146+
}
147+
148+
val jetbrainsProject = findProject(":protocol") ?: rootProject
149+
val licenseHeader = Regex("( . Copyright [\\S\\s]+)")
150+
.find(File(jetbrainsProject.projectDir, "LICENSE").readText())!!
151+
.value.lines().joinToString("\n") {
152+
if (it.trim().isEmpty()) {
153+
" *"
154+
} else {
155+
" * " + it.trim()
156+
}
157+
}
158+
val formattedLicenseHeader = buildString {
159+
append("/*\n")
160+
append(
161+
licenseHeader.replace(
162+
"Copyright [yyyy] [name of copyright owner]",
163+
"Source++, the open-source live coding platform.\n" +
164+
" * Copyright (C) $copyrightYears CodeBrig, Inc."
165+
).replace(
166+
"http://www.apache.org/licenses/LICENSE-2.0",
167+
" http://www.apache.org/licenses/LICENSE-2.0"
168+
)
169+
)
170+
append("/")
171+
}
172+
licenseHeader(formattedLicenseHeader)
138173
}
139174
}
140175

0 commit comments

Comments
 (0)