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

    Copyright (c) 2019, 2023 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
                             http://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>3.1.2</version>
    </parent>
    <artifactId>helidon-integrations-cdi-jpa</artifactId>
    <name>Helidon CDI Integrations JPA</name>

    <properties>
      <doclint>-syntax</doclint>
      <spotbugs.exclude>etc/spotbugs/exclude.xml</spotbugs.exclude>
    </properties>

    <dependencies>

        <!-- Compile-scoped dependencies. -->
        <dependency>
            <groupId>io.helidon.integrations.cdi</groupId>
            <artifactId>helidon-integrations-cdi-delegates</artifactId>
            <scope>compile</scope>
        </dependency>
        <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>

        <!-- Provided-scoped dependencies. -->
        <dependency>
            <groupId>jakarta.persistence</groupId>
            <artifactId>jakarta.persistence-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <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.transaction</groupId>
            <artifactId>jakarta.transaction-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Runtime-scoped dependencies. -->
        <dependency>
            <groupId>org.jboss</groupId>
            <artifactId>jandex</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.activation</groupId>
            <artifactId>jakarta.activation-api</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- Test-scoped dependencies. -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</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>
        <dependency>
            <groupId>io.helidon.microprofile.cdi</groupId>
            <artifactId>helidon-microprofile-cdi</artifactId>
            <scope>test</scope>
        </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>
                            </configuration>
                        </execution>
                    </executions>
                </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>org.jboss.jandex</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>
                        <classpathDependencyExclude>io.helidon.integrations.cdi:helidon-integrations-cdi-hibernate</classpathDependencyExclude>
                        <classpathDependencyExclude>org.hibernate.orm:hibernate-core</classpathDependencyExclude>
                    </classpathDependencyExcludes>
                    <reportNameSuffix>eclipselink</reportNameSuffix>
                    <skip>true</skip>
                    <systemPropertyVariables>
                        <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>default-cli</id>
                        <configuration>
                            <skip>false</skip>
                        </configuration>
                    </execution>
                    <execution>
                        <id>default-test</id>
                        <configuration>
                            <skip>false</skip>
                        </configuration>
                    </execution>
                    <execution>
                        <id>hibernate</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <classpathDependencyExcludes>
                                <classpathDependencyExclude>io.helidon.integrations.cdi:helidon-integrations-cdi-eclipselink</classpathDependencyExclude>
                                <classpathDependencyExclude>org.eclipse.persistence:org.eclipse.persistence.jpa</classpathDependencyExclude>
                            </classpathDependencyExcludes>
                            <reportNameSuffix>hibernate</reportNameSuffix>
                            <skip>false</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
                        * maven-surefire-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>
