asciidoctor / asciidoctor-ant

:ant: Ant task to render Asciidoc documentation
Apache License 2.0
9 stars 5 forks source link

Can't run example extension #42

Closed rockyallen closed 8 years ago

rockyallen commented 8 years ago

Trying the "ChangeAttributeValuePreprocessor" example from the AsciidoctorJ project, and my own Ant build script. test1 works as expected, and produces dist/test.xml. When I run test2, I get:

org.jruby.exceptions.RaiseException: (Errno::ENOENT) /home/rocky/doc/test.ad at org.jruby.RubyFile.initialize(org/jruby/RubyFile.java:361) at org.jruby.RubyIO.new(org/jruby/RubyIO.java:851) at RUBY.convert_file(/home/rocky/Documents/asciidoc-demo/lib/asciidoctor-ant-1.5.2-SNAPSHOT.jar!/gems/asciidoctor-1.5.2/lib/asciidoctor.rb:1562) at RUBY.convertFile(script:68) at org.jruby.gen.InterfaceImpl2006909763.convertFile(org/jruby/gen/InterfaceImpl2006909763.gen:13) BUILD FAILED (total time: 11 seconds)

ChangeAttributeValuePreprocessor .java:

import java.util.Map;
import org.asciidoctor.ast.Document;
import org.asciidoctor.extension.Preprocessor;
import org.asciidoctor.extension.PreprocessorReader;

public class ChangeAttributeValuePreprocessor extends Preprocessor {

    public ChangeAttributeValuePreprocessor(Map<String, Object> config) {
        super(config);
    }

    @Override
    public PreprocessorReader process(Document document, PreprocessorReader reader) {
        document.getAttributes().put("content", "Alex");
        return reader;
    }
}

build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project name="asciidoc-demo" default="default" basedir="." xmlns:asciidoctor="antlib:org.asciidoctor.ant">
<!-- snapshot 1 December 2015 -->
    <property name="aa.jar" location="lib/asciidoctor-ant-1.5.2-SNAPSHOT.jar"/>

    <target name="clean">
        <delete dir="build"/>
        <delete dir="dist"/>
   </target>

    <target name="test1" depends="clean">
         <taskdef uri="antlib:org.asciidoctor.ant" resource="org/asciidoctor/ant/antlib.xml" classpath="${aa.jar}"/>
        <mkdir dir="dist"/>
        <asciidoctor:convert sourceDirectory="doc" outputDirectory="dist"/>
    </target>

     <target name="test2" depends="clean">
        <mkdir dir="build/classes"/>
        <mkdir dir="dist"/>
        <javac srcdir="src" destdir="build/classes" classpath="${aa.jar}" includeantruntime="false"/>
        <taskdef uri="antlib:org.asciidoctor.ant" resource="org/asciidoctor/ant/antlib.xml" classpath="${aa.jar};build/classes"/>
        <asciidoctor:convert sourceDirectory="doc" outputDirectory="dist">
            <preprocessor className="ChangeAttributeValuePreprocessor"/>
        </asciidoctor:convert>     
    </target>
</project>

Using Ubuntu 14.04, Java 1.8.0_66, Apache Ant 1.9.3, Asciidoctor-ant 1.52 SNAPSHOT @ 2015-12-01.

Am I missing something?

binout commented 8 years ago

thx for the detail, i have reproduced the problem ...

and in fact the problem is in AsciidoctorJ, there is a problem with loading java class without a package such as com.*

if you add a package com.binout to the Prepropcessor, it works !!

package com.binout;

import java.util.Map;
import org.asciidoctor.ast.Document;
import org.asciidoctor.extension.Preprocessor;
import org.asciidoctor.extension.PreprocessorReader;

public class ChangeAttributeValuePreprocessor extends Preprocessor {

    public ChangeAttributeValuePreprocessor(Map<String, Object> config) {
        super(config);
    }

    @Override
    public PreprocessorReader process(Document document, PreprocessorReader reader) {
        document.getAttributes().put("content", "Alex");
        return reader;
    }
}
     <target name="test2" depends="clean">
        <mkdir dir="build/classes"/>
        <mkdir dir="dist"/>
        <javac srcdir="src" destdir="build/classes" classpath="${aa.jar}" includeantruntime="false"/>
        <taskdef uri="antlib:org.asciidoctor.ant" resource="org/asciidoctor/ant/antlib.xml" classpath="${aa.jar};build/classes"/>
        <asciidoctor:convert sourceDirectory="doc" outputDirectory="dist">
            <preprocessor className="com.binout.ChangeAttributeValuePreprocessor"/>
        </asciidoctor:convert>     
    </target>
rockyallen commented 8 years ago

Fix works, thanks. Where should this be documented?

binout commented 8 years ago

It's an issue of asciidoctorj https://github.com/asciidoctor/asciidoctorj/issues/250 and it seems to be fixed in 1.5.2.1. It will be included in next release of asciidoctor-ant ;-)