Skip to content

Commit 1381c01

Browse files
Add licenseHeader conversion function to goBuild (#115)
1 parent 87451a0 commit 1381c01

File tree

1 file changed

+12
-0
lines changed
  • gradle-modules/src/main/kotlin/org/sonarsource/cloudnative/gradle

1 file changed

+12
-0
lines changed

gradle-modules/src/main/kotlin/org/sonarsource/cloudnative/gradle/GoBuild.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.sonarsource.cloudnative.gradle
1818

19+
import java.io.File
1920
import org.gradle.api.Project
2021
import org.gradle.api.file.FileTree
2122
import org.gradle.api.file.RegularFile
@@ -72,3 +73,14 @@ fun Project.goSources(): FileTree =
7273
include("**/*.go")
7374
exclude("build/**", "**/*_generated.go")
7475
}
76+
77+
fun convertLicenseHeaderToGoCommentStyle(inputFile: File): String {
78+
val lines = inputFile.readLines()
79+
80+
if (lines.size <= 2) return ""
81+
82+
// drop(1) removes the first, dropLast(1) removes the last
83+
return lines.drop(1).dropLast(1).joinToString("\n") { line ->
84+
line.replace(" *", "//")
85+
}
86+
}

0 commit comments

Comments
 (0)