diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 882a2d1b6..439327dab 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -108,12 +108,17 @@ tasks.create("tectonicDocs") { } } } + + val linksAll = HashMap>() + sources.forEach { (name, unit) -> val doc = StringBuilder() doc.append("# ${generify(name, refactor)}\n") var applicable = false + val links = HashSet() + unit.getClassByName(name).ifPresent { declaration -> applicable = scanForParent(sources, declaration, "ConfigTemplate", "ValidatedConfigTemplate", "ObjectTemplate") if(applicable) println("Validated $name") @@ -122,13 +127,13 @@ tasks.create("tectonicDocs") { } declaration.extendedTypes.forEach { if (!it.name.asString().equals("AbstractableTemplate")) { - doc.append("Inherits from ${parseTypeLink(it, refactor, false)} \n \n") + doc.append("Inherits from ${parseTypeLink(it, refactor, links, false)} \n \n") } } if (children.containsKey(name)) { doc.append("Children:\n") children[name]!!.forEach { - doc.append("* ${parseTypeLink(it.name, refactor)}\n") + doc.append("* ${parseTypeLink(it.name, refactor, links)}\n") } doc.append(" \n\n") } @@ -143,7 +148,7 @@ tasks.create("tectonicDocs") { doc.append("* Default value: ${fieldDeclaration.variables[0]} \n") } val type = fieldDeclaration.commonType - doc.append("* Type: ${parseTypeLink(type, refactor)} \n") + doc.append("* Type: ${parseTypeLink(type, refactor, links)} \n") doc.append("\n") fieldDeclaration.javadoc.ifPresent { @@ -155,22 +160,33 @@ tasks.create("tectonicDocs") { val s = doc.toString() if (s.isNotEmpty() && applicable) { docs[generify(name, refactor)] = s + linksAll[name] = links } } println("Done. Generated ${docs.size} files") val docsDir = File(buildDir, "tectonic") docsDir.mkdirs() + val files = HashSet() + docs.forEach { val save = File(docsDir, "${it.key}.md") + files.add(it.key) if (save.exists()) save.delete() save.createNewFile() save.writeText(it.value) } sourceSets["tectonic"].resources.forEach { + files.add(it.name.substringBefore('.')) it.copyTo(File(docsDir, it.name), true) } + + linksAll.forEach { (file, links) -> + links.forEach { + if(!files.contains(it)) println("WARNING: Dead link to \"$it\" in file \"$file\"") + } + } } fun scanForParent(map: HashMap, current: ClassOrInterfaceDeclaration, vararg parent: String): Boolean { @@ -189,7 +205,7 @@ fun scanForParent(map: HashMap, current: ClassOrInterfa return false } -fun parseTypeLink(type: Node, refactor: Map, generic: Boolean = true): String { +fun parseTypeLink(type: Node, refactor: Map, links: MutableSet, generic: Boolean = true): String { val st = parseType(type, refactor) if (type is Type && type.childNodes.size > 1 && generic) { @@ -197,9 +213,10 @@ fun parseTypeLink(type: Node, refactor: Map, generic: Boolean = val builder = StringBuilder() builder.append("[$outer](./$outer)\\<") + links.add(outer) for (i in 1 until type.childNodes.size) { - builder.append(parseTypeLink(type.childNodes[i], refactor)) + builder.append(parseTypeLink(type.childNodes[i], refactor, links, generic)) if (i != type.childNodes.size - 1) builder.append(", ") } @@ -207,6 +224,7 @@ fun parseTypeLink(type: Node, refactor: Map, generic: Boolean = return builder.toString() } + links.add(st) return "[$st](./$st)" }