tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject [1/4] tomee-site-generator git commit: TOMEE-2345 Add to all annotations outside codeblocks
Date Tue, 25 Dec 2018 04:29:06 GMT
Repository: tomee-site-generator
Updated Branches:
  refs/heads/master d244f5288 -> ee0724fcd


TOMEE-2345 Add  to all annotations outside codeblocks


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/c7c4e443
Tree: http://git-wip-us.apache.org/repos/asf/tomee-site-generator/tree/c7c4e443
Diff: http://git-wip-us.apache.org/repos/asf/tomee-site-generator/diff/c7c4e443

Branch: refs/heads/master
Commit: c7c4e443ead08280eda4ac96d0bac4d10ba0cc7c
Parents: a96d235
Author: Carlos Chacin <cchacin@gmail.com>
Authored: Sun Dec 16 15:04:23 2018 -0800
Committer: Carlos Chacin <cchacin@gmail.com>
Committed: Sun Dec 16 15:04:23 2018 -0800

----------------------------------------------------------------------
 .../tomee/website/AddBacktickToAnnotations.java | 84 ++++++++++++++++++++
 1 file changed, 84 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/c7c4e443/src/main/java/org/apache/tomee/website/AddBacktickToAnnotations.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tomee/website/AddBacktickToAnnotations.java b/src/main/java/org/apache/tomee/website/AddBacktickToAnnotations.java
new file mode 100644
index 0000000..01ea9d7
--- /dev/null
+++ b/src/main/java/org/apache/tomee/website/AddBacktickToAnnotations.java
@@ -0,0 +1,84 @@
+/*
+ * 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.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.regex.Pattern;
+
+public class AddBacktickToAnnotations {
+
+    private static final String REGEX = "([^=*].*)([^`]@\\w+)(.*)";
+
+    private static final Pattern annotation = Pattern.compile(REGEX);
+
+    private static final AtomicBoolean isCodeBlock = new AtomicBoolean(false);
+
+    public static void main(String[] args) throws Exception {
+
+        final File docs = new File("repos/tomee-8.0/docs/");
+
+        Files.walk(docs.toPath())
+             .map(Path::toFile)
+             .filter(File::isFile)
+             .filter(path -> path.getName().endsWith(".adoc"))
+             .forEach(AddBacktickToAnnotations::process);
+
+    }
+
+    public static void process(final File destReadme) {
+        try {
+            final List<String> completed = new ArrayList<>();
+            for (String line : IO.slurp(destReadme).split("\n")) {
+                if (line == null) { return; }
+                if (line.equals("----")) {
+                    if (!isCodeBlock.get()) {
+                        isCodeBlock.set(true);
+                    } else {
+                        isCodeBlock.set(false);
+                    }
+                    completed.add(line);
+                } else if (!isCodeBlock.get()) {
+                    completed.add(replace(line));
+                } else {
+                    completed.add(line);
+                }
+            }
+            // Update the destination readme file
+            IO.copy(IO.read(Join.join("\n", completed) + "\n"), destReadme);
+
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private static String replace(final String line) {
+        if (annotation.matcher(line).matches()) {
+            return line.replaceAll("([^a-z|`])(@\\w+)", "$1`$2`");
+        } else {
+            return line;
+        }
+    }
+}


Mime
View raw message