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

Maven Site does not work with .adoc where dependency depends from gem like ditaa extension #168

Closed
alexandrenavarro opened this issue Sep 4, 2015 · 14 comments
Assignees
Milestone

Comments

@alexandrenavarro
Copy link

Maven Site does not work with .adoc where dependency depends from gem like ditaa extension

I try to generate a maven site a .adoc with dita.

When I used asciidoctor-maven-plugin directly with .adoc, it works but not with the maven-site.

To reproduce the problem take this sample

https://github.com/asciidoctor/asciidoctor-maven-examples/tree/master/asciidoctor-diagram-example

add in your pom.xml

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <version>3.4</version>
            <dependencies>
                <dependency>
                    <groupId>org.asciidoctor</groupId>
                    <artifactId>asciidoctor-maven-plugin</artifactId>
                    <version>${asciidoctor.maven.plugin.version}</version>
                </dependency>
            </dependencies>
        </plugin>

and copy src/docs/asciidoc into src/site/asciidoc .

You will see

[INFO] Rendering 1 Doxia document: 1 asciidoc
asciidoctor: WARNING: <stdin>: line 18: invalid style for literal block: ditaa
asciidoctor: WARNING: <stdin>: line 38: invalid style for literal block: plantuml

I think the problem is the maven-site-plugin does not know the dependency of the gem but I can't add the dependency of the gems (maven can't download) or add an equivalent of

<gemPath>${project.build.directory}/gems-provided</gemPath>
<requires>
<require>asciidoctor-diagram</require>
</requires>

Tell me is a way to configure the maven-site to succeed to generate site or if it is a bug.

@abelsromero
Copy link
Member

This is a know issue realted to this #160.

The thing is that the site module is a completely different component running under doxia API and we haven't figured out a nice way to pass configurations parameters to the site plugin.

Let's awaken the beast again and continue the conversation on the other side.

@robertpanzer
Copy link
Member

There is actually a way to work around this problem when using AsciidoctorJ 1.5.3.2:
You have to build an own artifact, let's say t's called foo.bar:asciidoctor-site-diagram-activator:1.0, that contains a service implementation of the class org.asciidoctor.extension.spi.ExtensionRegistry:

package foo.bar;

import org.asciidoctor.Asciidoctor;
import org.asciidoctor.extension.spi.ExtensionRegistry;

public class AsciidoctorDiagramConfigurator implements ExtensionRegistry {
    @Override
    public void register(Asciidoctor asciidoctor) {
        asciidoctor.requireLibrary("asciidoctor-diagram");
    }
}

Then configure it as a service implementation by adding a file META-INF/services/org.asciidoctor.extension.spi.ExtensionRegistry that only contains the fully qualified class name of AsciidoctorDiagramConfigurator.

Then you have to configure the site plugin to use this artifact:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-site-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctor-maven-plugin</artifactId>
            <version>1.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj</artifactId>
            <version>1.5.3.2</version>
        </dependency>
        <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj-diagram</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>foo.bar</groupId>
            <artifactId>asciidoctor-site-diagram-activator</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>
</plugin>

Finally in your document ensure that the diagrams get generated to the correct directories:

= Test document
:imagesoutdir: target/site/resources/images
:imagesdir: images

A small diagram:

[plantuml,classdiagram,png]
----
class A
class B
A --|> B
----

@robertpanzer
Copy link
Member

I somehow got the imagesoutdir wrong in my last comment, have to recheck how it has to be.
But I think you get the idea.

@mojavelinux
Copy link
Member

mojavelinux commented Dec 13, 2015 via email

@robertpanzer
Copy link
Member

Just retested and there was an error in the imagesoutdir attribute:
It must be target/site/images:

= Test document
:imagesoutdir: target/site/images
:imagesdir: images

A small diagram:

[plantuml,classdiagram,png]
----
class A
class B
A --|> B
----

@robertpanzer
Copy link
Member

Another point: mvn site:run doesn't seem to pick up the images.
But the diagrams appear when rendering the site via mvn site and serving it via another HTTP server like ruby -run -e httpd . -p 9090

@mojavelinux
Copy link
Member

It will be possible to specify requires in version 1.5.3 of the plugin.

@mojavelinux mojavelinux added this to the 1.5.3 milestone Dec 14, 2015
@mojavelinux mojavelinux self-assigned this Dec 14, 2015
mojavelinux added a commit to mojavelinux/asciidoctor-maven-plugin that referenced this issue Dec 14, 2015
…or#168 & asciidoctor#160 enable configuratino for site parser

- rewrite Maven Site parser to make more organized and extensible
- pass AsciiDoc configuration in Maven Site plugin to Asciidoctor API
- enhance Maven Site integration test
  - add custom template
  - add include
  - add source highlighting
  - make validation code compatible with Java 6
- enable integration tests on Travis
- remove unused legacy site module
mojavelinux added a commit to mojavelinux/asciidoctor-maven-plugin that referenced this issue Dec 14, 2015
…or#168 & asciidoctor#160 enable configuration for site parser

