<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.apache.nifi.registry</groupId>
        <artifactId>nifi-registry-core</artifactId>
        <version>1.15.2</version>
    </parent>
    <packaging>pom</packaging>
    <artifactId>nifi-registry-docs</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.apache.nifi.registry</groupId>
            <artifactId>nifi-registry-web-api</artifactId>
            <version>1.15.2</version>
            <type>war</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-asciidoc</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>src/main/asciidoc</directory>
                                </resource>
                            </resources>
                            <outputDirectory>${project.build.directory}/asciidoc</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>            
            <plugin>
                <groupId>org.asciidoctor</groupId>
                <artifactId>asciidoctor-maven-plugin</artifactId>
                <version>1.5.8</version>
                <executions>
                    <execution>
                        <id>output-html</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>process-asciidoc</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <sourceDirectory>${project.build.directory}/asciidoc</sourceDirectory>
                    <outputDirectory>${project.build.directory}/generated-docs</outputDirectory>
                    <backend>html5</backend>
                    <attributes>
                        <imagesdir>./images</imagesdir>
                        <icons>font</icons>
                        <toc>true</toc>
                        <docVersion>${project.version}</docVersion>
                        <sectanchors>true</sectanchors>
                        <idprefix />
                        <idseparator>-</idseparator>
                        <docinfo1>true</docinfo1>
                        <stylesheet>asciidoc-mod.css</stylesheet>
                    </attributes>
                </configuration>
            </plugin>
            <!-- Unpack rest-api.html that was generated from nifi-registry-web-api and place it into a temp folder in the target dir -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <id>unpack-rest-api-doc</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeGroupIds>org.apache.nifi.registry</includeGroupIds>
                            <includeArtifactIds>nifi-registry-web-api</includeArtifactIds>
                            <outputDirectory>${project.build.directory}/nifi-registry-web-api/</outputDirectory>
                            <includes>**/rest-api.html</includes>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Copy rest-api.html from the tmp dir to the generated-docs dir where the other html docs are, this is done
                    in two steps to eliminate the nested path that was created in the temp dir when running unpack-dependencies
             -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <id>copy-rest-api-doc</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <sequential>
                                    <echo>Copy unpacked rest-api.html to generated-docs dir</echo>
                                    <copy todir="${project.build.directory}/generated-docs">
                                        <fileset dir="${project.build.directory}/nifi-registry-web-api/docs/rest-api/">
                                            <include name="**" />
                                        </fileset>
                                    </copy>
                                </sequential>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- This plugin is used to insert the Apache License into the output HMTL because
            AsciiDoc doesn't appear to provide a mechanism for doing this. -->
            <plugin>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>replacer</artifactId>
                <version>1.5.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <filesToInclude>${project.build.directory}/generated-docs/**.html</filesToInclude>
                    <regex>true</regex>
                    <regexFlags>
                        <regexFlag>DOTALL</regexFlag>
                        <regexFlag>MULTILINE</regexFlag>
                    </regexFlags>
                    <token>^(.*)$</token>
                    <value>
&lt;!--
                        Licensed to the Apache Software Foundation (ASF) under one or more
                        contributor license agreements.  See the NOTICE file distributed with
                        this work for additional information regarding copyright ownership.
                        The ASF licenses this file to You under the Apache License, Version 2.0
                        (the "License"); you may not use this file except in compliance with
                        the License.  You may obtain a copy of the License at

                        http://www.apache.org/licenses/LICENSE-2.0

                        Unless required by applicable law or agreed to in writing, software
                        distributed under the License is distributed on an "AS IS" BASIS,
                        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
                        See the License for the specific language governing permissions and
                        limitations under the License.
                        --&gt;
                        $1
                    </value>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.rat</groupId>
                <artifactId>apache-rat-plugin</artifactId>
                <configuration>
                    <excludes combine.children="append">
                        <!-- MIT license confirmed.  Excluding due to parse error-->
                        <exclude>src/main/asciidoc/asciidoc-mod.css</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <id>make shared resource</id>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                            <descriptors>
                                <descriptor>src/main/assembly/dependencies.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>            
        </plugins>
    </build>
</project>
