Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't run example extension #42

Closed
rockyallen opened this issue Nov 30, 2015 · 3 comments
Closed

Can't run example extension #42

rockyallen opened this issue Nov 30, 2015 · 3 comments

Comments

@rockyallen
Copy link
Contributor

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
Copy link
Contributor

binout commented Dec 4, 2015

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
Copy link
Contributor Author

Fix works, thanks. Where should this be documented?

@binout
Copy link
Contributor

binout commented Dec 13, 2015

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

@binout binout closed this as completed Dec 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants