<?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>${groupId}</groupId>
    <artifactId>${rootArtifactId}</artifactId>
    <version>${version}</version>
  </parent>

  <name>Apache Syncope sample project - FIT</name>
  <groupId>${groupId}</groupId>
  <artifactId>${artifactId}</artifactId>
  <packaging>war</packaging>

  <properties>
    <spring.profiles.active>embedded,https</spring.profiles.active>
    <exec.skip>true</exec.skip>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.syncope.fit</groupId>
      <artifactId>syncope-fit-build-tools</artifactId>
      <version>${syncope.version}</version>
      <type>war</type>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-install-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <inherited>false</inherited>
        <configuration>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
        <executions>
          <execution>
            <id>default-war</id>
            <phase>none</phase>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <inherited>true</inherited>
        <executions>
          <execution>
            <id>addFlowableTestContent</id>
            <phase>prepare-package</phase>
            <configuration>
              <target>
                <taskdef resource="net/sf/antcontrib/antcontrib.properties"
                         classpathref="maven.plugin.classpath"/>

                <if>
                  <not>
                    <available file="../core/target/test-classes/backup/MasterContent.xml"/>
                  </not>
                  <then>
                    <mkdir dir="../core/target/test-classes/backup"/>
                    <copy file="../core/target/test-classes/domains/MasterContent.xml" 
                          todir="../core/target/test-classes/backup"/>
                  </then>
                </if>
                <if>
                  <available file="../core/target/syncope/WEB-INF/lib/flowable-engine-${flowable.version}.jar"/>
                  <then>
                    <xslt basedir="../core/target/test-classes/backup" 
                          includes="MasterContent.xml"
                          destdir="../core/target/test-classes/domains"
                          extension=".xml"
                          force="true"
                          style="../core/src/test/resources/addFlowableToContent.xsl"/>
                  </then>
                </if>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
          <execution>
            <id>setupEmbeddedConf</id>
            <phase>package</phase>
            <configuration>
              <target>
                <delete dir="../core/target/syncope/WEB-INF/classes/domains"/>
                <copy todir="../core/target/syncope/WEB-INF/classes/domains">
                  <fileset dir="../core/target/test-classes/domains"/>
                </copy>
                <copy file="../core/target/test-classes/core-embedded.properties" 
                      todir="../core/target/syncope/WEB-INF/classes" 
                      overwrite="true"/>
                <copy file="../core/target/test-classes/core-https.properties" 
                      todir="../core/target/syncope/WEB-INF/classes" 
                      overwrite="true"/>
                <copy file="../core/target/test-classes/core-all.properties" 
                      todir="../core/target/syncope/WEB-INF/classes" 
                      overwrite="true"/>

                <copy file="../console/target/test-classes/console-embedded.properties" 
                      todir="../console/target/syncope-console/WEB-INF/classes" 
                      overwrite="true"/>
                <copy file="../console/target/test-classes/console-https.properties" 
                      todir="../console/target/syncope-console/WEB-INF/classes" 
                      overwrite="true"/>

                <copy file="../enduser/target/test-classes/enduser-embedded.properties" 
                      todir="../enduser/target/syncope-enduser/WEB-INF/classes" 
                      overwrite="true"/>                
                <copy file="../enduser/target/test-classes/enduser-https.properties" 
                      todir="../enduser/target/syncope-enduser/WEB-INF/classes" 
                      overwrite="true"/>                

                <copy file="../wa/target/test-classes/wa-embedded.properties" 
                      todir="../wa/target/syncope-wa/WEB-INF/classes" 
                      overwrite="true"/>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>ant-contrib</groupId>
            <artifactId>ant-contrib</artifactId>
            <version>20020829</version>
          </dependency>
        </dependencies>
      </plugin>
      
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <inherited>true</inherited>
        <executions>
          <execution>
            <id>default-cli</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>${JAVA_HOME}/bin/java</executable>
              <arguments>
                <argument>-Djavax.net.ssl.trustStore=${basedir}/src/test/resources/keystore.jks</argument>
                <argument>-Djavax.net.ssl.trustStorePassword=password</argument>
                <argument>-jar</argument>
                <argument>${basedir}/../sra/target/syncope-sra-exec.jar</argument>
                <argument>-Dreactor.netty.http.server.accessLogEnabled=true</argument>
              </arguments>
              <environmentVariables>
                <LOADER_PATH>${basedir}/../sra/target/test-classes</LOADER_PATH>
                <SPRING_PROFILES_ACTIVE>cas</SPRING_PROFILES_ACTIVE>
              </environmentVariables>
              <async>true</async>
              <asyncDestroyOnShutdown>true</asyncDestroyOnShutdown>
            </configuration>                        
          </execution>
        </executions>
      </plugin>
      
      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven3-plugin</artifactId>
        <inherited>true</inherited>
        <configuration>
          <container>
            <containerId>tomcat9x</containerId>
            <zipUrlInstaller>
              <url>https://repo1.maven.org/maven2/org/apache/tomcat/tomcat/${tomcat.version}/tomcat-${tomcat.version}.zip</url>
              <downloadDir>${settings.localRepository}/org/codehaus/cargo/cargo-container-archives</downloadDir>
              <extractDir>${project.build.directory}/cargo/extract</extractDir>
            </zipUrlInstaller>
            <timeout>600000</timeout>
            <log>${cargo.log}</log>
            <output>${cargo.output}</output> 

            <dependencies>
              <dependency>
                <groupId>com.h2database</groupId>
                <artifactId>h2</artifactId>
              </dependency>
            </dependencies>

            <systemProperties>
              <java.security.egd>file:/dev/./urandom</java.security.egd>
              <java.util.secureRandomSeed>true</java.util.secureRandomSeed>

              <h2.returnOffsetDateTime>true</h2.returnOffsetDateTime>

              <javax.net.ssl.trustStore>${basedir}/src/test/resources/keystore.jks</javax.net.ssl.trustStore>
              <javax.net.ssl.trustStorePassword>password</javax.net.ssl.trustStorePassword>
            </systemProperties>
          </container>
          <configuration>
            <properties>
              <cargo.jvmargs>
                -Dspring.profiles.active=${spring.profiles.active}
                -Dwicket.ioc.useByteBuddy=true
                -Xmx1024m -Xms512m</cargo.jvmargs>

              <cargo.servlet.port>9443</cargo.servlet.port>
              <cargo.protocol>https</cargo.protocol>
              <cargo.tomcat.connector.keystoreFile>${basedir}/src/test/resources/keystore.jks</cargo.tomcat.connector.keystoreFile>
              <cargo.tomcat.connector.keystorePass>password</cargo.tomcat.connector.keystorePass>
              <cargo.tomcat.connector.keyAlias>tomcat</cargo.tomcat.connector.keyAlias>
              <cargo.tomcat.connector.clientAuth>false</cargo.tomcat.connector.clientAuth>
              <cargo.tomcat.connector.sslProtocol>TLS</cargo.tomcat.connector.sslProtocol>
              <cargo.tomcat.connector.redirectPort>9443</cargo.tomcat.connector.redirectPort>
              <cargo.tomcat.httpSecure>true</cargo.tomcat.httpSecure>
            </properties>
          </configuration>
          <deployables>
            <deployable>
              <groupId>org.apache.syncope.fit</groupId>
              <artifactId>syncope-fit-build-tools</artifactId>
              <type>war</type>
              <properties>
                <context>syncope-fit-build-tools</context>
              </properties>
            </deployable>
            <deployable>
              <location>../core/target/syncope</location>
              <pingURL>https://localhost:9443/syncope/index.html</pingURL>
              <pingTimeout>${cargo.deployable.ping.timeout}</pingTimeout>
              <properties>
                <context>syncope</context>
              </properties>
            </deployable>
            <deployable>
              <location>../console/target/syncope-console</location>
              <properties>
                <context>syncope-console</context>
              </properties>
            </deployable>
            <deployable>
              <location>../enduser/target/syncope-enduser</location>
              <properties>
                <context>syncope-enduser</context>
              </properties>
            </deployable>
            <deployable>
              <location>../wa/target/syncope-wa</location>
              <properties>
                <context>syncope-wa</context>
              </properties>
            </deployable>
          </deployables>
        </configuration>
      </plugin>
    </plugins> 
  </build>
  
  <profiles>
    <profile>
      <id>embedded</id>

      <properties>
        <exec.skip>false</exec.skip>
      </properties>

      <build>
        <defaultGoal>clean verify cargo:run</defaultGoal>  
      </build>
    </profile>

    <profile>
      <id>all</id>

      <properties>
        <spring.profiles.active>embedded,https,all</spring.profiles.active>
      </properties>

      <build>
        <defaultGoal>clean verify cargo:run</defaultGoal>  
      </build>
    </profile>

    <profile>
      <id>docker</id>

      <properties>
        <exec.skip>true</exec.skip>
        <docker.autoCreateCustomNetworks>true</docker.autoCreateCustomNetworks>
      </properties>

      <dependencies>
        <dependency>
          <groupId>${groupId}</groupId>
          <artifactId>syncope-core</artifactId>
          <version>${project.version}</version>
          <classifier>classes</classifier>
        </dependency>
        <dependency>
          <groupId>${groupId}</groupId>
          <artifactId>syncope-console</artifactId>
          <version>${project.version}</version>
          <classifier>classes</classifier>
        </dependency>
        <dependency>
          <groupId>${groupId}</groupId>
          <artifactId>syncope-enduser</artifactId>
          <version>${project.version}</version>
          <classifier>classes</classifier>
        </dependency>
        <dependency>
          <groupId>${groupId}</groupId>
          <artifactId>syncope-wa</artifactId>
          <version>${project.version}</version>
          <classifier>classes</classifier>
        </dependency>
        <dependency>
          <groupId>${groupId}</groupId>
          <artifactId>syncope-sra</artifactId>
          <version>${project.version}</version>
        </dependency>
      </dependencies>

      <build>
        <defaultGoal>clean package io.fabric8:docker-maven-plugin:start</defaultGoal>

        <plugins>
          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <configuration>
              <verbose>true</verbose>
              <images>
                <image>
                  <alias>postgres</alias>
                  <name>postgres:${docker.postgresql.version}</name>
                  <run>
                    <containerNamePattern>%a</containerNamePattern>
                    <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>
                    <network>
                      <name>archetype</name>
                      <mode>custom</mode>
                    </network>
                  </run>
                </image>

                <image>
                  <alias>syncope</alias>
                  <name>apache/syncope:${syncope.version}</name>
                  <run>
                    <containerNamePattern>%a</containerNamePattern>
                    <dependsOn>
                      <container>postgres</container>
                    </dependsOn>
                    <env>
                      <SPRING_PROFILES_ACTIVE>docker,postgresql,all</SPRING_PROFILES_ACTIVE>
                      <DB_URL>jdbc:postgresql://postgres:5432/syncope?stringtype=unspecified</DB_URL>
                      <DB_USER>syncope</DB_USER>
                      <DB_PASSWORD>syncope</DB_PASSWORD>
                      <DB_POOL_MAX>20</DB_POOL_MAX>
                      <DB_POOL_MIN>5</DB_POOL_MIN>
                      <OPENJPA_REMOTE_COMMIT>sjvm</OPENJPA_REMOTE_COMMIT>
                      <SERVICE_DISCOVERY_ADDRESS>http://syncope:8080/syncope/rest/</SERVICE_DISCOVERY_ADDRESS>
                      <KEYMASTER_ADDRESS>http://syncope:8080/syncope/rest/keymaster</KEYMASTER_ADDRESS>
                      <KEYMASTER_USERNAME>${anonymousUser}</KEYMASTER_USERNAME>
                      <KEYMASTER_PASSWORD>${anonymousKey}</KEYMASTER_PASSWORD>
                      <ANONYMOUS_USER>${anonymousUser}</ANONYMOUS_USER>
                      <ANONYMOUS_KEY>${anonymousKey}</ANONYMOUS_KEY>
                    </env>
                    <volumes>
                      <bind>
                        <volume>${basedir}/../core/target/classes/domains/MasterContent.xml:/opt/syncope/conf/domains/MasterContent.xml:ro</volume>
                        <volume>${settings.localRepository}/${groupId}/syncope-core/${project.version}/syncope-core-${project.version}-classes.jar:/opt/syncope/lib/${groupId}-syncope-core-classes.jar:ro</volume>
                      </bind>
                    </volumes>
                    <network>
                      <name>archetype</name>
                      <mode>custom</mode>
                    </network>
                  </run>
                </image>

                <image>
                  <alias>syncope-console</alias>
                  <name>apache/syncope-console:${syncope.version}</name>
                  <run>
                    <containerNamePattern>%a</containerNamePattern>
                    <dependsOn>
                      <container>syncope</container>
                    </dependsOn>
                    <env>
                      <JAVA_OPTS>-Dfile.encoding=UTF-8 -Dwicket.ioc.useByteBuddy=true -server -Xms1536m -Xmx1536m 
                        -XX:NewSize=256m -XX:MaxNewSize=256m -XX:+DisableExplicitGC 
                        -Djava.security.egd=file:/dev/./urandom 
                        -Djavax.net.ssl.trustStore=/opt/syncope/conf/keystore.p12 
                        -Djavax.net.ssl.trustStorePassword=password</JAVA_OPTS>
                      <SPRING_PROFILES_ACTIVE>docker,all</SPRING_PROFILES_ACTIVE>
                      <SERVICE_DISCOVERY_ADDRESS>http://syncope-console:8080/syncope-console/</SERVICE_DISCOVERY_ADDRESS>
                      <KEYMASTER_ADDRESS>http://syncope:8080/syncope/rest/keymaster</KEYMASTER_ADDRESS>
                      <KEYMASTER_USERNAME>${anonymousUser}</KEYMASTER_USERNAME>
                      <KEYMASTER_PASSWORD>${anonymousKey}</KEYMASTER_PASSWORD>
                      <ANONYMOUS_USER>${anonymousUser}</ANONYMOUS_USER>
                      <ANONYMOUS_KEY>${anonymousKey}</ANONYMOUS_KEY>
                    </env>
                    <volumes>
                      <bind>
                        <volume>${basedir}/src/test/resources/keystore.p12:/opt/syncope/conf/keystore.p12:ro</volume>
                        <volume>${settings.localRepository}/${groupId}/syncope-console/${project.version}/syncope-console-${project.version}-classes.jar:/opt/syncope/lib/${groupId}-syncope-console-classes.jar:ro</volume>
                      </bind>
                    </volumes>
                    <network>
                      <name>archetype</name>
                      <mode>custom</mode>
                    </network>
                    <cmd>wait-for-it syncope:8080 -t 60 -- /opt/syncope/bin/startup.sh</cmd>
                  </run>
                </image>

                <image>
                  <alias>syncope-enduser</alias>
                  <name>apache/syncope-enduser:${syncope.version}</name>
                  <run>
                    <containerNamePattern>%a</containerNamePattern>
                    <dependsOn>
                      <container>syncope</container>
                    </dependsOn>
                    <env>
                      <SPRING_PROFILES_ACTIVE>docker,all</SPRING_PROFILES_ACTIVE>
                      <SERVICE_DISCOVERY_ADDRESS>http://syncope-enduser:8080/syncope-console/</SERVICE_DISCOVERY_ADDRESS>
                      <KEYMASTER_ADDRESS>http://syncope:8080/syncope/rest/keymaster</KEYMASTER_ADDRESS>
                      <KEYMASTER_USERNAME>${anonymousUser}</KEYMASTER_USERNAME>
                      <KEYMASTER_PASSWORD>${anonymousKey}</KEYMASTER_PASSWORD>
                      <ANONYMOUS_USER>${anonymousUser}</ANONYMOUS_USER>
                      <ANONYMOUS_KEY>${anonymousKey}</ANONYMOUS_KEY>
                    </env>
                    <volumes>
                      <bind>
                        <volume>${settings.localRepository}/${groupId}/syncope-enduser/${project.version}/syncope-enduser-${project.version}-classes.jar:/opt/syncope/lib/${groupId}-syncope-enduser-classes.jar:ro</volume>
                      </bind>
                    </volumes>
                    <network>
                      <name>archetype</name>
                      <mode>custom</mode>
                    </network>
                    <cmd>wait-for-it syncope:8080 -t 60 -- /opt/syncope/bin/startup.sh</cmd>
                  </run>
                </image>

                <image>
                  <alias>syncope-wa</alias>
                  <name>apache/syncope-wa:${syncope.version}</name>
                  <run>
                    <containerNamePattern>%a</containerNamePattern>
                    <dependsOn>
                      <container>syncope</container>
                    </dependsOn>
                    <env>
                      <SPRING_PROFILES_ACTIVE>docker,docker-https,all</SPRING_PROFILES_ACTIVE>
                      <CAS_SERVER_NAME>https://localhost:9443</CAS_SERVER_NAME>
                      <SERVICE_DISCOVERY_ADDRESS>https://syncope-wa:9443/syncope-wa/</SERVICE_DISCOVERY_ADDRESS>
                      <KEYMASTER_ADDRESS>http://syncope:8080/syncope/rest/keymaster</KEYMASTER_ADDRESS>
                      <KEYMASTER_USERNAME>${anonymousUser}</KEYMASTER_USERNAME>
                      <KEYMASTER_PASSWORD>${anonymousKey}</KEYMASTER_PASSWORD>
                      <ANONYMOUS_USER>${anonymousUser}</ANONYMOUS_USER>
                      <ANONYMOUS_KEY>${anonymousKey}</ANONYMOUS_KEY>
                    </env>
                    <volumes>
                      <bind>
                        <volume>${basedir}/../wa/src/test/resources/wa-docker-https.properties:/opt/syncope/conf/wa-docker-https.properties:ro</volume>
                        <volume>${basedir}/src/test/resources/keystore.p12:/opt/syncope/conf/keystore.p12:ro</volume>
                        <volume>${settings.localRepository}/${groupId}/syncope-wa/${project.version}/syncope-wa-${project.version}-classes.jar:/opt/syncope/lib/${groupId}-syncope-wa-classes.jar:ro</volume>
                      </bind>
                    </volumes>
                    <network>
                      <name>archetype</name>
                      <mode>custom</mode>
                    </network>
                    <ports>
                      <port>9443:9443</port>
                    </ports>
                    <cmd>wait-for-it syncope:8080 -t 60 -- /opt/syncope/bin/startup.sh</cmd>
                  </run>
                </image>

                <image>
                  <alias>syncope-sra</alias>
                  <name>apache/syncope-sra:${syncope.version}</name>
                  <run>
                    <containerNamePattern>%a</containerNamePattern>
                    <dependsOn>
                      <container>syncope</container>
                    </dependsOn>
                    <env>
                      <SPRING_PROFILES_ACTIVE>docker,all</SPRING_PROFILES_ACTIVE>
                      <SERVICE_DISCOVERY_ADDRESS>http://syncope-sra:8080/</SERVICE_DISCOVERY_ADDRESS>
                      <KEYMASTER_ADDRESS>http://syncope:8080/syncope/rest/keymaster</KEYMASTER_ADDRESS>
                      <KEYMASTER_USERNAME>${anonymousUser}</KEYMASTER_USERNAME>
                      <KEYMASTER_PASSWORD>${anonymousKey}</KEYMASTER_PASSWORD>
                      <ANONYMOUS_USER>${anonymousUser}</ANONYMOUS_USER>
                      <ANONYMOUS_KEY>${anonymousKey}</ANONYMOUS_KEY>
                    </env>
                    <volumes>
                      <bind>
                        <volume>${settings.localRepository}/${groupId}/syncope-sra/${project.version}/syncope-sra-${project.version}.jar:/opt/syncope/lib/${groupId}-syncope-sra.jar:ro</volume>
                      </bind>
                    </volumes>
                    <network>
                      <name>archetype</name>
                      <mode>custom</mode>
                    </network>
                    <cmd>wait-for-it syncope:8080 -t 60 -- /opt/syncope/bin/startup.sh</cmd>
                  </run>
                </image>
              </images>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
