<?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.44.0.Final</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.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.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>
              <environmentVariables>
                <CI>true</CI>
              </environmentVariables>
              <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>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
      </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>
