<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>com.hotels</groupId>
    <artifactId>waggle-dance-parent</artifactId>
    <version>3.13.5</version>
  </parent>

  <artifactId>waggle-dance-rpm</artifactId>
  <description>Packages Waggle Dance for deployment using RPM.</description>
  <packaging>pom</packaging>

  <properties>
    <tmp.directory>${project.build.directory}/tmp-directory</tmp.directory>
    <rpm.maven.plugin.version>2.2.0</rpm.maven.plugin.version>
    <rpm-sources.directory>${tmp.directory}/waggle-dance-${project.version}</rpm-sources.directory>
    <rpm.install.dir>/opt/waggle-dance</rpm.install.dir>
    <rpm.install.user>waggle-dance</rpm.install.user>
    <rpm.install.group>waggle-dance</rpm.install.group>
  </properties>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>waggle-dance-bin</id>
            <phase>package</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>com.hotels</groupId>
                  <artifactId>waggle-dance</artifactId>
                  <version>${project.version}</version>
                  <classifier>bin</classifier>
                  <type>tgz</type>
                  <overWrite>true</overWrite>
                  <outputDirectory>${tmp.directory}</outputDirectory>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>rpm-maven-plugin</artifactId>
        <version>${rpm.maven.plugin.version}</version>
        <executions>
          <execution>
            <id>attach-rpm</id>
            <phase>package</phase>
            <goals>
              <goal>attached-rpm</goal>
            </goals>
            <configuration>
              <description>${project.description}</description>
              <group>Applications/Engineering</group>
              <targetOS>Linux</targetOS>
              <targetVendor>redhat</targetVendor>
              <defaultUsername>${rpm.install.user}</defaultUsername>
              <defaultGroupname>${rpm.install.group}</defaultGroupname>
              <defaultDirmode>775</defaultDirmode>
              <defaultFilemode>644</defaultFilemode>
              <mappings>
                <mapping>
                  <directory>${rpm.install.dir}/conf</directory>
                  <sources>
                    <source>
                      <location>${rpm-sources.directory}/conf</location>
                    </source>
                  </sources>
                </mapping>
                <mapping>
                  <!-- Jar needs to be executable for spring boot/init.d -->
                  <filemode>775</filemode>
                  <directory>${rpm.install.dir}/service</directory>
                  <sources>
                    <source>
                      <location>${rpm-sources.directory}/service</location>
                    </source>
                  </sources>
                </mapping>
                <mapping>
                  <directory>/var/log/waggle-dance</directory>
                </mapping>
                <mapping>
                  <directory>/etc/init.d</directory>
                  <sources>
                    <softlinkSource>
                      <destination>waggle-dance</destination>
                      <location>${rpm.install.dir}/service/waggle-dance-core-latest-exec.jar</location>
                    </softlinkSource>
                  </sources>
                </mapping>
                <mapping>
                  <directory>/etc/logrotate.d</directory>
                  <sources>
                    <softlinkSource>
                      <destination>waggle-dance</destination>
                      <location>${rpm.install.dir}/conf/waggle-dance.logrotate</location>
                    </softlinkSource>
                  </sources>
                </mapping>
              </mappings>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>sonatype-oss-release-github-actions</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>rpm-maven-plugin</artifactId>
            <version>${rpm.maven.plugin.version}</version>
            <executions>
              <execution>
                <id>attach-rpm</id>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
