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

<!--
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<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>
    <groupId>org.xwiki.platform</groupId>
    <artifactId>xwiki-platform-livedata</artifactId>
    <version>13.10.7</version>
  </parent>
  <packaging>webjar</packaging>
  <artifactId>xwiki-platform-livedata-webjar</artifactId>
  <name>XWiki Platform - Live Data - WebJar</name>
  <properties>
    <!-- Name to display by the Extension Manager -->
    <xwiki.extension.name>Live Data WebJar</xwiki.extension.name>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.webjars</groupId>
      <artifactId>requirejs</artifactId>
    </dependency>
    <dependency>
      <groupId>org.webjars.npm</groupId>
      <artifactId>vue-i18n</artifactId>
      <version>8.15.5</version>
    </dependency>
    <dependency>
      <groupId>org.webjars</groupId>
      <artifactId>jquery</artifactId>
    </dependency>
    <dependency>
      <groupId>org.webjars</groupId>
      <artifactId>vue</artifactId>
      <version>2.6.14</version>
    </dependency>
    <!-- Used by the date filter. -->
    <dependency>
      <groupId>org.webjars</groupId>
      <artifactId>momentjs</artifactId>
    </dependency>
    <dependency>
      <groupId>org.webjars</groupId>
      <artifactId>bootstrap-daterangepicker</artifactId>
    </dependency>
    <!-- Used by the suggest filter. -->
    <dependency>
      <groupId>org.webjars</groupId>
      <artifactId>selectize.js</artifactId>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>xwiki-platform-livedata-rest</artifactId>
      <version>${project.version}</version>
      <scope>runtime</scope>
    </dependency>
    <!-- Used for the translations. -->
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <!-- We keep the Vue files and the build configuration files in separate folders in the source tree but
              we need them in the same folder when building the Vue components. -->
            <id>copy-vue-resources</id>
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/vue</outputDirectory>
              <resources>
                <resource>
                  <directory>src/main/vue</directory>
                </resource>
                <resource>
                  <directory>src/main/config</directory>
                </resource>
              </resources>
            </configuration>
          </execution>
          <execution>
            <!-- We need to copy the tests in the target directory. -->
            <id>copy-vue-tests</id>
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/vue/tests</outputDirectory>
              <resources>
                <resource>
                  <directory>src/main/tests</directory>
                </resource>
              </resources>
            </configuration>
          </execution>
          <execution>
            <!-- Copy the generated Vue components to the WebJar folder. -->
            <id>copy-vue-components</id>
            <phase>process-resources</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.outputDirectory}/META-INF/resources/webjars/${project.artifactId}/${project.version}</outputDirectory>
              <resources>
                <resource>
                  <directory>${project.build.directory}/vue/dist</directory>
                  <excludes>
                    <exclude>demo.html</exclude>
                  </excludes>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- Skip jsHint because we use ESLint through the frontend-maven-plugin -->
      <plugin>
        <groupId>org.xwiki.contrib</groupId>
        <artifactId>jshint-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>default-lint</id>
            <phase>none</phase>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <version>1.11.0</version>
        <executions>
          <execution>
            <id>install-node-and-npm</id>
            <goals>
              <goal>install-node-and-npm</goal>
            </goals>
            <configuration>
              <nodeVersion>v10.23.3</nodeVersion>
            </configuration>
          </execution>
          <execution>
            <id>npm-install</id>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>ci</arguments>
            </configuration>
          </execution>
          <execution>
            <id>npm-run-build</id>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run build</arguments>
            </configuration>
          </execution>
          <execution>
            <id>npm-run-test</id>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run test</arguments>
            </configuration>
            <phase>test</phase>
          </execution>
        </executions>
        <configuration>
          <workingDirectory>${project.build.directory}/vue</workingDirectory>
        </configuration>
      </plugin>
      <plugin>
        <groupId>com.github.blutorange</groupId>
        <artifactId>closure-compiler-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>default-minify-1</id>
            <configuration>
              <!-- Change the name of the aggregated JavaScript file. -->
              <outputFilename>xwiki-livedata.min.js</outputFilename>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.github.searls</groupId>
        <artifactId>jasmine-maven-plugin</artifactId>
        <!-- We want a more recent version of Jasmine because we want to use the (headless) Chrome driver. -->
        <version>3.0-alpha-01</version>
        <!-- Skip the execution of the Jasmine tests at this point. We run the tests in the integration-tests profile. -->
        <executions>
          <execution>
            <id>default-test</id>
            <phase>none</phase>
          </execution>
        </executions>
        <configuration>
          <jsSrcDir>${project.basedir}/src/main/webjar</jsSrcDir>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <!-- We don't use 'integration-tests' because:
        * We cannot run the tests on CI yet (Chrome is not installed) and we're waiting for this issue
          https://github.com/searls/jasmine-maven-plugin/issues/349 to use docker.
        * We don't have any JavaScript tests ATM anyway -->
      <id>integration-tests-chrome</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>1.0.0</version>
            <executions>
              <execution>
                <goals>
                  <goal>set-system-properties</goal>
                </goals>
                <configuration>
                  <properties>
                    <property>
                      <!-- Force a slightly older version of the Chrome Driver in case we don't have the latest Chrome
                        installed locally. -->
                      <name>wdm.chromeDriverVersion</name>
                      <value>85.0.4183.87</value>
                    </property>
                    <property>
                      <!-- Try to work around error: "[SEVERE]: bind() failed: Cannot assign requested address (99)" -->
                      <name>webdriver.chrome.whitelistedIps</name>
                      <value />
                    </property>
                  </properties>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>com.github.searls</groupId>
            <artifactId>jasmine-maven-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>test</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
