<?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>com.vaadin</groupId>
        <artifactId>vaadin-quarkus-extension-parent</artifactId>
        <version>24.10-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>vaadin-quarkus-extension</artifactId>
    <name>Vaadin Quarkus Extension</name>
    <description>Dependency for a Quarkus project.</description>

    <properties>
        <vaadin.version>${project.version}</vaadin.version>
        <!-- Aligned with vaadin-quarkus -->
        <quarkus.version>3.20.1</quarkus.version>
    </properties>

    <repositories>
        <!-- The order of definitions matters. Explicitly defining central here to make sure it has the highest priority. -->

        <!-- Main Maven repository -->
        <repository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>vaadin-prereleases</id>
            <url>https://maven.vaadin.com/vaadin-prereleases</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <type>pom</type>
                <scope>import</scope>
                <version>${project.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-quarkus</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>com.vaadin</groupId>
                    <artifactId>flow-server</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-core</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>com.vaadin</groupId>
                    <artifactId>hilla-dev</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-core-jandex</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.5.0</version>
                <executions>
                    <execution>
                        <id>unpack-extension-resources</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.vaadin</groupId>
                                    <artifactId>vaadin-quarkus</artifactId>
                                    <type>jar</type>
                                    <outputDirectory>${project.build.directory}/build/quarkus-metadata</outputDirectory>
                                    <includes>META-INF/quarkus-extension.yaml</includes>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.vaadin</groupId>
                                    <artifactId>vaadin-quarkus</artifactId>
                                    <classifier>codestarts</classifier>
                                    <type>jar</type>
                                    <outputDirectory>${project.build.directory}/build/quarkus-codestarts
                                    </outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.5.1</version>
                <executions>
                    <execution>
                        <id>prepare-extension-metadata</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${env.JAVA_HOME}/bin/java</executable>
                            <workingDirectory>${project.basedir}/scripts</workingDirectory>
                            <arguments>
                                <argument>MetaDataReplacements.java</argument>
                                <argument>${project.build.directory}/build/quarkus-metadata/META-INF/quarkus-extension.yaml</argument>
                                <argument>${project.version}</argument>
                                <argument>${vaadin.quarkus.version}</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <!--
                        Extracts the contents of the 'vaadin-quarkus' codestarts and prepares for packaging
                        in vaadin-quarkus-extension codestart artifact, pinning platform version in codestart.yml
                        -->
                        <id>clone-extension-codestarts</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/processed-quarkus-codestarts</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.build.directory}/build/quarkus-codestarts</directory>
                                    <excludes>
                                        <exclude>**/codestart.yml</exclude>
                                        <exclude>META-INF/**</exclude>
                                    </excludes>
                                    <filtering>false</filtering>
                                </resource>
                                <resource>
                                    <directory>${project.build.directory}/build/quarkus-codestarts</directory>
                                    <includes>
                                        <include>**/codestart.yml</include>
                                    </includes>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-extension-maven-plugin</artifactId>
                <version>${quarkus.version}</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>extension-descriptor</goal>
                        </goals>
                        <configuration>
                            <extensionFile>
                                ${project.build.directory}/build/quarkus-metadata/META-INF/quarkus-extension.yaml
                            </extensionFile>
                            <deployment>${project.groupId}:${project.artifactId}-deployment:${project.version}
                            </deployment>
                            <skipExtensionValidation>true</skipExtensionValidation>
                            <skipCodestartValidation>true</skipCodestartValidation>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <!-- Attach cloned codestart jar to the build, for deployment -->
                        <id>generate-codestart-jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <classesDirectory>${project.build.directory}/processed-quarkus-codestarts</classesDirectory>
                            <classifier>codestarts</classifier>
                            <skipIfEmpty>true</skipIfEmpty>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
