Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fefee0a
commit 181098f
Showing
3 changed files
with
170 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
open class ToolsNewDiagnostic @javax.inject.Inject constructor(objects: ObjectFactory) : DefaultTask() { | ||
|
||
@Option(option = "key", description = "Diagnostic key (required)") | ||
private var key = ""; | ||
|
||
@Option(option = "nameRu", description = "Diagnostic name in Russian (optional)") | ||
private var nameRu = "<Имя диагностики>"; | ||
|
||
@Option(option = "nameEn", description = "Diagnostic name in English (optional)") | ||
private var nameEn = "<Diagnostic name>"; | ||
|
||
fun setKey(key: String) { | ||
this.key = key; | ||
} | ||
|
||
fun setNameRu(nameRu: String) { | ||
this.nameRu = nameRu; | ||
} | ||
|
||
fun setNameEn(nameEn: String) { | ||
this.nameEn = nameEn; | ||
} | ||
|
||
@OutputDirectory | ||
val outputDir: DirectoryProperty = objects.directoryProperty(); | ||
|
||
private fun createFile(path: String, text: String) { | ||
val f = File(path); | ||
f.writeText(text, charset("UTF-8")); | ||
logger.quiet(" Created file '{}'", f.absoluteFile); | ||
} | ||
|
||
@TaskAction | ||
fun createDiagnostic() { | ||
if(key.isEmpty()){ | ||
throw Throwable("Empty diagnostic key") | ||
} | ||
logger.quiet("Creating new diagnostics files with the key '{}'", key); | ||
val srcPath = File(outputDir.get().asFile.path, "src"); | ||
val packPath = "org/github/_1c_syntax/bsl/languageserver/diagnostics"; | ||
val docPath = File(outputDir.get().asFile.path, "docs"); | ||
createFile("${docPath}/diagnostics/${key}.md", | ||
"# ${nameRu}\n\n<Описание диагностики>\n\n## Параметры\n\n" + | ||
"* `ИмяПараметра` - `ТипПараметра` - Описание параметра\n"); | ||
createFile("${docPath}/en/diagnostics/${key}.md", | ||
"# ${nameEn}\n\n<Diagnostic description>\n\n## Params\n\n" + | ||
"* `ParamName` - `ParamType` - Param description\n"); | ||
|
||
createFile("${srcPath}/main/java/${packPath}/${key}Diagnostic.java", | ||
"package org.github._1c_syntax.bsl.languageserver.diagnostics;\n\n" + | ||
"@DiagnosticMetadata(\n\ttype = DiagnosticType.CODE_SMELL," + | ||
"\n\tseverity = DiagnosticSeverity.INFO,\n\tminutesToFix = 1\n)\n" + | ||
"public class ${key}Diagnostic implements QuickFixProvider, BSLDiagnostic {\n}\n"); | ||
|
||
createFile("${srcPath}/test/java/${packPath}/${key}DiagnosticTest.java", | ||
"package org.github._1c_syntax.bsl.languageserver.diagnostics;\n\n" + | ||
"public class ${key}DiagnosticTest extends AbstractDiagnosticTest<${key}Diagnostic> {\n" + | ||
"\t${key}DiagnosticTest() {\n\t\tsuper(${key}Diagnostic.class);\n\t}\n\n" + | ||
"\t@Test\n\tvoid test() {\n\t}\n}\n"); | ||
|
||
createFile("${srcPath}/main/resources/${packPath}/${key}Diagnostic_ru.properties", | ||
"diagnosticMessage=<Сообщение>\ndiagnosticName=${nameRu}\n"); | ||
createFile("${srcPath}/main/resources/${packPath}/${key}Diagnostic_en.properties", | ||
"diagnosticMessage=<Message>\ndiagnosticName=${nameEn}\n"); | ||
|
||
createFile("${srcPath}/test/resources/diagnostics/${key}Diagnostic.bsl", "\n"); | ||
} | ||
} | ||
|
||
tasks.register<ToolsNewDiagnostic>("newDiagnostic") { | ||
description = "Creating new diagnostics files"; | ||
group = "Developer tools"; | ||
outputDir.set(project.layout.projectDirectory); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import java.io.File | ||
|
||
open class ToolsUpdateDiagnosticsIndex @javax.inject.Inject constructor(objects: ObjectFactory) : DefaultTask() { | ||
|
||
private var pathPack = "org/github/_1c_syntax/bsl/languageserver/diagnostics"; | ||
private var namePattern = Regex("^diagnosticName\\s*=\\s*(.*)$", | ||
setOf(RegexOption.IGNORE_CASE, RegexOption.MULTILINE)); | ||
|
||
private var enabledPattern = Regex("^\\s*@DiagnosticMetadata\\([.\\s\\w\\W]*?\\s+activatedByDefault\\s*?=" + | ||
"\\s*?(true|false)\\s*?[.\\s\\w\\W]*?\\)\$", | ||
setOf(RegexOption.IGNORE_CASE, RegexOption.MULTILINE)); | ||
|
||
@OutputDirectory | ||
val outputDir: DirectoryProperty = objects.directoryProperty(); | ||
|
||
private fun getName(key: String, lang: String): String { | ||
val fileP = File(outputDir.get().asFile.path, | ||
"src/main/resources/${pathPack}/${key}Diagnostic_${lang}.properties"); | ||
if(fileP.exists()) { | ||
val match = namePattern.find(fileP.readText(charset("UTF-8"))); | ||
if(match != null && match.groups.isNotEmpty()) { | ||
return match.groups[1]?.value.toString(); | ||
} | ||
} | ||
logger.quiet("File '{}' not exist", fileP.path); | ||
return ""; | ||
} | ||
|
||
private fun getReadme(key: String, lang: String): String { | ||
val docPath = File(outputDir.get().asFile.path, "docs/${lang}diagnostics"); | ||
val readme = File(docPath.path, "${key}.md"); | ||
if(readme.exists()) { | ||
return "${docPath.name}/${readme.name}"; | ||
} | ||
logger.quiet("File '{}' not exist", readme.path); | ||
return ""; | ||
} | ||
|
||
private fun writeIndex(indexText: String, lang: String) { | ||
val indexPath = File(outputDir.get().asFile.path, "docs/${lang}index.md"); | ||
val text = indexPath.readText(charset("UTF-8")); | ||
|
||
var header = "### Список реализованных диагностик"; | ||
var table = "| Ключ | Название | Включена по умолчанию |\n| --- | --- | :-: |"; | ||
if(lang != "") { | ||
header = "### Implemented diagnostics"; | ||
table = "| Key | Name| Enabled by default |\n| --- | --- | :-: |"; | ||
} | ||
val indexHeader = text.indexOf(header); | ||
indexPath.writeText(text.substring(0, indexHeader - 1) + "\n${header}\n\n${table}${indexText}", | ||
charset("UTF-8")); | ||
} | ||
|
||
@TaskAction | ||
fun updateIndex() { | ||
logger.quiet("Update diagnostics index"); | ||
var indexRu = ""; | ||
var indexEn = ""; | ||
File(outputDir.get().asFile.path, "src/main/java/${pathPack}") | ||
.walkBottomUp() | ||
.filter { | ||
it.name.endsWith(".java") | ||
}.forEach { | ||
val text = it.readText(charset("UTF-8")); | ||
if(text.indexOf("@DiagnosticMetadata") == -1) { | ||
logger.quiet("File skipped {}", it); | ||
} else { | ||
val key = it.name.substring(0, it.name.indexOf("Diagnostic")); | ||
val nameRu = getName(key, "ru"); | ||
val nameEn = getName(key, "en"); | ||
var enabled = true; | ||
val match = enabledPattern.find(text); | ||
if(match != null && match.groups.isNotEmpty()) { | ||
enabled = match.groups[1]?.value?.toBoolean() ?: true; | ||
} | ||
val enabledRu = if(enabled) "Да" else "Нет"; | ||
val enabledEn = if(enabled) "Yes" else "No"; | ||
val readmeRu = getReadme(key, ""); | ||
val readmeEn = getReadme(key, "en/"); | ||
indexRu += "\n| [${key}](${readmeRu}) | $nameRu | $enabledRu |"; | ||
indexEn += "\n| [${key}](${readmeEn}) | $nameEn | $enabledEn |"; | ||
} | ||
} | ||
writeIndex(indexRu, ""); | ||
writeIndex(indexEn, "en/"); | ||
} | ||
} | ||
|
||
tasks.register<ToolsUpdateDiagnosticsIndex>("updateDiagnosticsIndex") { | ||
description = "Updates diagnostics index after changes"; | ||
group = "Developer tools"; | ||
outputDir.set(project.layout.projectDirectory); | ||
}; |