1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt-doc.git synced 2025-04-24 11:37:11 -07:00

Fix code examples.

Fixes some inconsistencies in the code examples (e.g. the name of plugin
class). It also addresses the problem that the code fails if one of the default
source directories does not exist.
This commit is contained in:
Dirk Dittert 2017-03-25 16:02:09 +01:00
parent 90b7041002
commit 9a34937836

View file

@ -121,11 +121,12 @@ val project = project {
</p>
<pre class="brush:java">
// LineCountPlugin.kt
package com.beust.kobalt.plugin.linecount
import com.beust.kobalt.api.*
public class Main : BasePlugin() {
class LineCountPlugin : BasePlugin() {
override val name = "kobalt-line-count"
override fun apply(project: Project, context: KobaltContext) {
@ -162,22 +163,25 @@ bintray {
</p>
<pre class="brush:java">
// Main.kt
// LineCountPlugin.kt
@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 {
Files.walkFileTree(Paths.get(it), object: SimpleFileVisitor&lt;Path&gt;() {
override public fun visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult {
if (matcher.matches(path)) {
fileCount++
lineCount += Files.lines(path).count()
val path = Paths.get(it)
if (Files.isDirectory(path)) {
Files.walkFileTree(path, object : SimpleFileVisitor&lt;Path&gt;() {
override fun visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult {
if (matcher.matches(path)) {
fileCount++
lineCount += Files.lines(path).count()
}
return FileVisitResult.CONTINUE
}
return FileVisitResult.CONTINUE
}
})
})
}
}
log(1, "Found $lineCount lines in $fileCount files")
return TaskResult()
@ -189,7 +193,7 @@ fun lineCount(project: Project): TaskResult {
</p>
<pre class="brush:java">
public class Main : BasePlugin() {
class LineCountPlugin : BasePlugin() {
</pre>
<p>
@ -276,7 +280,7 @@ fun main(argv: Array&lt;String&gt;) {
com.beust.kobalt.main(argv)
}
public class Main : BasePlugin() {
class LineCountPlugin : BasePlugin() {
// ...
</pre>