<?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>

    <groupId>de.qytera</groupId>
    <artifactId>qtaf</artifactId>
    <version>0.0.9</version>
    <packaging>pom</packaging>

    <name>${project.groupId}:${project.artifactId}</name>
    <description>The QTAF (Qytera Test Automation Framework) core library.</description>
    <url>https://github.com/Qytera-Gmbh/QTAF</url>

    <licenses>
        <license>
            <name>MIT License</name>
            <url>http://www.opensource.org/licenses/mit-license.php</url>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>Qytera Development</name>
            <email>info@qytera.de</email>
            <organization>Qytera Software Testing Solutions GmbH</organization>
            <organizationUrl>https://www.qytera.de/</organizationUrl>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:git://github.com/Qytera-Gmbh/QTAF.git</connection>
        <developerConnection>scm:git:ssh://github.com/Qytera-Gmbh/QTAF.git</developerConnection>
        <url>https://github.com/Qytera-Gmbh/QTAF</url>
    </scm>

    <modules>
        <module>qtaf-core</module>
        <module>qtaf-io</module>
        <module>qtaf-html-report-plugin</module>
        <module>qtaf-allure-plugin</module>
        <module>qtaf-xray-plugin</module>
        <module>qtaf-http</module>
        <module>qtaf-data</module>
    </modules>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <!-- versions -->
        <lombokVersion>1.18.26</lombokVersion>
        <mavenCompilerPluginVersion>3.10.1</mavenCompilerPluginVersion>
        <lombokPluginVersion>1.18.20.0</lombokPluginVersion>
        <surefirePluginVersion>3.0.0</surefirePluginVersion>
    </properties>

    <profiles>
        <!--
        A profile that automatically 'delomboks' submodules (i.e. converts them into vanilla Java). Delombokization is
        necessary because otherwise, the compiled and packaged class files would not match the packaged sources. This
        is problematic when QTAF is used as a dependency and developers would like to step through QTAF code during
        debugging. They would not be able to put 'proper' breakpoints into QTAF code, since the executed code
        (classfile) would not be consistent with the visible code (source file).

        The root module is excluded as it simply does not contain any sources to package into a JAR. Submodules are
        identified through absence of the 'qtaf-core' directory.
        -->
        <profile>
            <id>delombok-profile</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <file>
                    <missing>qtaf-core</missing>
                </file>
            </activation>
            <properties>
                <delombokDirectory>${project.build.directory}/delombok</delombokDirectory>
            </properties>
            <build>
                <plugins>
                    <!-- A plugin for transforming lombok-annotated classes back into vanilla Java. -->
                    <plugin>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok-maven-plugin</artifactId>
                        <version>${lombokPluginVersion}</version>
                        <configuration>
                            <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
                            <outputDirectory>${delombokDirectory}</outputDirectory>
                            <addOutputDirectory>false</addOutputDirectory>
                            <encoding>UTF-8</encoding>
                            <verbose>true</verbose>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>delombok</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- A plugin for packaging the delomboked sources into a JAR file. -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>generate-delomboked-sources-jar</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <jar
                                                destfile="${project.build.directory}/${project.build.finalName}-sources.jar"
                                                basedir="${delombokDirectory}"
                                        />
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- A plugin for attaching the packaged sources to the overall build artifacts. -->
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <version>3.3.0</version>
                        <executions>
                            <execution>
                                <id>attach-source-jar</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>attach-artifact</goal>
                                </goals>
                                <configuration>
                                    <artifacts>
                                        <artifact>
                                            <file>${project.build.directory}/${project.build.finalName}-sources.jar
                                            </file>
                                            <type>jar</type>
                                            <classifier>sources</classifier>
                                        </artifact>
                                    </artifacts>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- A plugin for creating Javadoc files from the delombokized sources. -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>3.5.0</version>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <sourcepath>${delombokDirectory}</sourcepath>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombokVersion}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

        <plugins>
            <!-- Plugin to compile the code -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${mavenCompilerPluginVersion}</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                </configuration>
            </plugin>

            <!-- Plugin to build a JAR file -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.3.0</version>

                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>/</classpathPrefix>
                            <mainClass>de.qytera.qtaf.testng.QtafTestNGRunner</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <!-- This maven plugin is responsible for generating the GPG signatures -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>sgn-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                        <configuration>
                            <keyname>0x643DE5DE</keyname>
                            <passphraseServerId>0x643DE5DE</passphraseServerId>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- This maven plugin deploys the artifacts to OSSRH -->
            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>1.6.13</version>
                <extensions>true</extensions>
                <configuration>
                    <serverId>ossrh</serverId>
                    <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
                    <autoReleaseAfterClose>true</autoReleaseAfterClose>
                </configuration>
            </plugin>

            <!-- A plugin for running testng test (suites, groups, ...). -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefirePluginVersion}</version>
            </plugin>

        </plugins>
    </build>

    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>

</project>
