diff --git a/asciidoctor-converter-doxia-module/src/main/java/org/asciidoctor/maven/site/AsciidoctorConverterDoxiaParser.java b/asciidoctor-converter-doxia-module/src/main/java/org/asciidoctor/maven/site/AsciidoctorConverterDoxiaParser.java index 0891ffd6..b3faf25c 100644 --- a/asciidoctor-converter-doxia-module/src/main/java/org/asciidoctor/maven/site/AsciidoctorConverterDoxiaParser.java +++ b/asciidoctor-converter-doxia-module/src/main/java/org/asciidoctor/maven/site/AsciidoctorConverterDoxiaParser.java @@ -73,7 +73,7 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept } final SiteConversionConfiguration conversionConfig = siteConfigParser.processAsciiDocConfig(mavenProject, ROLE_HINT); - final Xpp3Dom siteConfig = conversionConfig.getSiteConfig(); + final Xpp3Dom asciidocConfig = conversionConfig.getAsciidocConfig(); final File siteDirectory = conversionConfig.getSiteBaseDir(); // Doxia handles a single instance of this class and invokes it multiple times. @@ -86,7 +86,7 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept requireLibrary(asciidoctor, require); } - final LogHandler logHandler = logHandlerFactory.getConfiguration(siteConfig); + final LogHandler logHandler = logHandlerFactory.getConfiguration(asciidocConfig); final MemoryLogHandler memoryLogHandler = logHandlerFactory.create(asciidoctor, siteDirectory, logger); final Result headerMetadata = siteConverter.process(asciidoctor, source, conversionConfig.getOptions()); diff --git a/asciidoctor-maven-commons/src/main/java/org/asciidoctor/maven/site/LogHandlerFactory.java b/asciidoctor-maven-commons/src/main/java/org/asciidoctor/maven/site/LogHandlerFactory.java index 1bc554b8..dbca602a 100644 --- a/asciidoctor-maven-commons/src/main/java/org/asciidoctor/maven/site/LogHandlerFactory.java +++ b/asciidoctor-maven-commons/src/main/java/org/asciidoctor/maven/site/LogHandlerFactory.java @@ -18,9 +18,8 @@ */ public class LogHandlerFactory { - public LogHandler getConfiguration(Xpp3Dom siteConfig) { - Xpp3Dom asciidoc = siteConfig == null ? null : siteConfig.getChild("asciidoc"); - return new SiteLogHandlerDeserializer().deserialize(asciidoc); + public LogHandler getConfiguration(Xpp3Dom asciidocConfig) { + return new SiteLogHandlerDeserializer().deserialize(asciidocConfig); } public MemoryLogHandler create(Asciidoctor asciidoctor, File siteDirectory, Logger logger) { diff --git a/asciidoctor-maven-commons/src/main/java/org/asciidoctor/maven/site/SiteConversionConfiguration.java b/asciidoctor-maven-commons/src/main/java/org/asciidoctor/maven/site/SiteConversionConfiguration.java index 0ac8805f..642f5906 100644 --- a/asciidoctor-maven-commons/src/main/java/org/asciidoctor/maven/site/SiteConversionConfiguration.java +++ b/asciidoctor-maven-commons/src/main/java/org/asciidoctor/maven/site/SiteConversionConfiguration.java @@ -6,18 +6,22 @@ import org.asciidoctor.Options; import org.codehaus.plexus.util.xml.Xpp3Dom; +/** + * @author abelsromero + * @since 3.1.1 + */ public final class SiteConversionConfiguration { - private final Xpp3Dom siteConfig; + private final Xpp3Dom asciidocConfig; private final File siteBaseDir; private final Options options; private final List requires; - SiteConversionConfiguration(Xpp3Dom siteConfig, + SiteConversionConfiguration(Xpp3Dom asciidocConfig, File siteBaseDir, Options options, List requires) { - this.siteConfig = siteConfig; + this.asciidocConfig = asciidocConfig; this.siteBaseDir = siteBaseDir; this.options = options; this.requires = requires; @@ -27,8 +31,8 @@ public File getSiteBaseDir() { return siteBaseDir; } - public Xpp3Dom getSiteConfig() { - return siteConfig; + public Xpp3Dom getAsciidocConfig() { + return asciidocConfig; } public Options getOptions() { 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 cde397c9..854fcc19 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 @@ -7,6 +7,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -40,10 +41,6 @@ public SiteConversionConfigurationParser(SiteBaseDirResolver siteBaseDirResolver this.siteBaseDirResolver = siteBaseDirResolver; } - Xpp3Dom getSiteConfig(MavenProject project) { - return project.getGoalConfiguration("org.apache.maven.plugins", "maven-site-plugin", "site", "site"); - } - public SiteConversionConfiguration processAsciiDocConfig(MavenProject mavenProject, String roleHint) { final AttributesBuilder presetAttributes = defaultAttributes(); @@ -53,17 +50,13 @@ public SiteConversionConfiguration processAsciiDocConfig(MavenProject mavenProje final File siteDir = siteBaseDirResolver.resolveBaseDir(mavenProject.getBasedir(), getSiteConfig(mavenProject)); final OptionsBuilder presetOptions = defaultOptions(siteDir, roleHint); - final Xpp3Dom siteConfig = getSiteConfig(mavenProject); - if (siteConfig == null) { - final Options options = presetOptions.attributes(attributes).build(); - // TODO refactor this "always null" - return new SiteConversionConfiguration(siteConfig, siteDir, options, Collections.emptyList()); - } + final Xpp3Dom asciidocConfig = Optional.ofNullable(getSiteConfig(mavenProject)) + .map(node -> node.getChild("asciidoc")) + .orElse(null); - final Xpp3Dom asciidocConfig = siteConfig.getChild("asciidoc"); if (asciidocConfig == null) { final Options options = presetOptions.attributes(attributes).build(); - return new SiteConversionConfiguration(siteConfig, siteDir, options, Collections.emptyList()); + return new SiteConversionConfiguration(null, siteDir, options, Collections.emptyList()); } final List gemsToRequire = new ArrayList<>(); @@ -108,7 +101,11 @@ public SiteConversionConfiguration processAsciiDocConfig(MavenProject mavenProje } final Options options = presetOptions.attributes(attributes).build(); - return new SiteConversionConfiguration(siteConfig, siteDir, options, gemsToRequire); + return new SiteConversionConfiguration(asciidocConfig, siteDir, options, gemsToRequire); + } + + private Xpp3Dom getSiteConfig(MavenProject project) { + return project.getGoalConfiguration("org.apache.maven.plugins", "maven-site-plugin", "site", "site"); } private File resolveProjectDir(MavenProject project, String path) { diff --git a/asciidoctor-maven-commons/src/test/java/org/asciidoctor/maven/site/SiteConversionConfigurationParserTest.java b/asciidoctor-maven-commons/src/test/java/org/asciidoctor/maven/site/SiteConversionConfigurationParserTest.java index f40de2b7..0d667f32 100644 --- a/asciidoctor-maven-commons/src/test/java/org/asciidoctor/maven/site/SiteConversionConfigurationParserTest.java +++ b/asciidoctor-maven-commons/src/test/java/org/asciidoctor/maven/site/SiteConversionConfigurationParserTest.java @@ -38,7 +38,7 @@ void should_return_default_configuration_when_site_xml_is_null() { // then assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNull(); + assertThat(configuration.getAsciidocConfig()).isNull(); assertContainsDefaultOptions(configuration); assertContainsDefaultAttributes(configuration); assertThat(configuration.getRequires()).isEmpty(); @@ -55,7 +55,7 @@ void should_return_default_configuration_when_asciidoc_xml_is_null() { // then assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNotNull(); + assertThat(configuration.getAsciidocConfig()).isNull(); final Map optionsMap = assertContainsDefaultAttributes(configuration); assertThat((String) optionsMap.get(BACKEND)).isEqualTo("xhtml"); assertThat((String) optionsMap.get(BASEDIR)).endsWith(defaultPluginSources()); @@ -86,7 +86,7 @@ void should_return_simple_single_requires() { // then assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNotNull(); + assertThat(configuration.getAsciidocConfig()).isNotNull(); assertContainsDefaultOptions(configuration); assertContainsDefaultAttributes(configuration); assertThat(configuration.getRequires()) @@ -107,7 +107,7 @@ void should_return_multiple_requires() { // then assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNotNull(); + assertThat(configuration.getAsciidocConfig()).isNotNull(); assertContainsDefaultOptions(configuration); assertContainsDefaultAttributes(configuration); assertThat(configuration.getRequires()) @@ -128,7 +128,7 @@ void should_return_multiple_requires_when_defined_in_single_element() { // then assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNotNull(); + assertThat(configuration.getAsciidocConfig()).isNotNull(); assertContainsDefaultOptions(configuration); assertContainsDefaultAttributes(configuration); assertThat(configuration.getRequires()) @@ -149,7 +149,7 @@ void should_remove_empty_and_blank_requires() { // then assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNotNull(); + assertThat(configuration.getAsciidocConfig()).isNotNull(); assertContainsDefaultOptions(configuration); assertContainsDefaultAttributes(configuration); assertThat(configuration.getRequires()) @@ -173,7 +173,7 @@ void should_return_attributes() { // then assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNotNull(); + assertThat(configuration.getAsciidocConfig()).isNotNull(); assertContainsDefaultOptions(configuration); assertThat(configuration.getRequires()).isEmpty(); Map attributes = (Map) configuration.getOptions() @@ -203,7 +203,7 @@ void should_map_null_attributes_as_empty_string() { // then assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNotNull(); + assertThat(configuration.getAsciidocConfig()).isNotNull(); assertContainsDefaultOptions(configuration); assertThat(configuration.getRequires()).isEmpty(); Map attributes = (Map) configuration.getOptions() @@ -231,7 +231,7 @@ void should_map_true_boolean_attribute_as_empty_string_value() { // then assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNotNull(); + assertThat(configuration.getAsciidocConfig()).isNotNull(); assertContainsDefaultOptions(configuration); assertThat(configuration.getRequires()).isEmpty(); Map attributes = (Map) configuration @@ -259,7 +259,7 @@ void should_map_false_boolean_attribute_as_null_value() { // then assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNotNull(); + assertThat(configuration.getAsciidocConfig()).isNotNull(); assertContainsDefaultOptions(configuration); assertThat(configuration.getRequires()).isEmpty(); Map attributes = (Map) configuration @@ -289,7 +289,7 @@ void should_return_template_dirs_when_defined_as_templateDirs_dir() { // then assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNotNull(); + assertThat(configuration.getAsciidocConfig()).isNotNull(); assertContainsDefaultAttributes(configuration); assertThat(configuration.getRequires()).isEmpty(); @@ -318,7 +318,7 @@ void should_return_template_dirs_when_defined_as_template_dirs_dir() { // then assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNotNull(); + assertThat(configuration.getAsciidocConfig()).isNotNull(); assertContainsDefaultAttributes(configuration); assertThat(configuration.getRequires()).isEmpty(); @@ -347,7 +347,7 @@ void should_not_return_empty_template_dirs() { // then: BASE_DIR option is not even added assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNotNull(); + assertThat(configuration.getAsciidocConfig()).isNotNull(); assertContainsDefaultOptions(configuration); assertContainsDefaultAttributes(configuration); assertThat(configuration.getRequires()).isEmpty(); @@ -366,7 +366,7 @@ void should_return_baseDir_dirs_when_defined_as_template_dirs_dir() { // then assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNotNull(); + assertThat(configuration.getAsciidocConfig()).isNotNull(); assertContainsDefaultAttributes(configuration); assertThat(configuration.getRequires()).isEmpty(); @@ -395,7 +395,7 @@ void should_return_any_configuration_inside_asciidoc_node_as_option() { // then assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNotNull(); + assertThat(configuration.getAsciidocConfig()).isNotNull(); assertContainsDefaultAttributes(configuration); assertThat(configuration.getRequires()).isEmpty(); @@ -424,7 +424,7 @@ void should_return_and_format_any_maven_project_property_as_attribute_when_site_ // then assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNull(); + assertThat(configuration.getAsciidocConfig()).isNull(); assertContainsDefaultOptions(configuration); assertThat(configuration.getRequires()).isEmpty(); @@ -455,7 +455,7 @@ void should_return_and_format_any_maven_project_property_as_attribute_when_site_ // then assertThat(configuration.getSiteBaseDir().getPath()).endsWith(defaultSiteSources()); - assertThat(configuration.getSiteConfig()).isNotNull(); + assertThat(configuration.getAsciidocConfig()).isNotNull(); assertContainsDefaultOptions(configuration); assertThat(configuration.getRequires()).isEmpty(); diff --git a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParser.java b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParser.java index 44269848..f1c035b4 100644 --- a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParser.java +++ b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParser.java @@ -77,7 +77,7 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept } final SiteConversionConfiguration conversionConfig = siteConfigParser.processAsciiDocConfig(mavenProject, ROLE_HINT); - final Xpp3Dom siteConfig = conversionConfig.getSiteConfig(); + final Xpp3Dom siteConfig = conversionConfig.getAsciidocConfig(); final File siteDirectory = conversionConfig.getSiteBaseDir(); // Doxia handles a single instance of this class and invokes it multiple times.