<?xml version="1.0" encoding="UTF-8"?>
<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.eclipse.pass</groupId>
    <artifactId>pass-journal-loader</artifactId>
    <version>1.2.0</version>
  </parent>

  <artifactId>pass-journal-loader-nih</artifactId>

  <!-- Properties for ITs -->
  <properties>
    <pass.core.port>8080</pass.core.port>
    <pass.core.url>http://localhost:8080</pass.core.url>
    <pass.core.user>backend</pass.core.user>
    <pass.core.password>backend</pass.core.password>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.eclipse.pass</groupId>
      <artifactId>pass-data-client</artifactId>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-csv</artifactId>
    </dependency>

    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <scope>compile</scope>
    </dependency>

    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-junit-jupiter</artifactId>
    </dependency>

    <dependency>
      <groupId>com.github.tomakehurst</groupId>
      <artifactId>wiremock-jre8</artifactId>
      <version>2.35.0</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <shadedArtifactAttached>true</shadedArtifactAttached>
              <shadedClassifierName>exe</shadedClassifierName>
              <finalName>pass-journal-loader-nih-exec</finalName>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>org.eclipse.pass.loader.journal.nih.Main</mainClass>
                </transformer>
              </transformers>
              <filters>
                <filter>
                  <artifact>*:*</artifact>
                  <excludes>
                    <exclude>META-INF/*.SF</exclude>
                    <exclude>META-INF/*.DSA</exclude>
                    <exclude>META-INF/*.RSA</exclude>
                  </excludes>
                </filter>
              </filters>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>start</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>start</goal>
            </goals>
          </execution>
          <execution>
            <id>stop</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>stop</goal>
            </goals>
          </execution>
          <execution>
            <id>build-after-its</id>
            <phase>post-integration-test</phase>
            <configuration>
              <images>
                <image>
                  <name>ghcr.io/eclipse-pass/pass-journal-loader:%v</name>
                </image>
              </images>
            </configuration>
            <goals>
              <goal>build</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <images>
            <image>
              <name>ghcr.io/eclipse-pass/pass-core-main:%v</name>
              <run>
		<env>
                  <PASS_CORE_BASE_URL>${pass.core.url}</PASS_CORE_BASE_URL>
                  <PASS_CORE_BACKEND_USER>${pass.core.user}</PASS_CORE_BACKEND_USER>
                  <PASS_CORE_BACKEND_PASSWORD>${pass.core.password}</PASS_CORE_BACKEND_PASSWORD>
		</env>
                <wait>
                  <http>
                    <url>
                      ${pass.core.url}/data/grant
                    </url>
		    <status>401</status>
                  </http>
                  <time>60000</time>
                </wait>
                <ports>
                  <port>${pass.core.port}:${pass.core.port}</port>
                </ports>
              </run>
            </image>
          </images>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
	      <configuration>
          <systemPropertyVariables>
            <pass.core.url>${pass.core.url}</pass.core.url>
            <pass.core.user>${pass.core.user}</pass.core.user>
            <pass.core.password>${pass.core.password}</pass.core.password>
            <nih.loader.jar>${org.eclipse.pass:pass-journal-loader-nih:jar:exe}</nih.loader.jar>            
          </systemPropertyVariables>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
