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

    <name>Starlake Orchestration</name>
    <description>Starlake Orchestration Modules</description>
    <url>https://starlake.ai</url>
    <inceptionYear>2025</inceptionYear>

    <organization>
        <name>Starlake AI</name>
        <url>https://starlake.ai</url>
    </organization>

    <licenses>
        <license>
            <name>The Apache License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>

    <scm>
        <connection>scm:git:git://github.com/starlake-ai/starlake.git</connection>
        <developerConnection>scm:git:ssh://github.com:starlake-ai/starlake.git</developerConnection>
        <url>https://github.com/starlake-ai/starlake</url>
        <tag>HEAD</tag>
    </scm>

    <developers>
        <developer>
            <id>fupelaqu</id>
            <name>Stéphane Manciot</name>
            <email>admin@softnetwork.fr</email>
            <organization>Softnetwork</organization>
            <organizationUrl>https://github.com/SOFTNETWORK-APP</organizationUrl>
        </developer>
    </developers>

    <groupId>ai.starlake</groupId>
    <artifactId>orchestration</artifactId>
    <version>0.4.3</version>
    <packaging>pom</packaging>

    <modules>
        <module>starlake-orchestration</module>
        <module>starlake-airflow</module>
        <module>starlake-dagster</module>
        <module>starlake-snowflake</module>
    </modules>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <python.executable>python3</python.executable>
        <python.repo.url>https://upload.pypi.org/legacy/</python.repo.url>
    </properties>

    <pluginRepositories>
        <pluginRepository>
            <id>ossrh</id>
            <name>Sonatype OSSRH</name>
            <url>https://s01.oss.sonatype.org/content/repositories/releases/</url>
        </pluginRepository>
    </pluginRepositories>

    <build>
        <pluginManagement>
            <plugins>
                <!-- plugin for jar packaging -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.3.0</version>
                    <configuration>
                        <includes>
                            <include>**/*</include>
                        </includes>
                    </configuration>
                </plugin>

                <!-- GPG signature -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-gpg-plugin</artifactId>
                    <version>3.2.4</version>
                    <executions>
                        <execution>
                            <id>sign-artifacts</id>
                            <phase>verify</phase>
                            <goals><goal>sign</goal></goals>
                        </execution>
                    </executions>
                    <configuration>
                        <signer>bc</signer>
                        <gpgArguments>
                            <arg>--batch</arg>
                            <arg>--pinentry-mode</arg>
                            <arg>loopback</arg>
                        </gpgArguments>
                    </configuration>
                </plugin>

                <!-- OSSRH publication -->
                <plugin>
                    <groupId>org.sonatype.central</groupId>
                    <artifactId>central-publishing-maven-plugin</artifactId>
                    <version>0.9.0</version>
                    <extensions>true</extensions>
                    <configuration>
                        <publishingServerId>central</publishingServerId>
                        <autoPublish>true</autoPublish>
                        <waitUntil>published</waitUntil>
                    </configuration>
                </plugin>

                <!-- plugin to deploy jar -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>3.1.2</version>
                </plugin>

                <!-- copy README.md to src/main/python before packaging -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.3.1</version>
                    <executions>
                        <execution>
                            <id>copy-readme</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.basedir}/src/main/python</outputDirectory>
                                <resources>
                                    <resource>
                                        <directory>${project.basedir}</directory>
                                        <includes>
                                            <include>README.md</include>
                                        </includes>
                                        <filtering>false</filtering>
                                    </resource>
                                </resources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <!-- plugin to manage license headers in Python files -->
                <plugin>
                    <groupId>com.mycila</groupId>
                    <artifactId>license-maven-plugin</artifactId>
                    <version>4.2</version>
                    <configuration>
                        <properties>
                            <year>${project.inceptionYear}</year>
                            <owner>${project.organization.name}</owner>
                            <url>${project.organization.url}</url>
                        </properties>
                        <licenseSets>
                            <licenseSet>
                                <header>${project.basedir}/../LICENSE.txt</header>
                                <excludes>
                                    <exclude>src/main/python/setup.py</exclude>
                                </excludes>
                                <includes>
                                    <include>src/main/python/**/*.py</include>
                                </includes>
                            </licenseSet>
                        </licenseSets>
                        <!--<strictCheck>false</strictCheck>//-->
                    </configuration>
                    <executions>
                        <execution>
                            <phase>validate</phase>
                            <goals>
                                <goal>format</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <!-- plugin to build and deploy Python package -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>3.1.0</version>

                    <executions>
                        <!-- build Python package -->
                        <execution>
                            <id>build-python-package</id>
                            <phase>package</phase>
                            <goals><goal>exec</goal></goals>
                            <configuration>
                                <executable>${python.executable}</executable>
                                <workingDirectory>${project.basedir}/src/main/python</workingDirectory>
                                <arguments>
                                    <argument>-m</argument>
                                    <argument>build</argument>
                                    <argument>--outdir</argument>
                                    <argument>${project.build.directory}/dist</argument>
                                </arguments>
                                <environmentVariables>
                                    <PROJECT_VERSION>${project.version}</PROJECT_VERSION>
                                </environmentVariables>
                            </configuration>
                        </execution>

                        <!-- deploy Python package to PyPI -->
                        <execution>
                            <id>deploy-python-package</id>
                            <phase>deploy</phase>
                            <goals><goal>exec</goal></goals>
                            <configuration>
                                <executable>${python.executable}</executable>
                                <workingDirectory>${project.build.directory}</workingDirectory>
                                <arguments>
                                    <argument>-m</argument>
                                    <argument>twine</argument>
                                    <argument>upload</argument>
                                    <argument>--repository-url</argument>
                                    <argument>${python.repo.url}</argument>
                                    <argument>dist/*</argument>
                                </arguments>
                                <environmentVariables>
                                    <TWINE_USERNAME>__token__</TWINE_USERNAME>
                                    <TWINE_PASSWORD>${env.PYPI_TOKEN}</TWINE_PASSWORD>
                                </environmentVariables>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <!-- ====================================================================== -->
    <!-- 3️⃣ Profils : release / snapshot / deploy -->
    <!-- ====================================================================== -->
    <profiles>

        <!-- Profil RELEASE activated by default -->
        <profile>
            <id>release</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.sonatype.central</groupId>
                        <artifactId>central-publishing-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- Profil SNAPSHOT to activate if version includes -SNAPSHOT -->
        <profile>
            <id>snapshot</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- JAR ONLY -->
        <profile>
            <id>jar</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <!-- skip Python plugin -->
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- PY only -->
        <profile>
            <id>py</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <!-- skip build/deploy JAR -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- JAR + PY -->
        <profile>
            <id>all</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
        </profile>
    </profiles>
</project>
