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

    Copyright (c) 2019, 2021 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>2.4.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>
        <!-- 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>

        <!-- Runtime-scoped dependencies. -->
        <dependency>
            <groupId>org.jboss</groupId>
            <artifactId>jandex</artifactId>
            <scope>runtime</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>
        <dependency>
            <groupId>jakarta.activation</groupId>
            <artifactId>jakarta.activation-api</artifactId>
        </dependency>

        <!-- 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>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <configuration>
                        <sourceFileExcludes>
                            <!--
                                The eclipselink-maven-plugin's
                                modelgen goal (see below) irrevocably
                                adds its generatedSourcesDirectory to
                                the source roots processed by the
                                maven-javadoc-plugin.  We need to
                                exclude these static metamodel sources
                                because in our case they reference
                                unit-test-only files.  Note that these
                                source roots are added to the javadoc
                                *report*, not just its "generate test
                                javadocs" goal, and even though the
                                sources from which they are generated
                                are only found under src/test/java.
                            -->
                            <sourceFileExclude>**/*_.java</sourceFileExclude>
                        </sourceFileExcludes>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <executions>
                    <execution>
                        <id>Generate persistence.xml Java objects</id>
                        <goals>
                          <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generatePackage>io.helidon.integrations.cdi.jpa.jaxb</generatePackage>
                            <markGenerated>true</markGenerated>
                            <schemas>
                                <schema>
                                    <dependencyResource>
                                        <groupId>jakarta.persistence</groupId>
                                        <artifactId>jakarta.persistence-api</artifactId>
                                        <resource>javax/persistence/persistence_2_2.xsd</resource>
                                    </dependencyResource>
                                </schema>
                            </schemas>
                            <strict>false</strict>
                        </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: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
                        * eclipselink-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>com.ethlo.persistence.tools</groupId>
                        <artifactId>eclipselink-maven-plugin</artifactId>
                        <dependencies>
                            <dependency>
                                <groupId>org.junit.jupiter</groupId>
                                <artifactId>junit-jupiter-api</artifactId>
                                <version>${version.lib.junit}</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>Statically weave JPA entities for Eclipselink</id>
                                <phase>process-test-classes</phase>
                                <goals>
                                    <goal>weave</goal>
                                </goals>
                                <configuration>
                                    <source>${project.build.directory}/eclipselink/test-classes</source>
                                    <target>${project.build.directory}/eclipselink/test-classes</target>
                                    <persistenceInfoLocation>${project.build.directory}/eclipselink/test-classes</persistenceInfoLocation>
                                </configuration>
                            </execution>
                            <execution>
                                <id>modelgen</id>
                                <phase>generate-test-sources</phase>
                                <goals>
                                    <goal>modelgen</goal>
                                </goals>
                                <configuration>
                                    <source>${project.build.testSourceDirectory}</source>
                                    <generatedSourcesDirectory>${project.build.directory}/generated-test-sources/apt</generatedSourcesDirectory>
                                </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>
        <profile>
            <id>xmlbind</id>
            <activation>
                <jdk>[9,)</jdk>
                <activeByDefault>false</activeByDefault>
            </activation>
            <dependencies>
                <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>
            </dependencies>
        </profile>
    </profiles>
</project>
