<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright 2014 - 2022 Blazebit.

  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>com.blazebit</groupId>
        <artifactId>blaze-persistence-entity-view</artifactId>
        <version>1.6.7</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>blaze-persistence-entity-view-impl</artifactId>
    <packaging>jar</packaging>
    
    <name>Blazebit Persistence Entity-View Impl</name>

    <properties>
        <module.name>com.blazebit.persistence.view.impl</module.name>
    </properties>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>blaze-persistence-core-api</artifactId>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>blaze-persistence-core-parser</artifactId>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>blaze-persistence-entity-view-api</artifactId>
        </dependency>
        
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>blaze-common-utils</artifactId>
        </dependency>
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>${version.javassist}</version>
        </dependency>
        
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>blaze-apt-utils</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Actually we only need JPA but since there is no official artifact we rather use this than provider specific apis -->
        <dependency>
            <groupId>org.apache.openejb</groupId>
            <artifactId>javaee-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-resource</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>add-resource</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>target/generated/resources</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <executions>
                    <execution>
                        <id>process-resources</id>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <outputDirectory>target/generated/resources</outputDirectory>
                            <processors>
                                <!-- list of processors to use -->
                                <processor>com.blazebit.apt.service.ServiceProviderAnnotationProcessor</processor>
                            </processors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.moditect</groupId>
                <artifactId>moditect-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-module-infos</id>
                        <phase>package</phase>
                        <goals>
                            <goal>add-module-info</goal>
                        </goals>
                        <configuration>
                            <module>
                                <moduleInfoSource>
                                    module ${module.name} {
                                        requires java.naming;
                                        requires java.sql;
                                        requires java.persistence;
                                        requires javassist;
                                        requires com.blazebit.common.utils;
                                        requires com.blazebit.persistence.core;
                                        requires com.blazebit.persistence.core.parser;
                                        requires com.blazebit.persistence.view;
                                        exports com.blazebit.persistence.view.impl;
                                        exports com.blazebit.persistence.view.impl.accessor;
                                        exports com.blazebit.persistence.view.impl.change;
                                        exports com.blazebit.persistence.view.impl.collection;
                                        exports com.blazebit.persistence.view.impl.entity;
                                        exports com.blazebit.persistence.view.impl.filter;
                                        exports com.blazebit.persistence.view.impl.macro;
                                        exports com.blazebit.persistence.view.impl.mapper;
                                        exports com.blazebit.persistence.view.impl.metamodel;
                                        exports com.blazebit.persistence.view.impl.metamodel.analysis;
                                        exports com.blazebit.persistence.view.impl.metamodel.attribute;
                                        exports com.blazebit.persistence.view.impl.objectbuilder;
                                        exports com.blazebit.persistence.view.impl.objectbuilder.mapper;
                                        exports com.blazebit.persistence.view.impl.objectbuilder.transformator;
                                        exports com.blazebit.persistence.view.impl.objectbuilder.transformer;
                                        exports com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation;
                                        exports com.blazebit.persistence.view.impl.proxy;
                                        exports com.blazebit.persistence.view.impl.tx;
                                        exports com.blazebit.persistence.view.impl.type;
                                        exports com.blazebit.persistence.view.impl.update;
                                        exports com.blazebit.persistence.view.impl.update.flush;
                                        exports com.blazebit.persistence.view.impl.update.listener;
                                        provides com.blazebit.persistence.view.spi.EntityViewConfigurationProvider with com.blazebit.persistence.view.impl.EntityViewConfigurationProviderImpl;
                                    }
                                </moduleInfoSource>
                            </module>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>pre-11-unsafe-code</id>
            <activation>
                <jdk>[1.7,11)</jdk>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>add-source</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>add-source</goal>
                                </goals>
                                <configuration>
                                    <sources>
                                        <source>src/main/java8</source>
                                    </sources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>post-10-unsafe-code-non-mac</id>
            <activation>
                <jdk>[11,)</jdk>
                <file>
                    <exists>${jdk8.home}${file.separator}jre${file.separator}lib${file.separator}rt.jar</exists>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>add-source</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>add-source</goal>
                                </goals>
                                <configuration>
                                    <sources>
                                        <source>src/main/java8</source>
                                    </sources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>default-compile</id>
                                <inherited>true</inherited>
                                <configuration>
                                    <!-- When we use a Java 11+ JVM, we need a JDK 8, otherwise we can't compile the old unsafe code -->
                                    <compilerArguments>
                                        <bootclasspath>${jdk8.home}${file.separator}jre${file.separator}lib${file.separator}rt.jar</bootclasspath>
                                        <!--
                                        Not sure exactly why, but we need to compile this with source and target 1.7 so that the UNSAFE can be found.
                                        It's not too terrible, as this profile is rather special. Compiling a release jar with a newer classfile version shouldn't happen.
                                         -->
                                        <source>1.7</source>
                                        <target>1.7</target>
