<?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>drools-build-parent</artifactId>
    <version>8.26.0.Beta</version>
    <relativePath>../build-parent/pom.xml</relativePath>
  </parent>

  <artifactId>drools-docs</artifactId>
  <packaging>pom</packaging>

  <name>Drools documentation</name>
  <url>https://www.drools.org/</url>

  <properties>
    <!--
    Antora ignores hidden files. The docs website should not incorporate this file as it brings the single-paged docs
    duplicating the other content.
    -->
    <source.document.name>.index.adoc</source.document.name>
    <antora.playbook>antora-playbook.yml</antora.playbook>
    <antora.binary>node_modules/.bin/antora</antora.binary>
    <version.node>v16.2.0</version.node>
    <version.npm>7.15.1</version.npm>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.asciidoctor</groupId>
        <artifactId>asciidoctor-maven-plugin</artifactId>
        <configuration>
          <sourceDirectory>${basedir}/src/modules/ROOT/pages</sourceDirectory>
          <resources>
            <resource>
              <directory>${basedir}/src/modules/ROOT/images</directory>
            </resource>
          </resources>
          <attributes>
            <drools-repo-dir>${basedir}/..</drools-repo-dir>
            <drools-version>${project.version}</drools-version>
            <java-version>${maven.compiler.release}</java-version>
            <maven-version>${maven.min.version}</maven-version>
            <quarkus-version>${version.io.quarkus}</quarkus-version>
          </attributes>
        </configuration>
        <executions>
          <execution>
            <id>generate-single-html</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>process-asciidoc</goal>
            </goals>
            <configuration>
              <sourceDocumentName>${source.document.name}</sourceDocumentName>
              <backend>html5</backend>
              <outputDirectory>${project.build.directory}/generated-docs/html_single</outputDirectory>
              <outputFile>index.html</outputFile>
              <attributes>
                <imagesdir>.</imagesdir>
                <source-highlighter>highlightjs</source-highlighter>
              </attributes>
            </configuration>
          </execution>
          <execution>
            <id>generate-pdf</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>process-asciidoc</goal>
            </goals>
            <configuration>
              <sourceDocumentName>${source.document.name}</sourceDocumentName>
              <backend>pdf</backend>
              <outputDirectory>${project.build.directory}/generated-docs/pdf</outputDirectory>
              <outputFile>index.pdf</outputFile>
              <attributes>
                <imagesdir>${basedir}/src/modules/ROOT/images</imagesdir>
                <source-highlighter>coderay</source-highlighter>
              </attributes>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>generate-antora-yml</id>
            <goals>
              <goal>resources</goal>
            </goals>
            <phase>process-resources</phase>
            <configuration>
              <resources>
                <resource>
                  <directory>${project.basedir}/src</directory>
                  <targetPath>${project.build.directory}</targetPath>
                  <includes>
                    <include>antora-template.yml</include>
                  </includes>
                  <filtering>true</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>rename-antora-yml</id>
            <goals>
              <goal>run</goal>
            </goals>
            <phase>process-resources</phase>
            <configuration>
              <target>
                <copy file="${project.build.directory}/antora-template.yml" tofile="${project.basedir}/src/antora.yml" />
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>install node and npm</id>
            <goals>
              <goal>install-node-and-npm</goal>
            </goals>
            <phase>initialize</phase>
            <configuration>
              <nodeVersion>${version.node}</nodeVersion>
              <npmVersion>${version.npm}</npmVersion>
            </configuration>
          </execution>
          <execution>
            <id>npm install antora</id>
            <goals>
              <goal>npm</goal>
            </goals>
            <phase>initialize</phase>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>exec</goal>
            </goals>
            <phase>compile</phase>
            <configuration>
              <executable>node/node</executable>
              <arguments>
                <argument>${antora.binary}</argument>
                <argument>--generator</argument>
                <argument>@antora/site-generator</argument>
                <argument>${antora.playbook}</argument>
                <argument>--to-dir=target/website/docs</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>

    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-assembly-plugin</artifactId>
          <executions>
            <execution>
              <id>package-generated-docs</id>
              <phase>package</phase>
              <goals>
                <goal>single</goal>
              </goals>
              <configuration>
                <finalName>${project.artifactId}-${project.version}</finalName>
                <appendAssemblyId>false</appendAssemblyId>
                <descriptors>
                  <descriptor>src/main/assembly/generated-docs-zip.xml</descriptor>
                </descriptors>
                <archive>
                  <addMavenDescriptor>true</addMavenDescriptor>
                </archive>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

  <profiles>
    <profile>
      <id>antora-windows</id>
      <activation>
        <os>
          <family>Windows</family>
        </os>
      </activation>
      <properties>
        <!-- The wrapper script node_modules/.bin/antora does not resolve the path to this file correctly. -->
        <antora.binary>node_modules/@antora/cli/bin/antora</antora.binary>
      </properties>
    </profile>
  </profiles>
</project>
