<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you 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>org.apache.syncope</groupId>
    <artifactId>syncope-core</artifactId>
    <version>3.0.3</version>
  </parent>

  <name>Apache Syncope Core Persistence JPA JSON</name>
  <description>Apache Syncope Core Persistence JPA JSON</description>
  <groupId>org.apache.syncope.core</groupId>
  <artifactId>syncope-core-persistence-jpa-json</artifactId>
  <packaging>jar</packaging>
  
  <properties>
    <orm>pgjsonb</orm>
    <rootpom.basedir>${basedir}/../..</rootpom.basedir>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.apache.syncope.core</groupId>
      <artifactId>syncope-core-persistence-jpa</artifactId>
      <version>${project.version}</version>
    </dependency>

    <!-- TEST -->
    <dependency>
      <groupId>org.bouncycastle</groupId>
      <artifactId>bcpkix-jdk15on</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.bouncycastle</groupId>
      <artifactId>bcprov-jdk15on</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency> 
      <groupId>jakarta.servlet</groupId> 
      <artifactId>jakarta.servlet-api</artifactId> 
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>jcl-over-slf4j</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.openjpa</groupId>
        <artifactId>openjpa-maven-plugin</artifactId>
        <inherited>true</inherited>
        <dependencies>
          <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>${h2.version}</version>
          </dependency>
        </dependencies>
        <configuration>
          <persistenceXmlFile>${project.build.directory}/classes/persistence-enhance.xml</persistenceXmlFile> 
          <includes>org/apache/syncope/core/persistence/jpa/entity/**/*.class</includes>
          <connectionDriverName>org.springframework.jdbc.datasource.DriverManagerDataSource</connectionDriverName>
          <connectionProperties>
            driverClassName=org.h2.Driver,
            url=jdbc:h2:mem:syncopedb
            username=sa,
            password=
          </connectionProperties>
        </configuration>
        <executions>
          <execution>
            <id>enhancer</id>
            <phase>process-classes</phase>
            <goals>
              <goal>enhance</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
      </plugin>
    </plugins>

    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>src/test/resources</directory>
        <filtering>true</filtering>
      </testResource>
      <testResource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <excludes>
          <exclude>domains/MasterContent.xml</exclude>
        </excludes>
      </testResource>
      <testResource>
        <directory>${basedir}/../persistence-jpa/src/test/resources</directory>
        <filtering>true</filtering>
        <includes>
          <include>*-metadata.xml</include>
        </includes>
      </testResource>
    </testResources>
  </build>

  <profiles>
    <profile>
      <id>openjpa</id>
      
      <properties>
        <!-- possible values: sql | schema -->
        <action>sql</action>

        <!-- possible values: pgjsonb | myjson | ojson -->
        <orm>ojson</orm>

        <skipTests>true</skipTests>
      </properties>
      
      <build>
        <defaultGoal>clean verify</defaultGoal>
        
        <plugins>
          <plugin>
            <groupId>org.apache.openjpa</groupId>
            <artifactId>openjpa-maven-plugin</artifactId>
            <inherited>true</inherited>
            <executions>
              <execution>
                <id>schemagen</id>
                <phase>process-classes</phase>
                <goals>
                  <goal>${action}</goal>
                </goals>
              </execution>
            </executions>
          </plugin>          
        </plugins>
      </build>
    </profile>

    <profile>
      <id>pgjsonb</id>

      <dependencies>
        <dependency>
          <groupId>org.postgresql</groupId>
          <artifactId>postgresql</artifactId>
          <version>${jdbc.postgresql.version}</version>
          <scope>test</scope>
        </dependency>
      </dependencies>

      <build>
        <defaultGoal>clean verify</defaultGoal>
        
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>add-test-source</id>
                <phase>generate-test-sources</phase>
                <goals>
                  <goal>add-test-source</goal>
                </goals>
                <configuration>
                  <sources>
                    <source>${basedir}/../persistence-jpa/src/test/java</source>
                  </sources>
                </configuration>
              </execution>
            </executions>
          </plugin>
      
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skip>true</skip>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <configuration>
              <includes>
                <include>**/*Test.java</include>
              </includes>
              <excludedGroups>multitenancy,plainAttrTable</excludedGroups>
              <systemPropertyVariables>
                <profileId>${project.activeProfiles[0].id}</profileId>
                <CORE_PROPERTIES>classpath:core-pgjsonb.properties,classpath:core-pgjsonb-test.properties</CORE_PROPERTIES>
                <DB_CONTAINER_IP>${docker.container.postgres.ip}</DB_CONTAINER_IP>
                <syncope.connid.location>file:${bundles.directory}/</syncope.connid.location>
              </systemPropertyVariables>
            </configuration>
          </plugin>

          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <configuration>
              <images>
                <image>
                  <alias>postgres</alias>
                  <name>postgres:${docker.postgresql.version}</name>
                  <run>
                    <cmd>postgres -N 200</cmd>
                    <env>
                      <POSTGRES_DB>syncope</POSTGRES_DB>
                      <POSTGRES_USER>syncope</POSTGRES_USER>
                      <POSTGRES_PASSWORD>syncope</POSTGRES_PASSWORD>
                    </env>
                    <wait>
                      <log>database system is ready to accept connections</log>
                      <time>30000</time>
                    </wait>
                    <tmpfs>
                      <mount>/var/lib/postgresql/data:rw</mount>
                    </tmpfs>
                  </run>
                </image>
              </images>
            </configuration>
            <executions>
              <execution>
                <id>start-postgres</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
              </execution>
              <execution>
                <id>stop-postgres</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>stop</goal>
                  <goal>remove</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
        
        <testResources>
          <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
          </testResource>
        </testResources>
      </build>
    </profile>
    
    <profile>
      <id>myjson</id>
      
      <dependencies>
        <dependency>
          <groupId>com.mysql</groupId>
          <artifactId>mysql-connector-j</artifactId>
          <version>${jdbc.mysql.version}</version>
          <scope>test</scope>
        </dependency>
      </dependencies>

      <build>
        <defaultGoal>clean verify</defaultGoal>

        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>add-test-source</id>
                <phase>generate-test-sources</phase>
                <goals>
                  <goal>add-test-source</goal>
                </goals>
                <configuration>
                  <sources>
                    <source>${basedir}/../persistence-jpa/src/test/java</source>
                  </sources>
                </configuration>
              </execution>
            </executions>
          </plugin>
      
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skip>true</skip>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <configuration>
              <includes>
                <include>**/*Test.java</include>
              </includes>
              <excludedGroups>multitenancy,plainAttrTable</excludedGroups>
              <systemPropertyVariables>
                <profileId>${project.activeProfiles[0].id}</profileId>
                <CORE_PROPERTIES>classpath:core-myjson.properties,classpath:core-myjson-test.properties</CORE_PROPERTIES>
                <DB_CONTAINER_IP>${docker.container.mysql.ip}</DB_CONTAINER_IP>
                <syncope.connid.location>file:${bundles.directory}/</syncope.connid.location>
              </systemPropertyVariables>
            </configuration>
          </plugin>

          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <configuration>
              <images>
                <image>
                  <alias>mysql</alias>
                  <name>mysql/mysql-server:${docker.mysql.version}</name>
                  <run>
                    <cmd>--skip-log-bin --server-id=1</cmd>
                    <env>
                      <MYSQL_ROOT_PASSWORD>password</MYSQL_ROOT_PASSWORD>
                      <MYSQL_DATABASE>syncope</MYSQL_DATABASE>
                      <MYSQL_USER>syncope</MYSQL_USER>
                      <MYSQL_PASSWORD>syncope</MYSQL_PASSWORD>
                    </env>
                    <tmpfs>
                      <mount>/var/lib/mysql:rw</mount>
                    </tmpfs>
                    <wait>
                      <log>MySQL init process done. Ready for start up.</log>
                      <time>30000</time>
                    </wait>
                  </run>
                </image>
              </images>
            </configuration>
            <executions>
              <execution>
                <id>start-mysql</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
              </execution>
              <execution>
                <id>stop-mysql</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>stop</goal>
                  <goal>remove</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
        
        <testResources>
          <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
          </testResource>
        </testResources>
      </build>
    </profile>

    <profile>
      <id>ojson</id>

      <dependencies>
        <dependency>
          <groupId>com.oracle.database.jdbc</groupId>
          <artifactId>ojdbc11</artifactId>
          <version>${jdbc.oracle.version}</version>
          <scope>test</scope>
        </dependency>
      </dependencies>

      <build>
        <defaultGoal>clean verify</defaultGoal>
        
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>add-test-source</id>
                <phase>generate-test-sources</phase>
                <goals>
                  <goal>add-test-source</goal>
                </goals>
                <configuration>
                  <sources>
                    <source>${basedir}/../persistence-jpa/src/test/java</source>
                  </sources>
                </configuration>
              </execution>
            </executions>
          </plugin>
      
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skip>true</skip>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <configuration>
              <includes>
                <include>**/*Test.java</include>
              </includes>
              <excludedGroups>multitenancy,plainAttrTable</excludedGroups>
              <systemPropertyVariables>
                <profileId>${project.activeProfiles[0].id}</profileId>
                <CORE_PROPERTIES>classpath:core-ojson.properties,classpath:core-ojson-test.properties</CORE_PROPERTIES>
                <DB_CONTAINER_IP>${docker.container.oracle.ip}</DB_CONTAINER_IP>
                <syncope.connid.location>file:${bundles.directory}/</syncope.connid.location>
              </systemPropertyVariables>
            </configuration>
          </plugin>

          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <configuration>
              <images>
                <image>
                  <alias>oracle</alias>
                  <name>gvenzl/oracle-xe:21-slim</name>
                  <run>
                    <env>
                      <ORACLE_PASSWORD>password</ORACLE_PASSWORD>
                      <APP_USER>syncope</APP_USER>
                      <APP_USER_PASSWORD>syncope</APP_USER_PASSWORD>
                    </env>
                    <wait>
                      <log>DATABASE IS READY TO USE</log>
                      <time>120000</time>
                    </wait>
                  </run>
                </image>
              </images>
            </configuration>
            <executions>
              <execution>
                <id>start-oracle</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
              </execution>
              <execution>
                <id>stop-oracle</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>stop</goal>
                  <goal>remove</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
        
        <testResources>
          <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
          </testResource>
        </testResources>
      </build>
    </profile>
  </profiles>
</project>