- rewrite Maven Site parser to make more organized and extensible
- pass AsciiDoc configuration in Maven Site plugin to Asciidoctor API
- enhance Maven Site integration test
  - add custom template
  - add include
  - add source highlighting
  - make validation code compatible with Java 6
- enable integration tests on Travis
- remove unused legacy site module
mojavelinux added a commit to mojavelinux/asciidoctor-maven-plugin that referenced this issue Dec 14, 2015
…or#168 & asciidoctor#160 enable configuration for site parser

- rewrite AsciidoctorParser (used by Maven Site Plugin) to make it more organized and extensible
- pass AsciiDoc configuration defined in Maven Site plugin to the Asciidoctor API
- enhance Maven Site integration test
  - add custom template
  - add include
  - add source highlighting
  - make validation code compatible with Java 6
- enable integration tests on Travis CI
- remove unused legacy site module
- fix license headers
- minor cleanups
mojavelinux added a commit to mojavelinux/asciidoctor-maven-plugin that referenced this issue Dec 14, 2015
…or#168 & asciidoctor#160 enable configuration for site parser

- rewrite AsciidoctorParser (used by Maven Site Plugin) to make it more organized and extensible
- pass AsciiDoc configuration defined in Maven Site plugin to the Asciidoctor API
- enhance Maven Site integration test
  - add custom template
  - add include
  - add source highlighting
  - make validation code compatible with Java 6
- enable integration tests on Travis CI
- remove unused legacy site module
- fix license headers
- minor cleanups
@mojavelinux
Copy link
Member

Once version 1.5.3 of the plugin is out, you'll be able to do the following:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-site-plugin</artifactId>
    <version>3.3</version> <!-- 3.4 also works -->
    <configuration>
        <asciidoc>
            <requires>
                <require>asciidoctor-diagram</require>
            </requires>
        </asciidoc>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctor-maven-plugin</artifactId>
            <version>1.5.3</version>
        </dependency>
    </dependencies>
</plugin>

mojavelinux added a commit to mojavelinux/asciidoctor-maven-plugin that referenced this issue Dec 14, 2015
…or#168 & asciidoctor#160 enable configuration for site parser

- rewrite AsciidoctorParser (used by Maven Site Plugin) to make it more organized and extensible
- specify baseDir by default when invoking Asciidoctor API
- pass AsciiDoc configuration defined in Maven Site plugin to the Asciidoctor API
  - API options (e.g., templateDir)
  - Ruby options (e.g., requires)
  - AsciiDoc attributes (e.g., icons=font)
- enhance Maven Site integration test
  - add custom template
  - add include
  - add source highlighting
  - make validation code compatible with Java 6
- enable integration tests on Travis CI
- remove unused legacy site module
- fix license headers
- minor cleanups
mojavelinux added a commit to mojavelinux/asciidoctor-maven-plugin that referenced this issue Dec 14, 2015
…or#168 & asciidoctor#160 enable configuration for site parser

- rewrite AsciidoctorParser (used by Maven Site Plugin) to make it more organized and extensible
- specify baseDir by default when invoking Asciidoctor API
- pass AsciiDoc configuration defined in Maven Site plugin to the Asciidoctor API
  - API options (e.g., templateDir)
  - Ruby options (e.g., requires)
  - AsciiDoc attributes (e.g., icons=font)
- enhance Maven Site integration test
  - add custom template
  - add include
  - add source highlighting
  - make validation code compatible with Java 6
- enable integration tests on Travis CI and Appveyor
- remove unused legacy site module
- fix license headers
- minor cleanups
mojavelinux added a commit to mojavelinux/asciidoctor-maven-plugin that referenced this issue Dec 14, 2015
…or#168 & asciidoctor#160 enable configuration for site parser

- rewrite AsciidoctorParser (used by Maven Site Plugin) to make it more organized and extensible
- specify baseDir by default when invoking Asciidoctor API
- pass AsciiDoc configuration defined in Maven Site plugin to the Asciidoctor API
  - API options (e.g., templateDir)
  - Ruby options (e.g., requires)
  - AsciiDoc attributes (e.g., icons=font)
- enhance Maven Site integration test
  - add custom template
  - add include
  - add source highlighting
  - make validation code compatible with Java 6
- enable integration tests on Travis CI and Appveyor
- remove unused legacy site module
- fix license headers
- minor cleanups
mojavelinux added a commit that referenced this issue Dec 15, 2015
resolves #170, #180, #179, #168 & #160 enable configuration for site parser
@ptahchiev
Copy link
Contributor

