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/12/09 17:35:24 UTC

[2/4] tomee-site-generator git commit: Prune old examples code

Prune old examples code


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

Branch: refs/heads/master
Commit: d54197d47d07757af3dc91a4c3dc8dd5a7be20c4
Parents: bb31cae
Author: David Blevins <da...@gmail.com>
Authored: Sun Dec 9 09:09:15 2018 -0800
Committer: David Blevins <da...@gmail.com>
Committed: Sun Dec 9 09:09:15 2018 -0800

----------------------------------------------------------------------
 .../java/org/apache/tomee/website/Examples.java | 319 -------------------
 .../java/org/apache/tomee/website/JBake.java    |   2 -
 src/main/jbake/jbake.properties                 |   1 -
 src/main/jbake/templates/examples.gsp           | 202 ------------
 4 files changed, 524 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/d54197d4/src/main/java/org/apache/tomee/website/Examples.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tomee/website/Examples.java b/src/main/java/org/apache/tomee/website/Examples.java
deleted file mode 100755
index efab3d5..0000000
--- a/src/main/java/org/apache/tomee/website/Examples.java
+++ /dev/null
@@ -1,319 +0,0 @@
-package org.apache.tomee.website;
-
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import org.apache.johnzon.jaxrs.JohnzonProvider;
-import org.apache.johnzon.mapper.JohnzonProperty;
-import org.apache.johnzon.mapper.MapperBuilder;
-
-import javax.ws.rs.ForbiddenException;
-import javax.ws.rs.NotFoundException;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.GenericType;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.nio.charset.StandardCharsets;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Stream;
-
-import static java.util.Arrays.asList;
-import static java.util.Optional.ofNullable;
-import static java.util.stream.Collectors.toList;
-import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
-import static lombok.AccessLevel.PRIVATE;
-import static org.apache.commons.codec.binary.Base64.decodeBase64;
-
-@NoArgsConstructor(access = PRIVATE)
-public class Examples {
-    private static final String DEFAULT_README = "No README.md yet, be the first to contribute one!";
-
-    // don't load it for each page, would be pretty inefficient
-    private static final Map<String, Collection<Example>> CACHE = new TreeMap<>();
-    private static final String CACHE_FILE = "examples.cache";
-    private static final Collection<String> EXCLUDED_KEYWORDS = new HashSet<>(asList(
-            "with", "jvm", "preview", "demo", "to", "a", "access", "and", "app", "application", "auto", "basic", "bean", "by", "change", "complete",
-            "composer", "custom", "declared", "example", "handling", "in", "by", "change", "simple", "interface"));
-
-    public static void populateTree() {
-        final String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
-        load();
-        CACHE.forEach((tag, examples) -> examples.forEach(e -> {
-            try (final Writer w = new FileWriter("src/main/jbake/content/examples/" + e.getName() + ".adoc")) {
-                w.write("= " + findTitle(e.getName(), e.getReadme()) + "\n" +
-                        ":jbake-date: " + date + "\n" +
-                        ":jbake-type: page\n" +
-                        ":jbake-tomeepdf:\n" +
-                        ":jbake-status: published\n\n" +
-                        "Example " + e.getName() + " can be browsed at " + e.getUrl() + "\n\n" +
-                        mdToAdoc(e.getReadme()));
-            } catch (final IOException ioe) {
-                throw new IllegalStateException(ioe);
-            }
-        }));
-    }
-
-    public static ExampleWrapper loadAll() {
-        load();
-        return new ExampleWrapper(CACHE, CACHE.values().stream().mapToInt(Collection::size).sum());
-    }
-
-    public static void load() {
-        if (!CACHE.isEmpty()) {
-            return;
-        }
-
-        final File cache = new File(CACHE_FILE);
-        if (cache.isFile()) {
-            System.out.println("Reading examples from cache, delete " + CACHE_FILE + " if you want to reload them");
-            try (final InputStream is = new FileInputStream(cache)) {
-                final ExampleWrapper wrapper = new MapperBuilder().build().readObject(is, ExampleWrapper.class);
-                CACHE.putAll(wrapper.getAll());
-            } catch (IOException e) {
-                throw new IllegalArgumentException(e);
-            }
-            return;
-        }
-
-        final Client client = ClientBuilder.newClient().register(new JohnzonProvider<>());
-        try {
-            final WebTarget github = client.target("https://api.github.com");
-            final Invocation.Builder request = github.path("repos/apache/tomee/contents/examples").request(APPLICATION_JSON_TYPE);
-            final String auth = System.getProperty("github.auth");
-            if (auth != null) {
-                request.header("Authorization", auth);
-            }
-            request
-                    .get(new GenericType<Collection<GithubContentItem>>() {
-                    }).stream().filter(i -> "dir".equals(i.getType()))
-                    .parallel()
-                    .sorted((i1, i2) -> i1.getName().compareTo(i2.getName()))
-                    .map(i -> new Example(i.getName(), i.getHtmlUrl(), loadReadme(auth, github, i)))
-                    .forEach(example -> {
-                        final Collection<String> split = Stream.of(example.getName()
-                                .replace("application-composer", "applicationcomposer")
-                                .replace("configproperty", "config")
-                                .replace("descriptors", "descriptor")
-                                .replace("ejbs", "ejb")
-                                .replace("env-entry", "enventry")
-                                .replace("events", "event")
-                                .replace("interceptors", "interceptor")
-                                .split("-"))
-                                .filter(s -> !EXCLUDED_KEYWORDS.contains(s))
-                                .filter(s -> {
-                                    try {
-                                        Integer.parseInt(s);
-                                        return false;
-                                    } catch (final NumberFormatException nfe) {
-                                        return true;
-                                    }
-                                })
-                                .collect(toList());
-                        if (split.isEmpty()) {
-                            CACHE.computeIfAbsent("Unclassified", k -> new ArrayList<>()).add(example);
-                        } else {
-                            for (final String keyword : split) {
-                                CACHE.computeIfAbsent(keyword, k -> new ArrayList<>()).add(example);
-                            }
-                        }
-                    });
-
-            // debug stats
-            final int totalExamples = CACHE.size();
-            final long exampleMissingReadme = CACHE.values().stream().flatMap(Collection::stream).filter(e -> DEFAULT_README.equals(e.getReadme())).count();
-            System.out.println(exampleMissingReadme + "/" + totalExamples + " miss a README.md");
-            CACHE.values().stream().flatMap(Collection::stream).filter(e -> DEFAULT_README.equals(e.getReadme())).forEach(e -> System.out.println("  - " + e.getName()));
-
-            try (final OutputStream os = new FileOutputStream(CACHE_FILE)) {
-                new MapperBuilder().setPretty(true).build().writeObject(loadAll(), os);
-            } catch (final IOException e) {
-                throw new IllegalArgumentException(e);
-            }
-        } finally {
-            client.close();
-        }
-    }
-
-    private static String loadReadme(final String auth, final WebTarget github, final GithubContentItem i) {
-        try {
-            final Invocation.Builder request = github.path("repos/apache/tomee/contents/examples/{name}/README.md")
-                    .resolveTemplate("name", i.getName()).request(APPLICATION_JSON_TYPE);
-            if (auth != null) {
-                request.header("Authorization", auth);
-            }
-            return ofNullable(request
-                    .get(GithubContentItem.class)
-                    .getContent())
-                    .map(c -> new String(decodeBase64(c), StandardCharsets.UTF_8))
-                    .orElse(DEFAULT_README);
-        } catch (final NotFoundException wae) {
-            System.err.println(wae.getMessage() + " for the README.md of " + i.getName());
-            return DEFAULT_README;
-        } catch (final ForbiddenException wae) {
-            System.err.println("Can't retrieve examples, set -Dgithub.auth=.... to get a higher rate limit");
-            return DEFAULT_README;
-        }
-    }
-
-    private static String findTitle(final String name, final String readme) {
-        try (final BufferedReader reader = new BufferedReader(new StringReader(readme))) {
-            String line;
-            while ((line = reader.readLine()) != null) {
-                if (line.startsWith("Title: ")) {
-                    return line.substring("Title: ".length());
-                }
-            }
-        } catch (final IOException e) {
-            throw new IllegalStateException(e);
-        }
-        return name;
-    }
-
-    // quick cleanup of markdown syntax to adoc one used there
-    private static String mdToAdoc(final String s) {
-        final Pattern link = Pattern.compile("(.*)\\[([^\\]]*)\\]\\(([^\\)]*)\\)(.*)");
-
-        try (final StringWriter writer = new StringWriter();
-             final BufferedReader reader = new BufferedReader(new StringReader(s))) {
-            String line;
-            while ((line = reader.readLine()) != null) {
-                if (line.startsWith("Title: ")) {
-                    continue;
-                }
-                if (line.startsWith("#")) {
-                    for (int i = 0; i < line.length(); i++) {
-                        if (line.charAt(i) == '#') {
-                            writer.append('=');
-                        } else {
-                            writer.append(" ").append(line.substring(i));
-                            break;
-                        }
-                    }
-                } else if (line.startsWith("    package") || line.startsWith("    import") || line.startsWith("    public ") || line.startsWith("    @")) { // java code
-                    writer.append("\n[source,java]\n----\n");
-                    writer.append(line.replaceFirst("    ", "")).append('\n');
-                    while ((line = reader.readLine()) != null) {
-                        writer.append(line.replaceFirst("    ", "")).append('\n');
-                        if ("    }".equals(line)) {
-                            writer.append("----\n");
-                            break;
-                        }
-                    }
-                } else if (line.startsWith("    <")) { // xml code
-                    writer.append("\n[source,xml]\n----\n");
-                    if (line.startsWith("    <?")) { // prolog
-                        writer.append(line.replaceFirst("    ", "")).append('\n');
-                        line = reader.readLine();
-                    }
-                    while (line != null && line.trim().isEmpty()) {
-                        line = reader.readLine();
-                    }
-                    if (line.trim().startsWith("<!--")) {
-                        if (line.contains("-->")) {
-                            writer.append(line.replaceFirst("    ", "")).append('\n');
-                        } else {
-                            do {
-                                writer.append(line.replaceFirst("    ", "")).append('\n');
-                            } while ((line = reader.readLine()) != null && !line.trim().equals("-->"));
-                            writer.append(line.replaceFirst("    ", "")).append('\n');
-                        }
-                        line = reader.readLine();
-                        while (line != null && line.trim().isEmpty()) {
-                            line = reader.readLine();
-                        }
-                    }
-
-                    if (line.trim().endsWith("/>")) {
-                        writer.append(line.replaceFirst("    ", "")).append('\n');
-                        writer.append("----\n");
-                    } else {
-                        final int space = line.indexOf(' ', 5);
-                        final String end = "</" + line.substring(5, space < 0 ? line.indexOf('>') : space) + ">";
-                        writer.append(line.replaceFirst("    ", "")).append('\n');
-                        while ((line = reader.readLine()) != null) {
-                            writer.append(line.replaceFirst("    ", "")).append('\n');
-                            if (end.equals(line.trim())) {
-                                writer.append("----\n");
-                                break;
-                            }
-                        }
-                    }
-                } else if (line.startsWith("    -------------------------------------------------------")) { // run output
-                    writer.append("\n[source]\n----\n");
-                    writer.append(line.replaceFirst("    ", "")).append('\n');
-                    while ((line = reader.readLine()) != null) {
-                        writer.append(line.replaceFirst("    ", "")).append('\n');
-                        if (line.startsWith("    Tests run:") && !line.contains("Time elapsed:")) {
-                            writer.append("----\n");
-                            break;
-                        }
-                    }
-                } else if (line.startsWith(">")) {
-                    writer.append("\nNOTE: ").append(line.substring(1)).append("\n");
-                } else {
-                    final Matcher matcher = link.matcher(line);
-                    if (matcher.matches()) {
-                        String l = matcher.group(3);
-                        if (l.startsWith("../") && l.endsWith("README.html")) { // hack for old relative links
-                            l = l.substring("../".length(), l.length() - "/README.html".length()) + ".html";
-                        }
-                        writer.append(matcher.group(1)).append("link:").append(l).append('[').append(matcher.group(2)).append(']').append(matcher.group(4));
-                    } else {
-                        writer.append(line);
-                    }
-                }
-                writer.append('\n');
-            }
-            return writer.toString();
-        } catch (final IOException e) {
-            throw new IllegalStateException(e);
-        }
-    }
-
-    public static void main(final String[] args) {
-        populateTree();
-    }
-
-    @Data
-    public static class ExampleWrapper {
-        private final Map<String, Collection<Example>> all;
-        private final int total;
-    }
-
-    @Data
-    public static class Example {
-        private final String name;
-        private final String url;
-        private final String readme;
-    }
-
-    @Data
-    public static class GithubContentItem {
-        private String name;
-        private String path;
-        private String type;
-        private String content;
-
-        @JohnzonProperty("html_url")
-        private String htmlUrl;
-    }
-}

