1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt-line-count.git synced 2025-04-25 03:07:11 -07:00

Run on source directories only.

Otherwise, the plug-in also goes through .git/, which takes a while.
This commit is contained in:
Cedric Beust 2015-10-11 21:31:53 -07:00
parent 7780a54ffb
commit 430175cdbe
2 changed files with 18 additions and 17 deletions

View file

@ -10,8 +10,9 @@ val plugins = plugins(
) )
val lc = lineCount { val lc = lineCount {
suffix = "**.md" suffix = "**Plugin.kt"
} }
val project = kotlinProject { val project = kotlinProject {
name = "kobalt-line-count" name = "kobalt-line-count"
group = "com.beust.kobalt" group = "com.beust.kobalt"

View file

@ -1,6 +1,5 @@
package com.beust.kobalt.plugin.linecount package com.beust.kobalt.plugin.linecount
import com.beust.kobalt.Plugins
import com.beust.kobalt.api.BasePlugin import com.beust.kobalt.api.BasePlugin
import com.beust.kobalt.internal.TaskResult import com.beust.kobalt.internal.TaskResult
import com.beust.kobalt.api.* import com.beust.kobalt.api.*
@ -24,22 +23,22 @@ public class LineCountPlugin : BasePlugin(), KobaltLogger {
var info: LineCountInfo = LineCountInfo() var info: LineCountInfo = LineCountInfo()
override fun apply(project: Project, context: KobaltContext) { override fun apply(project: Project, context: KobaltContext) {
println("*** Applying plugin ${name} with project ${project}") println("*** Applying plugin $name with project $project")
println("*** Adding dynamic task") println("*** Adding dynamic task")
addTask(project, "dynamicTask", wrapAfter = arrayListOf("compile")) { addTask(project, "dynamicTask", runBefore = listOf("compile")) {
println("DYNAMIC") println("Dynamic task")
TaskResult() TaskResult()
} }
} }
@Task(name = "lineCount", description = "Count the lines", runBefore = arrayOf("compile")) @Task(name = "lineCount", description = "Count the lines", runBefore = arrayOf("compile"))
fun lineCount(project: Project): TaskResult { fun lineCount(project: Project): TaskResult {
var fileCount = 0 var fileCount = 0
var lineCount : Long = 0 var lineCount : Long = 0
log(1, "Finding files that end in ${info.suffix}") log(1, "Finding files that end in ${info.suffix}")
val matcher = FileSystems.getDefault().getPathMatcher("glob:" + info.suffix) val matcher = FileSystems.getDefault().getPathMatcher("glob:" + info.suffix)
val path = Paths.get(project.directory) project.sourceDirectories.forEach {
val path = Paths.get(it)
if (path.toFile().exists()) { if (path.toFile().exists()) {
Files.walkFileTree(path, object : SimpleFileVisitor<Path>() { Files.walkFileTree(path, object : SimpleFileVisitor<Path>() {
override public fun visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult { override public fun visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult {
@ -52,6 +51,7 @@ public class LineCountPlugin : BasePlugin(), KobaltLogger {
} }
}) })
} }
}
log(1, "Found $lineCount lines in $fileCount files") log(1, "Found $lineCount lines in $fileCount files")
return TaskResult() return TaskResult()
} }