Skip to content

Commit

Permalink
docs: properly parse docs
Browse files Browse the repository at this point in the history
  • Loading branch information
machi1990 committed Aug 30, 2019
1 parent fe53a63 commit c3621f2
Show file tree
Hide file tree
Showing 53 changed files with 738 additions and 3,150 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ docker/distroless/bazel-*
/.apt_generated_tests/
quarkus.log
replay_*.log
docs/src/main/asciidoc/generated/io.quarkus*.adoc
docs/src/main/asciidoc/generated

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.microprofile.config.Config;
import org.jboss.logging.Logger;
Expand Down Expand Up @@ -165,7 +167,7 @@ private void doProcess(CurateOutcome appState) throws AppCreatorException {
}

sb.append("\n#\n");
sb.append(i.getDocs());
sb.append(formatDocs(i.getDocs()));
sb.append("\n#\n#");
sb.append(i.getPropertyName() + "=" + i.getDefaultValue());
sb.append("\n");
Expand All @@ -191,6 +193,69 @@ private void doProcess(CurateOutcome appState) throws AppCreatorException {
}
}

private String formatDocs(String docs) {

if (docs == null) {
return "";
}
StringBuilder builder = new StringBuilder();

boolean lastEmpty = false;
boolean first = true;

for (String line : docs.replace("<p>", "\n").split("\n")) {
//process line by line
String trimmed = line.trim();
//if the lines are empty we only include a single empty line at most, and add a # character
if (trimmed.isEmpty()) {
if (!lastEmpty && !first) {
lastEmpty = true;
builder.append("\n#");
}
continue;
}
//add the newlines
lastEmpty = false;
if (first) {
first = false;
} else {
builder.append("\n");
}
//replace some special characters, others are taken care of by regex below
builder.append("# " + trimmed.replace("\n", "\n#")
.replace("<ul>", "")
.replace("</ul>", "")
.replace("<li>", " - ")
.replace("</li>", ""));
}

String ret = builder.toString();
//replace @code
ret = Pattern.compile("\\{@code (.*?)\\}").matcher(ret).replaceAll("'$1'");
//replace @link with a reference to the field name
Matcher matcher = Pattern.compile("\\{@link #(.*?)\\}").matcher(ret);
while (matcher.find()) {
ret = ret.replace(matcher.group(0), "'" + configify(matcher.group(1)) + "'");
}

return ret;
}

private String configify(String group) {
//replace uppercase characters with a - followed by lowercase
StringBuilder ret = new StringBuilder();
for (int i = 0; i < group.length(); ++i) {
char c = group.charAt(i);
if (Character.isUpperCase(c)) {
ret.append("-");
ret.append(Character.toLowerCase(c));
} else {
ret.append(c);
}
}
return ret.toString();
}

