From dd2a2d7d42796a2ba67eb04614397fb73af12e97 Mon Sep 17 00:00:00 2001 From: Abel Salgado Romero Date: Wed, 14 Jun 2023 22:45:32 +0200 Subject: [PATCH] WIP --- .../SiteConversionConfigurationParser.java | 28 ++++++++++++------- .../ChangeAttributeValuePreprocessor.java | 4 ++- .../test/processors/FailingPreprocessor.java | 3 +- .../ManpageInlineMacroProcessor.java | 8 +++--- .../test/processors/UriIncludeProcessor.java | 2 +- pom.xml | 5 ++-- 6 files changed, 31 insertions(+), 19 deletions(-) diff --git a/asciidoctor-maven-commons/src/main/java/org/asciidoctor/maven/site/SiteConversionConfigurationParser.java b/asciidoctor-maven-commons/src/main/java/org/asciidoctor/maven/site/SiteConversionConfigurationParser.java index f6ae9e63..845fb261 100644 --- a/asciidoctor-maven-commons/src/main/java/org/asciidoctor/maven/site/SiteConversionConfigurationParser.java +++ b/asciidoctor-maven-commons/src/main/java/org/asciidoctor/maven/site/SiteConversionConfigurationParser.java @@ -1,6 +1,7 @@ package org.asciidoctor.maven.site; import org.apache.maven.project.MavenProject; +import org.asciidoctor.Attributes; import org.asciidoctor.AttributesBuilder; import org.asciidoctor.Options; import org.asciidoctor.OptionsBuilder; @@ -9,7 +10,10 @@ import org.codehaus.plexus.util.xml.Xpp3Dom; import java.io.File; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -29,17 +33,21 @@ public SiteConversionConfiguration processAsciiDocConfig(Xpp3Dom siteConfig, AsciidoctorHelper.addProperties(project.getProperties(), presetAttributes); - final Xpp3Dom siteConfiguration = Optional.ofNullable(siteConfig) - .map(sc -> sc.getChild("asciidoc")) - .orElse(null); + final Attributes attributes = presetAttributes.build(); - if (siteConfiguration == null) { - final OptionsBuilder options = presetOptions.attributes(presetAttributes.build()); - return new SiteConversionConfiguration(options.build(), Collections.emptyList()); + if (siteConfig == null) { + final Options options = presetOptions.attributes(attributes).build(); + return new SiteConversionConfiguration(options, Collections.emptyList()); + } + + final Xpp3Dom asciidocConfig = siteConfig.getChild("asciidoc"); + if (asciidocConfig == null) { + final Options options = presetOptions.attributes(attributes).build(); + return new SiteConversionConfiguration(options, Collections.emptyList()); } final List gemsToRequire = new ArrayList<>(); - for (Xpp3Dom asciidocOpt : siteConfiguration.getChildren()) { + for (Xpp3Dom asciidocOpt : asciidocConfig.getChildren()) { String optName = asciidocOpt.getName(); if ("requires".equals(optName)) { @@ -79,12 +87,12 @@ public SiteConversionConfiguration processAsciiDocConfig(Xpp3Dom siteConfig, } } - final Options options = presetOptions.attributes(presetAttributes.build()).build(); + final Options options = presetOptions.attributes(attributes).build(); return new SiteConversionConfiguration(options, gemsToRequire); } private File resolveProjectDir(MavenProject project, String path) { final File filePath = new File(path); - return !filePath.isAbsolute() ? new File(project.getBasedir(), filePath.toString()): filePath; + return !filePath.isAbsolute() ? new File(project.getBasedir(), filePath.toString()) : filePath; } } diff --git a/asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/test/processors/ChangeAttributeValuePreprocessor.java b/asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/test/processors/ChangeAttributeValuePreprocessor.java index 636d9ab7..4e8ed118 100644 --- a/asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/test/processors/ChangeAttributeValuePreprocessor.java +++ b/asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/test/processors/ChangeAttributeValuePreprocessor.java @@ -3,6 +3,7 @@ import org.asciidoctor.ast.Document; import org.asciidoctor.extension.Preprocessor; import org.asciidoctor.extension.PreprocessorReader; +import org.asciidoctor.extension.Reader; import java.util.Map; @@ -16,9 +17,10 @@ public ChangeAttributeValuePreprocessor(Map config) { } @Override - public void process(Document document, PreprocessorReader reader) { + public Reader process(Document document, PreprocessorReader reader) { System.out.println("Processing " + this.getClass().getSimpleName()); System.out.println("Processing: blocks found: " + document.getBlocks().size()); document.getAttributes().put("author", AUTHOR_NAME); + return reader; } } diff --git a/asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/test/processors/FailingPreprocessor.java b/asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/test/processors/FailingPreprocessor.java index 2a14aa36..93638e81 100644 --- a/asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/test/processors/FailingPreprocessor.java +++ b/asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/test/processors/FailingPreprocessor.java @@ -3,6 +3,7 @@ import org.asciidoctor.ast.Document; import org.asciidoctor.extension.Preprocessor; import org.asciidoctor.extension.PreprocessorReader; +import org.asciidoctor.extension.Reader; import java.util.Map; @@ -14,7 +15,7 @@ public FailingPreprocessor(Map config) { } @Override - public void process(Document document, PreprocessorReader reader) { + public Reader process(Document document, PreprocessorReader reader) { System.out.println("Processing " + this.getClass().getSimpleName()); System.out.println("Processing: blocks found: " + document.getBlocks().size()); throw new RuntimeException("That's all folks"); diff --git a/asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/test/processors/ManpageInlineMacroProcessor.java b/asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/test/processors/ManpageInlineMacroProcessor.java index 0600ffb3..d05c95d7 100644 --- a/asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/test/processors/ManpageInlineMacroProcessor.java +++ b/asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/test/processors/ManpageInlineMacroProcessor.java @@ -1,6 +1,7 @@ package org.asciidoctor.maven.test.processors; -import org.asciidoctor.ast.ContentNode; +import org.asciidoctor.ast.PhraseNode; +import org.asciidoctor.ast.StructuralNode; import org.asciidoctor.extension.InlineMacroProcessor; import java.util.HashMap; @@ -13,11 +14,10 @@ public ManpageInlineMacroProcessor(String macroName) { } @Override - public String process(ContentNode parent, String target, Map attributes) { - + public PhraseNode process(StructuralNode parent, String target, Map attributes) { final Map options = new HashMap<>(); options.put("type", ":link"); options.put("target", target + ".html"); - return createPhraseNode(parent, "anchor", target, attributes, options).convert(); + return createPhraseNode(parent, "anchor", target, attributes, options); } } diff --git a/asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/test/processors/UriIncludeProcessor.java b/asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/test/processors/UriIncludeProcessor.java index 644d2919..91504007 100644 --- a/asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/test/processors/UriIncludeProcessor.java +++ b/asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/test/processors/UriIncludeProcessor.java @@ -28,7 +28,7 @@ public void process(Document document, PreprocessorReader reader, String target, Map attributes) { System.out.println("Processing " + this.getClass().getSimpleName()); final String content = readContent(target); - reader.push_include(content, target, target, 1, attributes); + reader.pushInclude(content, target, target, 1, attributes); } private String readContent(String target) { diff --git a/pom.xml b/pom.xml index 24c8dc01..2ecf1add 100644 --- a/pom.xml +++ b/pom.xml @@ -75,9 +75,10 @@ UTF-8 11 - 3.9.1 - 2.5.11 + JavaSE-1.8 + 3.0.0-alpha.1 9.4.5.0 + 3.9.1