<?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-core</artifactId>
    <version>7.4.6-struts2-1</version>
  </parent>
  <artifactId>xwiki-platform-web</artifactId>
  <name>XWiki Platform - Web Resources</name>
  <packaging>war</packaging>
  <description>Web Resources for the XWiki platform</description>
  <properties>
    <!-- Don't run CLIRR on this module since there's no Java code. -->
    <xwiki.clirr.skip>true</xwiki.clirr.skip>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.xwiki.platform</groupId>
      <artifactId>xwiki-platform-tree-war</artifactId>
      <version>${project.version}</version>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.xwiki.platform</groupId>
      <artifactId>xwiki-platform-index-tree-war</artifactId>
      <version>${project.version}</version>
      <type>war</type>
    </dependency>
    <!-- Test dependencies -->
    <dependency>
      <groupId>org.webjars</groupId>
      <artifactId>requirejs</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.webjars</groupId>
      <artifactId>jquery</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <!-- Javascript and CSS files compression -->
      <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>yuicompressor-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>compress</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <!-- Don't output in the default webapp location, since the war plugin will overwrite the files in there
               with the original, uncompressed ones. -->
          <webappDirectory>${project.build.directory}/minimized</webappDirectory>
          <!-- We don't need the suffix (.min) because the minified files are put in a separate folder. -->
          <nosuffix>true</nosuffix>
          <excludes>
            <!-- Exclude already minified files -->
            <exclude>**/*-min.js</exclude>
            <exclude>**/*-debug.js</exclude>
            <exclude>**/langs/*.js</exclude>
            <!-- Exclude files with complex Velocity code inside -->
            <!-- This one iterates over xobjects of type XWiki.SearchSuggestSourceClass -->
            <exclude>**/searchSuggest.js</exclude>
          </excludes>
          <aggregations>
            <!-- Aggregate the JavaScript code that is loaded on every page. -->
            <aggregation>
              <insertNewLine>true</insertNewLine>
              <inputDir>${project.build.directory}/minimized</inputDir>
              <output>${project.build.directory}/minimized/resources/js/xwiki/xwiki-min.js</output>
              <includes>
                <!-- entityReference.js is added first because it is used by xwiki.js -->
                <include>**/entityReference.js</include>
                <include>**/xwiki.js</include>
                <include>**/modalPopup.js</include>
                <include>**/jumpToPage.js</include>
                <include>**/confirmationBox.js</include>
                <include>**/confirmedAjaxRequest.js</include>
                <include>**/notification.js</include>
                <include>**/xlist.js</include>
                <include>**/suggest.js</include>
              </includes>
            </aggregation>
            <!-- Aggregate the CSS code that is loaded on every page. -->
            <aggregation>
              <insertNewLine>true</insertNewLine>
              <inputDir>${project.build.directory}/minimized</inputDir>
              <output>${project.build.directory}/minimized/resources/css/xwiki-min.css</output>
              <includes>
                <include>**/modalPopup.css</include>
                <include>**/jumpToPage.css</include>
                <include>**/confirmationBox.css</include>
                <include>**/notification.css</include>
                <include>**/suggest.css</include>
              </includes>
            </aggregation>
          </aggregations>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <webResources>
            <!-- Include License resources -->
            <resource>
              <directory>${project.build.directory}/maven-shared-archive-resources/META-INF</directory>
              <targetPath>META-INF</targetPath>
            </resource>
            <!-- Include version.properties file -->
            <resource>
              <directory>${basedir}/src/main/webInfResources</directory>
              <targetPath>WEB-INF</targetPath>
              <filtering>true</filtering>
            </resource>
            <!-- Add minified resources -->
            <resource>
              <directory>${project.build.directory}/minimized</directory>
              <targetPath>/</targetPath>
              <filtering>false</filtering>
            </resource>
          </webResources>
          <!-- Exclude the LICENSE/NOTICE files from the classes/ directory since we're including them in META-INF/ at
               the root of the WAR -->
          <packagingExcludes>WEB-INF/classes/META-INF/**</packagingExcludes>
        </configuration>
      </plugin>
      <plugin>
        <groupId>com.github.searls</groupId>
        <artifactId>jasmine-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>non-amd</id>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <sourceIncludes>
                <include>js/prototype/prototype.js</include>
                <include>uicomponents/widgets/list/xlist.js</include>
                <include>uicomponents/suggest/suggest.js</include>
                <include>uicomponents/model/entityReference.js</include>
              </sourceIncludes>
              <specIncludes>
                <include>non-amd/**/*.js</include>
              </specIncludes>
            </configuration>
          </execution>
          <execution>
            <!-- Tests for JavaScript code that follows the Asynchronous Module Definition pattern -->
            <id>amd</id>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <specRunnerTemplate>REQUIRE_JS</specRunnerTemplate>
              <customRunnerConfiguration>
                ${project.basedir}/src/test/resources/jasmine-require-config.txt
              </customRunnerConfiguration>
              <preloadSources>
                <source>webjars/require.js</source>
              </preloadSources>
              <specIncludes>
                <include>amd/**/*.js</include>
              </specIncludes>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <jsSrcDir>${project.basedir}/src/main/webapp/resources</jsSrcDir>
          <timeout>10</timeout>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <!-- This debug profile should be used to avoid JS/CSS compression. This is useful when debugging XWiki for
           example since we can put breakpoints in our browsers on the JS. -->
      <id>debug</id>
      <properties>
        <xwiki.minification.skip>true</xwiki.minification.skip>
      </properties>
      <build>
        <plugins>
          <plugin>
            <!-- Make sure the minimized dir exists, since it is expected by the war plugin and will not be created
                 in this profile -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <phase>prepare-package</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <tasks>
                    <mkdir dir="${project.build.directory}/minimized" />
                  </tasks>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
