Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsromero committed Jun 15, 2023
1 parent 5baa665 commit d487882
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ protected File resolveSiteDirectory(MavenProject project, Xpp3Dom siteConfig) {
}

protected OptionsBuilder defaultOptions(File siteDirectory) {
return OptionsBuilder.options()
return Options.builder()
.backend("xhtml")
.safe(SafeMode.UNSAFE)
.baseDir(new File(siteDirectory, ROLE_HINT));
}

protected AttributesBuilder defaultAttributes() {
return AttributesBuilder.attributes()
return Attributes.builder()
.attribute("idprefix", "@")
.attribute("showtitle", "@");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,4 @@ else if (value instanceof Boolean) {
attributesBuilder.attribute(attribute, value);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
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;
import org.asciidoctor.maven.commons.AsciidoctorHelper;
import org.asciidoctor.maven.commons.StringUtils;
Expand Down Expand Up @@ -29,19 +31,21 @@ public SiteConversionConfiguration processAsciiDocConfig(Xpp3Dom siteConfig,
OptionsBuilder presetOptions,
AttributesBuilder presetAttributes) {

AsciidoctorHelper.addProperties(project.getProperties(), presetAttributes);

final Attributes attributes = presetAttributes.build();

if (siteConfig == null) {
OptionsBuilder options = presetOptions.attributes(presetAttributes);
return new SiteConversionConfiguration(options.get(), Collections.emptyList());
final Options options = presetOptions.attributes(attributes).build();
return new SiteConversionConfiguration(options, Collections.emptyList());
}

final Xpp3Dom asciidocConfig = siteConfig.getChild("asciidoc");
if (asciidocConfig == null) {
OptionsBuilder options = presetOptions.attributes(presetAttributes);
return new SiteConversionConfiguration(options.get(), Collections.emptyList());
final Options options = presetOptions.attributes(attributes).build();
return new SiteConversionConfiguration(options, Collections.emptyList());
}

AsciidoctorHelper.addProperties(project.getProperties(), presetAttributes);

final List<String> gemsToRequire = new ArrayList<>();
for (Xpp3Dom asciidocOpt : asciidocConfig.getChildren()) {
String optName = asciidocOpt.getName();
Expand Down Expand Up @@ -83,7 +87,8 @@ public SiteConversionConfiguration processAsciiDocConfig(Xpp3Dom siteConfig,
}
}

return new SiteConversionConfiguration(presetOptions.attributes(presetAttributes).get(), gemsToRequire);
final Options options = presetOptions.attributes(attributes).build();
return new SiteConversionConfiguration(options, gemsToRequire);
}

private File resolveProjectDir(MavenProject project, String path) {
Expand All @@ -93,5 +98,4 @@ private File resolveProjectDir(MavenProject project, String path) {
}
return filePath;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import org.asciidoctor.Attributes;
import org.asciidoctor.AttributesBuilder;
import org.asciidoctor.Options;
import org.asciidoctor.OptionsBuilder;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.junit.jupiter.api.Test;
Expand All @@ -22,8 +24,8 @@ public class SiteConversionConfigurationParserTest {
public void should_return_default_configuration_when_site_xml_is_null() {
// given
final MavenProject project = fakeProject();
OptionsBuilder emptyOptions = OptionsBuilder.options();
AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();

// when
SiteConversionConfiguration configuration = new SiteConversionConfigurationParser(project)
Expand All @@ -40,8 +42,8 @@ public void should_return_default_configuration_when_site_xml_is_null() {
public void should_return_default_configuration_when_asciidoc_xml_is_null() {
// given
final MavenProject project = fakeProject();
OptionsBuilder emptyOptions = OptionsBuilder.options();
AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();
Xpp3Dom siteConfig = Xpp3DoomBuilder.siteNode()
.build();
// when
Expand All @@ -59,8 +61,8 @@ public void should_return_default_configuration_when_asciidoc_xml_is_null() {
public void should_return_simple_single_requires() {
// given
final MavenProject project = fakeProject();
OptionsBuilder emptyOptions = OptionsBuilder.options();
AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();
Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
.addChild("requires")
.addChild("require", "gem")
Expand All @@ -82,8 +84,8 @@ public void should_return_simple_single_requires() {
public void should_return_multiple_requires() {
// given
final MavenProject project = fakeProject();
OptionsBuilder emptyOptions = OptionsBuilder.options();
AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();
Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
.addChild("requires")
.addChild("require", "gem_1", "gem_2", "gem_3")
Expand All @@ -105,8 +107,8 @@ public void should_return_multiple_requires() {
public void should_return_multiple_requires_when_defined_in_single_element() {
// given
final MavenProject project = fakeProject();
OptionsBuilder emptyOptions = OptionsBuilder.options();
AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();
Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
.addChild("requires")
.addChild("require", "gem_1,gem_2, gem_3")
Expand All @@ -128,8 +130,8 @@ public void should_return_multiple_requires_when_defined_in_single_element() {
public void should_remove_empty_and_blank_requires() {
// given
final MavenProject project = fakeProject();
OptionsBuilder emptyOptions = OptionsBuilder.options();
AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();
Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
.addChild("requires")
.addChild("require", "gem_1,,gem_2", "", ",,", "gem_3")
Expand All @@ -151,8 +153,8 @@ public void should_remove_empty_and_blank_requires() {
public void should_return_attributes() {
// given
final MavenProject project = fakeProject();
OptionsBuilder emptyOptions = OptionsBuilder.options();
AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();
Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
.addChild("attributes")
.addChild("imagesdir", "./images")
Expand Down Expand Up @@ -182,8 +184,8 @@ public void should_return_attributes() {
public void should_map_null_attributes_as_empty_string() {
// given
final MavenProject project = fakeProject();
OptionsBuilder emptyOptions = OptionsBuilder.options();
AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();
Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
.addChild("attributes")
.addChild("toc", null)
Expand All @@ -208,8 +210,8 @@ public void should_map_null_attributes_as_empty_string() {
public void should_map_true_boolean_attribute_as_empty_string_value() {
// given
final MavenProject project = fakeProject();
OptionsBuilder emptyOptions = OptionsBuilder.options();
AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();
Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
.addChild("attributes")
.addChild("toc", "true")
Expand All @@ -234,8 +236,8 @@ public void should_map_true_boolean_attribute_as_empty_string_value() {
public void should_map_false_boolean_attribute_as_null_value() {
// given
final MavenProject project = fakeProject();
OptionsBuilder emptyOptions = OptionsBuilder.options();
AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();
Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
.addChild("attributes")
.addChild("toc", "false")
Expand All @@ -260,8 +262,8 @@ public void should_map_false_boolean_attribute_as_null_value() {
public void should_return_template_dirs_when_defined_as_templateDirs_dir() {
// given
final MavenProject project = fakeProject();
OptionsBuilder emptyOptions = OptionsBuilder.options();
AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();
Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
.addChild("templateDirs")
.addChild("dir", "path")
Expand All @@ -288,8 +290,8 @@ public void should_return_template_dirs_when_defined_as_templateDirs_dir() {
public void should_return_template_dirs_when_defined_as_template_dirs_dir() {
// given
final MavenProject project = fakeProject();
OptionsBuilder emptyOptions = OptionsBuilder.options();
AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();
Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
.addChild("template_dirs")
.addChild("dir", "path")
Expand All @@ -316,8 +318,8 @@ public void should_return_template_dirs_when_defined_as_template_dirs_dir() {
public void should_not_return_empty_template_dirs() {
// given
final MavenProject project = fakeProject();
OptionsBuilder emptyOptions = OptionsBuilder.options();
AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();
Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
.addChild("template_dirs")
.addChild("dir", "")
Expand All @@ -339,8 +341,8 @@ public void should_not_return_empty_template_dirs() {
public void should_return_baseDir_dirs_when_defined_as_template_dirs_dir() {
// given
final MavenProject project = fakeProject();
OptionsBuilder emptyOptions = OptionsBuilder.options();
AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();
Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
.addChild("baseDir", "path")
.build();
Expand All @@ -362,8 +364,8 @@ public void should_return_baseDir_dirs_when_defined_as_template_dirs_dir() {
public void should_return_any_configuration_inside_asciidoc_node_as_option() {
// given
final MavenProject project = fakeProject();
OptionsBuilder emptyOptions = OptionsBuilder.options();
AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();
Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
.addChild("option-1", "value-1")
.parent().addChild("option_2", "value-2")
Expand Down Expand Up @@ -395,8 +397,8 @@ public void should_return_and_format_any_maven_project_property_as_attribute() {
projectProperties.put("mvn.property-test1", "value-1");
projectProperties.put("mvn-property.test2", "value_2");
final MavenProject project = fakeProject(projectProperties);
OptionsBuilder emptyOptions = OptionsBuilder.options();
AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
OptionsBuilder emptyOptions = Options.builder();
AttributesBuilder emptyAttributes = Attributes.builder();
Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode().build();

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void processSources(List<File> sourceFiles, ResourcesProcessor resourcesP
if (!uniquePaths.add(destinationPath))
getLog().warn("Duplicated destination found: overwriting file: " + destinationPath.getAbsolutePath());

convertFile(asciidoctor, optionsBuilder.asMap(), source);
convertFile(asciidoctor, optionsBuilder.build(), source);

try {
// process log messages according to mojo configuration
Expand Down Expand Up @@ -359,7 +359,7 @@ protected List<File> findSourceFiles(File sourceDirectory) {
finder.find(sourceDirectoryPath, sourceDocumentExtensions);
}

protected void convertFile(Asciidoctor asciidoctor, Map<String, Object> options, File f) {
protected void convertFile(Asciidoctor asciidoctor, Options options, File f) {
asciidoctor.convertFile(f, options);
logConvertedFile(f);
}
Expand All @@ -384,7 +384,7 @@ protected boolean ensureOutputExists() {
*/
protected OptionsBuilder createOptionsBuilder(AsciidoctorMojo configuration, AttributesBuilder attributesBuilder) {

final OptionsBuilder optionsBuilder = OptionsBuilder.options()
final OptionsBuilder optionsBuilder = Options.builder()
.backend(configuration.getBackend())
.safe(SafeMode.UNSAFE)
.standalone(configuration.standalone)
Expand All @@ -411,8 +411,7 @@ protected OptionsBuilder createOptionsBuilder(AsciidoctorMojo configuration, Att
if (!configuration.getTemplateDirs().isEmpty())
optionsBuilder.templateDirs(templateDirs.toArray(new File[]{}));

if (!attributesBuilder.asMap().isEmpty())
optionsBuilder.attributes(attributesBuilder);
optionsBuilder.attributes(attributesBuilder.build());

return optionsBuilder;
}
Expand All @@ -427,7 +426,7 @@ protected OptionsBuilder createOptionsBuilder(AsciidoctorMojo configuration, Att
*/
protected AttributesBuilder createAttributesBuilder(AsciidoctorMojo configuration, MavenProject mavenProject) {

final AttributesBuilder attributesBuilder = AttributesBuilder.attributes();
final AttributesBuilder attributesBuilder = Attributes.builder();

if (configuration.isEmbedAssets()) {
attributesBuilder.linkCss(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package org.asciidoctor.maven.test.processors;

import java.util.Map;

import org.asciidoctor.ast.Document;
import org.asciidoctor.extension.Preprocessor;
import org.asciidoctor.extension.PreprocessorReader;
import org.asciidoctor.extension.Reader;

import java.util.Map;

public class ChangeAttributeValuePreprocessor extends Preprocessor {

public static final String AUTHOR_NAME = "ThisIsMe";

public ChangeAttributeValuePreprocessor(Map<String, Object> config) {
super(config);
System.out.println(this.getClass().getSimpleName() + "("
System.out.println(this.getClass().getSimpleName() + "("
+ this.getClass().getSuperclass().getSimpleName() + ") initialized");
}

@Override
public void process(Document document, PreprocessorReader reader) {
System.out.println("Processing "+ this.getClass().getSimpleName());
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -15,10 +16,9 @@ public FailingPreprocessor(Map<String, Object> config) {
}

@Override
public void process(Document document, PreprocessorReader reader) {
System.out.println("Processing "+ this.getClass().getSimpleName());
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");
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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;
Expand All @@ -13,12 +15,10 @@ public ManpageInlineMacroProcessor(String macroName) {
}

@Override
public String process(ContentNode parent, String target, Map<String, Object> attributes) {

Map<String, Object> options = new HashMap<String, Object>();
public PhraseNode process(StructuralNode parent, String target, Map<String, Object> attributes) {
Map<String, Object> 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);
}

}
Loading

0 comments on commit d487882

Please sign in to comment.