<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.kosdev.kos.sdk.bom</groupId>
        <artifactId>kos-bom-parent</artifactId>
        <version>1.9.0</version>
    </parent>

    <groupId>com.kosdev.kos.sdk.api</groupId>
    <artifactId>api-info</artifactId>
    <name>${project.groupId}:${project.artifactId}</name>
    <description>kOS SDK Bill-of-Materials meta-data</description>
    <url>https://kosdev.com</url>

    <!-- ====== Dependencies ======================================================================================= -->

    <dependencies>
        <dependency>
            <groupId>com.kosdev.kos.sdk.api</groupId>
            <artifactId>api-core-info</artifactId>
            <version>${api-core.version}</version>
        </dependency>
        <dependency>
            <groupId>com.kosdev.kos.sdk.api</groupId>
            <artifactId>api-dispense-info</artifactId>
            <version>${api-dispense.version}</version>
        </dependency>
        <dependency>
            <groupId>com.kosdev.kos.sdk.api</groupId>
            <artifactId>api-freestyle-info</artifactId>
            <version>${api-freestyle.version}</version>
        </dependency>
    </dependencies>

    <!-- ====== Build ============================================================================================== -->

    <build>
        <plugins>
            <!-- 2️⃣ Shade Plugin: include JSONs into kos.info inside the final JAR -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.5.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <transformers>
                                <!-- Append each file from temp folder individually -->
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>kos.sdk/sdk-kos.core.json</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>kos.sdk/sdk-kos.ext.dispense.json</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>kos.sdk/sdk-kos.ext.freestyle.json</resource>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

<!--            &lt;!&ndash; Build templates (pom-to-deploy.xml) &ndash;&gt;-->
<!--            <plugin>-->
<!--                <groupId>org.apache.maven.plugins</groupId>-->
<!--                <artifactId>maven-resources-plugin</artifactId>-->
<!--                <version>3.3.1</version>-->
<!--                <executions>-->
<!--                    <execution>-->
<!--                        <id>copy-templates</id>-->
<!--                        <phase>generate-resources</phase>-->
<!--                        <goals>-->
<!--                            <goal>resources</goal>-->
<!--                        </goals>-->
<!--                        <configuration>-->
<!--                            <outputDirectory>templates/output</outputDirectory>-->
<!--                            <resources>-->
<!--                                <resource>-->
<!--                                    <directory>templates</directory>-->
<!--                                    <includes>-->
<!--                                        <include>pom-to-deploy.xml</include>-->
<!--                                    </includes>-->
<!--                                    <filtering>true</filtering>-->
<!--                                </resource>-->
<!--                            </resources>-->
<!--                        </configuration>-->
<!--                    </execution>-->
<!--                </executions>-->
<!--            </plugin>-->
        </plugins>
    </build>

    <!-- ====== Profiles ================================================================ -->

    <profiles>

        <!-- ========================================================= -->
        <!-- Automation: attach + sign publishable artifacts           -->
        <!-- ========================================================= -->

        <profile>
            <id>automation</id>
            <build>
                <plugins>

                    <!-- Attach sources -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.3.1</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Attach pom-to-deploy.xml as a publishable artifact -->
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <version>3.5.0</version>
                        <executions>
                            <execution>
                                <id>attach-pom-to-deploy</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>attach-artifact</goal>
                                </goals>
                                <configuration>
                                    <artifacts>
                                        <artifact>
                                            <file>pom.xml</file>
                                            <type>xml</type>
                                            <classifier>pom</classifier>
                                        </artifact>
                                    </artifacts>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Sign all artifacts -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>3.2.4</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                </plugins>
            </build>
        </profile>

    </profiles>

    <!-- ====== Repositories ======================================================================================= -->

    <pluginRepositories>
        <pluginRepository>
            <id>kos.public</id>
            <url>https://kondra.mycloudrepo.io/public/repositories/kos-public</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>daily</updatePolicy>
                <checksumPolicy>fail</checksumPolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
                <checksumPolicy>fail</checksumPolicy>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</project>
