mirror of
https://github.com/ethauvin/kobalt-line-count.git
synced 2025-04-25 03:07:11 -07:00
0.10.
This commit is contained in:
parent
1ef8e4b945
commit
3989ef293d
7 changed files with 89 additions and 64 deletions
28
Build.kt
28
Build.kt
|
@ -2,30 +2,33 @@ import com.beust.kobalt.*
|
||||||
import com.beust.kobalt.plugin.packaging.*
|
import com.beust.kobalt.plugin.packaging.*
|
||||||
import com.beust.kobalt.plugin.kotlin.*
|
import com.beust.kobalt.plugin.kotlin.*
|
||||||
import com.beust.kobalt.plugin.publish.*
|
import com.beust.kobalt.plugin.publish.*
|
||||||
|
//import com.beust.kobalt.plugin.linecount.lineCount
|
||||||
|
//
|
||||||
val repos = repos("https://dl.bintray.com/cbeust/maven/")
|
//val plugins = plugins(
|
||||||
|
//// "com.beust.kobalt:kobalt-line-count:0.8"
|
||||||
val plugins = plugins(
|
//// file(homeDir("kotlin/kobalt-line-count/kobaltBuild/libs/kobalt-line-count-0.8.jar"))
|
||||||
"com.beust.kobalt:kobalt-line-count:0.8"
|
// file(homeDir("kotlin/kobalt-line-count/kobaltBuild/libs/kobalt-line-count-0.9.jar"))
|
||||||
// file("/Users/beust/kotlin/kobalt-line-count/kobaltBuild/libs/kobalt-line-count-0.6.jar")
|
//)
|
||||||
)
|
//
|
||||||
|
//val lc = lineCount {
|
||||||
|
// suffix = "**.md"
|
||||||
|
//}
|
||||||
val project = kotlinProject {
|
val project = kotlinProject {
|
||||||
name = "kobalt-line-count"
|
name = "kobalt-line-count"
|
||||||
group = "com.beust.kobalt"
|
group = "com.beust.kobalt"
|
||||||
artifactId = name
|
artifactId = name
|
||||||
version = "0.8"
|
version = "0.10"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile("com.beust:kobalt:0.154")
|
// compile("file:" + homeDir("kotlin/kobalt/kobaltBuild/libs/kobalt-0.168.jar"))
|
||||||
|
compile("com.beust:kobalt:0.170")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val packProject = assemble(project) {
|
val packProject = assemble(project) {
|
||||||
mavenJars {
|
mavenJars {
|
||||||
manifest {
|
manifest {
|
||||||
attributes("Kobalt-Plugin-Class", "com.beust.kobalt.plugin.linecount.Main")
|
attributes("Kobalt-Plugin-Class", "com.beust.kobalt.plugin.linecount.LineCountMain")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,4 +36,3 @@ val packProject = assemble(project) {
|
||||||
val jc = jcenter(project) {
|
val jc = jcenter(project) {
|
||||||
publish = true
|
publish = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
README.md
Normal file
1
README.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
# kobalt-line-count, a plug-in for the Kobalt build system
|
|
@ -23,7 +23,7 @@ apply plugin: 'kotlin'
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "com.google.guava:guava:18.0"
|
compile "com.google.guava:guava:18.0"
|
||||||
compile "com.beust:kobalt:0.155"
|
compile "com.beust:kobalt:0.170"
|
||||||
}
|
}
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main.java.srcDirs += 'src/main/kotlin'
|
main.java.srcDirs += 'src/main/kotlin'
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="Gradle: com.google.guava:guava:18.0" level="project" />
|
<orderEntry type="library" name="Gradle: com.google.guava:guava:18.0" level="project" />
|
||||||
<orderEntry type="library" name="Gradle: com.beust:kobalt:0.155" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:0.14.449" level="project" />
|
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:0.14.449" level="project" />
|
||||||
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-compiler-embeddable:0.14.449" level="project" />
|
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-compiler-embeddable:0.14.449" level="project" />
|
||||||
<orderEntry type="library" name="Gradle: com.beust:jcommander:1.48" level="project" />
|
<orderEntry type="library" name="Gradle: com.beust:jcommander:1.48" level="project" />
|
||||||
|
@ -37,5 +36,6 @@
|
||||||
<orderEntry type="library" name="Gradle: javax.inject:javax.inject:1" level="project" />
|
<orderEntry type="library" name="Gradle: javax.inject:javax.inject:1" level="project" />
|
||||||
<orderEntry type="library" name="Gradle: aopalliance:aopalliance:1.0" level="project" />
|
<orderEntry type="library" name="Gradle: aopalliance:aopalliance:1.0" level="project" />
|
||||||
<orderEntry type="library" name="Gradle: org.codehaus.plexus:plexus-utils:3.0.20" level="project" />
|
<orderEntry type="library" name="Gradle: org.codehaus.plexus:plexus-utils:3.0.20" level="project" />
|
||||||
|
<orderEntry type="library" name="Gradle: com.beust:kobalt:0.170" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
|
@ -1 +1 @@
|
||||||
kobalt.version=0.155
|
kobalt.version=0.170
|
|
@ -0,0 +1,70 @@
|
||||||
|
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.*
|
||||||
|
import com.beust.kobalt.api.annotation.Directive
|
||||||
|
import com.beust.kobalt.api.annotation.Task
|
||||||
|
import com.beust.kobalt.misc.KobaltLogger
|
||||||
|
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes
|
||||||
|
import java.nio.file.*
|
||||||
|
|
||||||
|
fun main(argv: Array<String>) {
|
||||||
|
com.beust.kobalt.main(argv)
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LineCountMain : BasePlugin(), KobaltLogger {
|
||||||
|
companion object {
|
||||||
|
const val NAME : String = "kobalt-line-count"
|
||||||
|
}
|
||||||
|
override val name = NAME
|
||||||
|
|
||||||
|
var info: LineCountInfo = LineCountInfo()
|
||||||
|
|
||||||
|
override fun apply(project: Project, context: KobaltContext) {
|
||||||
|
println("*** Applying plugin ${name} with project ${project}")
|
||||||
|
println("*** Adding dynamic task")
|
||||||
|
addTask(project, "dynamicTask", wrapAfter = arrayListOf("compile")) {
|
||||||
|
println("DYNAMIC")
|
||||||
|
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<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 $path")
|
||||||
|
}
|
||||||
|
return FileVisitResult.CONTINUE
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
log(1, "Found $lineCount lines in $fileCount files")
|
||||||
|
return TaskResult()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class LineCountInfo(var suffix: String = "**kt")
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
public fun lineCount(init: LineCountInfo.() -> Unit): LineCountInfo {
|
||||||
|
with(LineCountInfo()) {
|
||||||
|
init()
|
||||||
|
(Plugins.getPlugin(LineCountMain.NAME) as LineCountMain).info = this
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,48 +0,0 @@
|
||||||
package com.beust.kobalt.plugin.linecount
|
|
||||||
|
|
||||||
import com.beust.kobalt.api.BasePlugin
|
|
||||||
import com.beust.kobalt.internal.TaskResult
|
|
||||||
import com.beust.kobalt.api.*
|
|
||||||
import com.beust.kobalt.api.annotation.Task
|
|
||||||
import com.beust.kobalt.misc.KobaltLogger
|
|
||||||
|
|
||||||
import java.nio.file.attribute.BasicFileAttributes
|
|
||||||
import java.nio.file.*
|
|
||||||
|
|
||||||
fun main(argv: Array<String>) {
|
|
||||||
com.beust.kobalt.main(argv)
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Main : BasePlugin(), KobaltLogger {
|
|
||||||
override val name = "kobalt-line-count"
|
|
||||||
|
|
||||||
override fun apply(project: Project, context: KobaltContext) {
|
|
||||||
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 {
|
|
||||||
val path = Paths.get(it)
|
|
||||||
if (path.toFile().exists()) {
|
|
||||||
Files.walkFileTree(path, 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()
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue