<?xml version="1.0" encoding="UTF-8"?>
<!--
  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. See accompanying LICENSE file.
-->
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.apache.ozone</groupId>
    <artifactId>ozone</artifactId>
    <version>2.0.0</version>
  </parent>
  <artifactId>ozone-dist</artifactId>
  <version>2.0.0</version>
  <packaging>jar</packaging>
  <name>Apache Ozone Distribution</name>
  <properties>
    <!-- suffix appended to Ozone version to get Docker image version -->
    <docker.ozone-runner.version>20241216-1-jdk21</docker.ozone-runner.version>
    <docker.ozone-testkr5b.image>ghcr.io/apache/ozone-testkrb5:20241129-1</docker.ozone-testkr5b.image>
    <docker.ozone.image>apache/ozone</docker.ozone.image>
    <docker.ozone.image.flavor>-rocky</docker.ozone.image.flavor>
    <downloadSources>true</downloadSources>
    <file.encoding>UTF-8</file.encoding>
    <!-- no tests in this module so far -->
    <maven.test.skip>true</maven.test.skip>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.apache.ozone</groupId>
      <artifactId>hdds-container-service</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ozone</groupId>
      <artifactId>hdds-docs</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ozone</groupId>
      <artifactId>hdds-rocks-native</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ozone</groupId>
      <artifactId>hdds-server-scm</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ozone</groupId>
      <artifactId>hdds-tools</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ozone</groupId>
      <artifactId>ozone-cli-shell</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ozone</groupId>
      <artifactId>ozone-common</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ozone</groupId>
      <artifactId>ozone-csi</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ozone</groupId>
      <artifactId>ozone-datanode</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ozone</groupId>
      <artifactId>ozone-httpfsgateway</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ozone</groupId>
      <artifactId>ozone-insight</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ozone</groupId>
      <artifactId>ozone-manager</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ozone</groupId>
      <artifactId>ozone-recon</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ozone</groupId>
      <artifactId>ozone-s3-secret-store</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ozone</groupId>
      <artifactId>ozone-s3gateway</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ozone</groupId>
      <artifactId>ozone-tools</artifactId>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <proc>none</proc>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>dist</id>
            <goals>
              <goal>exec</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <executable>${shell-executable}</executable>
              <workingDirectory>${project.build.directory}</workingDirectory>
              <arguments>
                <argument>${basedir}/dev-support/bin/dist-layout-stitching</argument>
                <argument>${project.build.directory}</argument>
                <argument>${hdds.version}</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-omitted-jars</id>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <outputDirectory>target/ozone-${ozone.version}/share/ozone/lib</outputDirectory>
              <includeScope>runtime</includeScope>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-compose-files</id>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <phase>compile</phase>
            <configuration>
              <outputDirectory>${basedir}/target/compose</outputDirectory>
              <resources>
                <resource>
                  <directory>src/main/compose</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
          <execution>
            <id>copy-and-filter-dockerfile</id>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <phase>compile</phase>
            <configuration>
              <outputDirectory>${project.build.directory}</outputDirectory>
              <resources>
                <resource>
                  <directory>src/main/docker</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
          <execution>
            <id>copy-k8s</id>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <phase>compile</phase>
            <configuration>
              <outputDirectory>${basedir}/target/k8s</outputDirectory>
              <resources>
                <resource>
                  <directory>src/main/k8s</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
          <execution>
            <id>copy-smoketest-files</id>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <phase>compile</phase>
            <configuration>
              <outputDirectory>${basedir}/target/smoketest</outputDirectory>
              <resources>
                <resource>
                  <directory>src/main/smoketest</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>build-with-ozonefs</id>
      <activation>
        <property>
          <name>!skipShade</name>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>org.apache.ozone</groupId>
          <artifactId>ozone-filesystem-hadoop2</artifactId>
        </dependency>
        <dependency>
          <groupId>org.apache.ozone</groupId>
          <artifactId>ozone-filesystem-hadoop3</artifactId>
        </dependency>
        <dependency>
          <groupId>org.apache.ozone</groupId>
          <artifactId>ozone-filesystem-hadoop3-client</artifactId>
        </dependency>
      </dependencies>
    </profile>

    <profile>
      <!-- turn on the profile to copy all the required jar files to measure coverage -->
      <id>coverage</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>copy-jacoco-files</id>
                <goals>
                  <goal>copy</goal>
                </goals>
                <phase>prepare-package</phase>
                <configuration>
                  <outputDirectory>target/ozone-${ozone.version}/share/coverage</outputDirectory>
                  <artifactItems>
                    <artifactItem>
                      <groupId>org.jacoco</groupId>
                      <artifactId>org.jacoco.agent</artifactId>
                      <version>${jacoco.version}</version>
                      <classifier>runtime</classifier>
                      <destFileName>jacoco-agent.jar</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.jacoco</groupId>
                      <artifactId>org.jacoco.cli</artifactId>
                      <version>${jacoco.version}</version>
                      <classifier>nodeps</classifier>
                      <destFileName>jacoco-cli.jar</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.jacoco</groupId>
                      <artifactId>org.jacoco.core</artifactId>
                      <version>${jacoco.version}</version>
                      <destFileName>jacoco-core.jar</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.apache.ozone</groupId>
                      <artifactId>hdds-test-utils</artifactId>
                      <classifier>tests</classifier>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>src</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <inherited>false</inherited>
            <executions>
              <execution>
                <id>src-dist</id>
                <goals>
                  <goal>single</goal>
                </goals>
                <phase>package</phase>
                <configuration>
                  <archiveBaseDirectory>../..</archiveBaseDirectory>
                  <appendAssemblyId>false</appendAssemblyId>
                  <attach>false</attach>
                  <finalName>ozone-${project.version}-src</finalName>
                  <tarLongFileMode>posix</tarLongFileMode>
                  <outputDirectory>target</outputDirectory>
                  <basedir>${project.basedir}/../..</basedir>
                  <!-- Not using descriptorRef and hadoop-assembly dependency -->
                  <!-- to avoid making hadoop-main to depend on a module      -->
                  <descriptors>
                    <descriptor>${project.basedir}/src/main/assemblies/ozone-src.xml</descriptor>
                  </descriptors>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>docker-build</id>
      <build>
        <plugins>
          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <configuration>
              <images>
                <image>
                  <name>${docker.image}</name>
                  <build>
                    <dockerFileDir>${project.build.directory}/ozone-${project.version}</dockerFileDir>
                  </build>
                </image>
              </images>
            </configuration>
            <executions>
              <execution>
                <goals>
                  <goal>build</goal>
                </goals>
                <phase>package</phase>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>docker-push</id>
      <build>
        <plugins>
          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>push</goal>
                </goals>
                <phase>package</phase>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>dist</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>tar-ozone</id>
                <goals>
                  <goal>exec</goal>
                </goals>
                <phase>package</phase>
                <configuration>
                  <executable>${shell-executable}</executable>
                  <workingDirectory>${project.build.directory}</workingDirectory>
                  <arguments>
                    <argument>${basedir}/dev-support/bin/dist-tar-stitching</argument>
                    <argument>${hdds.version}</argument>
                    <argument>${project.build.directory}</argument>
                  </arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
