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

pgpainless / sop-java / #20

15 Nov 2023 05:34PM UTC coverage: 64.454% (-1.1%) from 65.57%
#20

push

other

vanitasvitae
Kotlin conversion: VersionExternal

25 of 43 new or added lines in 1 file covered. (58.14%)

1097 of 1702 relevant lines covered (64.45%)

0.64 hits per line

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

58.14
/external-sop/src/main/kotlin/sop/external/operation/VersionExternal.kt
1
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
2
//
3
// SPDX-License-Identifier: Apache-2.0
4

5
package sop.external.operation
6

7
import java.io.IOException
8
import java.util.Properties
9
import sop.external.ExternalSOP
10
import sop.operation.Version
11

12
/** Implementation of the [Version] operation using an external SOP binary. */
13
class VersionExternal(binary: String, environment: Properties) : Version {
1✔
14

15
    private val commandList = listOf(binary, "version")
1✔
16
    private val envList = ExternalSOP.propertiesToEnv(environment)
1✔
17

18
    override fun getName(): String {
19
        val info = executeForLine(commandList)
1✔
20
        return if (info.contains(" ")) {
1✔
21
            info.substring(0, info.lastIndexOf(" "))
1✔
22
        } else {
NEW
23
            info
×
24
        }
25
    }
26

27
    override fun getVersion(): String {
28
        val info = executeForLine(commandList)
1✔
29
        return if (info.contains(" ")) {
1✔
30
            info.substring(info.lastIndexOf(" ") + 1)
1✔
31
        } else {
NEW
32
            info
×
33
        }
34
    }
35

36
    override fun getBackendVersion(): String {
37
        return executeForLines(commandList.plus("--backend"))
1✔
38
    }
39

40
    override fun getExtendedVersion(): String {
41
        return executeForLines(commandList.plus("--extended"))
1✔
42
    }
43

44
    override fun getSopSpecRevisionNumber(): Int {
NEW
45
        val revision = getSopSpecVersion()
×
NEW
46
        val firstLine =
×
NEW
47
            if (revision.contains("\n")) {
×
NEW
48
                revision.substring(0, revision.indexOf("\n"))
×
49
            } else {
NEW
50
                revision
×
51
            }
52

NEW
53
        if (!firstLine.contains("-")) {
×
NEW
54
            return -1
×
55
        }
NEW
56
        return Integer.parseInt(firstLine.substring(firstLine.lastIndexOf("-") + 1))
×
57
    }
58

59
    override fun isSopSpecImplementationIncomplete(): Boolean {
NEW
60
        return getSopSpecVersion().startsWith("~")
×
61
    }
62

63
    override fun getSopSpecImplementationRemarks(): String? {
NEW
64
        val revision = getSopSpecVersion()
×
NEW
65
        if (revision.contains("\n")) {
×
NEW
66
            revision.substring(revision.indexOf("\n")).trim().takeIf { it.isNotBlank() }
×
67
        }
NEW
68
        return null
×
69
    }
70

71
    override fun getSopSpecVersion(): String {
NEW
72
        return executeForLines(commandList.plus("--sop-spec"))
×
73
    }
74

75
    private fun executeForLine(commandList: List<String>): String {
76
        return try {
1✔
77
            val process =
1✔
78
                Runtime.getRuntime().exec(commandList.toTypedArray(), envList.toTypedArray())
1✔
79
            val result = process.inputStream.bufferedReader().readLine()
1✔
80
            ExternalSOP.finish(process)
1✔
81
            result.trim()
1✔
NEW
82
        } catch (e: IOException) {
×
83
            throw RuntimeException(e)
1✔
84
        }
85
    }
86

87
    private fun executeForLines(commandList: List<String>): String {
88
        return try {
1✔
89
            val process =
1✔
90
                Runtime.getRuntime().exec(commandList.toTypedArray(), envList.toTypedArray())
1✔
91
            val result = process.inputStream.bufferedReader().readLines().joinToString("\n")
1✔
92
            ExternalSOP.finish(process)
1✔
93
            result.trim()
1✔
NEW
94
        } catch (e: IOException) {
×
95
            throw RuntimeException(e)
1✔
96
        }
97
    }
98
}
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