Save all of the config comments and include in JAR

This commit is contained in:
Norbi Peti 2021-04-06 02:25:23 +02:00
parent 74bce1ecf9
commit ad3bd451ba
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 32 additions and 16 deletions

View file

@ -45,44 +45,61 @@ assemblyMergeStrategy in assembly := {
case x => (assemblyMergeStrategy in assembly).value(x) case x => (assemblyMergeStrategy in assembly).value(x)
} }
val getConfigComments = TaskKey[Unit]("getConfigComments") val saveConfigComments = TaskKey[Seq[File]]("saveConfigComments")
getConfigComments := { saveConfigComments := {
val sv = (Compile / sources).value val sv = (Compile / sources).value
val cdataRegex = Pattern.compile("(?:def|val|var) (\\w+)(?::[^=]+)? = get(?:I)?Config") val cdataRegex = Pattern.compile("(?:def|val|var) (\\w+)(?::[^=]+)? = (?:(?:get(?:I)?Config)|(?:DPUtils.\\w+Data))") //Hack: DPUtils
val clRegex = Pattern.compile("class (\\w+) extends (\\w+)") val clRegex = Pattern.compile("class (\\w+) extends (\\w+)")
val objRegex = Pattern.compile("object (\\w+)")
val config = new YamlConfiguration() val config = new YamlConfiguration()
for (file <- sv) { for (file <- sv) {
Using(Source.fromFile(file)) { src => Using(Source.fromFile(file)) { src =>
var pkg: String = null
var clKey: String = null var clKey: String = null
var comment: String = null var comment: String = null
var justCommented: Boolean = false var justCommented: Boolean = false
for (line <- src.getLines) { for (line <- src.getLines) {
val clMatcher = clRegex.matcher(line) val clMatcher = clRegex.matcher(line)
if (line.startsWith("package")) { if (clKey == null && clMatcher.find()) { //First occurrence
pkg = line.substring("package ".length)
} else if (line.contains("class") && pkg != null && clKey == null && clMatcher.find()) { //First occurrence
clKey = if (clMatcher.group(2).contains("Component")) clKey = if (clMatcher.group(2).contains("Component"))
"component." + clMatcher.group(1) "components." + clMatcher.group(1)
else else
"global" "global"
} else if (line.contains("/**") && clKey != null) { /*println("Class: "+clKey)
println("Comment: "+comment)
println("Just commented: "+justCommented)
if (comment != null) { //Not checking justCommented because the object may have the comment and not extend anything
config.set(s"$clKey.generalDescriptionInsteadOfAConfig", comment.trim)
justCommented = false
comment = null
println("Found class comment for " + clKey)
}*/
} else if (line.contains("/**")) {
comment = "" comment = ""
justCommented = false justCommented = false
} else if (line.contains("*/") && comment != null) } else if (line.contains("*/") && comment != null)
justCommented = true justCommented = true
else if (comment != null) { else if (comment != null) {
if (justCommented) { if (justCommented) {
val matcher = cdataRegex.matcher(line) if (clKey != null) {
if (matcher.find()) val matcher = cdataRegex.matcher(line)
config.set(s"$clKey.${matcher.group(1)}", comment.trim) if (matcher.find())
config.set(s"$clKey.${matcher.group(1)}", comment.trim)
}
else {
val matcher = objRegex.matcher(line)
if (matcher.find())
config.set(s"${matcher.group(1)}.generalDescriptionInsteadOfAConfig", comment.trim)
}
justCommented = false justCommented = false
comment = null comment = null
} }
else comment += line.replaceFirst("^\\s*\\*\\s+", "") + "\n" else comment += line.replaceFirst("^\\s*\\*\\s+", "") + "\n"
} }
} }
config.save("configHelp.yml") config.save("target/configHelp.yml")
}.recover[Unit]({ case t => t.printStackTrace() }) }.recover[Unit]({ case t => t.printStackTrace() })
} }
Seq(file("target/configHelp.yml"))
} }
resourceGenerators in Compile += saveConfigComments

View file

@ -38,9 +38,8 @@ class MinecraftChatModule extends Component[DiscordPlugin] {
/** /**
* A list of commands that can be used in public chats - Warning: Some plugins will treat players as OPs, always test before allowing a command! * A list of commands that can be used in public chats - Warning: Some plugins will treat players as OPs, always test before allowing a command!
*/ */
val whitelistedCommands: ConfigData[util.ArrayList[String]] = val whitelistedCommands: ConfigData[util.ArrayList[String]] = getConfig.getData("whitelistedCommands",
getConfig.getData("whitelistedCommands", () => Lists.newArrayList("list", "u", "shrug", "tableflip", "unflip", "mwiki", "yeehaw", "lenny", "rp", "plugins"))
() => Lists.newArrayList("list", "u", "shrug", "tableflip", "unflip", "mwiki", "yeehaw", "lenny", "rp", "plugins"))
/** /**
* The channel to use as the public Minecraft chat - everything public gets broadcasted here * The channel to use as the public Minecraft chat - everything public gets broadcasted here