@Override
public String getConfigPropertyName() {
return "augment";
Expand Down
19 changes: 19 additions & 0 deletions core/processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@
<artifactId>jdeparser</artifactId>
<version>2.0.2.Final</version>
</dependency>

<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.12.1</version>
</dependency>

<dependency>
<groupId>com.github.javaparser</groupId>
<artifactId>javaparser-core</artifactId>
<version>3.14.10</version>
</dependency>

<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.quarkus.annotation.processor;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -10,13 +13,21 @@
import java.util.regex.Pattern;

public class Constants {
public static final char DOT = '.';
public static final String EMPTY = "";
public static final String DASH = "-";
public static final String CORE = "core-";
public static final String ADOC_EXTENSION = ".adoc";
public static final String DIGIT_OR_LOWERCASE = "^[a-z0-9]+$";

public static final String PARENT = "<<parent>>";
public static final String NO_DEFAULT = "<<no default>>";
public static final String HYPHENATED_ELEMENT_NAME = "<<hyphenated element name>>";

public static final Pattern JAVA_DOC_SEE_PATTERN = Pattern.compile("@see\\s+(.+)\\s*");
public static final Pattern JAVA_DOC_CODE_PATTERN = Pattern.compile("\\{@code (.*?)\\}");
public static final Pattern JAVA_DOC_LINK_PATTERN = Pattern.compile("\\{@link #(.*?)\\}");
public static final String COMMON = "common";
public static final String RUNTIME = "runtime";
public static final String DEPLOYMENT = "deployment";

public static final Pattern CONFIG_ROOT_PATTERN = Pattern.compile("^(\\w+)Config(uration)?");
public static final Pattern PKG_PATTERN = Pattern.compile("^io\\.quarkus\\.(\\w+)\\.?(\\w+)?\\.?(\\w+)?");

Expand All @@ -28,12 +39,18 @@ public class Constants {
public static final String ANNOTATION_TEMPLATE = "io.quarkus.runtime.annotations.Template";
public static final String ANNOTATION_RECORDER = "io.quarkus.runtime.annotations.Recorder";
public static final String INSTANCE_SYM = "__instance";
public static final String QUARKUS = "quarkus.";
public static final String QUARKUS = "quarkus";

public static final Set<String> SUPPOERTED_ANNOTATIONS_TYPES = new HashSet<>();
public static final Set<String> SUPPORTED_ANNOTATIONS_TYPES = new HashSet<>();
public static final Map<String, String> OPTIONAL_NUMBER_TYPES = new HashMap<>();
public static final String DOCS_SRC_MAIN_ASCIIDOC_GENERATED = "/docs/src/main/asciidoc/generated/";
public static final String MAVEN_MULTI_MODULE_PROJECT_DIRECTORY = "maven.multiModuleProjectDirectory";
public static final Path GENERATED_DOCS_PATH = Paths
.get(System.getProperties().getProperty("maven.multiModuleProjectDirectory")
+ Constants.DOCS_SRC_MAIN_ASCIIDOC_GENERATED);
public static final File GENERATED_DOCS_DIR = GENERATED_DOCS_PATH.toFile();
public static final File ALL_CR_GENERATED_DOC = GENERATED_DOCS_PATH
.resolve("all-configuration-roots-generated-doc.properties").toFile();

public static final String SEE_DURATION_NOTE_BELOW = ". _See duration note below_";
public static final String SEE_MEMORY_SIZE_NOTE_BELOW = ". _See memory size note below_";

Expand All @@ -59,11 +76,11 @@ public class Constants {
OPTIONAL_NUMBER_TYPES.put(OptionalLong.class.getName(), Long.class.getName());
OPTIONAL_NUMBER_TYPES.put(OptionalInt.class.getName(), Integer.class.getName());
OPTIONAL_NUMBER_TYPES.put(OptionalDouble.class.getName(), Double.class.getName());
SUPPOERTED_ANNOTATIONS_TYPES.add(ANNOTATION_BUILD_STEP);
SUPPOERTED_ANNOTATIONS_TYPES.add(ANNOTATION_CONFIG_GROUP);
SUPPOERTED_ANNOTATIONS_TYPES.add(ANNOTATION_CONFIG_ROOT);
SUPPOERTED_ANNOTATIONS_TYPES.add(ANNOTATION_TEMPLATE);
SUPPOERTED_ANNOTATIONS_TYPES.add(ANNOTATION_RECORDER);
SUPPORTED_ANNOTATIONS_TYPES.add(ANNOTATION_BUILD_STEP);
SUPPORTED_ANNOTATIONS_TYPES.add(ANNOTATION_CONFIG_GROUP);
SUPPORTED_ANNOTATIONS_TYPES.add(ANNOTATION_CONFIG_ROOT);
SUPPORTED_ANNOTATIONS_TYPES.add(ANNOTATION_TEMPLATE);
SUPPORTED_ANNOTATIONS_TYPES.add(ANNOTATION_RECORDER);
}

}
Loading

0 comments on commit c3621f2

Please sign in to comment.