From f8a05fe75130db312fcc61fd24bb7ad3d48ab7eb Mon Sep 17 00:00:00 2001 From: Abel Salgado Romero Date: Sat, 27 May 2023 22:53:17 +0200 Subject: [PATCH] Add IT for maven-site-plugin v3.10.0 This tests validates the minimal maven-site-plugin supported version --- .github/workflows/build.yaml | 2 +- CHANGELOG.adoc | 5 +- .../invoker.properties | 1 + src/it/maven-site-plugin-v3.10/pom.xml | 70 +++++++++++ .../src/site/asciidoc/_include.adoc | 1 + .../src/site/asciidoc/file-with-toc.adoc | 31 +++++ .../asciidoc/templates/paragraph.html.slim | 1 + .../maven-site-plugin-v3.10/src/site/site.xml | 8 ++ src/it/maven-site-plugin-v3.10/validate.bsh | 111 ++++++++++++++++++ 9 files changed, 227 insertions(+), 3 deletions(-) create mode 100644 src/it/maven-site-plugin-v3.10/invoker.properties create mode 100644 src/it/maven-site-plugin-v3.10/pom.xml create mode 100644 src/it/maven-site-plugin-v3.10/src/site/asciidoc/_include.adoc create mode 100644 src/it/maven-site-plugin-v3.10/src/site/asciidoc/file-with-toc.adoc create mode 100644 src/it/maven-site-plugin-v3.10/src/site/asciidoc/templates/paragraph.html.slim create mode 100644 src/it/maven-site-plugin-v3.10/src/site/site.xml create mode 100644 src/it/maven-site-plugin-v3.10/validate.bsh diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a02a34d5..f7d48dd4 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -20,7 +20,7 @@ jobs: name: Build strategy: fail-fast: false - max-parallel: 4 + max-parallel: 16 matrix: os: - ubuntu-latest diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 2cd02665..1d5e3d94 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -15,8 +15,9 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/main[co Build / Infrastructure:: - * Add Maven matrix testing + define Maven compatibility policy (#632) - * Bump Asciidoctorj to v2.5.8 and jRuby to v9.3.10.0 (#639) + * Add Maven matrix testing + define Maven compatibility policy (#632) + * Bump Asciidoctorj to v2.5.8 and jRuby to v9.3.10.0 (#639) + * Add maven-site-pluing v3.10.0 integration test (#641) == v2.2.3 (2023-03-18) diff --git a/src/it/maven-site-plugin-v3.10/invoker.properties b/src/it/maven-site-plugin-v3.10/invoker.properties new file mode 100644 index 00000000..9a737b7f --- /dev/null +++ b/src/it/maven-site-plugin-v3.10/invoker.properties @@ -0,0 +1 @@ +invoker.goals=clean site:site diff --git a/src/it/maven-site-plugin-v3.10/pom.xml b/src/it/maven-site-plugin-v3.10/pom.xml new file mode 100644 index 00000000..12c26171 --- /dev/null +++ b/src/it/maven-site-plugin-v3.10/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + org.asciidoctor + maven-site-plugin-it + 1.0-SNAPSHOT + Maven Site Plugin IT + Checks asciidoctor integration in Maven Site Plugin through Doxia Parser Module + + + v1.2.3 + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 3.1.2 + + + + org.apache.maven.plugins + maven-site-plugin + + 3.10.0 + + + ${project.basedir}/src/site/asciidoc + + src/site/asciidoc/templates + + + + base64 + time + + + + coderay + style + 2 + + + + **/_*.adoc + + + + + org.asciidoctor + asciidoctor-maven-plugin + @project.version@ + + + + + + + diff --git a/src/it/maven-site-plugin-v3.10/src/site/asciidoc/_include.adoc b/src/it/maven-site-plugin-v3.10/src/site/asciidoc/_include.adoc new file mode 100644 index 00000000..0ab34110 --- /dev/null +++ b/src/it/maven-site-plugin-v3.10/src/site/asciidoc/_include.adoc @@ -0,0 +1 @@ +Content included from the file `_include.adoc`. diff --git a/src/it/maven-site-plugin-v3.10/src/site/asciidoc/file-with-toc.adoc b/src/it/maven-site-plugin-v3.10/src/site/asciidoc/file-with-toc.adoc new file mode 100644 index 00000000..061f8b7d --- /dev/null +++ b/src/it/maven-site-plugin-v3.10/src/site/asciidoc/file-with-toc.adoc @@ -0,0 +1,31 @@ += File with TOC +:toc: + +[.lead] +This is an example `.adoc` file that was processed by the Doxia Parser module in the Asciidoctor Maven Plugin. +Version {docs-version}. + +== First section + +This is the first section of the page. + +include::_include.adoc[] + +=== Sub section + +This is a subsection of the first section + +TIP: You can control the number of section levels displayed in the TOC using the `toclevels` attribute. + +== Second section + +This is the first section of the page. + +=== Sub section + +This is a subsection of the second section. + +[source,xml,indent=0] +---- +include::../../../pom.xml[tag=plugin-decl] +---- diff --git a/src/it/maven-site-plugin-v3.10/src/site/asciidoc/templates/paragraph.html.slim b/src/it/maven-site-plugin-v3.10/src/site/asciidoc/templates/paragraph.html.slim new file mode 100644 index 00000000..0e213e64 --- /dev/null +++ b/src/it/maven-site-plugin-v3.10/src/site/asciidoc/templates/paragraph.html.slim @@ -0,0 +1 @@ +p class=role =content diff --git a/src/it/maven-site-plugin-v3.10/src/site/site.xml b/src/it/maven-site-plugin-v3.10/src/site/site.xml new file mode 100644 index 00000000..31e63818 --- /dev/null +++ b/src/it/maven-site-plugin-v3.10/src/site/site.xml @@ -0,0 +1,8 @@ + + + + + + ${reports} + + diff --git a/src/it/maven-site-plugin-v3.10/validate.bsh b/src/it/maven-site-plugin-v3.10/validate.bsh new file mode 100644 index 00000000..3cc2ca8b --- /dev/null +++ b/src/it/maven-site-plugin-v3.10/validate.bsh @@ -0,0 +1,111 @@ +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +File outputDir = new File(basedir, "target/site"); + +String[] expectedFiles = { + "file-with-toc.html" +}; + +String[] unexpectedFiles = { + "_include.html" +}; + +Pattern tocEntry = Pattern.compile("
  • .*"); +Pattern elementIdPattern = Pattern.compile(".* id=\"(.*?)\".*"); + +for (String expectedFile : expectedFiles) { + File file = new File(outputDir, expectedFile); + System.out.println("Checking for presence of " + file); + if (!file.isFile()) { + throw new Exception("Missing file " + file); + } + + List lines = new ArrayList(); + Closeable resource = null; + try { + String line = null; + BufferedReader bReader = new BufferedReader(resource = new FileReader(file)); + while ((line = bReader.readLine()) != null) { + lines.add(line); + } + } + finally { + try { + resource.close(); + } + catch (IOException ignore) {} + } + + System.out.println("Ensuring IDs match TOC links"); + + List tocEntries = new ArrayList(); + + for (String line : lines) { + Matcher matcher = null; + + matcher = tocEntry.matcher(line); + if (matcher.matches()) { + tocEntries.add(matcher.group(1)); + } + + matcher = elementIdPattern.matcher(line); + if (matcher.matches()) { + String elementId = matcher.group(1); + if (tocEntries.contains(elementId)) { + tocEntries.remove(tocEntries.indexOf(elementId)); + } + } + } + + if (tocEntries.size() != 0) { + throw new Exception("Couldn't find matching IDs for the following TOC entries: " + tocEntries); + } + + boolean includeResolved = false; + boolean sourceHighlighted = false; + + for (String line : lines) { + if (!includeResolved && line.contains("Content included from the file ")) { + includeResolved = true; + } + else if (!sourceHighlighted && line.contains("<plugin>")) { + sourceHighlighted = true; + } + } + + if (!includeResolved) { + throw new Exception("Include file was not resolved."); + } + + if (!sourceHighlighted) { + throw new Exception("Source code was not highlighted."); + } + + // validate that maven properties are replaced same as attributes + boolean foundReplacement = false; + for (String line: lines) { + System.out.println(line); + if (line.contains("v1.2.3")) { + foundReplacement = true; + break; + } + } + if (!foundReplacement) { + throw new Exception("Maven properties not replaced."); + } +} + +for (String unexpectedFile : unexpectedFiles) { + File file = new File(outputDir, unexpectedFile); + System.out.println("Checking for absence of " + file); + if (file.isFile()) { + throw new Exception("Unexpected file " + file); + } +} + +return true;