<?xml version="1.0"?>
<!--
  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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.apache.cxf.fediz</groupId>
        <artifactId>fediz</artifactId>
        <version>1.6.2</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>
    <artifactId>fediz-idp</artifactId>
    <name>Apache Fediz IDP</name>
    <packaging>war</packaging>
    
    <dependencies>
        <dependency>
            <groupId>org.apache.cxf.fediz</groupId>
            <artifactId>fediz-idp-core</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-rs-service-description-swagger</artifactId>
            <version>${cxf.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.validation</groupId>
                    <artifactId>validation-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/realm.properties</include>
                    <include>**/persistence.properties</include>
                    <include>**/web.xml</include>
                    <include>**/restContext.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <excludes>
                    <exclude>**/realm.properties</exclude>
                    <exclude>**/persistence.properties</exclude>
                    <exclude>**/web.xml</exclude>
                    <exclude>**/restContext.xml</exclude>
                </excludes>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/test/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </testResource>
            <testResource>
                <directory>src/test/resources</directory>
                <includes>
                    <include>**/*</include>
                </includes>
                <excludes>
                    <exclude>**/*.jks</exclude>
                </excludes>
                <filtering>true</filtering>
            </testResource>
            <testResource>
                <directory>src/test/resources</directory>
                <includes>
                    <include>**/*.jks</include>
                </includes>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <!--for mvn tomcat:deploy/:undeploy/:redeploy -->
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <version>1.1</version>
                <configuration>
                    <server>myTomcat</server>
                    <url>http://localhost:9080/manager/text</url>
                    <path>/${project.build.finalName}</path>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>src/main/webapp</directory>
                            <filtering>true</filtering>
                            <includes>
                                <include>**/applicationContext.xml</include>
                                <include>**/web.xml</include>
								<include>**/restContext.xml</include>
                            </includes>
                        </resource>
                        <resource>
                            <directory>src/main/webapp</directory>
                            <filtering>false</filtering>
                            <excludes>
                                <exclude>**/applicationContext.xml</exclude>
                                <exclude>**/web.xml</exclude>
								<exclude>**/restContext.xml</exclude>
                            </excludes>
                        </resource>
                    </webResources>
                    <attachClasses>true</attachClasses>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>reserve-network-port</id>
                        <goals>
                            <goal>reserve-network-port</goal>
                        </goals>
                        <phase>initialize</phase>
                        <configuration>
                            <portNames>
                                <portName>idp.https.port</portName>
                                <portName>idp.stop.port</portName>
                            </portNames>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>set-tomcat-properties</id>
                        <goals>
                            <goal>set-system-properties</goal>
                        </goals>
                        <configuration>
                            <properties>
                                <property>
                                    <name>catalina.base</name>
                                    <value>${project.build.directory}</value>
                                </property>
                            </properties>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty9.version}</version>
                <inherited>true</inherited>
                <configuration>
                    <skip>${skipTests}</skip>
                    <stopPort>${idp.stop.port}</stopPort>
                    <stopKey>STOP</stopKey>
                    <jettyXml>${project.build.directory}/test-classes/jetty.xml,${project.build.directory}/test-classes/jetty-ssl-context.xml,
                    ${project.build.directory}/test-classes/jetty-ssl.xml,${project.build.directory}/test-classes/jetty-https.xml</jettyXml>
                    <contextHandlers>
                        <contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
                            <war>${project.build.directory}/fediz-idp-sts.war</war>
                            <contextPath>/fediz-idp-sts</contextPath>
                            <throwUnavailableOnStartupException>false</throwUnavailableOnStartupException>
                        </contextHandler>
                        <contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
                            <war>${project.build.directory}/fediz-idp.war</war>
                            <contextPath>/fediz-idp</contextPath>
                        </contextHandler>
                    </contextHandlers>
                </configuration>
                <executions>
                    <execution>
                        <id>start-jetty</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>deploy-war</goal>
                        </goals>
                        <configuration>
                            <scanIntervalSeconds>0</scanIntervalSeconds>
                            <daemon>true</daemon>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop-jetty</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.hsqldb</groupId>
                        <artifactId>hsqldb</artifactId>
                        <version>${hsqldb.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <inherited>true</inherited>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <configuration>
                            <skip>${skipTests}</skip>
                            <systemPropertyVariables>
                                <idp.https.port>${idp.https.port}</idp.https.port>
                                <realm>${realm}</realm>
                                <catalina.base>${project.build.directory}</catalina.base>
                            </systemPropertyVariables>
                            <includes>
                                <include>**/integrationtests/**</include>
                            </includes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>verify</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <inherited>true</inherited>
                <configuration>
                    <excludes>
                        <exclude>**/integrationtests/**</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
        <!-- Name of the generated WAR file -->
        <finalName>fediz-idp</finalName>
    </build>

    <profiles>
        <profile>
            <id>default</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <jpa.url>jdbc:hsqldb:target/db/realma/myDB;shutdown=true</jpa.url>
                <realm>realm-a</realm>
            </properties>
            <build>
                <filters>
                    <filter>src/main/filters/realm-a/env.properties</filter>
                </filters>
            </build>
        </profile>
        <profile>
            <id>realm-a</id>
            <properties>
                <jpa.url>jdbc:hsqldb:target/db/realma/myDB;shutdown=true</jpa.url>
                <idp.https.port>9443</idp.https.port>
                <realm>realm-a</realm>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.hsqldb</groupId>
                    <artifactId>hsqldb</artifactId>
                    <version>${hsqldb.version}</version>
                </dependency>
            </dependencies>
            <build>
                <filters>
                    <filter>src/main/filters/realm-a/env.properties</filter>
                </filters>
                <plugins>
                    <plugin>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-maven-plugin</artifactId>
                        <configuration>
                            <contextHandlers>
                                <contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
                                    <war>${project.build.directory}/fediz-idp.war</war>
                                    <contextPath>/fediz-idp</contextPath>
                                </contextHandler>
                            </contextHandlers>
                         </configuration>
                     </plugin>
                 </plugins>
            </build>
        </profile>
        <profile>
            <id>realm-b</id>
            <properties>
                <jpa.url>jdbc:hsqldb:target/db/realmb/myDB;shutdown=true</jpa.url>
                <idp.https.port>12346</idp.https.port>
                <realm>realm-b</realm>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.hsqldb</groupId>
                    <artifactId>hsqldb</artifactId>
                    <version>${hsqldb.version}</version>
                </dependency>
            </dependencies>
            <build>
                <filters>
                    <filter>src/main/filters/realm-b/env.properties</filter>
                </filters>
                <plugins>
                    <plugin>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-maven-plugin</artifactId>
                        <configuration>
                            <contextHandlers>
                                <contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
                                    <war>${project.build.directory}/fediz-idp-remote.war</war>
                                    <contextPath>/fediz-idp-remote</contextPath>
                                </contextHandler>
                            </contextHandlers>
                         </configuration>
                     </plugin>
                 </plugins>
                <finalName>fediz-idp-remote</finalName>
            </build>
        </profile>
        <profile>
            <id>standalone</id>
            <properties>
                <maven.test.skip>true</maven.test.skip>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.hsqldb</groupId>
                    <artifactId>hsqldb</artifactId>
                    <version>${hsqldb.version}</version>
                </dependency>
            </dependencies>
            <build>
                <defaultGoal>jetty:run-war</defaultGoal>
            </build>
        </profile>

        <profile>
            <id>sts</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-sts</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>copy</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>org.apache.cxf.fediz</groupId>
                                            <artifactId>fediz-idp-sts</artifactId>
                                            <version>${project.version}</version>
                                            <type>war</type>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>${project.build.directory}</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                    <outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename>
                                    <overWriteSnapshots>true</overWriteSnapshots>
                                    <overWriteIfNewer>true</overWriteIfNewer>
                                    <stripVersion>true</stripVersion>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-maven-plugin</artifactId>
                        <configuration>
                            <contextHandlers combine.children="append">
                                <contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
                                    <war>${project.build.directory}/fediz-idp-sts.war</war>
                                    <contextPath>/fediz-idp-sts</contextPath>
                                </contextHandler>
                            </contextHandlers>
                         </configuration>
                     </plugin>
                 </plugins>
            </build>
        </profile>
    </profiles>
</project>
