<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2019 Red Hat, Inc. and/or its affiliates.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

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

  <groupId>org.optaweb.vehiclerouting</groupId>
  <artifactId>optaweb-vehicle-routing</artifactId>
  <packaging>pom</packaging>

  <name>OptaWeb Vehicle Routing</name>

  <!-- Modules are sorted in preferred build order. -->
  <modules>
    <module>optaweb-vehicle-routing-backend</module>
    <module>optaweb-vehicle-routing-frontend</module>
    <module>optaweb-vehicle-routing-standalone</module>
    <module>optaweb-vehicle-routing-docs</module>
    <module>optaweb-vehicle-routing-distribution</module>
  </modules>

  <properties>
    <format.directory>${project.basedir}/../ide-configuration</format.directory>
    <formatter.skip>false</formatter.skip>
    <formatter.goal>format</formatter.goal>
    <impsort.goal>sort</impsort.goal>
    <!-- Define JaCoCo agent argLine property to avoid Surefire failure when JaCoCo is not enabled. -->
    <jacoco.agent.argLine/>
    <version.com.h2database>1.4.199</version.com.h2database>
    <version.org.mockito>3.1.0</version.org.mockito>
  </properties>

  <dependencyManagement>
    <dependencies>
      <!-- Internal dependencies -->
      <dependency>
        <groupId>org.optaweb.vehiclerouting</groupId>
        <artifactId>optaweb-vehicle-routing-backend</artifactId>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>org.optaweb.vehiclerouting</groupId>
        <artifactId>optaweb-vehicle-routing-docs</artifactId>
        <version>${project.version}</version>
        <type>zip</type>
      </dependency>
      <dependency>
        <groupId>org.optaweb.vehiclerouting</groupId>
        <artifactId>optaweb-vehicle-routing-frontend</artifactId>
        <version>${project.version}</version>
        <type>war</type>
      </dependency>
      <!-- BOM imports -->
      <dependency>
        <groupId>org.optaweb.vehiclerouting</groupId>
        <artifactId>optaweb-vehicle-routing-standalone</artifactId>
        <version>${project.version}</version>
      </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>
      <dependency>
        <groupId>org.optaplanner</groupId>
        <artifactId>optaplanner-bom</artifactId>
        <version>${version.org.optaplanner}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <!-- Dependencies not managed by kie-parent and version overrides -->
      <dependency>
        <groupId>com.graphhopper</groupId>
        <artifactId>graphhopper-reader-osm</artifactId>
        <version>0.13.0-pre13</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>org.jacoco</groupId>
          <artifactId>jacoco-maven-plugin</artifactId>
          <executions>
            <execution>
              <id>jacoco-prepare-agent</id>
              <goals>
                <goal>prepare-agent</goal>
              </goals>
              <configuration>
                <propertyName>jacoco.agent.argLine</propertyName>
              </configuration>
            </execution>
            <execution>
              <id>jacoco-generate-report</id>
              <goals>
                <goal>report</goal>
              </goals>
            </execution>
          </executions>
        </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>
    <!-- Skip Sonar plugin execution if SONARCLOUD_TOKEN is not set. -->
    <profile>
      <id>skipSonar</id>
      <activation>
        <property>
          <name>!env.SONARCLOUD_TOKEN</name>
        </property>
      </activation>
      <properties>
        <sonar.skip>true</sonar.skip>
      </properties>
    </profile>
    <profile>
      <id>pullRequestAnalysis-Travis</id>
      <!--
        Only set sonar.pullrequest properties when the Travis build is triggered by a PR.
        When the build is triggered by push to a branch or by cron, the consumed env.TRAVIS properties are empty,
        resulting in invalid sonar.pullrequest properties and the Sonar plugin would fail.
      -->
      <activation>
        <property>
          <name>env.TRAVIS_EVENT_TYPE</name>
          <value>pull_request</value>
        </property>
      </activation>
      <!--
        See https://docs.travis-ci.com/user/environment-variables/ for list of Travis environment variables.
        See https://docs.sonarqube.org/latest/analysis/pull-request/ for properties required by Sonar for PR analysis.
      -->
      <properties>
        <!--suppress UnresolvedMavenProperty -->
        <sonar.pullrequest.branch>${env.TRAVIS_PULL_REQUEST_BRANCH}</sonar.pullrequest.branch>
        <!--suppress UnresolvedMavenProperty -->
        <sonar.pullrequest.key>${env.TRAVIS_PULL_REQUEST}</sonar.pullrequest.key>
        <!--suppress UnresolvedMavenProperty -->
        <sonar.pullrequest.base>${env.TRAVIS_BRANCH}</sonar.pullrequest.base>
      </properties>
    </profile>
    <profile>
      <id>branchAnalysis-Travis</id>
      <activation>
        <property>
          <name>env.TRAVIS_EVENT_TYPE</name>
          <value>!pull_request</value>
        </property>
      </activation>
      <!--
        See https://docs.travis-ci.com/user/environment-variables/ for list of Travis environment variables.
        See https://docs.sonarqube.org/latest/branches/overview/ for properties required by Sonar for branch analysis.
      -->
      <properties>
        <!--suppress UnresolvedMavenProperty -->
        <sonar.branch.name>${env.TRAVIS_BRANCH}</sonar.branch.name>
      </properties>
    </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>

  <repositories>
    <!-- Bootstrap repository to locate the parent POM when it has not been built 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>
</project>
