<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
        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>
        <artifactId>org.apache.sling.cms</artifactId>
        <groupId>org.apache.sling</groupId>
        <version>1.1.8</version>
    </parent>

    <artifactId>org.apache.sling.cms.it</artifactId>
    <name>Apache Sling - CMS Integration Tests</name>

    <properties>
        <bnd.baseline.skip>true</bnd.baseline.skip>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>${basedir}</directory>
                            <includes>
                                <include>sling/**</include>
                                <include>coverage.ec</include>
                                <include>launcher/**</include>
                            </includes>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <plugin>
                    <!-- Extend RAT configuration from parent pom -->
                    <groupId>org.apache.rat</groupId>
                    <artifactId>apache-rat-plugin</artifactId>
                    <configuration>
                        <excludes combine.children="append">
                            <!-- Exclude sling instance -->
                            <exclude>sling/**</exclude>
                            <exclude>launcher/**</exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    <profiles>
        <profile>
            <id>ci</id>
            <activation>
                <property>
                    <name>ci</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <!-- reserve a network port for the integration tests -->
                    <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>pre-integration-test</phase>
                                <configuration>
                                    <portNames>
                                        <portName>http.port</portName>
                                    </portNames>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.sling</groupId>
                        <artifactId>feature-launcher-maven-plugin</artifactId>
                        <version>0.1.6</version>
                        <configuration>
                            <launches>
                                <launch>
                                    <id>sling-cms</id>
                                    <feature>
                                        <groupId>${project.groupId}</groupId>
                                        <artifactId>org.apache.sling.cms.feature</artifactId>
                                        <version>${project.version}</version>
                                        <classifier>slingcms-standalone</classifier>
                                        <type>slingosgifeature</type>
                                    </feature>
                                    <launcherArguments>
                                        <frameworkProperties>
                                            <org.osgi.service.http.port>${http.port}</org.osgi.service.http.port>
                                        </frameworkProperties>
                                    </launcherArguments>
                                    <startTimeoutSeconds>180</startTimeoutSeconds>
                                </launch>
                            </launches>
                        </configuration>
                        <executions>
                            <execution>
                                <id>start-sling</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>stop-sling</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>com.github.eirslett</groupId>
                        <artifactId>frontend-maven-plugin</artifactId>
                        <version>1.14.2</version>
                        <executions>
                            <execution>
                                <id>install node and npm</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>install-node-and-npm</goal>
                                </goals>
                                <configuration>
                                    <nodeVersion>${node.version}</nodeVersion>
                                    <npmVersion>${npm.version}</npmVersion>
                                </configuration>
                            </execution>
                            <execution>
                                <id>npm install</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>npm</goal>
                                </goals>
                                <configuration>
                                    <arguments>ci</arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>install cypress</id>
                                <goals>
                                    <goal>npm</goal>
                                </goals>
                                <phase>validate</phase>
                                <configuration>
                                    <arguments>run cypress:install</arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>wait for sling</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>npm</goal>
                                </goals>
                                <configuration>
                                    <arguments>run wait-for-ready</arguments>
                                    <environmentVariables>
                                        <CYPRESS_BASE_URL>http://localhost:${http.port}</CYPRESS_BASE_URL>
                                    </environmentVariables>
                                </configuration>
                            </execution>
                            <execution>
                                <id>run cypress</id>
                                <goals>
                                    <goal>npm</goal>
                                </goals>
                                <phase>integration-test</phase>
                                <configuration>
                                    <arguments>run test</arguments>
                                    <environmentVariables>
                                        <CYPRESS_BASE_URL>http://localhost:${http.port}</CYPRESS_BASE_URL>
                                    </environmentVariables>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>