<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright © 2012-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>4.0.1</version>
  </parent>

  <artifactId>cdap-cli</artifactId>
  <name>CDAP CLI</name>

  <properties>
    <main.class>co.cask.cdap.cli.CLIMain</main.class>
  </properties>

  <dependencies>
    <dependency>
      <groupId>co.cask.cdap</groupId>
      <artifactId>cdap-client</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>co.cask.common</groupId>
      <artifactId>common-cli</artifactId>
    </dependency>
    <dependency>
      <groupId>commons-cli</groupId>
      <artifactId>commons-cli</artifactId>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-core</artifactId>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.code.findbugs</groupId>
      <artifactId>jsr305</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.inject</groupId>
      <artifactId>guice</artifactId>
    </dependency>
    <dependency>
      <groupId>jline</groupId>
      <artifactId>jline</artifactId>
    </dependency>
    <dependency>
      <groupId>com.googlecode.concurrent-trees</groupId>
      <artifactId>concurrent-trees</artifactId>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <goal>package</goal>
          <createDependencyReducedPom>false</createDependencyReducedPom>
          <transformers>
            <transformer
                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <mainClass>${main.class}</mainClass>
            </transformer>
          </transformers>
        </configuration>
        <executions>
          <execution>
            <id>shade-jar</id>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>dist</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <executions>
              <execution>
                <id>default-jar</id>
                <phase>prepare-package</phase>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <executions>
              <execution>
                <id>shade-jar</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>shade</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>
              <!-- Copy CDAP and CLI scripts -->
              <execution>
                <id>copy-cli-scripts</id>
                <phase>process-resources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration combine.self="override">
                  <outputDirectory>${stage.opt.dir}</outputDirectory>
                  <useDefaultDelimiters>false</useDefaultDelimiters>
                  <delimiters>
                    <delimiter>@@</delimiter>
                  </delimiters>
                  <resources>
                    <resource>
                      <directory>${project.parent.basedir}/cdap-cli/bin</directory>
                      <targetPath>bin</targetPath>
                      <includes>
                        <include>cdap-cli.bat</include>
                        <include>cdap-cli.sh</include>
                      </includes>
                      <filtering>true</filtering>
                    </resource>
                    <resource>
                      <directory>${project.parent.basedir}/cdap-common/bin</directory>
                      <targetPath>bin</targetPath>
                      <includes>
                        <include>cdap</include>
                        <include>functions.sh</include>
                      </includes>
                      <filtering>true</filtering>
                    </resource>
                  </resources>
                </configuration>
              </execution>

              <!-- Copy CLI profile.d file -->
              <execution>
                <id>copy-cli-etc</id>
                <phase>process-resources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration combine.self="override">
                  <outputDirectory>${stage.dir}</outputDirectory>
                  <resources>
                    <resource>
                      <directory>${project.parent.basedir}/cdap-cli/etc</directory>
                      <targetPath>etc</targetPath>
                    </resource>
                  </resources>
                </configuration>
              </execution>

            </executions>
          </plugin>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
              <execution>
                <id>copy-jar-to-stage-packaging</id>
                <phase>package</phase>
                <configuration>
                  <target>
                    <copy file="${project.build.directory}/${project.artifactId}-${project.version}.jar"
                          tofile="${stage.opt.dir}/lib/${project.groupId}.${project.artifactId}-${project.version}.jar"/>
                  </target>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>rpm-prepare</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
              <!-- Override parent to not generate init.d service script -->
              <execution>
                <id>rename-rpm-service</id>
                <phase/>
              </execution>
              <execution>
                <id>rpm-init-permission</id>
                <phase/>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>deb-prepare</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
              <!-- Override parent to not generate init.d service script -->
              <execution>
                <id>rename-deb-service</id>
                <phase/>
              </execution>
              <execution>
                <id>deb-init-permission</id>
                <phase/>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>rpm</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.3.1</version>
          </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>${project.artifactId}</artifactId>
                  <packaging>noarch.rpm</packaging>
                  <generatePom>false</generatePom>
                  <file>${project.build.directory}/${project.artifactId}-${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>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.3.1</version>
          </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>${project.artifactId}</artifactId>
                  <packaging>deb</packaging>
                  <generatePom>false</generatePom>
                  <file>${project.build.directory}/${project.artifactId}_${package.version}-1_all.deb</file>
                  <repositoryId>continuuity</repositoryId>
                  <url>${deploy.url}</url>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>tgz</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
          </plugin>

          <!-- Extra deployment for tgz 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-tgz</id>
                <phase>deploy</phase>
                <goals>
                  <goal>deploy-file</goal>
                </goals>
                <configuration>
                  <version>${project.version}</version>
                  <groupId>${dist.deploy.groupId}</groupId>
                  <artifactId>${project.artifactId}</artifactId>
                  <packaging>tar.gz</packaging>
                  <generatePom>false</generatePom>
                  <file>${project.build.directory}/${project.artifactId}-${package.version}.tar.gz</file>
                  <repositoryId>continuuity</repositoryId>
                  <url>${deploy.url}</url>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

  </profiles>
</project>
