<?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>
    <parent>
        <groupId>io.smallrye</groupId>
        <artifactId>smallrye-open-api-tools</artifactId>
        <version>3.3.2</version>
    </parent>
    <artifactId>smallrye-open-api-gradle-plugin</artifactId>
    <packaging>pom</packaging>

    <name>SmallRye: OpenAPI Tools :: Gradle</name>
    <description>a Gradle plugin that can generate the schema on build</description>

    <properties>
        <gradle.executable>./gradlew</gradle.executable>
        <gradle.task>build</gradle.task>
        <skip.gradle.build>false</skip.gradle.build>
        <artifactFilePrefix>${project.artifactId}</artifactFilePrefix>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.smallrye</groupId>
            <artifactId>smallrye-open-api-core</artifactId>
        </dependency>
        <dependency>
            <groupId>io.smallrye</groupId>
            <artifactId>smallrye-open-api-jaxrs</artifactId>
        </dependency>
        <dependency>
            <groupId>io.smallrye</groupId>
            <artifactId>smallrye-open-api-spring</artifactId>
        </dependency>
        <dependency>
            <groupId>io.smallrye</groupId>
            <artifactId>smallrye-open-api-vertx</artifactId>
        </dependency>
        <dependency>
            <groupId>io.smallrye.config</groupId>
            <artifactId>smallrye-config</artifactId>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- copy all dependencies to target/dependencies -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <inherited>false</inherited>
                        <configuration>
                            <useBaseVersion>true</useBaseVersion>
                            <addParentPoms>true</addParentPoms>
                            <copyPom>true</copyPom>
                            <useRepositoryLayout>true</useRepositoryLayout>
                            <outputDirectory>${project.build.directory}/dependencies</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>write-gradle-properties</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>.</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/maven-build</directory>
                                    <includes>
                                        <include>gradle.properties</include>
                                    </includes>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>gradle</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${gradle.executable}</executable>
                            <arguments>
                                <argument>clean</argument>
                                <argument>${gradle.task}</argument>
                                <argument>-Pdescription=${project.description}</argument>
                                <argument>-Dmaven.repo.local=${settings.localRepository}</argument>
                                <argument>-S</argument>
                                <argument>--stacktrace</argument>
                                <argument>--no-daemon</argument>
                            </arguments>
                            <environmentVariables>
                                <MAVEN_REPO_LOCAL>${settings.localRepository}</MAVEN_REPO_LOCAL>
                                <GRADLE_OPTS>${env.MAVEN_OPTS}</GRADLE_OPTS>
                            </environmentVariables>
                            <skip>${skip.gradle.build}</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>build/libs/${artifactFilePrefix}-${project.version}.jar</file>
                                    <type>jar</type>
                                </artifact>
                                <artifact>
                                    <file>build/libs/${artifactFilePrefix}-${project.version}-javadoc.jar</file>
                                    <type>jar</type>
                                    <classifier>javadoc</classifier>
                                </artifact>
                                <artifact>
                                    <file>build/libs/${artifactFilePrefix}-${project.version}-sources.jar</file>
                                    <type>jar</type>
                                    <classifier>sources</classifier>
                                </artifact>
                            </artifacts>
                            <skipAttach>${skip.gradle.build}</skipAttach>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-compile</id>
                        <phase>none</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>windows</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
            </activation>
            <properties>
                <gradle.executable>gradlew.bat</gradle.executable>
            </properties>
        </profile>
        <profile>
            <id>skipTests</id>
            <activation>
                <property>
                    <name>skipTests</name>
                    <value>true</value>
                </property>
            </activation>
            <properties>
                <gradle.task>assemble</gradle.task>
            </properties>
        </profile>
        <profile>
            <id>maven.test.skip</id>
            <activation>
                <property>
                    <name>maven.test.skip</name>
                    <value>true</value>
                </property>
            </activation>
            <properties>
                <gradle.task>assemble</gradle.task>
            </properties>
        </profile>
        <profile>
            <id>gradle-smoke-test</id>
            <build>
                <plugins>
                    <!--
                    Set up the Gradle plugin smoke test, reflecting the order of artifact install /
                    publish as the release process does:
                    1. Call Gradle to publish to the local Meven repo
                    2. Maven "install"
                    Then call the "smoke test Gradle build", so it has the "same" artifacts as a release.
                    -->
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>gradle-smoketest-publish</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>${gradle.executable}</executable>
                                    <arguments>
                                        <argument>publishToMavenLocal</argument>
                                        <argument>-Dsmallrye-openapi-version=${project.version}</argument>
                                        <argument>-Dmaven.repo.local=${settings.localRepository}</argument>
                                        <argument>--stacktrace</argument>
                                        <argument>--no-daemon</argument>
                                    </arguments>
                                    <environmentVariables>
                                        <MAVEN_REPO_LOCAL>${settings.localRepository}</MAVEN_REPO_LOCAL>
                                        <GRADLE_OPTS>${env.MAVEN_OPTS}</GRADLE_OPTS>
                                    </environmentVariables>
                                    <skip>${skip.gradle.build}</skip>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-install-plugin</artifactId>
                        <!-- Need the artifacts installed for the Gradle plugin smoke test -->
                        <!-- Downside: install happens twice :( -->
                        <executions>
                            <execution>
                                <id>gradle-smoketest-install</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>install</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>gradle-smoketest</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>${gradle.executable}</executable>
                                    <arguments>
                                        <argument>--project-dir</argument>
                                        <argument>smoke-test/</argument>
                                        <argument>clean</argument>
                                        <argument>assemble</argument>
                                        <argument>-Dsmallrye-openapi-version=${project.version}</argument>
                                        <argument>-Dmaven.repo.local=${settings.localRepository}</argument>
                                        <argument>--stacktrace</argument>
                                        <argument>--no-daemon</argument>
                                        <argument>--info</argument>
                                    </arguments>
                                    <environmentVariables>
                                        <MAVEN_REPO_LOCAL>${settings.localRepository}</MAVEN_REPO_LOCAL>
                                        <GRADLE_OPTS>${env.MAVEN_OPTS}</GRADLE_OPTS>
                                    </environmentVariables>
                                    <skip>${skip.gradle.build}</skip>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
