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

    Copyright (C) 2020 Dremio

    Licensed 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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.projectnessie</groupId>
    <artifactId>nessie</artifactId>
    <version>0.9.2</version>
  </parent>

  <artifactId>nessie-ui</artifactId>

  <name>Nessie - UI</name>

  <build>
    <resources>
      <!-- Generated by react-scripts -->
      <resource>
        <!-- Standard resources path per Servlet spec -->
        <targetPath>META-INF/resources</targetPath>
        <directory>build</directory>
        <filtering>false</filtering>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-clean-plugin</artifactId>
        <configuration>
          <filesets>
            <fileset>
              <directory>build</directory>
              <followSymlinks>false</followSymlinks>
            </fileset>
            <fileset>
              <directory>node_modules</directory>
              <followSymlinks>false</followSymlinks>
            </fileset>
          </filesets>
        </configuration>
      </plugin>
      <plugin>
        <groupId>com.mycila</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <configuration>
          <includes combine.children="append">
            <include>**</include>
          </includes>
          <excludes combine.children="append">
            <exclude>target/**</exclude> <!-- todo: ${project.build.directory} not working, unsure why -->
            <exclude>build/**</exclude>
            <exclude>src/generated/**</exclude>
            <exclude>coverage/**</exclude>
            <exclude>.nyc_output/**</exclude>
            <exclude>**/*.pattern</exclude>
            <exclude>src/utils/api/**</exclude>
          </excludes>
          <mapping>
            <!-- full file names -->
            <browserslistrc>SCRIPT_STYLE</browserslistrc>
          </mapping>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <phase>generate-resources</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.projectnessie</groupId>
                  <artifactId>nessie-model</artifactId>
                  <version>${project.version}</version>
                  <outputDirectory>${project.build.directory}/openapi</outputDirectory>
                  <includes>META-INF/openapi/**</includes>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <configuration>
          <environmentVariables>
            <CI>true</CI>
          </environmentVariables>
        </configuration>
        <executions>
          <execution>
            <id>install node and npm</id>
            <goals>
              <goal>install-node-and-npm</goal>
            </goals>
            <phase>generate-resources</phase>
          </execution>
          <execution>
            <id>npm install</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>install</arguments>
            </configuration>
          </execution>
          <execution>
            <id>generate OpenAPI client code</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run generate-api</arguments>
            </configuration>
          </execution>
          <execution>
            <id>Fix Generated OpenAPI client code</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run fix-generated-client</arguments>
            </configuration>
          </execution>
          <execution>
            <id>build minimized webpack bundle</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run build</arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
