asciidoctor / asciidoclet

:clipboard: A Javadoc Doclet based on Asciidoctor that lets you write Javadoc in the AsciiDoc syntax.
https://github.com/asciidoctor/asciidoclet
Apache License 2.0
132 stars 40 forks source link

SPI extensions not loading #64

Open adpr opened 7 years ago

adpr commented 7 years ago

I am using asciidoctorj 1.5.4, asciidoctorj-pdf 1.5.0-alpha.11 and asciidoclet 1.5.4 in a maven project. I have defined some custom BlockProcessors and registered them using the javaExtensionRegistry and created the proper files in my META-INF/services folder.

Generating the PDF works flawlessly, and my custom BlockProcessors are recognized and rendered as they should be. In the Javadoc however, the custom BlockProcessors are not rendered at all, and asciidoctor reports the many warnings about the BlockProcessors not being recognized:

asciidoctor: WARNING: <stdin>: line 7: invalid style for paragraph: eks

If I throw a RuntimeException in the register method of my class that implements ExtensionRegistry, I can see that generating a PDF will throw the exception, but generating the Javadoc does not. It would seem that that extensions are not being loaded by AsciidoctorJ when generating the Javadoc.

Here is one of my BlockProcessors:

public class EksBlock extends BlockProcessor {

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

  @Override
  public Object process(AbstractBlock parent, Reader reader, Map<String, Object> attributes) {
    // attributes that a normal admonition would accept
    attributes.put("name", "EKS");
    attributes.put("caption", "EKS.");

    // just pass along the text
    String admonitionText = reader.read();

    return createBlock(parent, "admonition", admonitionText, attributes, new HashMap<Object, Object>());
  }
}

My ExtensionRegistry implementation:

public class BlockExtensionRegistry implements ExtensionRegistry {

  public void register(Asciidoctor asciidoctor) {
    Map<String, Object> config = new HashMap<String, Object>();
    config.put("contexts", Arrays.asList(":paragraph"));
    config.put("content_model", ":compound");

    EksBlock eksBlock = new EksBlock("eks", config);
  }
}

I also have the following file:

src/main/resources/META-INF/services/org.asciidoctor.extension.spi.ExtensionRegistry

File content:

com.example.extension.asciidoctor.BlockExtensionRegistry

Snippet from pom.xml

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <configuration>
      <failOnError>false</failOnError>
      <noqualifier>all</noqualifier>
      <show>private</show>
      <doclet>org.asciidoctor.Asciidoclet</doclet>
      <docletArtifact>
        <groupId>org.asciidoctor</groupId>
        <artifactId>asciidoclet</artifactId>
        <version>1.5.4</version>
      </docletArtifact>
      <additionalparam>
        --base-dir ${project.basedir}
        --attribute "name=${project.name}"
        --attribute "version=${project.version}"
        --attribute
        "templateDir=${project.basedir}/src/docs/asciidoc/template"
      </additionalparam>
    </configuration>
</plugin>

Am I missing some configuration in my pom.xml that will allow Asciidoclet to register the extensions, or is this an issue with Asciidoclet?

johncarl81 commented 5 years ago

Are you expecting Asciidoclet to pick up your EksBlock block processor within your project?