http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/d54197d4/src/main/java/org/apache/tomee/website/JBake.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tomee/website/JBake.java b/src/main/java/org/apache/tomee/website/JBake.java
index 7105a9d..147fe8d 100755
--- a/src/main/java/org/apache/tomee/website/JBake.java
+++ b/src/main/java/org/apache/tomee/website/JBake.java
@@ -33,10 +33,8 @@ public class JBake {
         System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "64"); // try to have parallelStream better than default
 
         final File source = args == null || args.length < 1 ? new File("src/main/jbake") : new File(args[0]);
-        final File pdfSource = new File(source, "content");
         final File destination = args == null || args.length < 2 ? new File("target/site-tmp") : new File(args[1]);
         final boolean startHttp = args == null || args.length < 2 || Boolean.parseBoolean(args[2]); // by default we dev
-        final boolean skipPdf = args == null || args.length < 3 || Boolean.parseBoolean(args[3]); // by default...too slow sorry
 
         final Sources sources = new Sources(
                 new File("target/jbake"),

http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/d54197d4/src/main/jbake/jbake.properties
----------------------------------------------------------------------
diff --git a/src/main/jbake/jbake.properties b/src/main/jbake/jbake.properties
index 4e56dfa..739db5a 100755
--- a/src/main/jbake/jbake.properties
+++ b/src/main/jbake/jbake.properties
@@ -12,7 +12,6 @@ template.docsindex.file = docs-index.gsp
 template.examplesindex.file = examples-index.gsp
 template.post.file = post.gsp
 template.contributors.file = contributors.gsp
-template.examples.file = examples.gsp
 template.blog.file = blog.gsp
 # template.archive.file = archive.gsp
 # template.tag.file = tags.gsp

http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/d54197d4/src/main/jbake/templates/examples.gsp
----------------------------------------------------------------------
diff --git a/src/main/jbake/templates/examples.gsp b/src/main/jbake/templates/examples.gsp
deleted file mode 100755
index b68f547..0000000
--- a/src/main/jbake/templates/examples.gsp
+++ /dev/null
@@ -1,202 +0,0 @@
-<%include "header.gsp"%>
-<%include "menu.gsp"%>
-
-<div id="main-block" class="container main-block">
-<div class="row title">
-  <div class='page-header'>
-    <% if (content.containsKey('tomeepdf')) { %>
-    <div class='btn-toolbar pull-right'>
-      <div class='btn-group'>
-        <a class="btn" href="<%if (content.rootpath) {%>${content.rootpath}<% } else { %><% }%>${content.uri.replace('html', 'pdf')}">
-          <i class="fa fa-file-pdf-o"></i> Download as PDF
-        </a>
-      </div>
-    </div>
-    <% } %>
-    <h2>${content.title}</h2>
-  </div>
-</div>
-<div class="row">
-  <div class="col-md-12">
-    <input id="example-search" placeholder="Search an example and click on it to browse it..." class="typeahead"/>
-  </div>
-  <div class="vspace">&nbsp;</div>
-  <div class="col-md-12 examples text-center">
-    <%
-    def all = org.apache.tomee.website.Examples.loadAll()
-    def keys = []
-    keys.addAll(all.all.keySet())
-
-    [keys.subList(0, (int) keys.size() / 2), keys.subList((int) keys.size() / 2, keys.size())].each { list ->
-      keys.subList(0, (int) keys.size() / 2).each { tag ->
-      examples = all.all[tag]
-    %>
-    <div class="col-sm-6">
-      <h3>${tag}</h3>
-      <ul class="list-unstyled">
-        <% examples.each {example -> %>
-        <li><a href="${example.name}.html">${example.name}</a></li>
-        <% } %>
-      </ul>
-    </div>
-    <% }} %>
-  </div>
-</div>
-</div>
-
-<style>
-.typeahead {
-    padding-left: 43px;
-    padding-right: 43px;
-    border-radius: 23px;
-    border:1px #ccc solid;
-    height: 46px;
-    width: 100%;
-    outline: none;
-}
-.typeahead:focus {
-    border-color: #66afe9;
-    outline: 0;
-    box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
-}
-
-
-/* typeahead styling*/
-.tt-menu hr {
-    margin-bottom: 5px;
-    margin-top: 5px;
-}
-.tt-menu h3 {
-    margin-bottom: 2px;
-    margin-top: 2px;
-    padding-bottom: 2px;
-    padding-top: 2px;
-    font-size: 18px;
-    font-weight: bolder;
-}
-.tt-menu h2 {
-    font-weight: bold;
-}
-span.twitter-typeahead .tt-menu,
-span.twitter-typeahead .tt-dropdown-menu {
-  z-index: 1000;
-  display: none;
-  width: 100%;
-  min-width: 160px;
-  padding: 5px 0;
-  margin: 2px 0 0;
-  list-style: none;
-  text-align: left;
-  background-color: #ffffff;
-  border: 1px solid #cccccc;
-  border: 1px solid rgba(0, 0, 0, 0.15);
-  border-radius: 4px;
-  -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
-  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
-  background-clip: padding-box;
-}
-span.twitter-typeahead h3 {
-  padding-left: 15px;
-  clear: both;
-}
-span.twitter-typeahead .tt-suggestion {
-  display: block;
-  padding: 3px 15px;
-  clear: both;
-  font-weight: normal;
-  line-height: 1.42857143;
-  color: #333333;
-}
-span.twitter-typeahead .tt-suggestion.tt-cursor,
-span.twitter-typeahead .tt-suggestion:hover,
-span.twitter-typeahead .tt-suggestion:focus {
-  color: #ffffff;
-  text-decoration: none;
-  outline: 0;
-  background-color: #337ab7;
-}
-.input-group.input-group-lg span.twitter-typeahead .form-control {
-  height: 46px;
-  padding: 10px 16px;
-  line-height: 1.3333333;
-  border-radius: 6px;
-}
-.input-group.input-group-sm span.twitter-typeahead .form-control {
-  height: 30px;
-  padding: 5px 10px;
-  line-height: 1.5;
-  border-radius: 3px;
-}
-span.twitter-typeahead {
-  width: 100%;
-}
-.input-group span.twitter-typeahead {
-  display: block !important;
-  height: 34px;
-}
-.input-group span.twitter-typeahead .tt-menu,
-.input-group span.twitter-typeahead .tt-dropdown-menu {
-  top: 32px !important;
-}
-.input-group span.twitter-typeahead:not(:first-child):not(:last-child) .form-control {
-  border-radius: 0;
-}
-.input-group span.twitter-typeahead:first-child .form-control {
-  border-top-left-radius: 4px;
-  border-bottom-left-radius: 4px;
-  border-top-right-radius: 0;
-  border-bottom-right-radius: 0;
-}
-.input-group span.twitter-typeahead:last-child .form-control {
-  border-top-left-radius: 0;
-  border-bottom-left-radius: 0;
-  border-top-right-radius: 4px;
-  border-bottom-right-radius: 4px;
-}
-.input-group.input-group-sm span.twitter-typeahead {
-  height: 30px;
-}
-.input-group.input-group-sm span.twitter-typeahead .tt-menu,
-.input-group.input-group-sm span.twitter-typeahead .tt-dropdown-menu {
-  top: 30px !important;
-}
-.input-group.input-group-lg span.twitter-typeahead {
-  height: 46px;
-}
-.input-group.input-group-lg span.twitter-typeahead .tt-menu,
-.input-group.input-group-lg span.twitter-typeahead .tt-dropdown-menu {
-  top: 46px !important;
-}
-</style>
-<script src="<%if (content.rootpath) {%>${content.rootpath}<% } else { %><% }%>js/jquery-1.11.1.min.js"></script>
-<script src="<%if (content.rootpath) {%>${content.rootpath}<% } else { %><% }%>js/typeahead.bundle.min.js"></script>
-<script>
-(function () {
-  var names = [];
-  document.querySelectorAll('.examples li > a').forEach(function (s) {
-    names.push(s.innerHTML);
-  });
-  var engine = new Bloodhound({
-    datumTokenizer: Bloodhound.tokenizers.nonword,
-    queryTokenizer: Bloodhound.tokenizers.nonword,
-    local: names
-  });
-  var input = jQuery('#example-search');
-  input.typeahead({ minLength: 1, highlight: true }, {
-    name: 'Examples',
-    source: engine,
-    templates: {
-      suggestion: function (item) {
-        return '<a href="' + item + '.html">' + item + '</a>';
-      }
-    }
-  });
-  input.bind('typeahead:select', function (evt, item) {
-    jQuery('li > a[href="' + item + '.html"]').click();
-  });
-})();
-
-</script>
-
-<%include "footer.gsp"%>
-