<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>ratis</artifactId>
    <groupId>org.apache.ratis</groupId>
    <version>2.2.0</version>
  </parent>

  <artifactId>ratis-assembly</artifactId>
  <name>Apache Ratis Project Assembly</name>

  <packaging>pom</packaging>

  <properties>
    <ratis.tmp.dir>${project.build.directory}/test</ratis.tmp.dir>
    <test.build.data>${project.build.directory}/test/data</test.build.data>
    <ratis.log.dir>${project.build.directory}/log</ratis.log.dir>
    <test.build.webapps>${project.build.directory}/test-classes/webapps</test.build.webapps>
    <test.cache.data>${project.build.directory}/test-classes</test.cache.data>
    <test.build.classes>${project.build.directory}/test-classes</test.build.classes>
    <license.bundles.dependencies>true</license.bundles.dependencies>
  </properties>

  <build>
    <plugins>
<!-- licensing info from our dependencies -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-remote-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>process-remote-resources</id>
            <goals>
              <goal>process</goal>
            </goals>
            <configuration>
              <properties>
                <bundled-dependencies>${license.bundles.dependencies}</bundled-dependencies>
              </properties>
              <resourceBundles>
                <!-- Will generate META-INF/DEPENDENCIES META-INF/LICENSE META-INF/NOTICE -->
                <resourceBundle>${project.groupId}:ratis-resource-bundle:${project.version}
                </resourceBundle>
              </resourceBundles>
              <supplementalModelArtifacts>
                <supplementalModelArtifact>
                  ${project.groupId}:ratis-resource-bundle:${project.version}
                </supplementalModelArtifact>
              </supplementalModelArtifacts>
              <supplementalModels>
                <supplementalModel>supplemental-models.xml</supplementalModel>
              </supplementalModels>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <id>default-jar</id>
            <phase>never</phase>
          </execution>
          <execution>
            <id>prepare-jar</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
          <execution>
            <id>prepare-test-jar</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>test-jar</goal>
            </goals>
            <configuration>
              <includes>
                <include>**/*.class</include>
                <include>webapps/**</include>
              </includes>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <executions>
          <execution>
            <phase>prepare-package</phase>
            <goals>
              <goal>jar</goal>
              <goal>test-jar</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <attach>true</attach>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <!--Else will use ratis-assembly as final name.-->
          <finalName>apache-ratis-${project.version}</finalName>
          <skipAssembly>false</skipAssembly>
          <appendAssemblyId>true</appendAssemblyId>
          <tarLongFileMode>gnu</tarLongFileMode>
          <descriptors>
            <descriptor>src/main/assembly/src.xml</descriptor>
            <descriptor>src/main/assembly/bin.xml</descriptor>
            <descriptor>src/main/assembly/examples-bin.xml</descriptor>
          </descriptors>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <!-- generates the file that will be used by the bin/ratis script in the dev env -->
            <id>create-ratis-generated-classpath</id>
            <phase>test</phase>
            <goals>
              <goal>build-classpath</goal>
            </goals>
            <configuration>
              <outputFile>${project.parent.basedir}/target/cached_classpath.txt</outputFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <!-- Intra-project dependencies -->
    <dependency>
      <groupId>org.apache.ratis</groupId>
      <artifactId>ratis-thirdparty-misc</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ratis</groupId>
      <artifactId>ratis-resource-bundle</artifactId>
      <version>${project.version}</version>
      <optional>true</optional>
     </dependency>
    <dependency>
      <artifactId>ratis-docs</artifactId>
      <groupId>org.apache.ratis</groupId>
    </dependency>
    <dependency>
      <artifactId>ratis-proto</artifactId>
      <groupId>org.apache.ratis</groupId>
    </dependency>
    <dependency>
      <artifactId>ratis-common</artifactId>
      <groupId>org.apache.ratis</groupId>
    </dependency>
    <dependency>
      <artifactId>ratis-common</artifactId>
      <groupId>org.apache.ratis</groupId>
      <type>test-jar</type>
    </dependency>

    <dependency>
      <artifactId>ratis-client</artifactId>
      <groupId>org.apache.ratis</groupId>
    </dependency>
    <dependency>
      <artifactId>ratis-client</artifactId>
      <groupId>org.apache.ratis</groupId>
      <type>test-jar</type>
    </dependency>
    <dependency>
      <artifactId>ratis-server-api</artifactId>
      <groupId>org.apache.ratis</groupId>
    </dependency>
    <dependency>
      <artifactId>ratis-server</artifactId>
      <groupId>org.apache.ratis</groupId>
    </dependency>
    <dependency>
      <artifactId>ratis-server</artifactId>
      <groupId>org.apache.ratis</groupId>
      <type>test-jar</type>
    </dependency>

    <dependency>
      <artifactId>ratis-grpc</artifactId>
      <groupId>org.apache.ratis</groupId>
    </dependency>
    <dependency>
      <artifactId>ratis-grpc</artifactId>
      <groupId>org.apache.ratis</groupId>
      <type>test-jar</type>
    </dependency>

    <dependency>
      <artifactId>ratis-netty</artifactId>
      <groupId>org.apache.ratis</groupId>
    </dependency>
    <dependency>
      <artifactId>ratis-netty</artifactId>
      <groupId>org.apache.ratis</groupId>
      <type>test-jar</type>
    </dependency>

    <dependency>
      <artifactId>ratis-hadoop</artifactId>
      <groupId>org.apache.ratis</groupId>
    </dependency>
    <dependency>
      <artifactId>ratis-hadoop</artifactId>
      <groupId>org.apache.ratis</groupId>
      <type>test-jar</type>
    </dependency>

    <dependency>
      <artifactId>ratis-test</artifactId>
      <groupId>org.apache.ratis</groupId>
    </dependency>
    <dependency>
      <artifactId>ratis-test</artifactId>
      <groupId>org.apache.ratis</groupId>
      <type>test-jar</type>
    </dependency>

    <dependency>
      <artifactId>ratis-examples</artifactId>
      <groupId>org.apache.ratis</groupId>
    </dependency>
    <dependency>
      <artifactId>ratis-examples</artifactId>
      <groupId>org.apache.ratis</groupId>
      <type>test-jar</type>
    </dependency>

    <dependency>
      <artifactId>ratis-replicated-map</artifactId>
      <groupId>org.apache.ratis</groupId>
    </dependency>
    <dependency>
      <artifactId>ratis-replicated-map</artifactId>
      <groupId>org.apache.ratis</groupId>
      <type>test-jar</type>
    </dependency>

    <dependency>
      <artifactId>ratis-logservice</artifactId>
      <groupId>org.apache.ratis</groupId>
    </dependency>
    <dependency>
      <artifactId>ratis-logservice</artifactId>
      <groupId>org.apache.ratis</groupId>
      <type>test-jar</type>
    </dependency>
    <dependency>
      <groupId>org.apache.ratis</groupId>
      <artifactId>ratis-metrics</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.ratis</groupId>
      <artifactId>ratis-tools</artifactId>
    </dependency>
  </dependencies>

  <profiles>
    <profile>
      <id>release</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <!--
                 Build an aggregation of our templated NOTICE file and the NOTICE files in our dependencies.
                 If MASSEMBLY-382 is fixed we could do this in the assembly
                 Currently relies on env, bash, find, and cat.
              -->
              <execution>
                <!-- put all of the NOTICE files out of our dependencies -->
                <id>unpack-dependency-notices</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>unpack-dependencies</goal>
                </goals>
                <configuration>
                  <useSubDirectoryPerArtifact>true</useSubDirectoryPerArtifact>
                  <includes>**\/NOTICE,**\/NOTICE.txt</includes>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>concat-NOTICE-files</id>
                <phase>package</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>env</executable>
                  <arguments>
                    <argument>bash</argument>
                    <argument>-c</argument>
                    <argument>cat maven-shared-archive-resources/META-INF/NOTICE `find ${project.build.directory}/dependency -iname NOTICE -or -iname NOTICE.txt`</argument>
                  </arguments>
                  <outputFile>${project.build.directory}/NOTICE.aggregate</outputFile>
                  <workingDirectory>${project.build.directory}</workingDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
