Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# gradle

.kotlin/
.gradle/
build/
out/
Expand Down Expand Up @@ -41,3 +42,7 @@ docs/web/[0-9]*
# Affinity Photo
*.af~lock~
*.af~lock~:com.dropbox.ignored

node_modules/
**/.vitepress/cache/
**/.vitepress/dist/
51 changes: 44 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ val distDirFile = distDir.asFile
val docsBuildDir = layout.buildDirectory.dir("docs").get().asFile
val docletJarFile = layout.projectDirectory.file("buildSrc/build/libs/buildSrc.jar").asFile

repositories {
mavenCentral()
}

val docletClasspath = configurations.detachedConfiguration(
dependencies.create("com.google.code.gson:gson:2.9.0")
)

// Root-level properties (available in root gradle.properties)
val modIdProvider = providers.gradleProperty("mod_id")
val channelProvider = providers.gradleProperty("channel").orElse("release")
Expand Down Expand Up @@ -109,8 +117,8 @@ if (isVersionedProject && hasMinecraftVersion) {
source(documentationSources)
classpath = documentationClasspath
destinationDir = File(docsBuildDir, "python/JsMacrosAC")
options.doclet = "com.jsmacrosce.doclet.pydoclet.Main"
options.docletpath = mutableListOf(docletJarFile)
options.doclet = "com.jsmacrosce.doclet.core.pydoclet.Main"
options.docletpath = (listOf(docletJarFile) + docletClasspath.files).toMutableList()
(options as CoreJavadocOptions).addStringOption("v", project.version.toString())
}

Expand All @@ -128,8 +136,8 @@ if (isVersionedProject && hasMinecraftVersion) {
source(documentationSources)
classpath = documentationClasspath
destinationDir = File(docsBuildDir, "typescript/headers")
options.doclet = "com.jsmacrosce.doclet.tsdoclet.Main"
options.docletpath = mutableListOf(docletJarFile)
options.doclet = "com.jsmacrosce.doclet.core.tsdoclet.Main"
options.docletpath = (listOf(docletJarFile) + docletClasspath.files).toMutableList()
(options as CoreJavadocOptions).addStringOption("v", project.version.toString())
}

