<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright © 2014 Cask Data, Inc.

  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>co.cask.cdap</groupId>
    <artifactId>cdap</artifactId>
    <version>3.0.2</version>
  </parent>

  <artifactId>cdap-distributions</artifactId>
  <name>CDAP Distributions</name>
  <packaging>jar</packaging>

  <profiles>

    <profile>
      <id>rpm-prepare</id>
      <build>
        <resources>
          <resource>
            <directory>${project.basedir}/src/etc</directory>
            <targetPath>${stage.dir}/etc</targetPath>
          </resource>
        </resources>
      </build>
    </profile>

    <profile>
      <id>deb-prepare</id>
      <build>
        <resources>
          <resource>
            <directory>${project.basedir}/src/etc</directory>
            <targetPath>${stage.dir}-deb/etc</targetPath>
          </resource>
        </resources>
      </build>
    </profile>

    <profile>
      <id>rpm</id>
      <build>
        <plugins>
          <!-- Distribution builds top level package. It builds differently than others -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.3.1</version>
            <executions>
              <execution>
                <id>rpm-package</id>
                <phase>package</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration combine.self="override">
                  <workingDirectory>${project.build.directory}</workingDirectory>
                  <executable>fpm</executable>
                  <commandlineArgs>
                    --name "cdap"
                    --vendor "Cask Data, Inc."
                    --maintainer "support@cask.co"
                    --license "Copyright ${package.build.year} Cask Data, Inc. Licensed under the Apache License, Version 2.0."
                    --description "Component of Cask CDAP"
                    --category misc
                    -s dir
                    -t rpm
                    -C "${stage.dir}"
                    --version "${package.version}"
                    --architecture all
                    --url "http://www.cask.co"
                    --template-value "project=cdap"
                    --after-install "${project.basedir}/src/rpm/scripts/common-postinst"
                    --before-install "${project.basedir}/src/rpm/scripts/common-preinst"
                    --before-remove "${project.basedir}/src/rpm/scripts/common-prerm"
                    --iteration "${release.iteration}"
                    etc
                  </commandlineArgs>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- Extra deployment for rpm package. -->
          <!-- This has to be in child level, otherwise all modules would try to deploy. -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.8</version>
            <executions>
              <execution>
                <id>deploy-rpm</id>
                <phase>deploy</phase>
                <goals>
                  <goal>deploy-file</goal>
                </goals>
                <configuration>
                  <version>${project.version}</version>
                  <groupId>${dist.deploy.groupId}</groupId>
                  <artifactId>cdap</artifactId>
                  <packaging>noarch.rpm</packaging>
                  <generatePom>false</generatePom>
                  <file>${project.build.directory}/cdap-${package.version}-1.noarch.rpm</file>
                  <classifier>1</classifier>
                  <repositoryId>continuuity</repositoryId>
                  <url>${deploy.url}</url>
                </configuration>
              </execution>
            </executions>
          </plugin>

        </plugins>
      </build>
    </profile>

    <profile>
      <id>deb</id>
      <build>
        <plugins>
          <!-- Distribution builds top level package. It builds differently than others -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.3.1</version>
            <executions>
              <execution>
                <id>deb-package</id>
                <phase>package</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration combine.self="override">
                  <workingDirectory>${project.build.directory}</workingDirectory>
                  <executable>fpm</executable>
                  <commandlineArgs>
                    --name "cdap"
                    --vendor "Cask Data, Inc."
                    --maintainer "support@cask.co"
                    --license "Copyright © 2014 Cask Data, Inc. All Rights Reserved."
                    --description "Component of Cask CDAP"
                    --category misc
                    -s dir
                    -t deb
                    -C "${stage.dir}-deb"
                    --version "${package.version}"
                    --architecture all
                    --url "http://www.cask.co"
                    --template-value "project=cdap"
                    --after-install "${project.basedir}/src/debian/scripts/common-postinst"
                    --before-install "${project.basedir}/src/debian/scripts/common-preinst"
                    --before-remove "${project.basedir}/src/debian/scripts/common-prerm"
                    --iteration "${release.iteration}"
                    etc
                  </commandlineArgs>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- Extra deployment for deb package -->
          <!-- This has to be in child level, otherwise all modules would try to deploy. -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.8</version>
            <executions>
              <execution>
                <id>deploy-deb</id>
                <phase>deploy</phase>
                <goals>
                  <goal>deploy-file</goal>
                </goals>
                <configuration>
                  <version>${project.version}</version>
                  <groupId>${dist.deploy.groupId}</groupId>
                  <artifactId>cdap</artifactId>
                  <packaging>deb</packaging>
                  <generatePom>false</generatePom>
                  <file>${project.build.directory}/cdap_${package.version}-1_all.deb</file>
                  <repositoryId>continuuity</repositoryId>
                  <url>${deploy.url}</url>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

  </profiles>

</project>
