<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright (c) 2022 Contributors to the Eclipse Foundation. All rights reserved.

    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.

    SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0

-->

<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>

    <groupId>org.glassfish.main.tests.tck</groupId>
    <version>3.0.0</version>
    <artifactId>glassfish-tck-security</artifactId>
    <packaging>pom</packaging>

    <name>TCK: Securityapi</name>

    <properties>
        <ant.version>1.10.2</ant.version>
        <ant.home>${project.build.directory}/apache-ant-${ant.version}</ant.home>
        <ant.zip.url>https://archive.apache.org/dist/ant/binaries/apache-ant-${ant.version}-bin.zip</ant.zip.url>
        <skipITs>false</skipITs>
        <tck.home>${maven.multiModuleProjectDirectory}/release/SECURITYAPI_BUILD/latest/security-tck</tck.home>
        <tck.tests.home>${tck.home}/src/com/sun/ts/tests/securityapi</tck.tests.home> 
        <tck.mode>standalone</tck.mode>        
        <glassfish.home>${project.build.directory}/glassfish8</glassfish.home>
        <glassfish.version>7.0.0-M4</glassfish.version>
        <glassfish.asadmin>${glassfish.home}/glassfish/bin/asadmin</glassfish.asadmin>
       
        <jacoco.includes>org/glassfish/**\:com/sun/enterprise/**</jacoco.includes>
        
        <port.admin>4848</port.admin>
        <port.derby>1527</port.derby>
        <port.http>8080</port.http>
        <port.https>8181</port.https>
        <port.jms>7676</port.jms>
        <port.jmx>8686</port.jmx>
        <port.orb>3700</port.orb>
        <port.orb.mutual>3920</port.orb.mutual>
        <port.orb.ssl>3820</port.orb.ssl>
        <port.harness.log>2000</port.harness.log>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.glassfish.main.distributions</groupId>
            <artifactId>glassfish</artifactId>
            <version>${glassfish.version}</version>
            <type>zip</type>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>jakarta-staging</id>
            <snapshots />
            <url>https://jakarta.oss.sonatype.org/content/repositories/staging</url>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>release/SECURITYAPI_BUILD</directory>
                            <includes>
                                <include>**</include>
                            </includes>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.googlecode.maven-download-plugin</groupId>
                <artifactId>download-maven-plugin</artifactId>
                <version>1.6.7</version>
                <executions>
                    <execution>
                        <id>download-ant</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>wget</goal>
                        </goals>
                        <configuration>
                            <skip>${skipITs}</skip>
                            <url>${ant.zip.url}</url>
                            <unpack>true</unpack>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                        </configuration>
                    </execution>                    
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <executions>
                    <execution>
                        <id>build-old-tck</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>docker/build_oldtck.sh</executable>
                            <skip>${skipITs}</skip>
                            <successCodes>
                                <successCode>0</successCode>
                                <successCode>1</successCode>
                            </successCodes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <configuration>
                    <skip>${skipITs}</skip>
                </configuration>
                <executions>
                    <execution>
                        <id>unpack-glassfish</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeArtifactIds>glassfish</includeArtifactIds>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-lib-jars</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                        <goal>copy</goal>
                        </goals>
                        <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>commons-codec</groupId>
                                <artifactId>commons-codec</artifactId>
                                <version>1.9</version>
                            </artifactItem>    
                            <artifactItem>
                                <groupId>commons-collections</groupId>
                                <artifactId>commons-collections</artifactId>
                                <version>3.2.1</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>commons-httpclient</groupId>
                                <artifactId>commons-httpclient</artifactId>
                                <version>3.1</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>commons-io</groupId>
                                <artifactId>commons-io</artifactId>
                                <version>2.4</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>org.apache.commons</groupId>
                                <artifactId>commons-lang3</artifactId>
                                <version>3.3.2</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>commons-logging</groupId>
                                <artifactId>commons-logging</artifactId>
                                <version>1.1.3</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>net.sourceforge.cssparser</groupId>
                                <artifactId>cssparser</artifactId>
                                <version>0.9.25</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>net.sourceforge.htmlunit</groupId>
                                <artifactId>htmlunit</artifactId>
                                <version>2.15</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>net.sourceforge.htmlunit</groupId>
                                <artifactId>htmlunit-core-js</artifactId>
                                <version>2.15</version>
                            </artifactItem>
                            <!--artifactItem>
                                <groupId>org.apache.httpcomponents</groupId>
                                <artifactId>httpclient</artifactId>
                                <version>4.5.5</version>
                            </artifactItem-->
                            <artifactItem>
                                <groupId>org.apache.httpcomponents</groupId>
                                <artifactId>httpcore</artifactId>
                                <version>4.4.9</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>org.apache.httpcomponents</groupId>
                                <artifactId>httpmime</artifactId>
                                <version>4.5.5</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>jaxen</groupId>
                                <artifactId>jaxen</artifactId>
                                <version>1.1.6</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>org.jdom</groupId>
                                <artifactId>jdom</artifactId>
                                <version>1.1.3</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>net.sourceforge.nekohtml</groupId>
                                <artifactId>nekohtml</artifactId>
                                <version>1.9.21</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>org.w3c.css</groupId>
                                <artifactId>sac</artifactId>
                                <version>1.3</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>xalan</groupId>
                                <artifactId>serializer</artifactId>
                                <version>2.7.2</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>xalan</groupId>
                                <artifactId>xalan</artifactId>
                                <version>2.7.2</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>xerces</groupId>
                                <artifactId>xercesImpl</artifactId>
                                <version>2.11.0</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>xml-apis</groupId>
                                <artifactId>xml-apis</artifactId>
                                <version>1.4.01</version>
                            </artifactItem>
                        </artifactItems>
                        <outputDirectory>${tck.home}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.ant</groupId>
                        <artifactId>ant</artifactId>
                        <version>${ant.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>ant-contrib</groupId>
                        <artifactId>ant-contrib</artifactId>
                        <version>1.0b3</version>
                        <exclusions>
                            <exclusion>
                                <groupId>ant</groupId>
                                <artifactId>ant</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                </dependencies>
                <configuration>
                    <skip>${skipITs}</skip>
                </configuration>
                <executions>
                    <execution>
                        <id>prepare-tck-and-glassfish</id>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <target xmlns:if="ant:if" xmlns:unless="ant:unless">
                            
                                <taskdef resource="net/sf/antcontrib/antcontrib.properties"
                                         classpathref="maven.plugin.classpath" />
                                         
                               <macrodef name="tck-setting">
                                    <attribute name="key" /> <attribute name="value" />
                                    <sequential>
                                      <replaceregexp file="${tck.home}/bin/ts.jte" byline="true"
                                        match="@{key}=.*" replace="@{key}=@{value}" />
                                    </sequential>
                                </macrodef>

                                <if>
                                    <equals arg1="${tck.mode}" arg2="platform" />
                                    <then>
                                        <copy file="${tck.home}/bin/ts.jtx.platform" tofile="${tck.home}/bin/ts.jtx" overwrite="true"  />
                                    </then>
                                    <elseif>
                                        <equals arg1="${tck.mode}" arg2="standalone" />
                                            <then>
                                                <copy file="${tck.home}/bin/ts.jtx.standalone" tofile="${tck.home}/bin/ts.jtx" overwrite="true"  />
                                            </then>
                                    </elseif>
                                    <else>
                                        <echo message="The value of property ${tck.mode} should be set as standalone or platform " />
                                    </else>
                                </if>


                                <!-- Change configuration -->
                                <!--copy file="${tck.home}/bin/ts.jte.jdk11" tofile="${tck.home}/bin/ts.jte" overwrite="true"  /-->
                                
                                <tck-setting key="webServerHost" value="localhost"/>
                                <tck-setting key="webServerPort" value="${port.http}"/>
                                <tck-setting key="securedWebServicePort" value="${port.https}"/>
                                <tck-setting key="s1as.admin.port" value="${port.admin}"/>
                                <tck-setting key="glassfish.admin.port" value="${port.admin}"/>
                                <tck-setting key="orb.port" value="${port.orb}"/>
                                <tck-setting key="database.port" value="${port.derby}"/>
                                <tck-setting key="harness.log.port" value="${port.harness.log}"/>
                                <tck-setting key="web.home" value="${glassfish.home}/glassfish"/>
                                
                                <tck-setting key="report.dir" value="${tck.home}/securityapireport/securityapi"/>
                                <tck-setting key="work.dir" value="${tck.home}/securityapiwork/securityapi"/>

                                <mkdir dir="${tck.home}/securityapireport"/>
                                <mkdir dir="${tck.home}/securityapireport/securityapi"/>
                                
                                <replace file="${tck.home}/bin/xml/ts.top.import.xml">
                                  <replacetoken><![CDATA[<jvmarg value="-Xmx512m" />]]></replacetoken>
                                  <replacevalue><![CDATA[<jvmarg value="-Xmx512m" />
                                <jvmarg value="-Djavatest.security.noSecurityManager=true"/>]]></replacevalue>
                                </replace>
                                
                                <replace file="${tck.home}/bin/xml/ts.top.import.xml" if:set="suspend-tck" >
                                  <replacetoken><![CDATA[<jvmarg value="-Xmx512m" />]]></replacetoken>
                                  <replacevalue><![CDATA[<jvmarg value="-Xmx512m" />
                                <jvmarg value="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=9008"/>]]></replacevalue>
                                </replace>
                                
                                
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>

                    <execution>
                        <id>configure-tck-tests</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                
                                <replace file="${glassfish.home}/glassfish/domains/domain1/config/domain.xml" 
                                    token="-Xmx512m" value="-Xmx1024m" />

                                <taskdef resource="net/sf/antcontrib/antcontrib.properties"
                                         classpathref="maven.plugin.classpath" />

                                <limit maxwait="300">
                                    <exec executable="${glassfish.asadmin}" dir="${glassfish.home}/glassfish/bin">
                                        <arg value="start-database"/>
                                    </exec>
                                </limit>
                                
                                <exec executable="${ant.home}/bin/ant" dir="${tck.home}/bin">
                                    <arg value="config.vi"  />
                                </exec>

                                <exec executable="${ant.home}/bin/ant" dir="${tck.home}/bin">
                                    <arg value="init.ldap"  />
                                </exec>

                                <exec executable="${ant.home}/bin/ant" dir="${tck.home}/bin">
                                    <arg value="deploy.all"  />
                                </exec>
                            </target>
                        </configuration>
                    </execution>
      

                     <execution>
                        <id>run-tck-tests</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target xmlns:if="ant:if" xmlns:unless="ant:unless">
                                <taskdef resource="net/sf/antcontrib/antcontrib.properties"
                                         classpathref="maven.plugin.classpath" />

                                <echo level="info" message="Start running all tests" unless:set="run.test"/>
                                <!--echo level="info" message="Start running single test" if:set="run.test"/-->
                                <exec executable="${ant.home}/bin/ant" dir="${tck.home}/bin" resultproperty="testResult">
                                    <!--arg value="-Dutil.dir=${tck.home}"  />
                                    <arg value="-Dmultiple.tests=${run.test}" if:set="run.test" /-->
                                    <arg value="run.all"/>
                                    <env key="LC_ALL" value="C" />
                                </exec>

                                <if>
                                    <not>
                                        <equals arg1="${testResult}" arg2="0" />
                                    </not>
                                    <then>
                                        <echo message="Running tests failed." />
                                        <loadfile property="contents" srcFile="${glassfish.home}/glassfish/domains/domain1/logs/server.log" />
                                        <echo message="${contents}" />
                                    </then>
                                </if>
                                
                                <exec executable="${glassfish.asadmin}" dir="${glassfish.home}/glassfish/bin">
                                    <arg value="stop-domain" />
                                </exec>

                            </target>
                        </configuration>
                    </execution>

                </executions>
            </plugin>
        </plugins>
    </build>
</project>
