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 {
|
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"
|
||||||
|
|
|
@ -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,33 +23,34 @@ 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 {
|
||||||
if (path.toFile().exists()) {
|
val path = Paths.get(it)
|
||||||
Files.walkFileTree(path, object : SimpleFileVisitor<Path>() {
|
if (path.toFile().exists()) {
|
||||||
override public fun visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult {
|
Files.walkFileTree(path, object : SimpleFileVisitor<Path>() {
|
||||||
if (matcher.matches(path)) {
|
override public fun visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult {
|
||||||
fileCount++
|
if (matcher.matches(path)) {
|
||||||
lineCount += Files.lines(path).count()
|
fileCount++
|
||||||
log(3, " MATCH $path")
|
lineCount += Files.lines(path).count()
|
||||||
|
log(3, " MATCH $path")
|
||||||
|
}
|
||||||
|
return FileVisitResult.CONTINUE
|
||||||
}
|
}
|
||||||
return FileVisitResult.CONTINUE
|
})
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
log(1, "Found $lineCount lines in $fileCount files")
|
log(1, "Found $lineCount lines in $fileCount files")
|
||||||
return TaskResult()
|
return TaskResult()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue