<?xml version="1.0"?>
<project
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
  xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>

  <!-- This is the Maven project object model (POM) file for VID web application
      based on the ECOMP SDK distribution. This file stands alone; it does not
      inherit from a parent maven module. -->
  <groupId>org.onap.vid</groupId>
  <artifactId>vid-webpack-master</artifactId>
  <version>5.0.2-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>VID UI</name>
  <description>VID UI</description>

  <properties>
    <encoding>UTF-8</encoding>
    <!--<springframework.version>5.1.6.RELEASE</springframework.version>-->
    <!--<hibernate.version>4.3.11.Final</hibernate.version>-->
    <!--<jackson.version>2.6.3</jackson.version>-->
    <!-- Skip assembling the zip by default -->
    <skipassembly>true</skipassembly>
    <!-- Tests usually require some setup that maven cannot do, so skip. -->
    <skiptests>false</skiptests>
    <!-- this should be commented for local debugging -->
    <!-- <deployenv>local</deployenv> -->
    <nexusproxy>https://nexus.onap.org</nexusproxy>
    <stagingNexusPath>content/repositories/staging/</stagingNexusPath>
    <snapshotNexusPath>content/repositories/snapshots/</snapshotNexusPath>
    <releaseNexusPath>content/repositories/releases/</releaseNexusPath>
    <NPM_CMD>build</NPM_CMD>
  </properties>


  <repositories>
    <repository>
      <id>onap-staging</id>
      <name>ONAP - Staging Repository</name>
      <url>${nexusproxy}/${stagingNexusPath}</url>
    </repository>
    <repository>
      <id>ecomp-releases</id>
      <name>OpenECOMP - Release Repository</name>
      <url>${nexusproxy}/${releaseNexusPath}</url>
    </repository>
    <repository>
      <id>ecomp-snapshots</id>
      <name>OpenECOMP - Snapshot Repository</name>
      <url>${nexusproxy}/${snapshotNexusPath}</url>
    </repository>
    <repository>
      <id>ecomp-public</id>
      <name>ecomp onap public Repository</name>
      <url>https://nexus.onap.org/content/groups/public</url>
    </repository>
  </repositories>

  <distributionManagement>
    <repository>
      <id>ecomp-releases</id>
      <name>VID Release Repository</name>
      <url>${nexusproxy}/${releaseNexusPath}</url>
    </repository>
    <snapshotRepository>
      <id>ecomp-snapshots</id>
      <name>VID Snapshot Repository</name>
      <url>${nexusproxy}/${snapshotNexusPath}</url>
    </snapshotRepository>

  </distributionManagement>

  <profiles>
    <profile>
      <id>if-not-webpack</id>
      <activation>
        <property>
          <name>skipModernUi</name>
          <value>true</value>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.8</version>
            <executions>
              <execution>
                <id>make-empty-dist</id>
                <phase>validate</phase>
                <configuration>
                  <target>
                    <mkdir dir="${project.basedir}/dist/"/>
                    <echo file="${project.basedir}/dist/NO-WEBPACK.txt" append="false">
                      Note: 'webpack' profile was not selected while mvn build. This 'dist' folder was created to make
                      the war creation through.
                    </echo>
                  </target>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

        </plugins>
      </build>
    </profile>
    <profile>
      <id>webpack-npm</id>
      <activation>
        <property>
          <name>skipModernUi</name>
          <value>!true</value>
        </property>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <!-- NB! Set <version> to the latest released version of frontend-maven-plugin, like in README.md -->
            <version>1.6</version>

            <executions>

              <execution>
                <id>install node and npm</id>
                <goals>
                  <goal>install-node-and-npm</goal>
                </goals>
                <configuration>
                  <!-- See https://nodejs.org/en/download/ for latest node and npm (lts) versions -->
                  <nodeVersion>v8.9.4</nodeVersion>
                  <npmVersion>5.6.0</npmVersion>
                </configuration>
              </execution>

              <execution>
                <id>npm set no-progress</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <configuration>
                  <arguments>set progress=false</arguments>
                </configuration>
              </execution>

              <execution>
                <id>npm install</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <!-- Optional configuration which provides for running any npm command -->
                <configuration>
                  <arguments>install</arguments>
                  <environmentVariables>
                    <CYPRESS_INSTALL_BINARY>0</CYPRESS_INSTALL_BINARY>
                  </environmentVariables>
                </configuration>
              </execution>

              <execution>
                <id>npm run</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <configuration>
                  <arguments>run ${NPM_CMD}</arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>cypress</id>
      <build>
        <plugins>
          <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <!-- NB! Set <version> to the latest released version of frontend-maven-plugin, like in README.md -->
            <version>1.6</version>

            <executions>

              <execution>
                <id>install node and npm</id>
                <goals>
                  <goal>install-node-and-npm</goal>
                </goals>
                <configuration>
                  <!-- See https://nodejs.org/en/download/ for latest node and npm (lts) versions -->
                  <nodeVersion>v8.9.4</nodeVersion>
                  <npmVersion>5.6.0</npmVersion>
                </configuration>
              </execution>

              <execution>
                <id>npm install cypress</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <!-- Optional configuration which provides for running any npm command -->
                <configuration>
                  <arguments>install --verbose cypress @bahmutov/add-typescript-to-cypress</arguments>
                  <environmentVariables>
                    <NO_PROXY>.att.com</NO_PROXY>
                    <http_proxy>http://one.proxy.att.com:8080</http_proxy>
                    <https_proxy>http://one.proxy.att.com:8080</https_proxy>
                  </environmentVariables>
                </configuration>
              </execution>

              <execution>
                <id>npm run cypress</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <configuration>
                  <npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven>
                  <arguments>run cypress:run -- --config baseUrl=http://${VID_HOST}:8080/vid</arguments>
                </configuration>
              </execution>

            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

  <build>
    <finalName>vid-webpack-master</finalName>
    <plugins>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>
          <webResources>
            <resource>
              <!-- this is relative to the pom.xml directory -->
              <directory>dist</directory>
              <targetPath>app/ui</targetPath>
            </resource>
          </webResources>
          <webXml>src/WEB-INF/web.xml</webXml>
        </configuration>
      </plugin>
    <plugin>
      <artifactId>maven-clean-plugin</artifactId>
      <configuration>
        <filesets>
          <fileset>
            <directory>dist</directory>
          </fileset>
        </filesets>
      </configuration>
    </plugin>
    </plugins>
  </build>
  <dependencies>
  </dependencies>
</project>