Is there anything special to do to make it work? My site-plugin configuration is the following (with asciidoctor-maven-plugin:1.5.3-SNAPSHOT):

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>${maven.site.plugin.version}</version>
                    <configuration>
                        <generateReports>false</generateReports>
                        <generateSitemap>true</generateSitemap>
                        <relativizeDecorationLinks>false</relativizeDecorationLinks>
                        <locales>en</locales>
                        <chmod>true</chmod>
                        <inputEncoding>UTF-8</inputEncoding>
                        <outputEncoding>UTF-8</outputEncoding>
                        <attributes>
                            <generated>${basedir}/target/asciidoc/generated</generated>
                        </attributes>
                        <asciidoc>
                            <requires>
                                <require>asciidoctor-diagram</require>
                            </requires>
                        </asciidoc>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.asciidoctor</groupId>
                            <artifactId>asciidoctor-maven-plugin</artifactId>
                            <version>${asciidoctor.version}</version>
                        </dependency>
                        <dependency>
                            <groupId>org.apache.maven.wagon</groupId>
                            <artifactId>wagon-ssh</artifactId>
                            <version>${wagon.version}</version>
                        </dependency>
                        <dependency>
                            <groupId>org.apache.maven.wagon</groupId>
                            <artifactId>wagon-ssh-common</artifactId>
                            <version>${wagon.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>

Still when I try to create a website, maven tells me:

[INFO] Rendering 6 Doxia documents: 6 asciidoc
[ERROR] (LoadError) no such file to load -- asciidoctor-diagram
[ERROR] (LoadError) no such file to load -- asciidoctor-diagram
[ERROR] (LoadError) no such file to load -- asciidoctor-diagram
[ERROR] (LoadError) no such file to load -- asciidoctor-diagram
[ERROR] (LoadError) no such file to load -- asciidoctor-diagram

@robertpanzer
Copy link
Member

Hi Petar!

yes, you also need to add the maven dependency to asciidoctorj-diagram:

                    <dependencies>
                        <dependency>
                            <groupId>org.asciidoctor</groupId>
                            <artifactId>asciidoctor-maven-plugin</artifactId>
                            <version>${asciidoctor.version}</version>
                        </dependency>
                        <dependency>
                            <groupId>org.asciidoctor</groupId>
                            <artifactId>asciidoctorj-diagram</artifactId>
                            <version>1.3.1</version>
                        </dependency>
                        <dependency>
                            <groupId>org.apache.maven.wagon</groupId>
                            <artifactId>wagon-ssh</artifactId>
                            <version>${wagon.version}</version>
                        </dependency>
                        <dependency>
                            <groupId>org.apache.maven.wagon</groupId>
                            <artifactId>wagon-ssh-common</artifactId>
                            <version>${wagon.version}</version>
                        </dependency>
                    </dependencies>

The require element will only tell asciidoctor to try to require this gem, but it is actually part of another module, that has to be included on the class path explicitly.

Cheers
Robert

@ptahchiev
Copy link
Contributor

I see... I added the asciidoctorj-diagram dependency and now errors are gone, the html is generated like this:

<div class="content">
<img src="asciidoctor-diagram-process.png" alt="asciidoctor diagram process" width="840" height="672">
</div>

But I can't find this asciidoctor-diagram-process.png file anywhere.

@ptahchiev
Copy link
Contributor

Sorry, my bad - I had it misconfigured. It works now

@robertpanzer
Copy link
Member

👍

Am Samstag, 19. Dezember 2015 schrieb Petar Tahchiev :

Sorry, my bad - I had it misconfigured. It works now


Reply to this email directly or view it on GitHub
#168 (comment)
.

abelsromero pushed a commit to abelsromero/asciidoctor-maven-plugin that referenced this issue Jan 8, 2016
…or#168 & asciidoctor#160 enable configuration for site parser

- rewrite AsciidoctorParser (used by Maven Site Plugin) to make it more organized and extensible
- specify baseDir by default when invoking Asciidoctor API
- pass AsciiDoc configuration defined in Maven Site plugin to the Asciidoctor API
  - API options (e.g., templateDir)
  - Ruby options (e.g., requires)
  - AsciiDoc attributes (e.g., icons=font)
- enhance Maven Site integration test
  - add custom template
  - add include
  - add source highlighting
  - make validation code compatible with Java 6
- enable integration tests on Travis CI and Appveyor
- remove unused legacy site module
- fix license headers
- minor cleanups
@smil2k
Copy link

smil2k commented Jul 13, 2017

Hi,

Just for the record:
In case you want to use diagrams in maven site generated content, then you need to do the following:

  1. Add asciidoctorj-diagram on the classpath of maven site plugin
  2. Add ruby "requires" on diagram
  3. Set the outdir attribute to the target/site. Otherwise the diagram will be rendered next to the adoc source.
  4. source-highlighter is unrelated, still was needed in order to get core syntax highlighting going

Full working example is:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.5.1</version>
        <dependencies>
          <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctor-maven-plugin</artifactId>
            <version>1.5.5</version>
          </dependency>
          <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj-diagram</artifactId>
            <version>1.5.4</version>
          </dependency>
          <dependency>
            <groupId>org.apache.maven.doxia</groupId>
            <artifactId>doxia-core</artifactId>
            <version>1.7</version>
          </dependency>
        </dependencies>

        <configuration>
          <asciidoc>
            <attributes>
              <source-highlighter>prettify</source-highlighter>
              <outdir>${basedir}/target/site</outdir>
            </attributes>
            <requires>
              <require>asciidoctor-diagram</require>
            </requires>
          </asciidoc>
        </configuration>
      </plugin>

Regarding step 3: I think this should be set by the doxia-asciidoc adapter, the same way it will also disable TOC and other stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants