Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/PRSDM-1877 update javadoc importer to work with hugo #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
11 changes: 9 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ task copyDist(type: Copy) {
}
compileJava.dependsOn copyDist

test {
useJUnitPlatform()
}

dependencies {
compile 'commons-cli:commons-cli:1.4'
compile files("${System.properties['java.home']}/../lib/tools.jar")
implementation('commons-cli:commons-cli:1.5.0')
implementation(files("${System.properties['java.home']}/../lib/tools.jar"))
implementation("org.yaml:snakeyaml:1.30")
testImplementation(platform("org.junit:junit-bom:5.8.2"))
testImplementation("org.junit.jupiter:junit-jupiter")
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu May 25 16:36:48 SAST 2017
#Fri Feb 11 10:50:42 SAST 2022
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
33 changes: 16 additions & 17 deletions src/main/java/net/spandigital/presidium/ClassWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@
*/
public class ClassWriter {

private RootDoc root;
private Path destination;
private String sectionUrl;
private final RootDoc root;
private final Path destination;
private final String sectionUrl;
private Set<String> knownQualifiers;

public static ClassWriter init(RootDoc root, Path destination, String sectionUrl) {
ClassWriter writer = new ClassWriter();
writer.root = root;
writer.destination = destination;
writer.sectionUrl = sectionUrl;
return writer;
public ClassWriter(RootDoc root, Path destination, String sectionUrl) {
this.root = root;
this.destination = destination;
this.sectionUrl = sectionUrl;
}


public void writeAll() throws IOException {

List<ClassDoc> classes = Arrays.stream(root.classes())
Expand All @@ -58,7 +57,7 @@ public void writeAll() throws IOException {

public void write(Path file, ClassDoc cls) throws IOException {
FileWriter.write(file,
Markdown.join(
Markdown.lines(
frontMatter(cls.name()),
header(cls),
newLine(),
Expand All @@ -74,7 +73,7 @@ public void write(Path file, ClassDoc cls) throws IOException {

private String header(ClassDoc cls) {
String containingPackage = cls.containingPackage().name();
return Markdown.join(
return Markdown.lines(
anchor(cls),
Markdown.siteLink(containingPackage, sectionUrl + "/packages/#" + containingPackage),
h1(title(cls))
Expand Down Expand Up @@ -118,7 +117,7 @@ private static ClassType classType(ClassDoc cls) {

private String constructorList(ClassDoc cls) {
return cls.constructors().length == 0 ? "" :
Markdown.join(
Markdown.lines(
h1("Constructor Summary"),
tableHeader("Modifiers", "Constructor"),
Arrays.stream(cls.constructors())
Expand All @@ -131,7 +130,7 @@ private String constructorList(ClassDoc cls) {

private String methodList(ClassDoc cls) {
return (cls.methods().length == 0) ? "" :
Markdown.join(
Markdown.lines(
h1("Method Summary"),
tableHeader("Modifiers", "Return", "Method"),
Arrays.stream(cls.methods())
Expand All @@ -145,7 +144,7 @@ private String methodList(ClassDoc cls) {
private String classDescription(ClassDoc cls) {
String comment = docComment(cls);
return (comment.length() == 0) ? "" :
Markdown.join(
Markdown.lines(
h1("Description"),
comment
);
Expand All @@ -171,7 +170,7 @@ private String methodLink(ExecutableMemberDoc method) {

private String constructorDetail(ClassDoc cls) {
return cls.constructors().length == 0 ? "" :
Markdown.join(
Markdown.lines(
h1("Constructor Detail"),
Arrays.stream(cls.constructors())
.map(c -> memberDetail(c))
Expand All @@ -182,7 +181,7 @@ private String constructorDetail(ClassDoc cls) {

private String methodDetail(ClassDoc cls) {
return cls.methods().length == 0 ? "" :
Markdown.join(
Markdown.lines(
h1("Method Detail"),
anchor(cls),
Arrays.stream(cls.methods())
Expand All @@ -193,7 +192,7 @@ private String methodDetail(ClassDoc cls) {
}

private String memberDetail(ExecutableMemberDoc member) {
return Markdown.join(
return Markdown.lines(
hr(),
anchor(member),
h2(member.name()),
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/net/spandigital/presidium/Doclet.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;

@SuppressWarnings("unused")
public class Doclet {

private static final List<String> opts = List.of("-d", "-t", "-u");//, "-doctitle", "-windowtitle");
Expand All @@ -20,17 +21,15 @@ public static boolean start(RootDoc root) throws IOException {
Path destination = Paths.get(option(root, "-d", "docs"));
String title = option(root, "-t", "javadoc");
String url = option(root, "-u", "reference/javadoc");

clean(destination);

Files.createDirectories(destination);
FileWriter.writeIndex(destination, title);
PackageWriter.init(root, destination.resolve("01-Packages"), url).writeAll();
ClassWriter.init(root, destination.resolve("02-Classes"), url).writeAll();

new PackageWriter(root, destination.resolve("packages"), url).writeAll();
new ClassWriter(root, destination.resolve("classes"), url).writeAll();
return true;
}


/**
* Allow custom doclet opts
*
Expand All @@ -54,7 +53,7 @@ private static String option(RootDoc root, String option, String defaultValue) {
}

private static void clean(Path target) throws IOException {
System.out.println(String.format("Cleaning: %s", target));
System.out.printf("Cleaning: %s%n", target);
if (!Files.exists(target)) {
return;
}
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/net/spandigital/presidium/FileWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.function.Consumer;

import static net.spandigital.presidium.Markdown.slugify;

/**
* Created by paco on 2017/05/26.
*/
public class FileWriter {

public static String fileName(int order, String name) {
return String.format("%03d-%s.md", order, name);
return String.format("%s.md", name);
}

public static void writeIndex(Path path, String title) {
write(path.resolve("index.md"), Markdown.frontMatter(title));
}

public static void write(Path file, StringBuffer content) {
write(file, content.toString());
Markdown.editFrontMapper(path.resolve("index.md"), (a) -> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be _index.md

a.put("title", title);
a.put("slug", slugify(title));
});
}

public static void write(Path file, String content) {
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/net/spandigital/presidium/IO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package net.spandigital.presidium;

import java.io.*;

public final class IO {

public static final int DEFAULT_BUFFER_SIZE = 8192;

private IO() {
}

public static int skipLines(RandomAccessFile f, int n) throws IOException {

if (n < 1) {
return 0;
}

while (n > 0) {
if (f.readLine() == null) {
break;
}
n -= 1;
}

return n;
}

public static void copy(File source, RandomAccessFile dest) throws IOException {
byte[] buff = new byte[DEFAULT_BUFFER_SIZE];
try (BufferedInputStream ins = new BufferedInputStream(new FileInputStream(source), DEFAULT_BUFFER_SIZE)) {
while (true) {
int n = ins.read(buff);
if (n == -1) break;
dest.write(buff, 0, n);
}
}
}

/**
* Wraps any exception due to an IO error as a runtime exception
*/
public static class Exception extends RuntimeException {
public Exception(String message, IOException cause) {
super(message);
initCause(cause);
}
}

public static String readText(File file) throws IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
try(InputStream fs = new BufferedInputStream(new FileInputStream(file), DEFAULT_BUFFER_SIZE)) {
byte[] buff = new byte[DEFAULT_BUFFER_SIZE];
while (true) {
int n = fs.read(buff);
if (n == -1) break;
bytes.write(buff, 0, n);
}
}
return bytes.toString("utf-8");
}

}
Loading