mirror of
https://github.com/ethauvin/kobalt-line-count.git
synced 2025-04-25 19:17:11 -07:00
Initial commit
This commit is contained in:
commit
26a16c6a55
6 changed files with 128 additions and 0 deletions
41
src/main/kotlin/com/beust/kobalt/plugin/linecount/Main.kt
Normal file
41
src/main/kotlin/com/beust/kobalt/plugin/linecount/Main.kt
Normal file
|
@ -0,0 +1,41 @@
|
|||
package com.beust.kobalt.plugin.linecount
|
||||
|
||||
import com.beust.kobalt.api.BasePlugin
|
||||
import com.beust.kobalt.internal.TaskResult
|
||||
import java.nio.file.attribute.BasicFileAttributes
|
||||
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.api.annotation.Task
|
||||
import com.beust.kobalt.misc.KobaltLogger
|
||||
import java.nio.file.*
|
||||
|
||||
public class Main : BasePlugin(), KobaltLogger {
|
||||
override val name = "kobalt-line-count"
|
||||
|
||||
override fun apply(project: Project) {
|
||||
println("*** Applying plugin ${name} with project ${project}")
|
||||
}
|
||||
|
||||
@Task(name = "lineCount", description = "Count the lines", runBefore = arrayOf("compile"))
|
||||
fun lineCount(project: Project): TaskResult {
|
||||
|
||||
var fileCount = 0
|
||||
var lineCount : Long = 0
|
||||
val matcher = FileSystems.getDefault().getPathMatcher("glob:**.kt")
|
||||
project.sourceDirectories.forEach {
|
||||
Files.walkFileTree(Paths.get(it), object: SimpleFileVisitor<Path>() {
|
||||
override public fun visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult {
|
||||
log(2, "File: ${path}")
|
||||
if (matcher.matches(path)) {
|
||||
fileCount++
|
||||
lineCount += Files.lines(path).count()
|
||||
log(2, " MATCH")
|
||||
}
|
||||
return FileVisitResult.CONTINUE
|
||||
}
|
||||
})
|
||||
}
|
||||
log(1, "Found ${lineCount} lines in ${fileCount} files")
|
||||
return TaskResult()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue