• 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

96.43
/markdowner-filter/src/main/kotlin/org/jesperancinha/parser/markdowner/filter/FileFilterChain.kt
1
package org.jesperancinha.parser.markdowner.filter
2

3
import java.nio.file.Path
4
import java.util.*
5

6
/**
7
 * Following a Chain of Responsibility Design pattern, this chain builds an chained object, which checks for the existence (as a example) of the following project types:
8
 *
9
 *
10
 * MAVEN, NPM, GRADLE, SBT
11
 *
12
 *
13
 * You can configure your own hierarchy with your own types and filters
14
 *
15
 *
16
 * And returns the first find. The algorithm is shortened by levels. This means that in one specific folder, it will prioritize the finding, being Maven the first type and lastly the Simple Build Tool
17
 * The first find is return in a [PackageInfo] object. It contains the Readme type found and the title of the the parsed object.
18
 * Each chain is created by specifying a [FileFilterChain] next chain object and a [ProjectFilter] filter.
19
 *
20
 *
21
 * See [FileFilterChain.findHighest] for more info.
22
 */
23
class FileFilterChain(
6✔
24
    private val nextFileFilterChain: FileFilterChain?,
6✔
25
    private val projectFilter: ProjectFilter<Path>
6✔
26
) {
27
    /**
28
     * Finds the highest element in the hierarchy found in the specified folder.
29
     * The deepness of the search will be limited by an element of [PackageInfo] given as an argument
30
     *
31
     * @param packageInfo Limiting search depth [PackageInfo]
32
     * @param path        Folder [Path] to classify the new to formed readme file
33
     * @return The package info found [PackageInfo]. Null if unknown.
34
     */
35
    fun findHighest(packageInfo: PackageInfo?, path: Path): PackageInfo? {
36
        if (Objects.nonNull(packageInfo) && packageInfo?.fileFilterChain === this) {
20✔
37
            return packageInfo
×
38
        }
39
        if (projectFilter.test(path)) {
10✔
40
            return PackageInfo(
8✔
41
                projectName = projectFilter.lastProjectName(),
10✔
42
                fileFilterChain = this
2✔
43
            )
44
        }
45
        return if (Objects.nonNull(nextFileFilterChain)) {
10✔
46
            nextFileFilterChain?.findHighest(packageInfo, path)
16✔
47
        } else packageInfo
2✔
48
    }
49

50
    companion object {
51
        /**
52
         * Creates a default chain to discover the project type and thus generate the correct project title for the newly formed Readme.md file
53
         *
54
         * @return A filter chain [FileFilterChain]
55
         */
56
        fun createDefaultChain(): FileFilterChain = FileFilterChain(
6✔
57
            projectFilter = MavenFilter(),
12✔
58
            nextFileFilterChain = createNPMChain()
8✔
59
        )
2✔
60

61

62
        private fun createNPMChain(): FileFilterChain = FileFilterChain(
6✔
63
            projectFilter = NPMFilter(),
12✔
64
            nextFileFilterChain = createGradleChain()
8✔
65
        )
2✔
66

67

68
        private fun createGradleChain(): FileFilterChain = FileFilterChain(
6✔
69
            projectFilter = GradleFilter(),
12✔
70
            nextFileFilterChain = createSBTChain()
8✔
71
        )
2✔
72

73
        private fun createSBTChain(): FileFilterChain = FileFilterChain(
6✔
74
            projectFilter = SBTFilter(),
12✔
75
            nextFileFilterChain = null
2✔
76
        )
2✔
77

78
    }
79
}
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