1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt-line-count.git synced 2025-04-25 03:07:11 -07:00
kobalt-line-count/src/main/kotlin/com/beust/kobalt/plugin/linecount/Main.kt
2015-09-26 22:14:54 -07:00

41 lines
1.5 KiB
Kotlin

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()
}
}