<?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.trino.epsg</groupId>
        <artifactId>epsg-catalog-root</artifactId>
        <version>1</version>
    </parent>

    <artifactId>epsg-catalog</artifactId>
    <name>${project.artifactId}</name>
    <description>EPSG catalog and basic runtime loader</description>

    <licenses>
        <license>
            <name>Apache License 2.0</name>
            <url>https://www.apache.org/licenses/LICENSE-2.0</url>
            <distribution>repo</distribution>
        </license>
        <license>
            <name>EPSG terms of use</name>
            <url>https://epsg.org/terms-of-use.html</url>
            <distribution>manual</distribution>
        </license>
    </licenses>

    <dependencies>
        <dependency>
            <groupId>io.airlift</groupId>
            <artifactId>aircompressor-v3</artifactId>
        </dependency>

        <dependency>
            <groupId>io.airlift</groupId>
            <artifactId>junit-extensions</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.sis.core</groupId>
            <artifactId>sis-referencing</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.opengis</groupId>
            <artifactId>geoapi</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <dependencies>
                    <dependency>
                        <groupId>io.trino.epsg</groupId>
                        <artifactId>epsg-catalog-generator</artifactId>
                        <version>${project.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>generate-epsg-catalog</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <!-- Run the generator in its own JVM: SIS shutdown hooks fail inside the Maven JVM, and the Zstd compressor
                                 needs sun.misc.Unsafe memory access, which the JDK warns about unless it is allowed -->
                            <executable>${java.home}/bin/java</executable>
                            <includePluginDependencies>true</includePluginDependencies>
                            <arguments>
                                <argument>--sun-misc-unsafe-memory-access=allow</argument>
                                <argument>-classpath</argument>
                                <classpath />
                                <argument>io.trino.epsg.generator.GenerateEpsgCatalog</argument>
                                <argument>${project.build.directory}/generated-resources/epsg</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-catalog</id>
                        <goals>
                            <goal>add-resource</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>${project.build.directory}/generated-resources/epsg</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
