<?xml version="1.0"?>
<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.openecomp.sdc</groupId>
    <artifactId>sdc-main</artifactId>
    <version>1.7.0-SNAPSHOT</version>
  </parent>
  <artifactId>cucumber-bdd</artifactId>
  <name>cucumber-bdd</name>
  <version>1.7.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>2.6.1</version>
        <executions>
          <execution>
            <id>clean.dist.folder</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
            <configuration>
              <filesets>
                <fileset>
                  <directory>${basedir}/node_modules</directory>
                  <includes>
                    <include>**/*</include>
                  </includes>
                </fileset>
                <fileset>
                  <directory>${basedir}/report</directory>
                  <includes>
                    <include>**/*</include>
                  </includes>
                </fileset>
                <fileset>
                  <directory>${basedir}/resources/downloads</directory>
                  <includes>
                    <include>**/*</include>
                  </includes>
                </fileset>
                <fileset>
                  <directory>${basedir}/docs</directory>
                  <includes>
                    <include>**/*</include>
                  </includes>
                </fileset>
                <fileset>
                  <directory>${basedir}</directory>
                  <includes>
                    <include>jenkinsConfig.json</include>
                  </includes>
                </fileset>
              </filesets>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.7</version>
        <configuration>
        </configuration>
      </plugin>
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>

        <configuration>
          <installDirectory>${project.parent.parent.basedir}</installDirectory>
        </configuration>

        <executions>
          <execution>
            <id>install node and npm</id>
            <goals>
              <goal>install-node-and-npm</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
              <nodeVersion>v10.17.0</nodeVersion>
              <npmVersion>6.11.3</npmVersion>
            </configuration>
          </execution>
          <execution>
            <id>npm run install</id>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>install</arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
    <resources>
      <resource>
        <directory>${basedir}/docker</directory>
        <targetPath>${project.build.directory}/docker_assembly</targetPath>
        <filtering>false</filtering>
      </resource>
    </resources>
  </build>
  <profiles>
    <profile>
      <id>dev</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>create-reporting-folders</id>
                <phase>initialize</phase>
                <configuration>
                  <tasks>
                    <echo message="Generate reports and downloads folders"/>
                    <mkdir dir="${basedir}/report"/>
                    <mkdir dir="${basedir}/resources/downloads"/>
                  </tasks>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>

            <configuration>
              <workingDirectory>${project.basedir}</workingDirectory>
              <installDirectory>${project.parent.parent.basedir}</installDirectory>
            </configuration>

            <executions>

              <execution>
                <id>npm run install</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <configuration>
                  <arguments>install</arguments>
                </configuration>
              </execution>

              <execution>
                <id>npm run cucumber test</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <configuration>
                  <npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven>
                  <arguments>run test-and-report</arguments>
                </configuration>
                <phase>test</phase>
              </execution>

              <execution>
                <id>npm run documentation</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <configuration>
                  <npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven>
                  <arguments>run cucumber-docs</arguments>
                </configuration>
                <phase>install</phase>
              </execution>

            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>docker</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.0.2</version>
            <executions>
              <execution>
                <id>copy-resources</id>
                <phase>package</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/docker_assembly/cucumber
                  </outputDirectory>
                  <resources>
                    <resource>
                      <directory>${basedir}</directory>
                      <includes>
                        <include>features/**/*</include>
                        <include>stepDefinitions/**/*</include>
                        <include>plugins/**/*</include>
                        <include>resources/**/*</include>
                        <include>node_modules/**/*</include>
                        <include>cucumber-common/**/*</include>
                        <include>*.js*</include>
                      </includes>
                      <filtering>false</filtering>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <configuration>
              <verbose>true</verbose>
              <apiVersion>1.23</apiVersion>
              <registry>nexus3.onap.org:10001</registry>
              <authConfig>
                <pull>
                  <username>docker</username>
                  <password>docker</password>
                </pull>
              </authConfig>
              <images>
                <!-- Build sanity image -->
                <image>
                  <name>onap/cucumber-sdc-api-tests</name>
                  <alias>cucumber-sdc-api-tests</alias>
                  <build>
                    <cleanup>try</cleanup>
                    <dockerFileDir>${project.build.directory}/docker_assembly</dockerFileDir>
                    <tags>
                      <tag>latest</tag>
                      <tag>
                        ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}-STAGING-latest
                      </tag>
                      <tag>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}-${maven.build.timestamp}</tag>
                    </tags>
                  </build>
                </image>
              </images>
            </configuration>
            <executions>
              <execution>
                <id>clean-images</id>
                <phase>pre-clean</phase>
                <goals>
                  <goal>remove</goal>
                </goals>
                <configuration>
                  <removeAll>true</removeAll>
                  <image>onap/cucumber-sdc-api-tests</image>
                </configuration>
              </execution>
              <execution>
                <id>generate-images</id>
                <phase>install</phase>
                <goals>
                  <goal>build</goal>
                </goals>
              </execution>
              <execution>
                <id>push-images</id>
                <phase>deploy</phase>
                <goals>
                  <goal>push</goal>
                </goals>
                <configuration>
                  <image>onap/cucumber-sdc-api-tests</image>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>