From 430175cdbe9240d7ab2493a8e115169f5c21d266 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 11 Oct 2015 21:31:53 -0700 Subject: [PATCH] Run on source directories only. Otherwise, the plug-in also goes through .git/, which takes a while. --- Build.kt | 3 +- .../plugin/linecount/LineCountPlugin.kt | 32 +++++++++---------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Build.kt b/Build.kt index 2c94a6f..500b03c 100644 --- a/Build.kt +++ b/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" diff --git a/src/main/kotlin/com/beust/kobalt/plugin/linecount/LineCountPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/linecount/LineCountPlugin.kt index 61a11e0..d4a93bd 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/linecount/LineCountPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/linecount/LineCountPlugin.kt @@ -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,33 +23,34 @@ 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) - if (path.toFile().exists()) { - Files.walkFileTree(path, object : SimpleFileVisitor() { - override public fun visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult { - if (matcher.matches(path)) { - fileCount++ - lineCount += Files.lines(path).count() - log(3, " MATCH $path") + project.sourceDirectories.forEach { + val path = Paths.get(it) + if (path.toFile().exists()) { + Files.walkFileTree(path, object : SimpleFileVisitor() { + override public fun visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult { + if (matcher.matches(path)) { + fileCount++ + lineCount += Files.lines(path).count() + log(3, " MATCH $path") + } + return FileVisitResult.CONTINUE } - return FileVisitResult.CONTINUE - } - }) + }) + } } log(1, "Found $lineCount lines in $fileCount files") return TaskResult()