<?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>org.jboss.windup.web</groupId>
        <artifactId>windup-web-parent</artifactId>
        <version>4.0.1.Final</version>
    </parent>

    <artifactId>windup-web-ui</artifactId>
    <name>Windup Web - UI</name>
    <packaging>war</packaging>

    <properties>
        <browser>phantomjs</browser>

        <!--
            This property gives Jenkins a hint as to where to find Karma test results. This is needed since the Jenkins
            Maven plugin does not currently automatically find this folder (as of Jenkins Maven 2.14 on November 28, 2016).


            Documention is here: https://wiki.jenkins-ci.org/display/JENKINS/Building+a+maven2+project
        -->
        <jenkins.karmaTests.reportsDirectory>target/karma-reports</jenkins.karmaTests.reportsDirectory>
        <webpack.environment>development</webpack.environment>
    </properties>

    <dependencies>
        <!-- Java EE -->
        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-7.0</artifactId>
            <version>${version.jboss.javaee}</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.25-incubating</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>

        <!-- Test Dependencies -->
        <dependency>
            <groupId>org.jboss.windup.web</groupId>
            <artifactId>test-authentication-client</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-client</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.extension</groupId>
            <artifactId>arquillian-warp</artifactId>
            <scope>test</scope>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.extension</groupId>
            <artifactId>arquillian-rest-warp-spi</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.extension</groupId>
            <artifactId>arquillian-rest-warp-impl-jaxrs-2.0</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jsapi</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxb-provider</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jackson2-provider</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.arquillian.graphene</groupId>
            <artifactId>graphene-webdriver</artifactId>
            <type>pom</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>rhamt-web</finalName>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>create</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <doCheck>false</doCheck>
                    <doUpdate>false</doUpdate>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>src/main/webapp/typings/</directory>
                            <followSymlinks>false</followSymlinks>
                        </fileset>
                        <fileset>
                            <directory>src/main/webapp/app/tsModels/</directory>
                            <followSymlinks>false</followSymlinks>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <warSourceExcludes>
                        app,
                        config/,
                        src/,
                        tests/,
                        typings/,
                        node_modules/,
                        .gitignore,
                        *.js,
                        version/,
                        *.json,
                        *.html</warSourceExcludes>
                    <delimiters>
                        <delimiter>$MAVEN_TOKEN{*}</delimiter>
                    </delimiters>
                    <webResources>
                        <resource>
                            <directory>src/main/webapp/</directory>
                            <filtering>true</filtering>
                            <includes>
                                <include>**/version.properties.js</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>npm-install</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>

                        <configuration>
                            <executable>yarn</executable>
                            <workingDirectory>src/main/webapp</workingDirectory>
                            <arguments>
                                <argument>install</argument>
                            </arguments>
                        </configuration>
                    </execution>

                    <execution>
                        <id>webpack-build</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>

                        <configuration>
                            <executable>./node_modules/.bin/webpack</executable>
                            <workingDirectory>src/main/webapp</workingDirectory>
                            <arguments>
                                <argument>--progress</argument>
                                <argument>--profile</argument>
                                <argument>--env.environment=${webpack.environment}</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.kelveden</groupId>
                <artifactId>maven-karma-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <id>karmaTests</id>
                        <phase>test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <workingDirectory>src/main/webapp</workingDirectory>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <karmaExecutable>node_modules/.bin/karma</karmaExecutable>
                    <configFile>src/main/webapp/karma.conf.js</configFile>
                    <junitReportFile>src/main/webapp/test-results.xml</junitReportFile>
                    <reportsDirectory>${project.build.directory}/karma-reports</reportsDirectory>
                    <browsers>PhantomJS</browsers>
                    <autoWatch>false</autoWatch>
                    <singleRun>true</singleRun>
                    <colors>true</colors>
                    <karmaFailureIgnore>false</karmaFailureIgnore>
                    <reporters>progress,junit</reporters>
                </configuration>
            </plugin>

        </plugins>
    </build>

    <profiles>
        <!-- Extract TS models from an artifact. -->
        <profile>
            <properties>
                <dirToPlaceTsModelsDirTo>src/main/webapp/src/app/generated</dirToPlaceTsModelsDirTo>
                <windup.tsmodelgen.importPathToWebapp>../../..</windup.tsmodelgen.importPathToWebapp>
            </properties>
            <id>extractTypescriptModels</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <!-- Delete old TS models -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-clean-plugin</artifactId>
                        <version>3.0.0</version>
                        <executions>
                            <execution>
                                <id>delete-tsModels</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>clean</goal>
                                </goals>
                                <configuration>
                                    <excludeDefaultDirectories>true</excludeDefaultDirectories>
                                    <filesets>
                                      <fileset>
                                          <directory>${project.basedir}/src/main/webapp/src/app/generated/tsModels</directory>
                                          <followSymlinks>false</followSymlinks>
                                          <useDefaultExcludes>false</useDefaultExcludes>
                                      </fileset>
                                    </filesets>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Extract TS models -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>3.0.0</version>
                        <executions>
                            <execution>
                                <id>unpack-tsModels</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>org.jboss.windup.web.ui</groupId>
                                            <artifactId>windup-web-ui-tsmodels</artifactId>
                                            <version>${project.version}</version>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>target/tsModels-tmp</outputDirectory>
                                            <includes>**/*.ts</includes>
                                            <excludes>META-INF/**</excludes>
                                        </artifactItem>
                                        <artifactItem>
                                            <groupId>org.jboss.windup.web</groupId>
                                            <artifactId>windup-web-services</artifactId>
                                            <classifier>typescript-models</classifier>
                                            <version>${project.version}</version>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>target/tsModels-tmp</outputDirectory>
                                            <includes>**/*.ts</includes>
                                            <excludes>META-INF/**</excludes>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- Process the TS models with the resource plugin to replace the tokens. -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>3.0.2</version>
                        <executions>
                            <execution>
                                <id>process-tsModels</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <resources><resource>
                                        <directory>target/tsModels-tmp</directory>
                                        <includes>
                                            <include>**/*.ts</include>
                                        </includes>
                                        <filtering>true</filtering>
                                    </resource></resources>
                                    <delimiters>
                                        <delimiter>$MAVEN_TOKEN{*}</delimiter>
                                    </delimiters>
                                    <outputDirectory>${dirToPlaceTsModelsDirTo}</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
