This is an automated email from the ASF dual-hosted git repository. dblevins pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomee-site-generator.git
The following commit(s) were added to refs/heads/main by this push: new f4c9f4a Fail build if new md/adoc files don't generate html f4c9f4a is described below commit f4c9f4a428d63457035db23f55c76633845d32b1 Author: David Blevins <dblev...@tomitribe.com> AuthorDate: Mon Oct 24 18:02:57 2022 -0700 Fail build if new md/adoc files don't generate html --- src/main/java/org/apache/tomee/website/Checks.java | 98 ++++++++++++++++++++++ src/main/java/org/apache/tomee/website/JBake.java | 6 +- src/main/resources/ignored.txt | 49 +++++++++++ 3 files changed, 151 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/tomee/website/Checks.java b/src/main/java/org/apache/tomee/website/Checks.java new file mode 100644 index 0000000..bfe75dd --- /dev/null +++ b/src/main/java/org/apache/tomee/website/Checks.java @@ -0,0 +1,98 @@ +/* + * 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.tomitribe.util.PrintString; + +import java.io.File; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.List; +import java.util.function.BiPredicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class Checks { + + public void check(final File contentDir, final File generatedDir) { + final List<String> ignored = getIgnored(); + + try { + final BiPredicate<Path, BasicFileAttributes> sources = (path, attributes) -> { + if (!path.toFile().isFile()) return false; + if (path.toString().endsWith(".adoc") || path.toString().endsWith(".md")) return true; + return false; + }; + + final List<String> missing = Files.find(contentDir.toPath(), 100, sources) + .map(Path::toFile) + .map(File::getAbsolutePath) + .map(s -> s.substring(contentDir.getAbsolutePath().length() + 1)) + // was the html not generated? + .filter(s -> { + final String html = s.replaceAll("\\.(adoc|md)$", ".html"); + final File expected = new File(generatedDir, html); + return !expected.exists(); + }) + // is this file not in the list of known issues? + .filter(s -> !ignored.contains(s)) + .collect(Collectors.toList()); + + if (missing.size() > 0) { + throw new HtmlGenerationFailedException(missing); + } + missing.forEach(System.out::println); + System.out.println(missing); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + private List<String> getIgnored() { + try { + final String content = IO.slurp(this.getClass().getClassLoader().getResource("ignored.txt")); + + return Stream.of(content.split(" *\r?\n *")) + .filter(s -> s.length() > 0) + .filter(s -> !s.startsWith("#")) + .collect(Collectors.toList()); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + public static class HtmlGenerationFailedException extends RuntimeException { + + private final List<String> missing; + + public HtmlGenerationFailedException(final List<String> missing) { + this.missing = missing; + } + + @Override + public String getMessage() { + final PrintString message = new PrintString(); + message.printf("%s source files did not generate html%n", missing.size()); + missing.forEach(message::println); + return message.toString(); + } + } +} diff --git a/src/main/java/org/apache/tomee/website/JBake.java b/src/main/java/org/apache/tomee/website/JBake.java index 08533da..ca81a5f 100755 --- a/src/main/java/org/apache/tomee/website/JBake.java +++ b/src/main/java/org/apache/tomee/website/JBake.java @@ -21,8 +21,6 @@ import java.nio.file.Path; import java.nio.file.WatchEvent; import java.nio.file.WatchKey; import java.nio.file.WatchService; -import java.util.Arrays; -import java.util.List; import java.util.Scanner; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -97,6 +95,9 @@ public class JBake { }; build.run(); + + new Checks().check(destJbakeDir, destination); + if (startHttp) { final Path watched = source.toPath(); final WatchService watchService = watched.getFileSystem().newWatchService(); @@ -226,4 +227,5 @@ public class JBake { FileUtils.copyFile(fileLayoutHtml, dirStructureHtml); } } + } diff --git a/src/main/resources/ignored.txt b/src/main/resources/ignored.txt new file mode 100644 index 0000000..f405468 --- /dev/null +++ b/src/main/resources/ignored.txt @@ -0,0 +1,49 @@ +# +# This file contains a list of adoc and md files that we know do not render +# We exclude them from our checks so the build does not fail +# +# Fixing or deleting these files is a good area for contribution +# +features.adoc +tomee-8.0/docs/documentation.old.adoc +tomee-8.0/pt/examples/webservice-holder.adoc +tomee-8.0/pt/examples/webservice-ssl-client-cert.adoc +tomee-8.0/pt/examples/websocket-tls-basic-auth.adoc +tomee-8.0/examples/webservice-ws-security.adoc +tomee-8.0/examples/webservice-holder.adoc +tomee-8.0/examples/webservice-security.adoc +tomee-8.0/examples/webservice-ssl-client-cert.adoc +tomee-8.0/examples/vaadin-lts-v10-simple.adoc +tomee-8.0/examples/webservice-inheritance.adoc +tomee-8.0/examples/schedule-methods-meta.adoc +tomee-8.0/examples/websocket-tls-basic-auth.adoc +tomee-8.0/es/examples/vaadin-lts-v10-simple.adoc +tomee-8.0/es/examples/vaadin-lts-v08-simple.adoc +latest/docs/documentation.old.adoc +latest/pt/examples/webservice-holder.adoc +latest/pt/examples/webservice-ssl-client-cert.adoc +latest/pt/examples/websocket-tls-basic-auth.adoc +latest/examples/webservice-ws-security.adoc +latest/examples/webservice-holder.adoc +latest/examples/webservice-security.adoc +latest/examples/webservice-ssl-client-cert.adoc +latest/examples/vaadin-lts-v10-simple.adoc +latest/examples/webservice-inheritance.adoc +latest/examples/schedule-methods-meta.adoc +latest/examples/websocket-tls-basic-auth.adoc +latest/es/examples/vaadin-lts-v10-simple.adoc +latest/es/examples/vaadin-lts-v08-simple.adoc +tomee-7.1/docs/documentation.old.adoc +tomee-9.0/docs/documentation.old.adoc +tomee-9.0/pt/examples/webservice-holder.adoc +tomee-9.0/pt/examples/webservice-ssl-client-cert.adoc +tomee-9.0/examples/webservice-ws-security.adoc +tomee-9.0/examples/webservice-holder.adoc +tomee-9.0/examples/webservice-security.adoc +tomee-9.0/examples/webservice-ssl-client-cert.adoc +tomee-9.0/examples/vaadin-lts-v10-simple.adoc +tomee-9.0/examples/webservice-inheritance.adoc +tomee-9.0/examples/schedule-methods-meta.adoc +tomee-9.0/es/examples/vaadin-lts-v10-simple.adoc +tomee-9.0/es/examples/vaadin-lts-v08-simple.adoc +tomee-7.0/docs/documentation.old.adoc