<?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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>app.getxray</groupId>
  <artifactId>xray-maven-plugin</artifactId>
  <version>0.8.0</version>
  <packaging>maven-plugin</packaging>
  <name>xray-maven-plugin</name>
  <description>Maven plugin for interacting with Xray (server/datacenter and cloud), used in CI/CD for assisting in test automation flows, such as reporting test results back to Xray and, by consequence, Jira.</description>
  <url>https://github.com/Xray-App/xray-maven-plugin</url>

  <licenses>
    <license>
      <name>BSD 3-Clause</name>
      <url>https://raw.githubusercontent.com/Xray-App/xray-maven-plugin/main/LICENSE</url>
      <distribution>repo</distribution>
    </license>
  </licenses>

  <organization>
    <name>Xblend</name>
    <url>https://www.getxray.app</url>
  </organization>

  <developers>
    <developer>
      <name>Sergio Freire</name>
      <email>sergio.freire@getxray.app</email>
      <organization>Xblend</organization>
      <organizationUrl>https://www.getxray.app</organizationUrl>
    </developer>
    <developer>
      <name>Cristiano Cunha</name>
      <email>cristiano.cunha@getxray.app</email>
      <organization>Xblend</organization>
      <organizationUrl>https://www.getxray.app</organizationUrl>
    </developer>
  </developers>

  <scm>
    <connection>scm:git:git://github.com/Xray-App/xray-maven-plugin.git</connection>
    <developerConnection>scm:git:ssh://github.com/Xray-App/xray-maven-plugin.git</developerConnection>
    <url>https://github.com/Xray-App/xray-maven-plugin/tree/main</url>
  </scm>

  <properties>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven-plugin-api.version>3.8.5</maven-plugin-api.version>
    <maven-plugin-annotations.version>3.6.4</maven-plugin-annotations.version>
    <maven-project.version>2.2.1</maven-project.version>
    <maven-plugin-plugin.version>3.6.4</maven-plugin-plugin.version>
    <maven-site-plugin.version>3.12.0</maven-site-plugin.version>
    <maven-failsafe-plugin.version>3.2.5</maven-failsafe-plugin.version>
    <maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
    <maven-gpg-plugin.version>3.0.1</maven-gpg-plugin.version>
    <mockito.version>4.11.0</mockito.version>
    <nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <itf.version>0.13.1</itf.version>
    <junit.version>5.10.2</junit.version>
    <junit-platform.version>1.10.2</junit-platform.version>
    <jacoco.version>0.8.11</jacoco.version>
    <internal.xray-maven-plugin.version>0.7.6</internal.xray-maven-plugin.version>
    <unit.coverage.file>${project.build.directory}/jacoco-output/jacoco-unit-tests.exec</unit.coverage.file>
    <it.coverage.file>${project.build.directory}/jacoco-output/jacoco-it-tests.exec</it.coverage.file>
    <merged.coverage.file>${project.build.directory}/jacoco-output/merged.exec</merged.coverage.file>
    <jacoco.maven.opts>-javaagent:${settings.localRepository}/org/jacoco/org.jacoco.agent/${jacoco.version}/org.jacoco.agent-${jacoco.version}-runtime.jar=destfile=${it.coverage.file},append=true</jacoco.maven.opts>
  </properties>

  <dependencyManagement>
    <dependencies>
            <dependency>
                    <groupId>org.junit</groupId>
                    <artifactId>junit-bom</artifactId>
                    <version>${junit.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
            </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>${maven-plugin-api.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.maven.plugin-tools</groupId>
      <artifactId>maven-plugin-annotations</artifactId>
      <version>${maven-plugin-annotations.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-project</artifactId>
      <version>${maven-project.version}</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>com.squareup.okhttp3</groupId>
      <artifactId>okhttp</artifactId>
      <version>4.9.3</version>
    </dependency>

    <dependency>
      <groupId>org.json</groupId>
      <artifactId>json</artifactId>
      <version>20231013</version>
    </dependency>

    <dependency>
      <groupId>org.codehaus.plexus</groupId>
      <artifactId>plexus-utils</artifactId>
      <version>3.4.1</version>
    </dependency>

    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <version>${mockito.version}</version>
      <scope>test</scope>
    </dependency>

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

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

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

    <dependency>
      <groupId>com.soebes.itf.jupiter.extension</groupId>
      <artifactId>itf-assertj</artifactId>
      <version>${itf.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.soebes.itf.jupiter.extension</groupId>
      <artifactId>itf-jupiter-extension</artifactId>
      <version>${itf.version}</version>
      <scope>test</scope>
    </dependency>
  
    <dependency>
      <groupId>org.apache.maven.plugin-testing</groupId>
      <artifactId>maven-plugin-testing-harness</artifactId>
      <version>3.3.0</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>app.getxray</groupId>
      <artifactId>xray-junit-extensions</artifactId>
      <version>0.7.2</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>app.getxray</groupId>
      <artifactId>xray-maven-plugin</artifactId>
      <version>${internal.xray-maven-plugin.version}</version>
      <scope>test</scope>
    </dependency>

  </dependencies>

  <distributionManagement>
    <snapshotRepository>
      <id>ossrh</id>
      <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
    </snapshotRepository>
    <repository>
      <id>ossrh</id>
      <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
    </repository>
  </distributionManagement>

  <build>
    <plugins>

      <plugin>
        <groupId>org.sonatype.plugins</groupId>
        <artifactId>nexus-staging-maven-plugin</artifactId>
        <version>${nexus-staging-maven-plugin.version}</version>
        <extensions>true</extensions>
        <configuration>
          <serverId>ossrh</serverId>
          <nexusUrl>https://s01.oss.sonatype.org</nexusUrl>
          <autoReleaseAfterClose>true</autoReleaseAfterClose>
        </configuration>
      </plugin>

        <!-- Jacoco runner to inspect code coverage -->
        <plugin>
          <groupId>org.jacoco</groupId>
          <artifactId>jacoco-maven-plugin</artifactId>
          <version>${jacoco.version}</version>

          <executions>
            <execution>
              <id>before-unit-test-execution</id>
              <goals>
                <goal>prepare-agent</goal>
              </goals>
              <configuration>
                <destFile>${unit.coverage.file}</destFile>
                <propertyName>surefire.jacoco.args</propertyName>
              </configuration>
            </execution>
            <execution>
              <id>after-unit-test-execution</id>
              <phase>test</phase>
              <goals>
                <goal>report</goal>
              </goals>
              <configuration>
                <dataFile>${unit.coverage.file}</dataFile>
                <outputDirectory>${project.reporting.outputDirectory}/jacoco-unit-test-coverage-report</outputDirectory>
              </configuration>
            </execution>

            <execution>
              <id>before-integration-test-execution</id>
              <phase>pre-integration-test</phase>
              <goals>
                <goal>prepare-agent-integration</goal>
              </goals>
              <configuration>
                <destFile>${it.coverage.file}</destFile>
                <propertyName>failsafe.jacoco.args</propertyName>
                <classDumpDir>${project.build.directory}/jacoco-dump</classDumpDir>
                <append>true</append>
              </configuration>
            </execution>
            <execution>
              <id>after-integration-test-execution</id>
              <phase>post-integration-test</phase>
              <goals>
                <goal>report</goal>
              </goals>
              <configuration>
                <dataFile>${it.coverage.file}</dataFile>
                <outputDirectory>${project.reporting.outputDirectory}/jacoco-it-coverage-report</outputDirectory>
              </configuration>
            </execution>

            <execution>
              <id>merge-unit-and-integration</id>
                <phase>post-integration-test</phase>
                  <goals>
                    <goal>merge</goal>
                  </goals>
                  <configuration>
                  <fileSets>
                    <fileSet>
                      <directory>${project.build.directory}/jacoco-output/</directory>
                      <includes>
                        <include>*.exec</include>
                      </includes>
                    </fileSet>
                  </fileSets>
                  <destFile>merged.coverage.file</destFile>
                </configuration>
              </execution>
              <execution>
                <id>create-merged-report</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>report</goal>
                </goals>
                <configuration>
                  <dataFile>merged.coverage.file</dataFile>
                  <outputDirectory>${project.reporting.outputDirectory}/jacoco-merged-test-coverage-report</outputDirectory>
                </configuration>
              </execution>

          </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven-surefire-plugin.version}</version>
        <configuration>
          <argLine>${surefire.jacoco.args}</argLine>
          <includes>
            <include>**/*Test.java</include>
          </includes>
          <excludes>
            <exclude>**/*IT.java</exclude>
          </excludes>

          <testFailureIgnore>false</testFailureIgnore>
          <disableXmlReport>true</disableXmlReport>
          <useFile>false</useFile>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-gpg-plugin</artifactId>
        <version>${maven-gpg-plugin.version}</version>
        <executions>
          <execution>
            <id>sign-artifacts</id>
            <phase>verify</phase>
            <goals>
              <goal>sign</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-plugin-plugin</artifactId>
        <version>${maven-plugin-plugin.version}</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <version>${maven-site-plugin.version}</version>
      </plugin>

      <plugin>
        <groupId>com.soebes.itf.jupiter.extension</groupId>
        <artifactId>itf-maven-plugin</artifactId>
        <version>${itf.version}</version>
        <executions>
          <execution>
            <id>installing</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>install</goal>
              <goal>resources-its</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>${maven-failsafe-plugin.version}</version>
        <configuration>
          <!--
            check if the following ones are actually needed or not to run the integration tests
            -->
          <systemProperties>
            <maven.version>${maven.version}</maven.version>
            <maven.home>${maven.home}</maven.home>
          </systemProperties>

          <argLine>${failsafe.jacoco.args}</argLine>
          <includes>
            <include>**/*IT.java</include>
          </includes>
          <excludes>
            <exclude>**/*Test.java</exclude>
          </excludes>

          <!-- based on https://github.com/khmarbaise/maven-it-extension/discussions/328 , to be able to track coverage of IT tests -->
          <environmentVariables>
            <MAVEN_OPTS>${jacoco.maven.opts}</MAVEN_OPTS>
          </environmentVariables>

          <properties>
            <configurationParameters>
              <!--
                these are the default values, but we want to make sure that they are not changed by the user
                https://maven.apache.org/surefire/maven-failsafe-plugin/examples/junit-platform.html
                -->
              junit.jupiter.execution.parallel.enabled = false
              junit.jupiter.execution.parallel.mode.default = same_thread
              junit.jupiter.execution.parallel.mode.classes.default = same_thread
            </configurationParameters>
        </properties>

        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>app.getxray</groupId>
        <artifactId>xray-maven-plugin</artifactId>
        <version>${internal.xray-maven-plugin.version}</version>
        <configuration>
          <cloud>true</cloud>
          <projectKey>XMP</projectKey>
          <version>${project.version}</version>
          <reportFormat>junit</reportFormat>
          <reportFile>reports/custom*.xml</reportFile>
        </configuration>
      </plugin>

    </plugins>

    <testResources>
      <testResource>
        <directory>src/test/resources</directory>
      </testResource>
      <testResource>
        <directory>src/test/resources-its</directory>
      </testResource>
    </testResources>
  </build>

  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-plugin-plugin</artifactId>
        <reportSets>
          <reportSet>
            <reports>
              <report>report</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>


</project>
