<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright (C) 2006-2022 Talend Inc. - www.talend.com
   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.talend.sdk.component</groupId>
    <artifactId>component-runtime</artifactId>
    <version>1.38.15</version>
  </parent>

  <artifactId>component-tools-webapp</artifactId>

  <name>Component Runtime :: Tools WebApp</name>
  <description>Light web application allowing to provide a light HTTP server to test components locally.</description>

  <properties>
    <npm.environment>production</npm.environment>
    <talend.build.name>${talend.build.name.base}.tools.webapp</talend.build.name>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.talend.sdk.component</groupId>
      <artifactId>component-server</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.talend.sdk.component</groupId>
      <artifactId>component-form-core</artifactId>
      <version>${project.version}</version>
      <exclusions>
        <exclusion>
          <groupId>org.talend.sdk.component</groupId>
          <artifactId>component-server</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.apache.openwebbeans</groupId>
      <artifactId>openwebbeans-se</artifactId>
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-clean-plugin</artifactId>
        <version>${clean-plugin.version}</version>
        <executions>
          <execution>
            <id>clean-frontend</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
            <configuration>
              <directory>${project.basedir}/src/main/frontend/dist</directory>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.meecrowave</groupId>
        <artifactId>meecrowave-maven-plugin</artifactId>
        <version>${meecrowave.version}</version>
        <configuration>
          <httpPort>10101</httpPort>
          <webapp>${project.basedir}/src/main/frontend/dist</webapp>
          <webResourceCached>false</webResourceCached>
          <systemProperties>
            <talend.component.server.documentation.active>true</talend.component.server.documentation.active>
            <talend.component.server.tomcat.valve.error.debug>true</talend.component.server.tomcat.valve.error.debug>
            <talend.component.server.component.coordinates>${talend.component.server.component.coordinates.samples}</talend.component.server.component.coordinates>
          </systemProperties>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.apache.johnzon</groupId>
            <artifactId>johnzon-jsonb</artifactId>
            <version>${johnzon.version}</version>
          </dependency>
          <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>${log4j2.version}</version>
          </dependency>
          <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-web</artifactId>
            <version>${log4j2.version}</version>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <version>${frontend.version}</version>
        <executions>
          <execution>
            <id>install-node-and-npm</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>install-node-and-npm</goal>
            </goals>
            <configuration>
              <nodeVersion>${node.version}</nodeVersion>
              <npmVersion>${npm.version}</npmVersion>
            </configuration>
          </execution>
          <execution>
            <id>npm-install</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>install</arguments>
            </configuration>
          </execution>
          <execution>
            <id>npm-build</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <skip>${component.front.build.skip}</skip>
              <arguments>run build</arguments>
              <environmentVariables>
                <NODE_ENV>${npm.environment}</NODE_ENV>
                <ICON_BUNDLE>true</ICON_BUNDLE>
              </environmentVariables>
            </configuration>
          </execution>
          <execution>
            <id>watch</id>
            <phase />
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run watch</arguments>
              <environmentVariables>
                <NODE_ENV>development</NODE_ENV>
                <ICON_BUNDLE>true</ICON_BUNDLE>
              </environmentVariables>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <installDirectory>${project.basedir}/.node</installDirectory>
          <workingDirectory>${project.basedir}/src/main/frontend</workingDirectory>
          <environmentVariables>
            <NODE_ENV>development</NODE_ENV>
          </environmentVariables>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>${build-helper-maven-plugin.version}</version>
        <executions>
          <execution>
            <id>add-resource</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>add-resource</goal>
            </goals>
            <configuration>
              <resources>
                <resource>
                  <directory>src/main/frontend/dist</directory>
                  <targetPath>META-INF/resources</targetPath>
                  <excludes>
                    <exclude>**/*.map</exclude>
                  </excludes>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile> <!-- esier debugging from the IDE -->
      <id>add-beam</id>
      <dependencies>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>component-runtime-beam</artifactId>
          <version>${project.version}</version>
          <scope>provided</scope>
        </dependency>
      </dependencies>
    </profile>
  </profiles>
</project>