<!--                                        <source>${maven.compiler.argument.source}</source>-->
<!--                                        <target>${maven.compiler.argument.target}</target>-->
                                    </compilerArguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <inherited>true</inherited>
                                <configuration>
                                    <!-- When we use a Java 11+ JVM, we need a JDK 8, otherwise we can't compile the old unsafe code -->
                                    <bootclasspath>${jdk8.home}${file.separator}jre${file.separator}lib${file.separator}rt.jar</bootclasspath>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>post-10-unsafe-code-mac</id>
            <activation>
                <jdk>[11,)</jdk>
                <file>
                    <exists>${jdk8.home}${file.separator}jre${file.separator}lib${file.separator}classes.jar</exists>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>add-source</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>add-source</goal>
                                </goals>
                                <configuration>
                                    <sources>
                                        <source>src/main/java8</source>
                                    </sources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>default-compile</id>
                                <inherited>true</inherited>
                                <configuration>
                                    <!-- When we use a Java 11+ JVM, we need a JDK 8, otherwise we can't compile the old unsafe code -->
                                    <compilerArguments>
                                        <bootclasspath>${jdk8.home}${file.separator}jre${file.separator}lib${file.separator}classes.jar</bootclasspath>
                                        <!--
                                        Not sure exactly why, but we need to compile this with source and target 1.7 so that the UNSAFE can be found.
                                        It's not too terrible, as this profile is rather special. Compiling a release jar with a newer classfile version shouldn't happen.
                                         -->
                                        <source>1.7</source>
                                        <target>1.7</target>
