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

Unable the access Maven Site properties from Asciidoctor Maven Plugin #170

Closed
obfischer opened this issue Sep 16, 2015 · 6 comments
Closed
Assignees
Milestone

Comments

@obfischer
Copy link
Contributor

The Asciidoctor Maven Plugin does not have access to the attributes for Maven Site defined in the configuration section of the Maven Site plugin. Here is an example configuration:

          <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.4</version>
                <inherited>true</inherited>
                <dependencies>
                    <dependency><!-- add support for ssh/scp -->
                        <groupId>org.apache.maven.wagon</groupId>
                        <artifactId>wagon-ssh</artifactId>
                        <version>1.0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.asciidoctor</groupId>
                        <artifactId>asciidoctor-maven-plugin</artifactId>
                        <version>${asciidoctor.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>lt.velykis.maven.skins</groupId>
                        <artifactId>reflow-velocity-tools</artifactId>
                        <version>${reflow-skin.version}</version>
                    </dependency>
                    <!-- Reflow skin requires Velocity >= 1.7  -->
                    <dependency>
                        <groupId>org.apache.velocity</groupId>
                        <artifactId>velocity</artifactId>
                        <version>1.7</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <attributes>
                        <ta>ddd</ta>
                    </attributes>
                </configuration>
            </plugin>

I can't in an Asciidoctor document now use any of there attributes while it is possible to do it when using the Maven plugin only to render Asciidoctor documents.

@mojavelinux
Copy link
Member

@abelsromero From what you seen, is it possible to pass on this configuration?

@abelsromero
Copy link
Member

Not that I know of, but this could be an options definetly worth looking into. Worst case scenario we just reverse engineer the whole plugin and confirm it does not work.

@obfischer
Copy link
Contributor Author

I found a workarount. I use the resouces plugin to write all properties to a file and include this file in my documents. A workaround. A direkt access to defined attributes would be more convenient.

@mojavelinux
Copy link
Member

@obfischer Neat workaround. I understand it's not ideal, but that at least gives us something to do to solve the problem in the meantime.

asfgit pushed a commit to apache/incubator-retired-tamaya that referenced this issue Sep 22, 2015
@mojavelinux
Copy link
Member

After a lot of trial and error, I've figured out how to get access to the configuration properties from parser. Pull request on the way. This is going to open a lot of doors.

@mojavelinux mojavelinux self-assigned this Dec 14, 2015
@mojavelinux mojavelinux added this to the 1.5.3 milestone 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
Copy link
Member

I finally figured out how to read the Maven model from within the site parser. This enables us to read the configuration block inside the site plugin declaration and pass those options and attributes on to Asciidoctor, just like with the main plugin. (The primary difference from the main plugin is that we have to process the entire configuration ourselves).

Since the site configuration is used for other purposes, I decided to move all the configuration under the <asciidoc> element. Here's an example that shows how to set both options and attributes:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-site-plugin</artifactId>
    <version>3.3</version> <!-- 3.4 also works -->
    <configuration>
        <asciidoc>
            <templateDir>src/site/asciidoc/templates</templateDir>
            <requires>
                <require>time</require>
            </requires>
            <attributes>
                <source-highlighter>coderay</source-highlighter>
                <coderay-css>style</coderay-css>
            </attributes>
        </asciidoc>
        <moduleExcludes>
            <asciidoc>**/_*.adoc</asciidoc>
        </moduleExcludes>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctor-maven-plugin</artifactId>
            <version>1.5.3</version>
        </dependency>
    </dependencies>
</plugin>

You'll notice that I added excludes for AsciiDoc. This prevents the site integration from processing include files as individual pages. You can tune this pattern to your liking. There is currently no way (that I can tell) to configure this automatically.

Here's how I made it all work.

First, I use the Plexus IoC container to inject the MavenProject instance into the AsciidoctorParser class (which took me several hours to figure out, btw):

@Requirement
protected MavenProject project;

Next, I use the MavenProject to access the configuration of the site plugin (which seems to work fine with the integration test project):

project.getGoalConfiguration("org.apache.maven.plugins", "maven-site-plugin", "site", "site");

From there, we have to walk the DOM to extract information and pass it on to the Asciidoctor API.

You can refer to the integration test project to see the full setup. https://github.com/asciidoctor/asciidoctor-maven-plugin/tree/master/src/it/maven-site-plugin

This change lays the groundwork for configuring the Asciidoctor instance used by the site plugin. There may be a better way to do it. The parser may not be passing on all the necessary configuration. But it's a starting point. We can improve on it from here.

Below is a list of the features that are now available from the site plugin:

  • set AsciiDoc attributes
  • set Asciidoctor options
  • specify a path to templates to activate and use the template converter
  • enable source highlighting from the plugin configuration
  • require additional Ruby libraries
  • designed to be extended to make it easier to create your own site parser

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 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 that referenced this issue Dec 15, 2015
resolves #170, #180, #179, #168 & #160 enable configuration for site parser
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
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

3 participants