<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-manifest</artifactId>
        <version>2.0.0-SNAPSHOT</version>
    </parent>
    <artifactId>nifi-runtime-manifest</artifactId>
    <packaging>jar</packaging>

    <properties>
        <extension.manifest.unpack.dir>${project.build.directory}</extension.manifest.unpack.dir>
        <build.properties.file>${project.build.directory}/classes/build.properties</build.properties.file>
        <runtime.manifest.file>${project.build.directory}/classes/nifi-runtime-manifest.json</runtime.manifest.file>
        <runtime.manifest.id>apache-nifi</runtime.manifest.id>
    </properties>

    <dependencies>
        <!-- Needed to unpack the extension-manifest.xml files during the build, marked as optional
             because it is not a real dependency for anyone depending on this module -->
        <dependency>
            <groupId>org.apache.nifi</groupId>
            <artifactId>nifi-assembly</artifactId>
            <version>2.0.0-SNAPSHOT</version>
            <classifier>manifests</classifier>
            <type>zip</type>
            <optional>true</optional>
        </dependency>

    </dependencies>

    <build>
        <!-- Replace variables in src/main/resource/build.properties when processing resources -->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>build.properties</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
        <!-- Populate buildBranch, buildRevision, and timestamp so variables are available to build.properties -->
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <inherited>true</inherited>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>create</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <doCheck>false</doCheck>
                    <doUpdate>false</doUpdate>
                    <shortRevisionLength>7</shortRevisionLength>
                    <getRevisionOnlyOnce>true</getRevisionOnlyOnce>
                    <revisionOnScmFailure />
                    <buildNumberPropertyName>buildRevision</buildNumberPropertyName>
                    <scmBranchPropertyName>buildBranch</scmBranchPropertyName>
                </configuration>
            </plugin>
            <!-- Unpack all of NiFi's extension manifests -->
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>extract-extension-manifests</id>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <includeArtifactIds>nifi-assembly</includeArtifactIds>
                            <includeClassifiers>manifests</includeClassifiers>
                            <excludeTransitive>true</excludeTransitive>
                            <outputDirectory>${extension.manifest.unpack.dir}</outputDirectory>
                            <silent>true</silent>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <ignoredUnusedDeclaredDependencies combine.children="append">
                        <ignoredUnusedDeclaredDependency>org.apache.nifi:nifi-assembly</ignoredUnusedDeclaredDependency>
                    </ignoredUnusedDeclaredDependencies>
                </configuration>
            </plugin>
            <!-- Execute the runtime manifest generator -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>generate-runtime-manifest</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>org.apache.nifi.runtime.manifest.impl.RuntimeManifestGenerator</mainClass>
                            <arguments>
                                <argument>${extension.manifest.unpack.dir}/nifi-manifests</argument>
                                <argument>${build.properties.file}</argument>
                                <argument>${runtime.manifest.file}</argument>
                                <argument>${runtime.manifest.id}</argument>
                            </arguments>
                            <includePluginDependencies>true</includePluginDependencies>
                            <includeProjectDependencies>false</includeProjectDependencies>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.nifi</groupId>
                        <artifactId>nifi-runtime-manifest-core</artifactId>
                        <version>2.0.0-SNAPSHOT</version>
                    </dependency>
                    <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
                        <version>${org.slf4j.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-simple</artifactId>
                        <version>${org.slf4j.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <!-- Specifies an empty buildRevision and buildBranch when building outside of a git repo -->
        <profile>
            <id>build-info-no-git</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <file>
                    <missing>../../.git/HEAD</missing>
                </file>
            </activation>
            <properties>
                <buildRevision />
                <buildBranch />
            </properties>
        </profile>
    </profiles>
</project>