-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: make license header configurable via 'license-header.txt' (#49)
Signed-off-by: Jendrik Johannes <[email protected]>
- Loading branch information
Showing
5 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
src/main/kotlin/org.hiero.gradle.check.spotless-kotlin.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import org.hiero.gradle.spotless.LicenseHeader | ||
|
||
plugins { id("com.diffplug.spotless") } | ||
|
||
spotless { | ||
kotlinGradle { | ||
ktfmt().kotlinlangStyle() | ||
|
||
licenseHeader( | ||
"// SPDX-License-Identifier: Apache-2.0\n", | ||
"(import|plugins|pluginManagement|dependencyResolutionManagement|repositories|tasks|allprojects|subprojects|buildCache|version)" | ||
) | ||
LicenseHeader.javaFormat(project), | ||
"(import|plugins|pluginManagement|dependencyResolutionManagement|repositories|tasks|allprojects|subprojects|buildCache|version)" | ||
) | ||
.updateYearWithLatest(true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/kotlin/org/hiero/gradle/spotless/LicenseHeader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package org.hiero.gradle.spotless | ||
|
||
import org.gradle.api.Project | ||
|
||
object LicenseHeader { | ||
const val default = "SPDX-License-Identifier: Apache-2.0" | ||
|
||
fun javaFormat(project: Project): String { | ||
val plainHeader = plainHeader(project).lines() | ||
return if (plainHeader.size == 1) "// " + plainHeader.single() | ||
else | ||
(listOf("/*") + | ||
plainHeader.map { line -> | ||
when (line) { | ||
"" -> " *" | ||
else -> " * $line" | ||
} | ||
} + | ||
listOf(" */", "", "")) | ||
.joinToString("\n") | ||
} | ||
|
||
fun yamlFormat(project: Project): String { | ||
val plainHeader = plainHeader(project).lines() | ||
return if (plainHeader.size == 1) "# " + plainHeader.single() | ||
else | ||
(listOf("##") + | ||
plainHeader.map { line -> | ||
when (line) { | ||
"" -> "#" | ||
else -> "# $line" | ||
} | ||
} + | ||
listOf("##", "", "")) | ||
.joinToString("\n") | ||
} | ||
|
||
private fun plainHeader(project: Project): String { | ||
@Suppress("UnstableApiUsage") val rootDir = project.isolated.rootProject.projectDirectory | ||
val headerFile = rootDir.file("gradle/license-header.txt").asFile | ||
val header = if (headerFile.exists()) headerFile.readText() else default | ||
return header | ||
} | ||
} |