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:
parent
7780a54ffb
commit
430175cdbe
2 changed files with 18 additions and 17 deletions
3
Build.kt
3
Build.kt
|
@ -10,8 +10,9 @@ val plugins = plugins(
|
|||
)
|
||||
|
||||
val lc = lineCount {
|
||||
suffix = "**.md"
|
||||
suffix = "**Plugin.kt"
|
||||
}
|
||||
|
||||
val project = kotlinProject {
|
||||
name = "kobalt-line-count"
|
||||
group = "com.beust.kobalt"
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.beust.kobalt.plugin.linecount
|
||||
|
||||
import com.beust.kobalt.Plugins
|
||||
import com.beust.kobalt.api.BasePlugin
|
||||
import com.beust.kobalt.internal.TaskResult
|
||||
import com.beust.kobalt.api.*
|
||||
|
@ -24,22 +23,22 @@ public class LineCountPlugin : BasePlugin(), KobaltLogger {
|
|||
var info: LineCountInfo = LineCountInfo()
|
||||
|
||||
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")
|
||||
addTask(project, "dynamicTask", wrapAfter = arrayListOf("compile")) {
|
||||
println("DYNAMIC")
|
||||
addTask(project, "dynamicTask", runBefore = listOf("compile")) {
|
||||
println("Dynamic task")
|
||||
TaskResult()
|
||||
}
|
||||
}
|
||||
|
||||
@Task(name = "lineCount", description = "Count the lines", runBefore = arrayOf("compile"))
|
||||
fun lineCount(project: Project): TaskResult {
|
||||
|
||||
var fileCount = 0
|
||||
var lineCount : Long = 0
|
||||
log(1, "Finding files that end in ${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()) {
|
||||
Files.walkFileTree(path, object : SimpleFileVisitor<Path>() {
|
||||
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")
|
||||
return TaskResult()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue