You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2018/11/30 22:27:18 UTC
[34/34] tomee-site-generator git commit: Make old content
jbake-compatible and clean.
Make old content jbake-compatible and clean.
Project: http://git-wip-us.apache.org/repos/asf/tomee-site-generator/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee-site-generator/commit/3538e28d
Tree: http://git-wip-us.apache.org/repos/asf/tomee-site-generator/tree/3538e28d
Diff: http://git-wip-us.apache.org/repos/asf/tomee-site-generator/diff/3538e28d
Branch: refs/heads/master
Commit: 3538e28d8b0c74a9760de39ac4b0c252ae4ef491
Parents: b34e23c
Author: dblevins <da...@gmail.com>
Authored: Mon Nov 26 03:22:55 2018 -0800
Committer: dblevins <da...@gmail.com>
Committed: Mon Nov 26 03:22:55 2018 -0800
----------------------------------------------------------------------
.../java/org/apache/tomee/website/Docs.java | 61 +++++++--
.../java/org/apache/tomee/website/Example.java | 6 +-
.../org/apache/tomee/website/Examples2.java | 95 +------------
.../org/apache/tomee/website/FixMarkdown.java | 15 ++-
.../org/apache/tomee/website/JbakeHeaders.java | 134 +++++++++++++++++++
5 files changed, 201 insertions(+), 110 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/3538e28d/src/main/java/org/apache/tomee/website/Docs.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tomee/website/Docs.java b/src/main/java/org/apache/tomee/website/Docs.java
index 547837a..9fc6e4b 100644
--- a/src/main/java/org/apache/tomee/website/Docs.java
+++ b/src/main/java/org/apache/tomee/website/Docs.java
@@ -47,8 +47,42 @@ public class Docs {
throw new RuntimeException(e);
}
+ try {
+ Files.walk(destDocs.toPath())
+ .filter(path -> path.toFile().isFile())
+ .filter(path -> path.toFile().getName().endsWith(".mdtext"))
+ .forEach(path -> renameMdtextFile(path.toFile()));
+
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ final List<Doc> docs;
+ try {
+ docs = Files.walk(destDocs.toPath())
+ .filter(path -> path.toFile().isFile())
+ .filter(this::isRendered)
+ .map(Path::toFile)
+ .map(path -> toLink(destDocs, path))
+ .collect(Collectors.toList());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ docs.stream()
+ .peek(JbakeHeaders::addJbakeHeader)
+ .forEach(FixMarkdown::process);
+ ;
+
if (!hasIndex(destDocs)) {
- buildIndex(destDocs);
+ buildIndex(destDocs, docs);
+ }
+ }
+
+ private void renameMdtextFile(final File file) {
+ final File newName = new File(file.getParentFile(), file.getName().replace(".mdtext", ".md"));
+ if (!file.renameTo(newName)) {
+ throw new IllegalStateException("Couldn't rename: " + file.getAbsolutePath() + "\n to: " + newName.getAbsolutePath());
}
}
@@ -60,13 +94,10 @@ public class Docs {
.findFirst().isPresent();
}
- private void buildIndex(final File destDocs) {
+ private void buildIndex(final File destDocs, final List<Doc> docs) {
try {
- final List<String> links = Files.walk(destDocs.toPath())
- .filter(path -> path.toFile().isFile())
- .filter(this::isRendered)
- .map(path -> toLink(destDocs, path))
- .map(Link::toAdoc)
+ final List<String> links = docs.stream()
+ .map(Doc::toAdoc)
.collect(Collectors.toList());
final StringBuilder index = new StringBuilder();
@@ -86,25 +117,31 @@ public class Docs {
}
}
- private Link toLink(final File base, final Path path) {
+ private Doc toLink(final File base, final File file) {
final int baseLength = base.getAbsolutePath().length() + 1;
- final String href = path.toFile().getAbsolutePath().substring(baseLength)
+ final String href = file.getAbsolutePath().substring(baseLength)
.replace(".adoc", ".html")
.replace(".mdtext", ".html")
.replace(".md", ".html");
final String name = href.replace(".html", "");
- return new Link(href, name);
+ return new Doc(href, name, file);
}
- public static class Link {
+ public static class Doc {
private final String href;
private final String name;
+ private final File source;
- public Link(final String href, final String name) {
+ public Doc(final String href, final String name, final File source) {
this.href = href;
this.name = name;
+ this.source = source;
+ }
+
+ public File getSource() {
+ return source;
}
public String getHref() {
http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/3538e28d/src/main/java/org/apache/tomee/website/Example.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tomee/website/Example.java b/src/main/java/org/apache/tomee/website/Example.java
index 152729b..f8ec9a9 100644
--- a/src/main/java/org/apache/tomee/website/Example.java
+++ b/src/main/java/org/apache/tomee/website/Example.java
@@ -67,9 +67,13 @@ public class Example {
}
public static Example from(final File readme) {
- final String ext = readme.getName().replaceFirst("[^.]+\\.", "");
+ final String ext = getExtension(readme);
final String exampleName = readme.getParentFile().getName();
return new Example(readme, exampleName, ext, exampleName + ".html", "Example");
}
+
+ public static String getExtension(final File readme) {
+ return readme.getName().replaceFirst("[^.]+\\.", "");
+ }
}
http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/3538e28d/src/main/java/org/apache/tomee/website/Examples2.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tomee/website/Examples2.java b/src/main/java/org/apache/tomee/website/Examples2.java
index f75e885..8b3baec 100644
--- a/src/main/java/org/apache/tomee/website/Examples2.java
+++ b/src/main/java/org/apache/tomee/website/Examples2.java
@@ -17,12 +17,9 @@
package org.apache.tomee.website;
import org.apache.openejb.loader.IO;
-import org.apache.openejb.util.Join;
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -49,7 +46,7 @@ public class Examples2 {
.map(Example::from)
.peek(example -> example.updateDestination(destDir))
.peek(this::copyToDest)
- .peek(this::addJbakeHeader)
+ .peek(JbakeHeaders::addJbakeHeader)
.peek(FixMarkdown::process)
.collect(Collectors.toList());
@@ -81,96 +78,6 @@ public class Examples2 {
// https://javaee.github.io/javaee-spec/javadocs/javax/servlet/http/HttpServletMapping.html
}
- private void addJbakeHeader(final Example example) {
-
- if (example.getExt().startsWith("md")) {
-
- addMarkdownHeader(example);
-
- } else if (example.getExt().startsWith("a")) {
-
- addAsciidocHeader(example);
- }
- }
-
- private void addAsciidocHeader(final Example example) {
- try {
- String content = IO.slurp(example.getDestReadme());
- if (content.contains(":jbake-type:")) return;
-
- String header = "" +
- ":jbake-type: page\n" +
- ":jbake-status: published\n";
-
- // The legacy Apache CMS setup for TomEE allowed a very similar header
- // called "Title: " to specify the title in the created html page.
- // If found, we convert it to the JBake version
- // TODO all docs should be updated and this code removed
- if (content.startsWith("Title:") || content.startsWith("title:")) {
- final List<String> lines = new ArrayList<>();
- Collections.addAll(lines, content.split("\n"));
-
- // remove the legacy title syntax
- final String titleLine = lines.remove(0);
-
- // update the header
- header += ":jbake-title:" + titleLine.substring("title:".length()).trim() + "\n";
-
- // update the content
- content = Join.join("\n", lines);
- }
-
-
- // Prepend the JBake header for Asciidoc
- content = header + content;
-
- // Update the destination readme file
- IO.copy(IO.read(content), example.getDestReadme());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- private void addMarkdownHeader(final Example example) {
- try {
- final File readme = example.getDestReadme();
- String content = IO.slurp(readme);
-
- if (content.contains("~~~~~~")) return;
-
-
- String header = "" +
- "type=page\n" +
- "status=published\n";
-
- // The legacy Apache CMS setup for TomEE allowed a very similar header
- // called "Title: " to specify the title in the created html page.
- // If found, we convert it to the JBake version
- // TODO all docs should be updated and this code removed
- if (content.startsWith("Title:") || content.startsWith("title:")) {
- final List<String> lines = new ArrayList<>();
- Collections.addAll(lines, content.split("\n"));
-
- // remove the legacy title syntax
- final String titleLine = lines.remove(0);
-
- // update the header
- header += "title=" + titleLine.substring("title:".length()).trim() + "\n";
-
- // update the content
- content = Join.join("\n", lines);
- }
-
- // Prepend the JBake header for Markdown
- content = header + "~~~~~~\n" + content;
-
- // Update the destination readme file
- IO.copy(IO.read(content), example.getDestReadme());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
/**
* Copy all the readme.mdtext to examples/foo-bar.mdtext
*/
http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/3538e28d/src/main/java/org/apache/tomee/website/FixMarkdown.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tomee/website/FixMarkdown.java b/src/main/java/org/apache/tomee/website/FixMarkdown.java
index daad57d..6936375 100644
--- a/src/main/java/org/apache/tomee/website/FixMarkdown.java
+++ b/src/main/java/org/apache/tomee/website/FixMarkdown.java
@@ -19,6 +19,7 @@ package org.apache.tomee.website;
import org.apache.openejb.loader.IO;
import org.apache.openejb.util.Join;
+import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
@@ -32,13 +33,21 @@ public class FixMarkdown {
private Consumer<String> processor = this::findJbakeHeader;
public static void process(final Example example) {
- if (!example.getExt().startsWith("md")) return;
+ process(example.getDestReadme());
+ }
+
+ public static void process(final Docs.Doc doc) {
+ process(doc.getSource());
+ }
+
+ public static void process(final File destReadme) {
+ if (!Example.getExtension(destReadme).startsWith("md")) return;
final FixMarkdown fixMarkdown = new FixMarkdown();
try {
final List<String> lines = new ArrayList<>();
- Collections.addAll(lines, IO.slurp(example.getDestReadme()).split("\n"));
+ Collections.addAll(lines, IO.slurp(destReadme).split("\n"));
for (final String line : lines) {
fixMarkdown.process(line);
@@ -47,7 +56,7 @@ public class FixMarkdown {
fixMarkdown.process("");
// Update the destination readme file
- IO.copy(IO.read(Join.join("\n", fixMarkdown.completed)), example.getDestReadme());
+ IO.copy(IO.read(Join.join("\n", fixMarkdown.completed)), destReadme);
} catch (IOException e) {
throw new RuntimeException(e);
http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/3538e28d/src/main/java/org/apache/tomee/website/JbakeHeaders.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tomee/website/JbakeHeaders.java b/src/main/java/org/apache/tomee/website/JbakeHeaders.java
new file mode 100644
index 0000000..51226d9
--- /dev/null
+++ b/src/main/java/org/apache/tomee/website/JbakeHeaders.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomee.website;
+
+import org.apache.openejb.loader.IO;
+import org.apache.openejb.util.Join;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class JbakeHeaders {
+
+ public static void addJbakeHeader(final Docs.Doc doc) {
+
+ final String extension = Example.getExtension(doc.getSource());
+
+ if (extension.startsWith("md")) {
+
+ addMarkdownHeader(doc.getSource());
+
+ } else if (extension.startsWith("a")) {
+
+ addAsciidocHeader(doc.getSource());
+ }
+ }
+
+ public static void addJbakeHeader(final Example example) {
+
+ if (example.getExt().startsWith("md")) {
+
+ addMarkdownHeader(example.getDestReadme());
+
+ } else if (example.getExt().startsWith("a")) {
+
+ addAsciidocHeader(example.getDestReadme());
+ }
+ }
+
+ private static void addAsciidocHeader(final File destReadme) {
+ try {
+ String content = IO.slurp(destReadme);
+ if (content.contains(":jbake-type:")) return;
+
+ String header = "" +
+ ":jbake-type: page\n" +
+ ":jbake-status: published\n";
+
+ // The legacy Apache CMS setup for TomEE allowed a very similar header
+ // called "Title: " to specify the title in the created html page.
+ // If found, we convert it to the JBake version
+ // TODO all docs should be updated and this code removed
+ if (content.startsWith("Title:") || content.startsWith("title:")) {
+ final List<String> lines = new ArrayList<>();
+ Collections.addAll(lines, content.split("\n"));
+
+ // remove the legacy title syntax
+ final String titleLine = lines.remove(0);
+
+ // update the header
+ header += ":jbake-title:" + titleLine.substring("title:".length()).trim() + "\n";
+
+ // update the content
+ content = Join.join("\n", lines);
+ }
+
+
+ // Prepend the JBake header for Asciidoc
+ content = header + content;
+
+ // Update the destination readme file
+ IO.copy(IO.read(content), destReadme);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static void addMarkdownHeader(final File destReadme) {
+ try {
+ final File readme = destReadme;
+ String content = IO.slurp(readme);
+
+ if (content.contains("~~~~~~")) return;
+
+
+ String header = "" +
+ "type=page\n" +
+ "status=published\n";
+
+ // The legacy Apache CMS setup for TomEE allowed a very similar header
+ // called "Title: " to specify the title in the created html page.
+ // If found, we convert it to the JBake version
+ // TODO all docs should be updated and this code removed
+ if (content.startsWith("Title:") || content.startsWith("title:")) {
+ final List<String> lines = new ArrayList<>();
+ Collections.addAll(lines, content.split("\n"));
+
+ // remove the legacy title syntax
+ final String titleLine = lines.remove(0);
+
+ // update the header
+ header += "title=" + titleLine.substring("title:".length()).trim() + "\n";
+
+ // update the content
+ content = Join.join("\n", lines);
+ }
+
+ // Prepend the JBake header for Markdown
+ content = header + "~~~~~~\n" + content;
+
+ // Update the destination readme file
+ IO.copy(IO.read(content), destReadme);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}