Skip to content

Commit 8a3b8d5

Browse files
author
Steve Ramage
committed
Resolves #90 - Add support for systemd networking
1 parent f60965a commit 8a3b8d5

File tree

9 files changed

+947
-6
lines changed

9 files changed

+947
-6
lines changed

buildSrc/src/main/groovy/GenerateDataFromManPages.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ class GenerateDataFromManPages extends DefaultTask {
647647

648648
NodeList paragraphList = (NodeList)xpath.evaluate("description/paragraph", parameterNode, XPathConstants.NODESET)
649649

650-
Matcher match = (variableName =~ /(\w+)=(.*)/)
650+
Matcher match = (variableName =~ /([^=]+)=(.*)/)
651651

652652
match.find()
653653
if (match.groupCount() != 2) {

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

Lines changed: 39 additions & 4 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,17 +71,22 @@ 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 ->
7480
var line: String?
7581
while (fr.readLine().also { line = it } != null) {
76-
val m = LINE_MATCHER.matcher(line)
82+
val lineWithoutComments = line?.replace(Regex("/\\*.*?\\*/"), "")
83+
val m = LINE_MATCHER.matcher(lineWithoutComments)
7784
if (m.find()) {
7885
val section = m.group("Section")
7986
val key = m.group("Key")
8087
val validator = m.group("Validator")
81-
val mysteryValue = m.group("MysteryColumn")
88+
val mysteryValue = m.group("MysteryColumn1")
89+
val mysteryValue2 = m.group("MysteryColumn2")
8290
when (mysteryValue) {
8391
LEGACY_PARAMETERS_KEY, EXPERIMENTAL_PARAMETERS_KEY -> {}
8492

@@ -88,6 +96,22 @@ class SemanticDataRepository private constructor() {
8896
fileClassToSectionToKeyAndValidatorMap.computeIfAbsent(fileClass.fileClass, { _: String? -> HashMap() }).computeIfAbsent(intern(cache, section)) { _: String? -> HashMap() }[intern(cache, key)] = intern(cache2, myValidator)
8997
}
9098
}
99+
100+
if (mysteryValue2 != "0") {
101+
102+
val validatorConfigKey = mysteryValue + "/" + mysteryValue2
103+
val validatorConfigToSectionKey = fileClassToValidatorConfigToSectionKeys.get(fileClass.fileClass)
104+
validatorConfigToSectionKey?.putIfAbsent(validatorConfigKey, HashSet())
105+
106+
val set = validatorConfigToSectionKey?.get(validatorConfigKey)
107+
108+
set?.add("$section.$key")
109+
110+
val sectionKeyToValidatorConfig = fileClassToSectionKeyToValidatorConfig.get(fileClass.fileClass)
111+
112+
sectionKeyToValidatorConfig?.put("$section.$key", validatorConfigKey)
113+
}
114+
91115
}
92116
}
93117
}
@@ -99,6 +123,7 @@ class SemanticDataRepository private constructor() {
99123
}
100124
}
101125

126+
102127
validatorMap = HashMap()
103128
validatorMap.putAll(BooleanOptionValue.validators)
104129
validatorMap.putAll(TriStateOptionValue.validators)
@@ -172,6 +197,16 @@ class SemanticDataRepository private constructor() {
172197
return Collections.unmodifiableSet(fileClassToSectionNameToKeyValuesFromDoc.getOrDefault(fileClass, emptyMap()).keys)
173198
}
174199

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

176211
/**
177212
* Returns the allowed keywords by a given section name.
@@ -709,7 +744,7 @@ unit types. These options are documented in <a href="http://man7.org/linux/man-p
709744
companion object {
710745
private val LOG = Logger.getInstance(SemanticDataRepository::class.java)
711746
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*,.+$"""
747+
private const val GPERF_REGEX = """^(?<Section>[a-zA-Z0-9_-]+)\.(?<Key>[a-zA-Z0-9_-]+)\s*,\s*(?<Validator>\w+)\s*,\s*(?<MysteryColumn1>\w+)\s*,\s*(?<MysteryColumn2>.+)$"""
713748
private val LINE_MATCHER = Pattern.compile(GPERF_REGEX)
714749
private val NULL_VALIDATOR = Validator("NULL", "0")
715750

Lines changed: 187 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)