• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jesperancinha / markdowner / #194

pending completion
#194

push

github-ci

web-flow
Merge pull request #149 from jesperancinha/migration-to-kotlin

Migration to kotlin

333 of 333 new or added lines in 13 files covered. (100.0%)

274 of 333 relevant lines covered (82.28%)

8.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.31
/markdowner-filter/src/main/kotlin/org/jesperancinha/parser/markdowner/filter/SBTFilter.kt
1
package org.jesperancinha.parser.markdowner.filter
2

3
import org.apache.logging.log4j.util.Strings
4
import org.slf4j.LoggerFactory
5
import java.io.BufferedReader
6
import java.io.FileReader
7
import java.io.IOException
8
import java.nio.file.Path
9

10
/**
11
 * Filter to check if folder contains a Simple Build Tool project and keeps the project name in memory
12
 */
13
class SBTFilter : ProjectFilter<Path>() {
6✔
14
    override fun test(path: Path): Boolean {
15
        val maybeSBTBuild = path.fileName.toString() == "build.sbt"
12✔
16
        if (maybeSBTBuild) {
4✔
17
            try {
2✔
18
                BufferedReader(FileReader(path.toFile())).use { bufferedReader ->
44✔
19
                    var line: String
8✔
20
                    while (bufferedReader.readLine().also { line = it } != null) {
26✔
21
                        if (hasName(line)) {
12✔
22
                            return true
8✔
23
                        }
24
                    }
25
                }
×
26
            } catch (e: IOException) {
×
27
                logger.trace("Not SBT format!")
×
28
            }
29
        }
30
        return false
4✔
31
    }
32

33
    override fun lastProjectName(): String? {
34
        return lastProjectName
6✔
35
    }
36

37
    private fun hasName(line: String): Boolean {
38
        val split: Array<String> = line.split("\\s*:=\\s*".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
58✔
39
        return if (split.size == 2) {
10✔
40
            isNameProperty(split)
8✔
41
        } else false
×
42
    }
43

44
    private fun isNameProperty(split: Array<String>): Boolean {
45
        val left = split.get(0).trim { it <= ' ' }
24✔
46
        return if (left == NAME) {
10✔
47
            isValueAString(split.get(1))
12✔
48
        } else false
×
49
    }
50

51
    private fun isValueAString(s: String): Boolean {
52
        val right = s.trim { it <= ' ' }
20✔
53
        if (Strings.isNotEmpty(right)) {
8✔
54
            lastProjectName = right.substring(1, right.length - 1)
24✔
55
            return true
4✔
56
        }
57
        return false
×
58
    }
59

60
    companion object {
61
        private val NAME: String = "name"
4✔
62
        val logger = LoggerFactory.getLogger(SBTFilter::class.java)
8✔
63
    }
64
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc