<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2022 the original author or authors.
  ~
  ~ Licensed 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
  ~
  ~      https://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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>net.ttddyy.observation</groupId>
        <artifactId>datasource-micrometer-parent</artifactId>
        <version>1.0.0-M1</version>
    </parent>

    <artifactId>datasource-micrometer-docs</artifactId>
    <name>datasource-micrometer-docs</name>

    <properties>
        <maven.compiler.target>17</maven.compiler.target>
        <maven.compiler.source>17</maven.compiler.source>

        <configprops.path>${project.basedir}/target/_configprops.adoc</configprops.path>
        <configprops.inclusionPattern>jdbc.*</configprops.inclusionPattern>

        <micrometer-docs-generator.inputPath>${maven.multiModuleProjectDirectory}/datasource-micrometer/</micrometer-docs-generator.inputPath>
        <micrometer-docs-generator.inclusionPattern>.*</micrometer-docs-generator.inclusionPattern>
        <micrometer-docs-generator.outputPath>${project.build.directory}</micrometer-docs-generator.outputPath>
    </properties>

    <dependencies>
        <!-- Script -->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>${script-commons-logging.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${script-spring-core.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${script-jackson-databind.version}</version>
            <scope>compile</scope>
        </dependency>

        <!-- Deps for which we want to build a table of configuration properties -->
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>datasource-micrometer-spring-boot</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>docs</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>pl.project13.maven</groupId>
                        <artifactId>git-commit-id-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>revision</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>generate-configprops</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration>
                                    <mainClass>net.ttddyy.observation.docs.Main
                                    </mainClass>
                                    <arguments>
                                        <argument>${configprops.path}</argument>
                                        <argument>${configprops.inclusionPattern}
                                        </argument>
                                    </arguments>
                                </configuration>
                            </execution>

                            <execution>
                                <id>generate-metrics-metadata</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration>
                                    <mainClass>
                                        io.micrometer.docs.metrics.DocsFromSources
                                    </mainClass>
                                </configuration>
                            </execution>

                            <execution>
                                <id>generate-tracing-metadata</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration>
                                    <mainClass>io.micrometer.docs.spans.DocsFromSources
                                    </mainClass>
                                </configuration>
                            </execution>

                        </executions>
                        <dependencies>
                            <dependency>
                                <groupId>io.micrometer</groupId>
                                <artifactId>micrometer-docs-generator-spans</artifactId>
                                <version>${micrometer-docs-generator.version}</version>
                                <type>jar</type>
                            </dependency>
                            <dependency>
                                <groupId>io.micrometer</groupId>
                                <artifactId>micrometer-docs-generator-metrics</artifactId>
                                <version>${micrometer-docs-generator.version}</version>
                                <type>jar</type>
                            </dependency>
                        </dependencies>
                        <configuration>
                            <includePluginDependencies>true</includePluginDependencies>
                            <arguments>
                                <argument>${micrometer-docs-generator.inputPath}
                                </argument>
                                <argument>${micrometer-docs-generator.inclusionPattern}
                                </argument>
                                <argument>${micrometer-docs-generator.outputPath}
                                </argument>
                            </arguments>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.asciidoctor</groupId>
                        <artifactId>asciidoctor-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>asciidoc-to-html</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>process-asciidoc</goal>
                                </goals>
                                <configuration>
                                    <backend>html5</backend>
                                    <outputDirectory>
                                        ${project.build.directory}/generated-docs/reference/html
                                    </outputDirectory>
                                    <doctype>book</doctype>
                                    <attributes>
                                        <docinfo>shared</docinfo>
                                        <icons>font</icons>
                                        <highlightjs-theme>github</highlightjs-theme>
                                        <imagesdir>./images</imagesdir>
                                        <attribute-missing>warn</attribute-missing>
                                        <revnumber>${project.version}</revnumber>
                                    </attributes>
                                </configuration>
                            </execution>
                        </executions>
                        <dependencies>
                            <dependency>
                                <groupId>io.spring.asciidoctor</groupId>
                                <artifactId>spring-asciidoctor-extensions-block-switch</artifactId>
                                <version>0.6.0</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <dependencies>
                            <dependency>
                                <groupId>ant-contrib</groupId>
                                <artifactId>ant-contrib</artifactId>
                                <version>${ant-contrib.version}</version>
                                <exclusions>
                                    <exclusion>
                                        <groupId>ant</groupId>
                                        <artifactId>ant</artifactId>
                                    </exclusion>
                                </exclusions>
                            </dependency>
                            <dependency>
                                <groupId>org.apache.ant</groupId>
                                <artifactId>ant-nodeps</artifactId>
                                <version>${ant-nodeps.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>org.tigris.antelope</groupId>
                                <artifactId>antelopetasks</artifactId>
                                <version>${antelopetasks.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>org.jruby</groupId>
                                <artifactId>jruby-complete</artifactId>
                                <version>${jruby-complete.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>org.asciidoctor</groupId>
                                <artifactId>asciidoctorj</artifactId>
                                <version>${asciidoctorj.version}</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>assert-no-unresolved-links</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <fileset id="unresolved.file"
                                                 dir="${basedir}/target/generated-docs/"
                                                 includes="**/*.html">
                                            <contains text="Unresolved"/>
                                        </fileset>
                                        <fail message="[Unresolved] Found...failing">
                                            <condition>
                                                <resourcecount when="greater"
                                                               count="0"
                                                               refid="unresolved.file"/>
                                            </condition>
                                        </fail>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>

            <pluginRepositories>
                <pluginRepository>
                    <id>spring-snapshots</id>
                    <name>Spring Snapshots</name>
                    <url>https://repo.spring.io/snapshot</url> <!-- For Snapshots -->
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                </pluginRepository>
                <pluginRepository>
                    <id>spring-milestones</id>
                    <name>Spring Milestones</name>
                    <url>https://repo.spring.io/milestone</url>  <!-- For Milestones -->
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>spring-release</id>
                    <name>Spring Releases</name>
                    <url>https://repo.spring.io/release</url>  <!-- For Releases -->
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>

</project>
