<?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>
    <groupId>ru.curs</groupId>
    <artifactId>hurdy-gurdy</artifactId>
    <version>3.3</version>
    <packaging>maven-plugin</packaging>

    <name>OpenAPI codegen Maven Plugin</name>
    <description>Client/server code generator for OpenAPI</description>
    <url>https://github.com/CourseOrchestra/hurdy-gurdy</url>

    <organization>
        <name>CURS</name>
        <url>https://corchestra.ru</url>
    </organization>

    <scm>
        <url>https://github.com/CourseOrchestra/hurdy-gurdy.git</url>
    </scm>

    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>Ivan Ponomarev</name>
            <email>iponomarev@mail.ru</email>
        </developer>
    </developers>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.release>17</maven.compiler.release>
        <maven.compiler.plugin.version>3.15.0</maven.compiler.plugin.version>
        <maven.jar.plugin.version>3.5.1</maven.jar.plugin.version>
        <junit.version>6.1.2</junit.version>
        <maven.source.plugin.version>3.4.0</maven.source.plugin.version>
        <maven.javadoc.plugin.version>3.12.0</maven.javadoc.plugin.version>
        <kotlin.version>2.4.10</kotlin.version>
        <checkstyle.maven.plugin.version>3.6.0</checkstyle.maven.plugin.version>
        <checkstyle.version>13.9.0</checkstyle.version>
        <maven.enforcer.plugin.version>3.6.3</maven.enforcer.plugin.version>
        <extra.enforcer.rules.version>1.12.0</extra.enforcer.rules.version>
        <exec.maven.plugin.version>3.6.3</exec.maven.plugin.version>
        <license.maven.plugin.version>2.7.1</license.maven.plugin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.palantir.javapoet</groupId>
            <artifactId>javapoet</artifactId>
            <version>0.18.0</version>
        </dependency>
        <dependency>
            <groupId>info.picocli</groupId>
            <artifactId>picocli</artifactId>
            <version>4.7.7</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.squareup</groupId>
            <artifactId>kotlinpoet-jvm</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.46</version>
        </dependency>
        <dependency>
            <groupId>io.swagger.parser.v3</groupId>
            <artifactId>swagger-parser</artifactId>
            <version>2.1.45</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>7.0.8</version>
            <scope>compile</scope>
        </dependency>
        <!-- test -->
        <dependency>
            <groupId>jakarta.ws.rs</groupId>
            <artifactId>jakarta.ws.rs-api</artifactId>
            <version>4.0.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.microprofile.rest.client</groupId>
            <artifactId>microprofile-rest-client-api</artifactId>
            <version>4.0</version>
            <scope>test</scope>
        </dependency>
        <!-- Provides @RestForm and FileUpload so that generated Quarkus
             multipart code can be compile-verified. -->
        <dependency>
            <groupId>io.quarkus.resteasy.reactive</groupId>
            <artifactId>resteasy-reactive-common</artifactId>
            <version>3.38.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.approvaltests</groupId>
            <artifactId>approvaltests</artifactId>
            <version>31.0.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>2.0.18</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>3.27.7</version>
            <scope>test</scope>
        </dependency>
        <!-- DtoEqualsContractTest exercises the equals/hashCode contract of every
             generated DTO with EqualsVerifier. The `-nodep` variant bundles its own
             (shaded) ByteBuddy/Objenesis so verifying classes loaded by the test's
             child URLClassLoader does not clash with any transitive ByteBuddy on the
             build classpath. -->
        <dependency>
            <groupId>nl.jqno.equalsverifier</groupId>
            <artifactId>equalsverifier-nodep</artifactId>
            <version>4.5</version>
            <scope>test</scope>
        </dependency>
        <!-- Required at RUNTIME: swagger-parser's ObjectMapperFactory.createJson()
             registers Jackson's JavaTimeModule, so the class must be on the runtime
             (and native-image) classpath, not just in tests. Pinned explicitly so the
             version does not silently drift on a dependency bump. Must stay compile
             scope: as test scope it was stripped from the CLI jar and native image,
             causing NoClassDefFoundError/NoSuchMethodError at parse time (#TBD).
             Also used by DtoRoundTripTest to (de)serialize LocalDate DTO fields. -->
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.22.1</version>
        </dependency>
        <!-- KotlinRoundTripTest deserializes generated Kotlin data classes, which
             bind through their primary constructor: Jackson needs the Kotlin module
             to discover constructor parameter names and honour default values.
             Version pinned to the same Jackson train as jsr310 above. -->
        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-kotlin</artifactId>
            <version>2.22.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-plugin-api</artifactId>
            <version>3.9.16</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-core</artifactId>
            <version>3.9.16</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugin-tools</groupId>
            <artifactId>maven-plugin-annotations</artifactId>
            <version>3.15.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-core</artifactId>
            <version>11.0.24</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jdk8</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-test</artifactId>
            <version>${kotlin.version}</version>
            <scope>test</scope>
        </dependency>
        <!-- In-process Kotlin compiler, used by the test harness to verify that
             generated Kotlin code actually compiles. -->
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-compiler-embeddable</artifactId>
            <version>${kotlin.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <!-- Filter only the version file so ${project.version} is interpolated;
                 copy everything else (incl. native-image JSON) verbatim. -->
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>hurdy-gurdy-version.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <excludes>
                    <exclude>hurdy-gurdy-version.properties</exclude>
                </excludes>
            </resource>
            <!-- Bundle this project's own Apache-2.0 license text into both the plugin
                 jar and the shaded CLI jar. Placed at the jar root (/LICENSE) rather
                 than META-INF/LICENSE so the ApacheLicenseResourceTransformer (which
                 strips META-INF/LICENSE entries to de-duplicate the bundled ones) does
                 not drop it too. The per-dependency licenses are listed in
                 META-INF/THIRD-PARTY.txt. -->
            <resource>
                <directory>${project.basedir}</directory>
                <filtering>false</filtering>
                <includes>
                    <include>LICENSE</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>${maven.enforcer.plugin.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>extra-enforcer-rules</artifactId>
                        <version>${extra.enforcer.rules.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>enforce</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requireMavenVersion>
                                    <version>[3.9.0,)</version>
                                </requireMavenVersion>
                                <requireJavaVersion>
                                    <version>[21,)</version>
                                </requireJavaVersion>
                                <!-- Released library must not depend on SNAPSHOT artifacts -->
                                <requireReleaseDeps/>
                                <!-- No duplicate <dependency> entries in this POM -->
                                <banDuplicatePomDependencyVersions/>
                                <!-- Non-test dependencies (including transitive ones)
                                    must not require a JVM newer than the target bytecode version -->
                                <enforceBytecodeVersion>
                                    <maxJdkVersion>${maven.compiler.release}</maxJdkVersion>
                                    <searchTransitive>true</searchTransitive>
                                    <ignoredScopes>
                                        <ignoredScope>test</ignoredScope>
                                    </ignoredScopes>
                                </enforceBytecodeVersion>
                                <!-- Sources and resources must be valid UTF-8
                                    (${project.build.sourceEncoding}, which this rule also
                                    requires to be set), so the build does not depend on
                                    the platform encoding -->
                                <requireEncoding>
                                    <includes>src/main/**,src/test/**</includes>
                                    <acceptAsciiSubset>true</acceptAsciiSubset>
                                </requireEncoding>
                            </rules>
                            <fail>true</fail>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>3.15.2</version>
                <configuration>
                    <goalPrefix>hurdy-gurdy</goalPrefix>
                </configuration>
                <executions>
                    <execution>
                        <id>default-descriptor</id>
                        <phase>process-classes</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.5.6</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>${maven.jar.plugin.version}</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>${checkstyle.maven.plugin.version}</version>
                <executions>
                    <execution>
                        <id>verify-style</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <configLocation>checkstyle.xml</configLocation>
                    <suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
                    <propertyExpansion>checkstyle.header.file=${project.basedir}/header.txt</propertyExpansion>
                    <!-- Kotlin sources live under src/main/java alongside the Java ones,
                         so include them too and the Apache license header is enforced
                         on .java and .kt alike (see the Header module in checkstyle.xml). -->
                    <includes>**/*.java,**/*.kt</includes>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.puppycrawl.tools</groupId>
                        <artifactId>checkstyle</artifactId>
                        <version>${checkstyle.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>${maven.source.plugin.version}</version>
                <configuration>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>${maven.javadoc.plugin.version}</version>
                <configuration>
                    <show>public</show>
                    <attach>true</attach>
                    <maxmemory>1024m</maxmemory>
                    <excludePackageNames>org.apache.poi.*</excludePackageNames>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>3.2.8</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>0.11.0</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>central</publishingServerId>
                    <autoPublish>true</autoPublish>
                    <waitUntil>validated</waitUntil>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>${kotlin.version}</version>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <jvmTarget>${maven.compiler.release}</jvmTarget>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.6.2</version>
                <executions>
                    <execution>
                        <id>cli-shade</id>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>cli</shadedClassifierName>
                            <!-- com.github.java-json-tools:uri-template is dual-licensed
                                 Apache-2.0 / LGPLv3 and ships both license texts plus an
                                 AUTHORS file at its jar root. We elect the Apache-2.0 arm,
                                 so drop these stray root files (they would otherwise land
                                 in the fat-jar root and misleadingly suggest LGPL). The
                                 dependency is still recorded in META-INF/THIRD-PARTY.txt. -->
                            <filters>
                                <filter>
                                    <artifact>com.github.java-json-tools:uri-template</artifact>
                                    <excludes>
                                        <exclude>ASL-2.0.txt</exclude>
                                        <exclude>LGPL-3.0.txt</exclude>
                                        <exclude>AUTHORS</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>ru.curs.hurdygurdy.Main</mainClass>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                                <!-- The CLI jar bundles third-party bytecode, so it must carry their
                                     notices (Apache-2.0 §4). ApacheNoticeResourceTransformer merges the
                                     dependencies' META-INF/NOTICE files; ApacheLicenseResourceTransformer
                                     collapses their colliding META-INF/LICENSE entries. The complete
                                     per-dependency license listing (incl. rhino's MPL-2.0) is bundled
                                     separately as META-INF/THIRD-PARTY.txt by the license-maven-plugin. -->
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer">
                                    <addHeader>false</addHeader>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"/>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Generate a complete third-party license listing straight into the
                 build output (META-INF/THIRD-PARTY.txt) so it is packaged into both
                 the plugin jar and the shaded CLI jar. Limited to the scopes that are
                 actually shipped (compile/runtime), so it mirrors what the fat jar
                 bundles. Runs in prepare-package, before jar/shade run in package. -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>license-maven-plugin</artifactId>
                <version>${license.maven.plugin.version}</version>
                <executions>
                    <execution>
                        <id>bundle-third-party-notices</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>add-third-party</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.outputDirectory}/META-INF</outputDirectory>
                            <thirdPartyFilename>THIRD-PARTY.txt</thirdPartyFilename>
                            <excludedScopes>test,provided,system</excludedScopes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.plugin.version}</version>
                <executions>
                    <execution>
                        <id>default-compile</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>default-testCompile</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>java-compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>java-test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <release>${maven.compiler.release}</release>
                    <testRelease>21</testRelease>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>info.picocli</groupId>
                            <artifactId>picocli-codegen</artifactId>
                            <version>4.7.7</version>
                        </path>
                    </annotationProcessorPaths>
                    <compilerArgs>
                        <arg>-Aproject=${project.groupId}/${project.artifactId}</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
            <!-- "One goal to build them all": after the core/maven-plugin artifact is
                 installed into the local repository (the packaging's default install goal
                 runs first within the install phase), build the standalone Gradle plugin,
                 which resolves the core from mavenLocal. Bound to install, not package,
                 precisely because the Gradle build needs the freshly installed artifact. -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>${exec.maven.plugin.version}</version>
                <executions>
                    <execution>
                        <id>build-gradle-plugin</id>
                        <phase>install</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${gradlew.executable}</executable>
                            <workingDirectory>${project.basedir}/gradle-plugin</workingDirectory>
                            <arguments>
                                <argument>--no-daemon</argument>
                                <argument>publishToMavenLocal</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <!-- Select the correct Gradle wrapper launcher for the host OS. -->
        <profile>
            <id>gradle-windows</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
            </activation>
            <properties>
                <gradlew.executable>${project.basedir}/gradle-plugin/gradlew.bat</gradlew.executable>
            </properties>
        </profile>
        <profile>
            <id>gradle-unix</id>
            <activation>
                <os>
                    <family>unix</family>
                </os>
            </activation>
            <properties>
                <gradlew.executable>${project.basedir}/gradle-plugin/gradlew</gradlew.executable>
            </properties>
        </profile>
        <profile>
            <id>native</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.graalvm.buildtools</groupId>
                        <artifactId>native-maven-plugin</artifactId>
                        <!-- Do not bump to 1.1.6: it is broken, see
                             https://github.com/graalvm/native-build-tools/issues/1000.
                             Upgrade once 1.1.7 is released. -->
                        <version>1.1.5</version>
                        <extensions>true</extensions>
                        <executions>
                            <execution>
                                <id>build-native</id>
                                <goals>
                                    <goal>compile-no-fork</goal>
                                </goals>
                                <phase>package</phase>
                            </execution>
                        </executions>
                        <configuration>
                            <imageName>hurdy-gurdy</imageName>
                            <mainClass>ru.curs.hurdygurdy.Main</mainClass>
                            <metadataRepository>
                                <enabled>true</enabled>
                            </metadataRepository>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
