<?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>
  <parent>
    <groupId>org.kie</groupId>
    <artifactId>kie-parent</artifactId>
    <version>7.57.0.Final</version>
  </parent>

  <groupId>org.optaweb.employeerostering</groupId>
  <artifactId>optaweb-employee-rostering</artifactId>
  <packaging>pom</packaging>

  <name>OptaWeb Employee Rostering as a Service Parent</name>
  <description>
    OptaWeb Employee Rostering as a Service with OptaPlanner on OpenShift 4.
  </description>
  <url>https://www.optaplanner.org</url>
  <inceptionYear>2017</inceptionYear>

  <repositories>
    <!-- Bootstrap repository to locate the parent pom when the parent pom has not been build locally. -->
    <repository>
      <id>jboss-public-repository-group</id>
      <name>JBoss Public Repository Group</name>
      <url>https://repository.jboss.org/nexus/content/groups/public/</url>
      <layout>default</layout>
      <releases>
        <enabled>true</enabled>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>true</enabled>
        <updatePolicy>daily</updatePolicy>
      </snapshots>
    </repository>
  </repositories>

  <properties>
    <!-- Define JaCoCo agent argLine property to avoid Surefire failure when JaCoCo is not enabled. -->
    <jacoco.agent.argLine/>
    <sonar.projectKey>optaweb-employee-rostering</sonar.projectKey>
    <sonar.moduleKey>${project.artifactId}</sonar.moduleKey>
    <!--
      Do not upgrade JUnit 4 to a version that is more complex than just MAJOR.MINOR
      unless the version of JUnit 5 is at least 5.7.0. The junit-vintage-engine < 5.7.0 cannot parse complex versions.
      See https://github.com/junit-team/junit5/commit/f30c96a9cad89a62a28750c5fe4dd83ad4333e99.
    -->
    <version.junit>4.13</version.junit>
    <version.org.mockito>2.12.0</version.org.mockito>
    <format.directory>${project.basedir}/../ide-configuration</format.directory>
    <formatter.skip>false</formatter.skip>
    <formatter.goal>format</formatter.goal>
    <!-- TODO name impsort should indicate it's related to formatting -->
    <impsort.goal>sort</impsort.goal>
  </properties>

  <modules>
    <module>optaweb-employee-rostering-frontend</module>
    <module>optaweb-employee-rostering-backend</module>
    <module>optaweb-employee-rostering-benchmark</module>
    <module>optaweb-employee-rostering-docs</module>
    <module>optaweb-employee-rostering-distribution</module>
    <module>optaweb-employee-rostering-standalone</module>
  </modules>

  <dependencyManagement>
    <dependencies>
      <!-- Internal modules -->
      <dependency>
        <groupId>org.optaweb.employeerostering</groupId>
        <artifactId>optaweb-employee-rostering-frontend</artifactId>
        <type>zip</type>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>org.optaweb.employeerostering</groupId>
        <artifactId>optaweb-employee-rostering-frontend</artifactId>
        <type>pom</type>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>org.optaweb.employeerostering</groupId>
        <artifactId>optaweb-employee-rostering-backend</artifactId>
        <type>jar</type>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>org.optaweb.employeerostering</groupId>
        <artifactId>optaweb-employee-rostering-backend</artifactId>
        <classifier>exec</classifier>
        <type>jar</type>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>org.optaweb.employeerostering</groupId>
        <artifactId>optaweb-employee-rostering-docs</artifactId>
        <type>zip</type>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>org.optaweb.employeerostering</groupId>
        <artifactId>optaweb-employee-rostering-standalone</artifactId>
        <classifier>exec</classifier>
        <version>${project.version}</version>
      </dependency>

      <!-- BOMs -->
      <dependency>
        <groupId>org.optaplanner</groupId>
        <artifactId>optaplanner-bom</artifactId>
        <type>pom</type>
        <version>${version.org.kie}</version>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${version.org.springframework.boot}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>

      <!-- Drools mvel -->
      <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-mvel</artifactId>
        <version>${version.org.kie}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
          <version>${version.org.springframework.boot}</version>
        </plugin>
        <plugin>
          <groupId>net.revelc.code.formatter</groupId>
          <artifactId>formatter-maven-plugin</artifactId>
          <version>2.11.0</version>
          <configuration>
            <configFile>${format.directory}/eclipse-format.xml</configFile>
            <lineEnding>LF</lineEnding>
            <skip>${formatter.skip}</skip>
          </configuration>
          <executions>
            <execution>
              <goals>
                <goal>${formatter.goal}</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>net.revelc.code</groupId>
          <artifactId>impsort-maven-plugin</artifactId>
          <version>1.4.1</version>
          <configuration>
            <groups>java.,javax.,org.,com.</groups>
            <staticGroups>*</staticGroups>
            <!-- keep in sync with the formatter-maven-plugin -->
            <skip>${formatter.skip}</skip>
            <removeUnused>true</removeUnused>
          </configuration>
          <executions>
            <execution>
              <goals>
                <goal>${impsort.goal}</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

  <profiles>
    <profile>
      <!-- Skip Sonar plugin execution if SONARCLOUD_TOKEN is not set. -->
      <id>skipSonar</id>
      <activation>
        <property>
          <name>!env.SONARCLOUD_TOKEN</name>
        </property>
      </activation>
      <properties>
        <sonar.skip>true</sonar.skip>
      </properties>
    </profile>
    <profile>
      <!--
        TODO: For moving the coverage measurement from Travis to Jenkins, add the repository name to
        SONARCLOUD_ENABLED_REPOSITORIES in
        https://github.com/kiegroup/kie-jenkins-scripts/blob/master/job-dsls/jobs/pr_jobs.groovy
      -->
      <id>run-code-coverage</id>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <artifactId>maven-surefire-plugin</artifactId>
              <configuration>
                <!-- Append jacoco.agent.argLine property populated by JaCoCo's prepare-agent goal. -->
                <argLine>@{jacoco.agent.argLine}</argLine>
              </configuration>
            </plugin>
          </plugins>
        </pluginManagement>
        <plugins>
          <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>jacoco-prepare-agent</id>
                <goals>
                  <goal>prepare-agent</goal>
                </goals>
                <configuration>
                  <!-- Append coverage data to a single file defined in the kie-parent -->
                  <append>true</append>
                  <destFile>${jacoco.exec.file}</destFile>
                  <propertyName>jacoco.agent.argLine</propertyName>
                  <excludes>
                    <exclude>*Lexer</exclude>
                  </excludes>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <!-- Fail the build in CI if code does not follow the standards. -->
      <id>validate-formatting-ci</id>
      <activation>
        <property>
          <name>env.CI</name>
        </property>
      </activation>
      <properties>
        <formatter.goal>validate</formatter.goal>
        <impsort.goal>check</impsort.goal>
      </properties>
    </profile>
  </profiles>
</project>