<!--                                        <source>${maven.compiler.argument.source}</source>-->
<!--                                        <target>${maven.compiler.argument.target}</target>-->
                                    </compilerArguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <inherited>true</inherited>
                                <configuration>
                                    <!-- When we use a Java 11+ JVM, we need a JDK 8, otherwise we can't compile the old unsafe code -->
                                    <bootclasspath>${jdk8.home}${file.separator}jre${file.separator}lib${file.separator}classes.jar</bootclasspath>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>post-8-unsafe-code-non-mac</id>
            <activation>
                <jdk>[1.9,)</jdk>
                <os>
                    <family>!mac</family>
                </os>
                <file>
                    <exists>${jdk8.home}${file.separator}jre${file.separator}lib${file.separator}rt.jar</exists>
                </file>
            </activation>
            <properties>
                <jdkSpecificSourceDirectory>src/main/java9</jdkSpecificSourceDirectory>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>compile-java9</id>
                                <phase>compile</phase>
                                <configuration>
                                    <target>
                                        <mkdir dir="${project.build.outputDirectory}/META-INF/versions/9" />
                                        <javac srcdir="${project.basedir}/src/main/java9" destdir="${project.build.outputDirectory}/META-INF/versions/9" classpath="${project.build.outputDirectory}" includeantruntime="false" source="9" target="9" />
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>compile-java9-only</id>
                                <phase>compile</phase>
                                <configuration>
                                    <target>
                                        <mkdir dir="${project.build.outputDirectory}/META-INF/versions/9" />
                                        <copy todir="${project.build.directory}/classes9">
                                            <fileset dir="${project.build.outputDirectory}" excludes="META-INF/versions/**,**/UnsafeHelper.class" />
                                        </copy>
                                        <javac srcdir="${project.basedir}/src/main/java9" destdir="${project.build.directory}/classes9" classpath="${project.build.outputDirectory}" includeantruntime="false" source="9" target="9" />
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-jar-plugin</artifactId>
                        <inherited>true</inherited>
                        <configuration>
                            <archive>
                                <manifestEntries>
                                    <Multi-Release>true</Multi-Release>
                                </manifestEntries>
                            </archive>
                        </configuration>
                        <executions>
                            <execution>
                                <id>default-jar</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>java-9-jar</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                                <configuration>
                                    <classifier>9</classifier>
                                    <classesDirectory>${project.build.directory}/classes9</classesDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>post-8-unsafe-code-mac</id>
            <activation>
                <jdk>[1.9,)</jdk>
                <os>
                    <family>mac</family>
                </os>
                <file>
                    <exists>${jdk8.home}${file.separator}jre${file.separator}lib${file.separator}classes.jar</exists>
                </file>
            </activation>
            <properties>
                <jdkSpecificSourceDirectory>src/main/java9</jdkSpecificSourceDirectory>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>compile-java9</id>
                                <phase>compile</phase>
                                <configuration>
                                    <target>
                                        <mkdir dir="${project.build.outputDirectory}/META-INF/versions/9" />
                                        <javac srcdir="${project.basedir}/src/main/java9" destdir="${project.build.outputDirectory}/META-INF/versions/9" classpath="${project.build.outputDirectory}" includeantruntime="false" source="9" target="9" />
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>compile-java9-only</id>
                                <phase>compile</phase>
                                <configuration>
                                    <target>
                                        <mkdir dir="${project.build.outputDirectory}/META-INF/versions/9" />
                                        <copy todir="${project.build.directory}/classes9">
                                            <fileset dir="${project.build.outputDirectory}" excludes="META-INF/versions/**,**/UnsafeHelper.class" />
                                        </copy>
                                        <javac srcdir="${project.basedir}/src/main/java9" destdir="${project.build.directory}/classes9" classpath="${project.build.outputDirectory}" includeantruntime="false" source="9" target="9" />
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-jar-plugin</artifactId>
                        <inherited>true</inherited>
                        <configuration>
                            <archive>
                                <manifestEntries>
                                    <Multi-Release>true</Multi-Release>
                                </manifestEntries>
                            </archive>
                        </configuration>
                        <executions>
                            <execution>
                                <id>default-jar</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>java-9-jar</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                                <configuration>
                                    <classifier>9</classifier>
                                    <classesDirectory>${project.build.directory}/classes9</classesDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>post-10-unsafe-code-non-mr-jar-non-mac</id>
            <activation>
                <jdk>[11,)</jdk>
                <os>
                    <family>!mac</family>
                </os>
                <file>
                    <missing>${jdk8.home}${file.separator}jre${file.separator}lib${file.separator}rt.jar</missing>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>add-source</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>add-source</goal>
                                </goals>
                                <configuration>
                                    <sources>
                                        <source>src/main/java9</source>
                                    </sources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>post-10-unsafe-code-non-mr-jar-mac</id>
            <activation>
                <jdk>[11,)</jdk>
                <os>
                    <family>mac</family>
                </os>
                <file>
                    <missing>${jdk8.home}${file.separator}jre${file.separator}lib${file.separator}classes.jar</missing>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>add-source</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>add-source</goal>
                                </goals>
                                <configuration>
                                    <sources>
                                        <source>src/main/java9</source>
                                    </sources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
