diff --git a/pom.xml b/pom.xml index 4b7a457..349c642 100644 --- a/pom.xml +++ b/pom.xml @@ -1,226 +1,243 @@ - - - 4.0.0 - - - org.sonatype.oss - oss-parent - 7 - - - - com.github.cukespace - arquillian-asciidoctor-extension - 0.0.3-SNAPSHOT - - Arquillian Asciidoctor Extension - https://github.com/cukespace/arquillian-asciidoctor-extension - - - - UTF-8 - 1.7 - 1.7 - - - 3.5.1 - 2.3.1 - 2.19.1 - - - 9.1.12.0 - 1.5.6 - 1.2.0 - 1.1.11.Final - 4.12 - 2.5.0 - - - - scm:git:https://github.com/cukespace/arquillian-asciidoctor-extension.git - scm:git:https://github.com/cukespace/arquillian-asciidoctor-extension.git - https://www.github.com/cukespace/arquillian-asciidoctor-extension - HEAD - - - - - MIT License - http://www.opensource.org/licenses/mit-license - repo - - - - - - org.jboss.arquillian.core - arquillian-core-spi - ${arquillian.version} - provided - - - org.jboss.arquillian.config - arquillian-config-api - ${arquillian.version} - provided - - - - org.jruby - jruby-complete - ${jruby.version} - - - org.asciidoctor - asciidoctorj - ${asciidoctorj.version} - - - org.jruby - jruby-complete - - - - - commons-io - commons-io - 2.5 - - - - org.jboss.arquillian.junit - arquillian-junit-container - ${arquillian.version} - test - - - junit - junit - ${junit.version} - test - - - - org.assertj - assertj-core - ${assertj.version} - test - - - - org.apache.tomee - apache-tomee - 7.0.1 - test - zip - webprofile - - - * - * - - - - - org.apache.tomee - arquillian-tomee-remote - 7.0.1 - test - - - org.asciidoctor - asciidoctorj-pdf - 1.5.0-alpha.16 - test - - - org.asciidoctor - asciidoctorj-diagram - 1.5.4.1 - test - - - - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.7 - true - - ossrh - https://oss.sonatype.org/ - true - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler.version} - true - - ${project.build.sourceEncoding} - ${project.build.source} - ${project.build.target} - - - - - org.apache.maven.plugins - maven-jar-plugin - ${maven-jar.version} - true - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire.version} - - - arquillian - - test - - - - **/AssertsTest* - - ${maven.test.skip} - - - - asserts - - test - - - - **/AdocGeneratorTest* - - ${maven.test.skip} - - - - - true - - - - + + + 4.0.0 + + + org.sonatype.oss + oss-parent + 7 + + + + com.github.cukespace + arquillian-asciidoctor-extension + 0.0.3-SNAPSHOT + + Arquillian Asciidoctor Extension + https://github.com/cukespace/arquillian-asciidoctor-extension + + + + UTF-8 + 1.7 + 1.7 + + + 3.5.1 + 2.3.1 + 2.19.1 + + + 9.1.12.0 + 1.5.0-alpha.16 + 1.6.0-alpha.6 + 1.2.0 + 1.1.11.Final + 4.12 + 2.5.0 + + + + scm:git:https://github.com/cukespace/arquillian-asciidoctor-extension.git + scm:git:https://github.com/cukespace/arquillian-asciidoctor-extension.git + + https://www.github.com/cukespace/arquillian-asciidoctor-extension + HEAD + + + + + MIT License + http://www.opensource.org/licenses/mit-license + repo + + + + + + org.jboss.arquillian.core + arquillian-core-spi + ${arquillian.version} + provided + + + org.jboss.arquillian.config + arquillian-config-api + ${arquillian.version} + provided + + + org.jruby + jruby-complete + ${jruby.version} + + + org.asciidoctor + asciidoctorj + ${asciidoctorj.version} + + + org.jruby + jruby-complete + + + org.jruby + jruby + + + + + org.asciidoctor + asciidoctorj-pdf + ${asciidoctorj-pdf.version} + + + org.asciidoctor + asciidoctorj + + + + + commons-io + commons-io + 2.5 + + + + org.jboss.arquillian.junit + arquillian-junit-container + ${arquillian.version} + test + + + junit + junit + ${junit.version} + test + + + + org.assertj + assertj-core + ${assertj.version} + test + + + + org.apache.tomee + apache-tomee + 7.0.1 + test + zip + webprofile + + + * + * + + + + + org.apache.tomee + arquillian-tomee-remote + 7.0.1 + test + + + org.asciidoctor + asciidoctorj-pdf + 1.5.0-alpha.16 + test + + + org.asciidoctor + asciidoctorj-diagram + 1.5.4.1 + test + + + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrh + https://oss.sonatype.org/ + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler.version} + true + + ${project.build.sourceEncoding} + ${project.build.source} + ${project.build.target} + + + + + org.apache.maven.plugins + maven-jar-plugin + ${maven-jar.version} + true + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire.version} + + + arquillian + + test + + + + **/AssertsTest* + + ${maven.test.skip} + + + + asserts + + test + + + + **/AdocGeneratorTest* + + ${maven.test.skip} + + + + + true + + + + diff --git a/src/main/java/com/github/cukespace/arquillian/asciidoctor/AsciidoctorObserver.java b/src/main/java/com/github/cukespace/arquillian/asciidoctor/AsciidoctorObserver.java index a35859c..9e35e53 100644 --- a/src/main/java/com/github/cukespace/arquillian/asciidoctor/AsciidoctorObserver.java +++ b/src/main/java/com/github/cukespace/arquillian/asciidoctor/AsciidoctorObserver.java @@ -7,16 +7,7 @@ import org.asciidoctor.AttributesBuilder; import org.asciidoctor.OptionsBuilder; import org.asciidoctor.SafeMode; -import org.asciidoctor.extension.BlockMacroProcessor; -import org.asciidoctor.extension.BlockProcessor; -import org.asciidoctor.extension.DocinfoProcessor; -import org.asciidoctor.extension.IncludeProcessor; -import org.asciidoctor.extension.InlineMacroProcessor; -import org.asciidoctor.extension.JavaExtensionRegistry; -import org.asciidoctor.extension.Postprocessor; -import org.asciidoctor.extension.Preprocessor; -import org.asciidoctor.extension.Processor; -import org.asciidoctor.extension.Treeprocessor; +import org.asciidoctor.extension.*; import org.asciidoctor.extension.spi.ExtensionRegistry; import org.asciidoctor.internal.JRubyRuntimeContext; import org.jboss.arquillian.config.descriptor.api.ArquillianDescriptor; @@ -29,22 +20,13 @@ import org.jboss.arquillian.core.spi.EventContext; import org.jruby.Ruby; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; +import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; @@ -53,11 +35,11 @@ // fork of asciidoctor maven plugin public class AsciidoctorObserver { - + private static Logger LOGGER; - + private static final Pattern ASCIIDOC_EXTENSION_PATTERN = Pattern.compile("^[^_.].*\\.a((sc(iidoc)?)|d(oc)?)$"); - + private static Map asciidoctorMap = new HashMap<>(); @Inject @@ -82,7 +64,7 @@ public void run() { adocThread.setDaemon(true); adocThread.start(); } - + private void initAsciidoctor(ArquillianDescriptor arquillianDescriptor) { for (final ExtensionDef extensionDef : arquillianDescriptor.getExtensions()) { @@ -208,7 +190,7 @@ private void render(final String name, final Map extensionDef) { throw new RuntimeException("Asciidoctor not initilizable properly."); } - final Ruby rubyInstance = JRubyRuntimeContext.get(); + final Ruby rubyInstance = JRubyRuntimeContext.get(asciidoctor); final String gemHome = rubyInstance.evalScriptlet("ENV['GEM_HOME']").toString(); final String gemHomeExpected = (gemPath == null || "".equals(gemPath)) ? "" : gemPath.split(java.io.File.pathSeparator)[0]; if (!"".equals(gemHome) && !gemHomeExpected.equals(gemHome)) { @@ -273,6 +255,7 @@ private void render(final String name, final Map extensionDef) { } optionsBuilder.attributes(attributesBuilder); + new AsciidoctorJExtensionRegistry(extensions, extensionDef).register(asciidoctor); for (final String resource : resources) { @@ -346,11 +329,27 @@ public FileVisitResult postVisitDirectory(final Path dir, final IOException exc) } - private void renderFile(final String name, final Asciidoctor asciidoctor, final Map options, final File f) { + private void renderFile(final String name, final Asciidoctor asciidoctor, final Map options, File f) { + ExtensionGroup cukedoctorExtensionGroup = asciidoctor.createGroup("com.github.cukedoctor"); + if (options.get("backend").toString().equalsIgnoreCase("pdf") && cukedoctorExtensionIsPresent()) { + cukedoctorExtensionGroup.unregister(); + } else if(cukedoctorExtensionIsPresent()){ + cukedoctorExtensionGroup.unregister();//avoid register twice + cukedoctorExtensionGroup.register(); + } asciidoctor.renderFile(f, options); getLogger().info("Rendered " + f + " @ " + name); } + private boolean cukedoctorExtensionIsPresent() { + try { + Class.forName("com.github.cukedoctor.extension.CukedoctorExtensionRegistry"); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } + private void setDestinationPaths(final OptionsBuilder optionsBuilder, final File sourceFile, final boolean preserveDirectories, final File outputDir, final boolean relativeBaseDir, final String baseDir, final File sourceDir) {