<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright (c) 2019, 2025 Oracle and/or its affiliates.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<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
                             https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>io.helidon.integrations.cdi</groupId>
        <artifactId>helidon-integrations-cdi-project</artifactId>
        <version>4.2.2</version>
    </parent>
    <artifactId>helidon-integrations-cdi-jpa</artifactId>
    <name>Helidon CDI Integrations JPA</name>

    <properties>
        <doclint>-syntax</doclint>
        <eclipselink.skip>false</eclipselink.skip>
        <helidon.jta.immediateEnlistment>false</helidon.jta.immediateEnlistment>
        <helidon.jta.interposedSynchronizations>true</helidon.jta.interposedSynchronizations>
        <helidon.jta.preemptiveEnlistmentChecks>true</helidon.jta.preemptiveEnlistmentChecks>
        <hibernate.skip>false</hibernate.skip>
        <spotbugs.exclude>etc/spotbugs/exclude.xml</spotbugs.exclude>
    </properties>

    <dependencies>

        <!-- Compile-scoped dependencies. -->
        <dependency>
            <groupId>io.helidon.integrations.cdi</groupId>
            <artifactId>helidon-integrations-cdi-reference-counted-context</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>io.helidon.integrations.jta</groupId>
            <artifactId>helidon-integrations-jta-jdbc</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <!--
                In a perfect world, this would be set to provided
                scope, since whatever JAXB runtime the user selects
                would provide the API jar it implements, assuming of
                course it's compatible with the version we select
                here.
                In practice, setting the scope to provided here causes
                the combination of JPMS and the maven-compiler-plugin
                to fail:
                * The jakarta.xml.bind module uses the
                  jakarta.activation module (this project does not). The
                  jakarta.activation module is, inconveniently,
                  "implemented" by two possible API artifacts (!):
                  jakarta.activation:activation-api and
                  com.sun.activation:jakarta.activation. The
                  jakarta.xml.bind:jakarta.xml.bind-api artifact depends
                  on com.sun.activation:jakarta.activation, not
                  jakarta.activation:activation-api (as one might
                  naively suspect). All of this is important to the
                  next bullet point.
                * When jakarta.xml.bind:jakarta.xml.bind-api is placed
                  in provided scope, the
                  com.sun.activation:jakarta.activation artifact's
                  jakarta.activation module does not end up on the
                  module path at compile time and a "module not found:
                  jakarta.activation" error is emitted.
                Happily, setting the scope to compile and setting the
                optional element to true, as is done here, gives the
                desired provided semantics while placing the
                transitive dependencies properly on the module path.
            -->
            <scope>compile</scope>
            <optional>true</optional>
        </dependency>

        <!-- Provided-scoped dependencies. -->
        <dependency>
            <groupId>jakarta.annotation</groupId>
            <artifactId>jakarta.annotation-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.enterprise</groupId>
            <artifactId>jakarta.enterprise.cdi-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.persistence</groupId>
            <artifactId>jakarta.persistence-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.transaction</groupId>
            <artifactId>jakarta.transaction-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.microprofile.config</groupId>
            <artifactId>microprofile-config-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Runtime-scoped dependencies. -->
        <dependency>
            <groupId>io.smallrye</groupId>
            <artifactId>jandex</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <!--
                In a perfect world, the scope of this dependency would
                be test, properly indicating that at runtime the end
                user is responsible for supplying her choice of JAXB
                runtime implementation that implements
                jakarta.xml.bind:jakarta.xml.bind-api (see above).
                In practice, Hibernate, probably the most popular of
                JPA runtimes used with this project, transitively
                includes org.glassfish.jaxb:jaxb-runtime whether we or
                our hypothetical end user want it or not. Eclipselink
                does not.
                Given (a) the predominance of Hibernate, (b) the
                relative infrequence of JAXB usage by end users these
                days and hence the probable lack of conflict, it
                probably makes sense to just include
                org.glassfish.jaxb:jaxb-runtime at runtime for minimum
                disruption since in any Hibernate-using installation
                it's going to be there anyway.
            -->
            <scope>runtime</scope> <!-- really should be test -->
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>io.helidon.microprofile.config</groupId>
            <artifactId>helidon-microprofile-config</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <!-- Test-scoped dependencies. -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.helidon.microprofile.cdi</groupId>
            <artifactId>helidon-microprofile-cdi</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>helidon-integrations-cdi-jta-weld</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>helidon-integrations-cdi-datasource-hikaricp</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>helidon-integrations-cdi-eclipselink</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>helidon-integrations-cdi-hibernate</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- Feature generation-->
        <dependency>
            <groupId>io.helidon.common.features</groupId>
            <artifactId>helidon-common-features-api</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>default-testCompile</id>
                            <configuration>
                                <annotationProcessorPaths>
                                    <annotationProcessorPath>
                                        <groupId>org.hibernate.orm</groupId>
                                        <artifactId>hibernate-jpamodelgen</artifactId>
                                        <version>${version.lib.hibernate}</version>
                                    </annotationProcessorPath>
                                </annotationProcessorPaths>
                                <compilerArgs combine.children="append">
                                    <arg>-Xlint:-processing</arg>
                                </compilerArgs>
                            </configuration>
                        </execution>
                    </executions>
                    <configuration>
                        <annotationProcessorPaths>
                            <path>
                                <groupId>io.helidon.common.features</groupId>
                                <artifactId>helidon-common-features-processor</artifactId>
                                <version>${helidon.version}</version>
                            </path>
                        </annotationProcessorPaths>
                        <compilerArgs combine.children="append">
                            <arg>-Xlint:-path</arg>
                        </compilerArgs>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>Generate persistence.xml Java objects</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/generated-sources/xjc</outputDirectory>
                            <addGeneratedAnnotation>true</addGeneratedAnnotation>
                            <xjbSources>
                                <xjbSource>src/main/xjb</xjbSource>
                            </xjbSources>
                            <sources>
                                <source>src/main/xsd</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>io.smallrye</groupId>
                <artifactId>jandex-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>make-index</id>
                        <goals>
                            <goal>jandex</goal>
                        </goals>
                        <phase>process-classes</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <classpathDependencyExcludes>
                    <!-- Exclude Hibernate and its transitive dependencies when Eclipselink is being tested. -->
                        <classpathDependencyExclude>com.fasterxml:classmate</classpathDependencyExclude>
                        <classpathDependencyExclude>io.helidon.integrations.cdi:helidon-integrations-cdi-hibernate</classpathDependencyExclude>
                        <classpathDependencyExclude>net.bytebuddy:byte-buddy</classpathDependencyExclude>
                        <classpathDependencyExclude>org.antlr:antlr4-runtime</classpathDependencyExclude>
                        <classpathDependencyExclude>org.hibernate.common:hibernate-commons-annotations</classpathDependencyExclude>
                        <classpathDependencyExclude>org.hibernate.orm:hibernate-core</classpathDependencyExclude>
                    </classpathDependencyExcludes>
                    <reportNameSuffix>eclipselink</reportNameSuffix>
                    <skip>${eclipselink.skip}</skip>
                    <systemPropertyVariables>
                        <helidon.jta.immediateEnlistment>${helidon.jta.immediateEnlistment}</helidon.jta.immediateEnlistment>
                        <helidon.jta.interposedSynchronizations>${helidon.jta.interposedSynchronizations}</helidon.jta.interposedSynchronizations>
                        <helidon.jta.preemptiveEnlistmentChecks>${helidon.jta.preemptiveEnlistmentChecks}</helidon.jta.preemptiveEnlistmentChecks>
                        <java.util.logging.config.file>${project.basedir}/src/test/logging.properties</java.util.logging.config.file>
                    </systemPropertyVariables>
                    <testClassesDirectory>${project.build.directory}/eclipselink/test-classes</testClassesDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>hibernate</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <classpathDependencyExcludes>
                                <!-- Exclude Eclipselink and its transitive dependencies when Hibernate is being tested. -->
                                <classpathDependencyExclude>io.helidon.integrations.cdi:helidon-integrations-cdi-eclipselink</classpathDependencyExclude>
                                <classpathDependencyExclude>org.eclipse.persistence:org.eclipse.persistence.asm</classpathDependencyExclude>
                                <classpathDependencyExclude>org.eclipse.persistence:org.eclipse.persistence.core</classpathDependencyExclude>
                                <classpathDependencyExclude>org.eclipse.persistence:org.eclipse.persistence.jpa</classpathDependencyExclude>
                                <classpathDependencyExclude>org.eclipse.persistence:org.eclipse.persistence.jpa.jpql</classpathDependencyExclude>
                            </classpathDependencyExcludes>
                            <reportNameSuffix>hibernate</reportNameSuffix>
                            <skip>${hibernate.skip}</skip>
                            <testClassesDirectory>${project.build.directory}/hibernate/test-classes</testClassesDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>static-jpa</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property>
                    <name>maven.test.skip</name>
                    <value>!true</value>
                </property>
            </activation>
            <build>
                <plugins>

                    <!--
                        Please note that the ordering of the following
                        plugins below is significant:

                        * maven-resources-plugin
                        * exec-maven-plugin
                        * hibernate-enhance-maven-plugin
                    -->

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-resources-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>Copy test classes to Eclipselink weaving area</id>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <phase>process-test-classes</phase>
                                <configuration>
                                    <resources>
                                        <resource>
                                            <directory>${project.build.testOutputDirectory}</directory>
                                            <filtering>false</filtering>
                                        </resource>
                                    </resources>
                                    <outputDirectory>${project.build.directory}/eclipselink/test-classes</outputDirectory>
                                    <overwrite>true</overwrite>
                                </configuration>
                            </execution>
                            <execution>
                                <id>Copy test classes to Hibernate weaving area</id>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <phase>process-test-classes</phase>
                                <configuration>
                                    <resources>
                                        <resource>
                                            <directory>${project.build.testOutputDirectory}</directory>
                                            <filtering>false</filtering>
                                        </resource>
                                    </resources>
                                    <outputDirectory>${project.build.directory}/hibernate/test-classes</outputDirectory>
                                    <overwrite>true</overwrite>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>weave</id>
                                <phase>process-test-classes</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration combine.self="override">
                                    <classpathScope>test</classpathScope>
                                    <mainClass>org.eclipse.persistence.tools.weaving.jpa.StaticWeave</mainClass>
                                    <arguments>
                                        <argument>-loglevel</argument>
                                        <argument>INFO</argument>
                                        <argument>-persistenceinfo</argument>
                                        <argument>${project.build.directory}/eclipselink/test-classes</argument>
                                        <argument>${project.build.directory}/eclipselink/test-classes</argument>
                                        <argument>${project.build.directory}/eclipselink/test-classes</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.hibernate.orm.tooling</groupId>
                        <artifactId>hibernate-enhance-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>Statically enhance JPA entities for Hibernate</id>
                                <phase>process-test-classes</phase>
                                <goals>
                                    <goal>enhance</goal>
                                </goals>
                                <configuration>
                                    <base>${project.build.directory}/hibernate/test-classes</base>
                                    <dir>${project.build.directory}/hibernate/test-classes</dir>
                                    <failOnError>true</failOnError>
                                    <enableAssociationManagement>true</enableAssociationManagement>
                                    <enableDirtyTracking>true</enableDirtyTracking>
                                    <enableExtendedEnhancement>true</enableExtendedEnhancement>
                                    <enableLazyInitialization>true</enableLazyInitialization>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>sources</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>resource-bundle</id>
                                <goals>
                                    <goal>resource-bundle</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
