<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright (c) 2021, 2025 Contributors to the Eclipse Foundation.

  This program and the accompanying materials are made available under the
  terms of the Eclipse Public License v. 2.0, which is available at
  http://www.eclipse.org/legal/epl-2.0.

  This Source Code may also be made available under the following Secondary
  Licenses when the conditions for such availability set forth in the
  Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
  version 2 with the GNU Classpath Exception, which is available at
  https://www.gnu.org/software/classpath/license.html.

-->

<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.eclipse.ee4j.security.tck</groupId>
        <artifactId>jakarta-security-tck</artifactId>
        <version>4.0.1</version>
    </parent>

    <artifactId>app-openid3</artifactId>
    <packaging>war</packaging>

    <properties>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <finalName>openid-client</finalName>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.eclipse.ee4j.security.tck</groupId>
            <artifactId>common</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>openid-client</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-tomcat</id>
                        <phase>process-test-classes</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${tomcat.root}</outputDirectory>
                            <markersDirectory>${tomcat.root}/dependency-maven-plugin-markers</markersDirectory>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.apache.tomcat</groupId>
                                    <artifactId>tomcat</artifactId>
                                    <version>${tomcat.version}</version>
                                    <type>zip</type>
                                    <overWrite>true</overWrite>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.mitre</groupId>
                                    <artifactId>openid-connect-server-webapp</artifactId>
                                    <type>war</type>
                                    <version>${mitre.version}</version>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${tomcat.dir}/webapps/openid-connect-server-webapp</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-tomcat</id>
                        <phase>process-test-classes</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${tomcat.dir}/webapps/openid-connect-server-webapp/WEB-INF/lib</outputDirectory>
                            <!-- Add JAX-B, since it's been removed from JDK 11 and openid-connect-server-webapp assumes 8 -->
                            <artifactItems>
                                <artifactItem>
                                    <groupId>jakarta.xml.bind</groupId>
                                    <artifactId>jakarta.xml.bind-api</artifactId>
                                    <version>2.3.2</version>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.glassfish.jaxb</groupId>
                                    <artifactId>jaxb-runtime</artifactId>
                                    <version>2.3.2</version>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>javax.activation</groupId>
                                    <artifactId>javax.activation-api</artifactId>
                                    <version>1.2.0</version>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.sun.istack</groupId>
                                    <artifactId>istack-commons-runtime</artifactId>
                                    <version>3.0.8</version>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>set-ports</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <echo level="info">Replacing in ${tomcat.dir}</echo>

                                <replace token="http://localhost:8080" value="https://localhost:8443" dir="${tomcat.dir}/webapps/openid-connect-server-webapp/WEB-INF" summary="yes">
                                    <include name="server-config.xml" />
                                </replace>
                                <replace token="http://localhost/" value="http://localhost:8080/openid-client/Callback" dir="${tomcat.dir}/webapps/openid-connect-server-webapp/WEB-INF/classes/db/hsql" summary="yes">
                                    <include name="clients.sql" />
                                </replace>
                                
                                <copy file="server.xml" todir="${tomcat.dir}/conf" verbose="true" overwrite="true" force="true" />
                                <copy file="localhost-rsa.jks" todir="${tomcat.dir}/conf" verbose="true" />

                                <chmod dir="${tomcat.dir}/bin" perm="ugo+rx" includes="*" />

                                <exec executable="${tomcat.dir}/bin/startup.sh" dir="${tomcat.dir}" >
                                    <env key="CATALINA_PID" value="${tomcat.pidfile}" />
                                </exec>

                                <!-- Give the server some time to settle down -->
                                <sleep seconds="5" />

                                <loadfile property="contents" srcFile="${tomcat.dir}/logs/catalina.out" />
                                <echo message="${contents}" />
                            </target>
                        </configuration>
                    </execution>
                    <execution>
                        <id>post-integration-test</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target xmlns:if="ant:if" xmlns:unless="ant:unless">
                                <!-- stop the server -->
                                <exec executable="${tomcat.dir}/bin/shutdown.sh" dir="${tomcat.dir}" unless:set="tomcat.keeprunning" >
                                    <env key="CATALINA_PID" value="${tomcat.pidfile}" />
                                    <arg value="30" />
                                    <arg value="-force" />
                                </exec>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>keytool-maven-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <id>import-tomcat-cert</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>importCertificate</goal>
                        </goals>
                        <configuration>
                            <file>tomcat.cert</file>
                            <alias>tomcat</alias>
                            <keystore>${trustStore.path}</keystore>
                            <storepass>${trustStore.password}</storepass>
                            <noprompt>true</noprompt>
                            <trustcacerts>true</trustcacerts>
                            <verbose>true</verbose>
                        </configuration>
                    </execution>
                    <execution>
                        <id>delete-tomcat-cert</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>deleteAlias</goal>
                        </goals>
                        <configuration>
                            <alias>tomcat</alias>
                            <keystore>${trustStore.path}</keystore>
                            <storepass>${trustStore.password}</storepass>
                            <verbose>true</verbose>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-dependency-plugin</artifactId>
                                        <versionRange>[3.2.0,)</versionRange>
                                        <goals>
                                            <goal>copy</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>
                                            org.codehaus.mojo
                                        </groupId>
                                        <artifactId>
                                            keytool-maven-plugin
                                        </artifactId>
                                        <versionRange>
                                            [1.6,)
                                        </versionRange>
                                        <goals>
                                            <goal>
                                                importCertificate
                                            </goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

</project>
