<?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>com.sap.cds</groupId>
    <artifactId>cds-feature-attachments-root</artifactId>
    <version>1.2.2</version>
  </parent>

  <artifactId>cds-feature-attachments</artifactId>
  <packaging>jar</packaging>

  <name>CDS Feature for Attachments</name>
  <url>https://cap.cloud.sap/docs/plugins/#attachments</url>

  <properties>
    <generation-package>com.sap.cds.feature.attachments.generated</generation-package>
    <test-generation-folder>src/test/gen</test-generation-folder>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.sap.cloud.sdk.cloudplatform</groupId>
      <artifactId>cloudplatform-core</artifactId>
      <exclusions>
        <exclusion>
          <groupId>com.google.guava</groupId>
          <artifactId>guava</artifactId>
        </exclusion>
        <exclusion>
          <groupId>io.vavr</groupId>
          <artifactId>vavr</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>com.sap.cds</groupId>
      <artifactId>cds-services-utils</artifactId>
      <exclusions>
        <exclusion>
          <groupId>com.sap.cds</groupId>
          <artifactId>cds-adapter-api</artifactId>
        </exclusion>
        <exclusion>
          <groupId>com.sap.cds</groupId>
          <artifactId>cds4j-core</artifactId>
        </exclusion>
        <exclusion>
          <groupId>com.sap.cloud.mt</groupId>
          <artifactId>tools</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <!-- TESTS -->
    <dependency>
      <groupId>com.sap.cds</groupId>
      <artifactId>cds-services-impl</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.github.spotbugs</groupId>
      <artifactId>spotbugs-annotations</artifactId>
      <version>4.9.8</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.awaitility</groupId>
      <artifactId>awaitility</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <!-- The deploy requires a stable artifact name -->
    <finalName>${project.artifactId}</finalName>
    <plugins>
      <plugin>
        <groupId>org.pitest</groupId>
        <artifactId>pitest-maven</artifactId>
        <configuration>
          <targetClasses>
            <param>com.sap.cds.feature.attachments.handler.*</param>
            <param>com.sap.cds.feature.attachments.service.*</param>
          </targetClasses>
          <mutators>
            <mutator>CONSTRUCTOR_CALLS</mutator>
            <mutator>VOID_METHOD_CALLS</mutator>
            <mutator>NON_VOID_METHOD_CALLS</mutator>
            <mutator>REMOVE_CONDITIONALS_ORDER_ELSE</mutator>
            <mutator>CONDITIONALS_BOUNDARY</mutator>
            <mutator>EMPTY_RETURNS</mutator>
            <mutator>NEGATE_CONDITIONALS</mutator>
            <mutator>REMOVE_CONDITIONALS_EQUAL_IF</mutator>
            <mutator>REMOVE_CONDITIONALS_EQUAL_ELSE</mutator>
            <mutator>REMOVE_CONDITIONALS_ORDER_IF</mutator>
            <mutator>REMOVE_CONDITIONALS_ORDER_ELSE</mutator>
          </mutators>
          <coverageThreshold>95</coverageThreshold>
          <aggregatedMutationThreshold>90</aggregatedMutationThreshold>
        </configuration>

        <dependencies>
          <dependency>
            <groupId>org.pitest</groupId>
            <artifactId>pitest-junit5-plugin</artifactId>
            <version>1.2.3</version>
          </dependency>
        </dependencies>
      </plugin>

      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <configuration>
          <filesets>
            <fileset>
              <directory>${test-generation-folder}</directory>
              <includes>
                <include>**/*</include>
              </includes>
              <followSymlinks>false</followSymlinks>
            </fileset>
            <fileset>
              <directory>src/test/resources</directory>
              <includes>
                <include>schema.sql</include>
              </includes>
            </fileset>
            <fileset>
              <directory>src/test/resources/cds</directory>
              <includes>
                <include>csn.json</include>
              </includes>
            </fileset>
            <fileset>
              <directory>src/test/resources/gen</directory>
              <includes>
                <include>**/*</include>
              </includes>
              <followSymlinks>false</followSymlinks>
            </fileset>
            <fileset>
              <directory>./</directory>
              <includes>
                <include>.flattened-pom.xml</include>
              </includes>
            </fileset>
          </filesets>
        </configuration>
        <executions>
          <execution>
            <id>auto-clean</id>
            <goals>
              <goal>clean</goal>
            </goals>
            <phase>clean</phase>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>com.sap.cds</groupId>
        <artifactId>cds-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>cds.clean</id>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>

          <execution>
            <id>cds.install-node</id>
            <goals>
              <goal>install-node</goal>
            </goals>
          </execution>

          <execution>
            <id>cds.build</id>
            <goals>
              <goal>cds</goal>
            </goals>
            <configuration>
              <workingDirectory>./src/main/resources/cds/com.sap.cds/cds-feature-attachments</workingDirectory>
              <commands>
                <command>build --for java --src ./ --dest ../../../../../../gen/srv</command>
              </commands>
            </configuration>
          </execution>

          <execution>
            <id>cds.generate</id>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <basePackage>${generation-package}.cds4j</basePackage>
              <csnFile>${project.basedir}/src/gen/srv/src/main/resources/edmx/csn.json</csnFile>
              <includes>
                <include>sap.attachments.**</include>
              </includes>
            </configuration>
          </execution>

          <execution>
            <id>cds.test.build</id>
            <goals>
              <goal>cds</goal>
            </goals>
            <configuration>
              <skip>${maven.test.skip}</skip>
              <workingDirectory>./src/test/resources/cds</workingDirectory>
              <commands>
                <command>build --for java --src . --dest ../../gen</command>
                <command>compile index.cds -2 sql &gt; ../schema.sql</command>
              </commands>
            </configuration>
          </execution>

          <execution>
            <id>cds.test.generate</id>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <skip>${maven.test.skip}</skip>
              <codeOutputDirectory>${project.basedir}/${test-generation-folder}/cds4j</codeOutputDirectory>
              <basePackage>${generation-package}.test.cds4j</basePackage>
              <testSources>true</testSources>
              <csnFile>${project.basedir}/src/test/resources/gen/src/main/resources/edmx/csn.json</csnFile>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <configuration>
          <excludes>
            <exclude>${excluded.generation.package}**/*</exclude>
          </excludes>
        </configuration>
        <executions>
          <execution>
            <id>jacoco-initialize</id>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
          </execution>
          <execution>
            <id>jacoco-site-report-all-tests</id>
            <goals>
              <goal>report</goal>
            </goals>
            <phase>verify</phase>
          </execution>
          <execution>
            <id>jacoco-site-report-only-unit-tests</id>
            <goals>
              <goal>report</goal>
            </goals>
            <phase>test</phase>
          </execution>
          <execution>
            <id>jacoco-check-unit-tests-only</id>
            <goals>
              <goal>check</goal>
            </goals>
            <phase>test</phase>
            <configuration>
              <rules>
                <rule implementation="org.jacoco.maven.RuleConfiguration">
                  <element>BUNDLE</element>
                  <limits>
                    <limit implementation="org.jacoco.report.check.Limit">
                      <counter>INSTRUCTION</counter>
                      <value>COVEREDRATIO</value>
                      <minimum>0.95</minimum>
                    </limit>
                    <limit implementation="org.jacoco.report.check.Limit">
                      <counter>BRANCH</counter>
                      <value>COVEREDRATIO</value>
                      <minimum>0.95</minimum>
                    </limit>
                    <limit implementation="org.jacoco.report.check.Limit">
                      <counter>COMPLEXITY</counter>
                      <value>COVEREDRATIO</value>
                      <minimum>0.95</minimum>
                    </limit>
                    <limit implementation="org.jacoco.report.check.Limit">
                      <counter>CLASS</counter>
                      <value>MISSEDCOUNT</value>
                      <maximum>0</maximum>
                    </limit>
                  </limits>
                </rule>
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-javadoc-plugin</artifactId>
        <configuration>
          <failOnError>true</failOnError>
          <doclint>all,-missing</doclint>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>jar</goal>
            </goals>
            <configuration>
              <excludePackageNames>${generation-package}.*</excludePackageNames>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-source-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>
