<?xml version="1.0" encoding="UTF-8"?>
<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>com.vaadin</groupId>
        <artifactId>flow-components-parent</artifactId>
        <version>0.1.17</version>
    </parent>
    <artifactId>flow-components-test</artifactId>
    <name>Flow component API integration test module</name>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>flow</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>flow-components</artifactId>
            <version>${flow.version}</version>
        </dependency>

        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>flow-test-util</artifactId>
            <version>${flow.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>${frontend.working.directory}/bower_components</directory>
                        </fileset>
                        <fileset>
                            <directory>${frontend.working.directory}/build</directory>
                        </fileset>
                        <fileset>
                            <directory>${frontend.working.directory}/node</directory>
                        </fileset>
                        <fileset>
                            <directory>${frontend.working.directory}/node_modules</directory>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>${frontend.maven.plugin.version}</version>
                <configuration>
                    <nodeVersion>${node.version}</nodeVersion>
                    <yarnVersion>${yarn.version}</yarnVersion>
                    <workingDirectory>${frontend.working.directory}</workingDirectory>
                </configuration>
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <id>install node and yarn</id>
                        <goals>
                            <goal>install-node-and-yarn</goal>
                        </goals>
                        <configuration></configuration>
                    </execution>
                    <execution>
                        <phase>generate-resources</phase>
                        <id>add bower</id>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <configuration>
                            <arguments>add bower</arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>generate-resources</phase>
                        <id>yarn install</id>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <configuration>
                            <arguments>${yarn.build.goal}</arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <systemPropertyVariables>
                        <webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
                    </systemPropertyVariables>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.version}</version>
                <configuration>
                    <scanIntervalSeconds>-1</scanIntervalSeconds>
                    <stopPort>8081</stopPort>
                    <stopWait>5</stopWait>
                    <stopKey>foo</stopKey>
                    <webAppConfig>
                        <webInfIncludeJarPattern>.*/flow-.*.jar$|.*/test-resources-.*.jar$</webInfIncludeJarPattern>
                        <containerIncludeJarPattern>^$</containerIncludeJarPattern>
                        <resourceBases>
                            <resourceBase>${project.basedir}/${webapp.directory}</resourceBase>
                            <resourceBase>${jetty.extra.resource.base}</resourceBase>
                        </resourceBases>
                    </webAppConfig>
                </configuration>
                <executions>
                    <!-- start and stop jetty (running our app) when running integration
                        tests -->
                    <execution>
                        <id>start-jetty</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-jetty</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>productionMode</id>
            <activation>
                <property>
                    <name>vaadin.productionMode</name>
                </property>
            </activation>

            <properties>
                <yarn.build.goal>run prodMode</yarn.build.goal>
                <jetty.extra.resource.base>${project.build.directory}/jetty-extra-resources</jetty.extra.resource.base>
            </properties>

            <dependencies>
                <dependency>
                    <groupId>com.vaadin</groupId>
                    <artifactId>flow-server-production-mode</artifactId>
                    <version>${flow.version}</version>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>${maven.war.plugin.version}</version>
                        <configuration>
                            <webResources>
                                <resource>
                                    <directory>${project.basedir}/${webapp.directory}</directory>
                                </resource>
                                <resource>
                                    <directory>${frontend.working.directory}/build</directory>
                                    <targetPath>${vaadin.frontend.path}</targetPath>
                                </resource>
                            </webResources>
                        </configuration>
                    </plugin>

                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>3.0.2</version>
                        <executions>
                            <execution>
                                <id>copy-resources</id>
                                <phase>process-resources</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.directory}/jetty-extra-resources/${vaadin.frontend.path}</outputDirectory>
                                    <overwrite>true</overwrite>
                                    <resources>
                                        <resource>
                                            <directory>${project.basedir}/${frontend.working.directory}/build</directory>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>debugMode</id>
            <activation>
                <property>
                    <name>!vaadin.productionMode</name>
                </property>
            </activation>

            <properties>
                <yarn.build.goal>run devMode</yarn.build.goal>
                <jetty.extra.resource.base>${project.basedir}/${frontend.working.directory}</jetty.extra.resource.base>
            </properties>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <configuration>
                            <webResources>
                                <resource>
                                    <directory>${project.basedir}/${webapp.directory}</directory>
                                </resource>
                                <resource>
                                    <directory>${frontend.working.directory}</directory>
                                    <excludes>
                                        <exclude>build/**</exclude>
                                    </excludes>
                                </resource>
                            </webResources>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>local-run</id>
            <activation>
                <property>
                    <name>!test.use.hub</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.lazerycode.selenium</groupId>
                        <artifactId>driver-binary-downloader-maven-plugin</artifactId>
                        <version>${driver.binary.downloader.maven.plugin.version}</version>
                        <configuration>
                            <onlyGetDriversForHostOperatingSystem>true</onlyGetDriversForHostOperatingSystem>
                            <rootStandaloneServerDirectory>${project.rootdir}/driver</rootStandaloneServerDirectory>
                            <downloadedZipFileDirectory>${project.rootdir}/driver_zips</downloadedZipFileDirectory>
                            <customRepositoryMap>${project.rootdir}/drivers.xml</customRepositoryMap>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>selenium</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

    </profiles>
</project>