Expand All @@ -147,8 +155,8 @@ if (isVersionedProject && hasMinecraftVersion) {
source(documentationSources)
classpath = documentationClasspath
destinationDir = File(docsBuildDir, "web")
options.doclet = "com.jsmacrosce.doclet.webdoclet.Main"
options.docletpath = mutableListOf(docletJarFile)
options.doclet = "com.jsmacrosce.doclet.core.webdoclet.Main"
options.docletpath = (listOf(docletJarFile) + docletClasspath.files).toMutableList()
(options as CoreJavadocOptions).addStringOption("v", project.version.toString())
(options as CoreJavadocOptions).addStringOption("mcv", mcVersion)
(options as StandardJavadocDocletOptions).links(
Expand All @@ -170,10 +178,39 @@ if (isVersionedProject && hasMinecraftVersion) {
}
}

tasks.register("generateVitepressDoc", Javadoc::class.java) {
group = "documentation"
description = "Generates the vitepress documentation for the project"
source(documentationSources)
classpath = documentationClasspath
destinationDir = File(docsBuildDir, "vitepress")
options.doclet = "com.jsmacrosce.doclet.core.mddoclet.Main"
options.docletpath = (listOf(docletJarFile) + docletClasspath.files).toMutableList()
(options as CoreJavadocOptions).addStringOption("v", project.version.toString())
(options as CoreJavadocOptions).addStringOption("mcv", mcVersion)
(options as StandardJavadocDocletOptions).links(
"https://docs.oracle.com/javase/8/docs/api/",
"https://www.javadoc.io/doc/org.slf4j/slf4j-api/1.7.30/",
"https://javadoc.io/doc/com.neovisionaries/nv-websocket-client/latest/"
)
}

tasks.register("copyVitepressDoc", Copy::class.java) {
group = "documentation"
description = "Copies the vitepress documentation to the build folder"
dependsOn("generateVitepressDoc")
from(rootProject.file("docs/vitepress"))
into(File(docsBuildDir, "vitepress"))
inputs.property("version", project.version.toString())
filesMatching("index.md") {
expand(mapOf("version" to project.version.toString()))
}
}

tasks.register("createDistDocs", Copy::class.java) {
group = "distribution"
description = "Packages generated documentation into the dist directory"
dependsOn("prepareDist", "copyPyDoc", "copyTSDoc", "copyWebDoc")
dependsOn("prepareDist", "copyPyDoc", "copyTSDoc", "copyWebDoc", "copyVitepressDoc")
from(docsBuildDir)
into(distDirFile)
}
Expand Down
17 changes: 17 additions & 0 deletions buildSrc/src/main/java/com/jsmacrosce/doclet/DocletCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.jsmacrosce.doclet;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Documented
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface DocletCategory {
/**
* The category name used for organizing classes or events.
*/
String value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.jsmacrosce.doclet.core;

import com.sun.source.doctree.DocCommentTree;
import com.sun.source.doctree.DocTree;
import com.sun.source.doctree.ParamTree;
import com.sun.source.doctree.ReferenceTree;
import com.sun.source.doctree.ReturnTree;
import com.sun.source.doctree.SeeTree;
import com.sun.source.doctree.SinceTree;
import com.sun.source.doctree.TextTree;
import com.sun.source.doctree.DeprecatedTree;
import com.sun.source.doctree.LinkTree;
import com.sun.source.doctree.LiteralTree;
import com.sun.source.util.DocTrees;
import com.jsmacrosce.doclet.core.model.DocComment;
import com.jsmacrosce.doclet.core.model.DocTag;
import com.jsmacrosce.doclet.core.model.DocTagKind;

import javax.lang.model.element.Element;
import java.util.ArrayList;
import java.util.List;

public class BasicDocCommentParser implements DocCommentParser {
private final DocTrees docTrees;

public BasicDocCommentParser(DocTrees docTrees) {
this.docTrees = docTrees;
}

@Override
public DocComment parse(Element element) {
DocCommentTree tree = docTrees.getDocCommentTree(element);
boolean isDeprecated = element.getAnnotation(Deprecated.class) != null;
if (tree == null) {
if (isDeprecated) {
return new DocComment("", "", List.of(new DocTag(DocTagKind.DEPRECATED, null, "")));
}
return new DocComment("", "", List.of());
}

String summary = renderText(tree.getFirstSentence());
String description = renderText(tree.getFullBody());
List<DocTag> tags = new ArrayList<>();

for (DocTree tag : tree.getBlockTags()) {
switch (tag.getKind()) {
case PARAM -> {
ParamTree param = (ParamTree) tag;
DocTagKind kind = param.isTypeParameter() ? DocTagKind.TEMPLATE : DocTagKind.PARAM;
tags.add(new DocTag(kind, param.getName().getName().toString(), renderText(param.getDescription())));
}
case RETURN -> {
ReturnTree ret = (ReturnTree) tag;
tags.add(new DocTag(DocTagKind.RETURN, null, renderText(ret.getDescription())));
}
case SINCE -> {
SinceTree since = (SinceTree) tag;
tags.add(new DocTag(DocTagKind.SINCE, null, renderText(since.getBody())));
}
case DEPRECATED -> {
DeprecatedTree dep = (DeprecatedTree) tag;
tags.add(new DocTag(DocTagKind.DEPRECATED, null, renderText(dep.getBody())));
}
case SEE -> {
SeeTree see = (SeeTree) tag;
for (DocTree ref : see.getReference()) {
if (ref.getKind() == DocTree.Kind.REFERENCE) {
String signature = ((ReferenceTree) ref).getSignature();
tags.add(new DocTag(DocTagKind.SEE, null, signature));
} else {
tags.add(new DocTag(DocTagKind.SEE, null, ref.toString()));
}
}
}
default -> tags.add(new DocTag(DocTagKind.OTHER, null, tag.toString()));
}
}

if (isDeprecated && tags.stream().noneMatch(tag -> tag.kind() == DocTagKind.DEPRECATED)) {
tags.add(new DocTag(DocTagKind.DEPRECATED, null, ""));
}

return new DocComment(summary, description, tags);
}

private String renderText(List<? extends DocTree> trees) {
StringBuilder builder = new StringBuilder();
for (DocTree tree : trees) {
switch (tree.getKind()) {
case TEXT -> builder.append(((TextTree) tree).getBody());
case CODE -> builder.append("`").append(((LiteralTree) tree).getBody()).append("`");
case LINK, LINK_PLAIN -> {
String signature = ((LinkTree) tree).getReference().getSignature();
builder.append("{@link ").append(signature).append("}");
}
default -> builder.append(tree.toString());
}
}
return builder.toString().trim();
}
}
Loading