Skip to content

Commit bfc3e4f

Browse files
author
Steve Ramage
committed
Resolves #90 - Add support for systemd networking
1 parent f8d0b7a commit bfc3e4f

File tree

7 files changed

+929
-3
lines changed

7 files changed

+929
-3
lines changed

src/main/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/SemanticDataRepository.kt

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import java.io.InputStreamReader
2121
import java.nio.charset.StandardCharsets
2222
import java.util.*
2323
import java.util.regex.Pattern
24-
import kotlin.collections.HashMap
2524

2625
enum class FileClass(val fileClass: String, val gperfFile: String) {
2726
UNIT_FILE("unit", "load-fragment-gperf.gperf"),
@@ -45,6 +44,10 @@ class SemanticDataRepository private constructor() {
4544

4645
private val fileClassToUndocumentedOptionInfo: MutableMap<String, MutableMap<String, Map<String, KeywordData>>>
4746

47+
private val fileClassToValidatorConfigToSectionKeys: MutableMap<String, MutableMap<String, MutableSet<String>>> = HashMap()
48+
49+
private val fileClassToSectionKeyToValidatorConfig: MutableMap<String, MutableMap<String, String>> = HashMap()
50+
4851
class KeywordData {
4952
var declaredUnderKeyword: String? = null
5053
var declaredInFile: String? = null
@@ -68,6 +71,9 @@ class SemanticDataRepository private constructor() {
6871
for (fileClass in FileClass.entries) {
6972
val name = SEMANTIC_DATA_ROOT + fileClass.gperfFile
7073
val resource = this.javaClass.classLoader.getResourceAsStream(name)
74+
fileClassToValidatorConfigToSectionKeys.put(fileClass.fileClass, HashMap())
75+
fileClassToSectionKeyToValidatorConfig.put(fileClass.fileClass, HashMap())
76+
7177
if (resource != null) {
7278
try {
7379
BufferedReader(InputStreamReader(resource)).use { fr ->
@@ -78,7 +84,8 @@ class SemanticDataRepository private constructor() {
7884
val section = m.group("Section")
7985
val key = m.group("Key")
8086
val validator = m.group("Validator")
81-
val mysteryValue = m.group("MysteryColumn")
87+
val mysteryValue = m.group("MysteryColumn1")
88+
val mysteryValue2 = m.group("MysteryColumn2")
8289
when (mysteryValue) {
8390
LEGACY_PARAMETERS_KEY, EXPERIMENTAL_PARAMETERS_KEY -> {}
8491

@@ -88,6 +95,22 @@ class SemanticDataRepository private constructor() {
8895
fileClassToSectionToKeyAndValidatorMap.computeIfAbsent(fileClass.fileClass, { _: String? -> HashMap() }).computeIfAbsent(intern(cache, section)) { _: String? -> HashMap() }[intern(cache, key)] = intern(cache2, myValidator)
8996
}
9097
}
98+
99+
if (mysteryValue2 != "0") {
100+
101+
val validatorConfigKey = mysteryValue + "/" + mysteryValue2
102+
val validatorConfigToSectionKey = fileClassToValidatorConfigToSectionKeys.get(fileClass.fileClass)
103+
validatorConfigToSectionKey?.putIfAbsent(validatorConfigKey, HashSet())
104+
105+
val set = validatorConfigToSectionKey?.get(validatorConfigKey)
106+
107+
set?.add("$section.$key")
108+
109+
val sectionKeyToValidatorConfig = fileClassToSectionKeyToValidatorConfig.get(fileClass.fileClass)
110+
111+
sectionKeyToValidatorConfig?.put("$section.$key", validatorConfigKey)
112+
}
113+
91114
}
92115
}
93116
}
@@ -99,6 +122,7 @@ class SemanticDataRepository private constructor() {
99122
}
100123
}
101124

125+
102126
validatorMap = HashMap()
103127
validatorMap.putAll(BooleanOptionValue.validators)
104128
validatorMap.putAll(TriStateOptionValue.validators)
@@ -172,6 +196,16 @@ class SemanticDataRepository private constructor() {
172196
return Collections.unmodifiableSet(fileClassToSectionNameToKeyValuesFromDoc.getOrDefault(fileClass, emptyMap()).keys)
173197
}
174198

199+
fun getAliasesForSectionKey(fileClass: String, sectionKey: String): Set<String> {
200+
201+
val validatorConfig = fileClassToSectionKeyToValidatorConfig.getOrDefault(fileClass, emptyMap())[sectionKey]
202+
203+
if (validatorConfig == null) {
204+
return emptySet()
205+
}
206+
207+
return Collections.unmodifiableSet(fileClassToValidatorConfigToSectionKeys.getOrDefault(fileClass, emptyMap()).getOrDefault(validatorConfig, emptySet()))
208+
}
175209

176210
/**
177211
* Returns the allowed keywords by a given section name.
@@ -709,7 +743,7 @@ unit types. These options are documented in <a href="http://man7.org/linux/man-p
709743
companion object {
710744
private val LOG = Logger.getInstance(SemanticDataRepository::class.java)
711745
const val SEMANTIC_DATA_ROOT = "net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/"
712-
private const val GPERF_REGEX = """^(?<Section>\w+)\.(?<Key>\w+)\s*,\s*(?<Validator>\w+)\s*,\s*(?<MysteryColumn>\w+)\s*,.+$"""
746+
private const val GPERF_REGEX = """^(?<Section>\w+)\.(?<Key>\w+)\s*,\s*(?<Validator>\w+)\s*,\s*(?<MysteryColumn1>\w+)\s*,\s*(?<MysteryColumn2>.+)$"""
713747
private val LINE_MATCHER = Pattern.compile(GPERF_REGEX)
714748
private val NULL_VALIDATOR = Validator("NULL", "0")
715749

Lines changed: 187 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)