<?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-fit</artifactId>
    <version>3.0.1</version>
  </parent>

  <name>Apache Syncope FIT WA Reference</name>
  <description>Apache Syncope FIT WA Reference</description>
  <groupId>org.apache.syncope.fit</groupId>
  <artifactId>syncope-fit-wa-reference</artifactId>
  <packaging>war</packaging>
  
  <properties>
    <ianal.phase>none</ianal.phase>

    <rootpom.basedir>${basedir}/../..</rootpom.basedir>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.apereo.cas</groupId>
        <artifactId>cas-server-support-bom</artifactId>
        <version>${cas.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>org.apache.syncope.wa</groupId>
      <artifactId>syncope-wa-starter</artifactId>
      <version>${project.version}</version>
    </dependency>

    <dependency>
      <groupId>org.apache.syncope.common.keymaster.self</groupId>
      <artifactId>syncope-common-keymaster-client-self</artifactId>
      <version>${project.version}</version>
    </dependency>

    <!-- required by JDBC attribute repository -->
    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
    </dependency>

    <!-- TEST -->
    <dependency>
      <groupId>org.apache.syncope.ext.saml2sp4ui</groupId>
      <artifactId>syncope-ext-saml2sp4ui-client-enduser</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.syncope.ext.oidcc4ui</groupId>
      <artifactId>syncope-ext-oidcc4ui-client-enduser</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.syncope</groupId>
      <artifactId>syncope-sra</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <artifactId>spring-cloud-starter</artifactId>
          <groupId>org.springframework.cloud</groupId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.apache.syncope.fit</groupId>
      <artifactId>syncope-fit-build-tools</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.syncope.fit</groupId>
      <artifactId>syncope-fit-core-reference</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.syncope.fit</groupId>
      <artifactId>syncope-fit-console-reference</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.syncope.fit</groupId>
      <artifactId>syncope-fit-enduser-reference</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.jsoup</groupId>
      <artifactId>jsoup</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.awaitility</groupId>
      <artifactId>awaitility</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.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>

            <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=embedded,https,all
                -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>
              <groupId>org.apache.syncope.fit</groupId>
              <artifactId>syncope-fit-core-reference</artifactId>
              <type>war</type>
              <pingURL>https://localhost:9443/syncope/index.html</pingURL>
              <pingTimeout>${cargo.deployable.ping.timeout}</pingTimeout>
              <properties>
                <context>syncope</context>
              </properties>
            </deployable>
            <deployable>
              <groupId>org.apache.syncope.fit</groupId>
              <artifactId>syncope-fit-console-reference</artifactId>
              <type>war</type>
              <properties>
                <context>syncope-console</context>
              </properties>
            </deployable>
            <deployable>
              <groupId>org.apache.syncope.fit</groupId>
              <artifactId>syncope-fit-enduser-reference</artifactId>
              <type>war</type>
              <properties>
                <context>syncope-enduser</context>
              </properties>
            </deployable>
            <deployable>
              <location>${project.build.directory}/${project.build.finalName}</location>
              <properties>
                <context>syncope-wa</context>
              </properties>
            </deployable>
          </deployables>
        </configuration>
        <executions>
          <execution>
            <id>start-container</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>start</goal>
            </goals>
            <configuration>
              <skip>${skipTests}</skip>
            </configuration>
          </execution>
          <execution>
            <id>stop-container</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>stop</goal>
            </goals>
            <configuration>
              <skip>${skipTests}</skip>
            </configuration>
          </execution>
        </executions>
      </plugin>
      
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <inherited>true</inherited>
        <configuration>
          <argLine>-Djavax.net.ssl.trustStore=${basedir}/src/test/resources/keystore.jks -Djavax.net.ssl.trustStorePassword=password</argLine>          
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <inherited>true</inherited>
        <configuration>
          <argLine>-Djavax.net.ssl.trustStore=${basedir}/src/test/resources/keystore.jks -Djavax.net.ssl.trustStorePassword=password</argLine>          
        </configuration>
        <executions>
          <execution>
            <id>verify</id>
            <goals>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <configuration>
          <resourceIncludes>src/main/resources/**/*.properties</resourceIncludes>
        </configuration>
      </plugin>
    </plugins>

    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>src/test/resources</directory>
        <filtering>true</filtering>
        <excludes>
          <exclude>keystore.jks</exclude>
        </excludes>
      </testResource>
      <testResource>
        <directory>${basedir}/../../sra/src/test/resources/debug</directory>
        <filtering>false</filtering>
        <includes>
          <include>saml.keystore.jks</include>
        </includes>
      </testResource>
    </testResources>
  </build>
  
  <profiles>
    <profile>
      <id>skipTests</id>
    </profile>

    <profile>
      <id>debug</id>

      <properties>
        <skipTests>true</skipTests>
      </properties>

      <build>
        <defaultGoal>clean verify cargo:run</defaultGoal>
        
        <plugins>
          <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven3-plugin</artifactId>
            <inherited>true</inherited>
            <configuration>
              <configuration>
                <properties>
                  <cargo.jvmargs>
                    -Dspring.profiles.active=embedded,https,all
                    -Dwicket.core.settings.general.configuration-type=development
                    -Dwicket.ioc.useByteBuddy=true
                    -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
                    -XX:+UseG1GC -Xmx1024m -Xms512m</cargo.jvmargs>
                </properties>
              </configuration>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    
    <!-- requires JAVA_HOME set to the latest JDK from https://github.com/TravaOpenJDK/trava-jdk-11-dcevm -->
    <profile>
      <id>hotswap</id>
      
      <build>
        <defaultGoal>clean verify cargo:run</defaultGoal>

        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <inherited>true</inherited>
            <executions>
              <execution>
                <id>enableHotSwapForCoreAndConsoleAndEnduser</id>
                <phase>package</phase>
                <configuration>
                  <target>                                               
                    <copy file="${basedir}/../core-reference/target/test-classes/hotswap-agent.properties"
                          tofile="${basedir}/../core-reference/target/syncope-fit-core-reference-${project.version}/WEB-INF/classes/hotswap-agent.properties"
                          overwrite="true"/>
                    <copy file="${basedir}/../console-reference/target/test-classes/hotswap-agent.properties"
                          tofile="${basedir}/../console-reference/target/syncope-fit-console-reference-${project.version}/WEB-INF/classes/hotswap-agent.properties"
                          overwrite="true"/>
                    <copy file="${basedir}/../enduser-reference/target/test-classes/hotswap-agent.properties"
                          tofile="${basedir}/../enduser-reference/target/syncope-fit-enduser-reference-${project.version}/WEB-INF/classes/hotswap-agent.properties"
                          overwrite="true"/>
                  </target>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven3-plugin</artifactId>
            <inherited>true</inherited>
            <configuration>
              <configuration>
                <properties>
                  <cargo.jvmargs>
                    -Dspring.profiles.active=embedded,all
                    -Dwicket.core.settings.general.configuration-type=development
                    -Dwicket.ioc.useByteBuddy=true
                    -javaagent:${java.home}/lib/hotswap/hotswap-agent.jar=autoHotswap=true,disablePlugin=Spring,disablePlugin=Hibernate,disablePlugin=CxfJAXRS
                    -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000
                    -XX:+UseConcMarkSweepGC -Xmx1024m -Xms512m</cargo.jvmargs>
                </properties>
              </configuration>
            </configuration>
          </plugin>
        </plugins>
        
        <resources>
          <resource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
            <includes>
              <include>hotswap-agent.properties</include>
            </includes>
          </resource>
        </resources>
      </build>
    </profile>

    <profile>
      <id>apache-release</id>

      <build>
        <plugins>
          <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-source-plugin</artifactId>
            <inherited>false</inherited>
            <configuration>
              <skipSource>true</skipSource>
            </configuration>
          </plugin>          
        </plugins>
      </build>
    </profile>

  </profiles>
</project>
