<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.kie</groupId>
    <artifactId>kie-docs</artifactId>
    <version>6.4.0.Final</version>
  </parent>

  <artifactId>jbpm-asciidocs</artifactId>
  <packaging>jdocbook</packaging>

  <name>KIE :: Documentation :: jBPM Asciidoc</name>
  <description>jBPM Asciidoc Documentation</description>

  <dependencies>
    <!-- Used by dependency:unpack. The explicit dependency is needed
         in order to make parallel builds work. -->
    <dependency>
      <groupId>org.jbpm</groupId>
      <artifactId>jbpm-docs</artifactId>
      <classifier>sources</classifier>
      <!-- Dependant modules do not need the sources jar, so use provided scope. -->
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <resources>
      <resource>
        <directory>src/main/asciidoc</directory>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
    </resources>

    <plugins>
      <!-- 0. clean up original docbook sources -->
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <configuration>
          <filesets>
            <fileset>
              <directory>src/main/docbook</directory>
              <followSymlinks>false</followSymlinks>
            </fileset>
          </filesets>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <!-- 1. copy original docbook sources -->
          <execution>
            <id>unpack-docbook-sources</id>
            <phase>initialize</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.jbpm</groupId>
                  <artifactId>jbpm-docs</artifactId>
                  <classifier>sources</classifier>
                  <type>jar</type>
                  <overWrite>false</overWrite>
                  <outputDirectory>src/main/docbook/en-US</outputDirectory>
                  <!-- *** exclude docbook files replaced by asciidoc generated docbook/xml files here: ** -->
                  <excludes>RemoteAPI/*,
                    RemoteAPI.xml</excludes>
                </artifactItem>
              </artifactItems>
              <excludes>**/*.properties,META-INF/*</excludes>
            </configuration>
          </execution>
          <!-- 1. copy code sources -->
          <execution>
            <id>unpack-example-code-sources</id>
            <phase>initialize</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.kie</groupId>
                  <artifactId>kie-docs-code</artifactId>
                  <version>${project.version}</version>
                  <classifier>sources</classifier>
                  <type>jar</type>
                  <overWrite>false</overWrite>
                  <!-- number of sub-directories is specific to allow linking to kie-docs/shared/ docbook -->
                  <outputDirectory>${project.build.directory}/code/</outputDirectory>
                  <includes>**/*.java</includes>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- 1. copy images from jbpm-docs -->
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-callout-icons</id>
            <phase>initialize</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/src/main/asciidoc/images/</outputDirectory>
              <resources>          
                <resource>
                  <directory>${basedir}/src/main/docbook/en-US/images/</directory>
                </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
      </plugin>
      
      <!-- 2. generate new docbook sources from asciidoc -->
      <plugin>
        <groupId>org.asciidoctor</groupId>
        <artifactId>asciidoctor-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>asciidoc-to-docbook</id>
            <phase>process-sources</phase>
            <goals>
              <goal>process-asciidoc</goal>
            </goals>
            <configuration>
              <sourceDirectory>src/main/asciidoc</sourceDirectory>
              <outputDirectory>src/main/docbook/en-US</outputDirectory>
              <preserveDirectories>true</preserveDirectories>
              <backend>docbook5</backend>
              <doctype>chapter</doctype>
              <sourceHighlighter>highlightjs</sourceHighlighter>
              <compact>true</compact>
              <attributes>
                <chapter/>
                <docinfo/>
                <nolang/>
                <icons>font</icons>
                <codeDir>${project.build.directory}/code</codeDir>
              </attributes>
            </configuration>
          </execution>
        </executions>
      </plugin>
      
      <!-- 3. fix generated docbook xml -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>xml-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>fix-docbook-chapters-and-sections</id>
            <phase>process-sources</phase>
            <goals>
              <goal>transform</goal>
            </goals>
            <configuration>
              <transformationSets>
                <!-- chapters -->
                <transformationSet>
                  <dir>src/main/docbook/en-US</dir>
                  <outputDir>src/main/docbook/en-US</outputDir>
                  <includes>
                    <include>*-chapter.xml</include>
                  </includes>
                  <stylesheet>src/main/resources/xslt/fixChapters.xslt</stylesheet>
                </transformationSet>
                <!-- sections -->
                <transformationSet>
                  <dir>src/main/docbook/en-US</dir>
                  <outputDir>src/main/docbook/en-US</outputDir>
                  <includes>
                    <include>**/*-section.xml</include>
                  </includes>
                  <stylesheet>src/main/resources/xslt/fixSections.xslt</stylesheet>
                </transformationSet>
                <!-- unique callout xml:id 
                <transformationSet>
                  <dir>src/main/docbook/en-US</dir>
                  <outputDir>src/main/docbook/en-US</outputDir>
                  <includes>
                    <include>**/*-section.xml</include>>
                  </includes>
                  <stylesheet>src/main/resources/xslt/unique-callout-xml-id.xslt</stylesheet>
                </transformationSet>
                <transformationSet>
                  <dir>src/main/docbook/en-US</dir>
                  <outputDir>src/main/docbook/en-US</outputDir>
                  <includes>
                    <include>**/*-section.xml</include>
                  </includes>
                  <stylesheet>src/main/resources/xslt/unique-callout-arearefs.xslt</stylesheet>
                </transformationSet>
                -->
              </transformationSets>
            </configuration>
          </execution>
        </executions>
      </plugin> 
     
      <!-- There are problems with the unique-ness of generate callout/co elements 
           ...So we don't generated the pdf.
      --> 
      <plugin>
        <groupId>org.jboss.maven.plugins</groupId>
        <artifactId>maven-jdocbook-plugin</artifactId>
        <extensions>true</extensions>
        <executions>
          <execution>
            <id>default-resources</id>
            <phase>process-resources</phase>
            <goals>
              <goal>resources</goal>
            </goals>
          </execution>
          <execution>
            <id>default-generate</id>
            <phase>compile</phase>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.jboss.pressgang</groupId>
            <artifactId>pressgang-xslt-ns</artifactId>
            <version>3.1.2</version>
            <scope>compile</scope>
          </dependency>
          <dependency>
            <groupId>org.jboss.pressgang</groupId>
            <artifactId>pressgang-jdocbook-style</artifactId>
            <version>3.1.2</version>
            <type>jdocbook-style</type>
            <scope>compile</scope>
          </dependency>
        </dependencies>
        <configuration>
          <sourceDocumentName>master.xml</sourceDocumentName>
          <masterTranslation>en-US</masterTranslation>
          <imageResource>
            <directory>${basedir}/src/main/docbook/en-US</directory>
            <includes>
              <include>images/</include>
            </includes>
          </imageResource>
          <formats>
            <format>
              <formatName>html_single</formatName>
              <stylesheetResource>classpath:/xslt/org/jboss/pressgang/xhtml-single.xsl</stylesheetResource>
              <finalName>index.html</finalName>
            </format>
            <format>
              <formatName>html</formatName>
              <stylesheetResource>classpath:/xslt/org/jboss/pressgang/xhtml.xsl</stylesheetResource>
              <finalName>index.html</finalName>
            </format>
          </formats>
          <injections>
            <injection>
              <name>project.version</name>
              <value>${project.version}</value>
            </injection>
          </injections>
          <options>
            <xmlTransformerType>saxon</xmlTransformerType>
            <xincludeSupported>true</xincludeSupported>
            <useRelativeImageUris>true</useRelativeImageUris>
          </options>
        </configuration>
      </plugin>
      
    </plugins>
  </build>
</project>
