<!--
  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-ingest</artifactId>
    <version>1.0.2</version>
  </parent>

  <artifactId>cdap-file-tailer</artifactId>
  <packaging>jar</packaging>

  <name>File Tailer</name>

  <properties>
    <script.app.mainclass>co.cask.cdap.filetailer.FileTailerMain</script.app.mainclass>
    <script.app.user>file-tailer</script.app.user>
    <script.app.name>file-tailer</script.app.name>
    <script.app.desc>File Tailer</script.app.desc>
  </properties>

  <dependencies>
    <dependency>
      <groupId>co.cask.cdap</groupId>
      <artifactId>cdap-stream-client</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>co.cask.cdap</groupId>
      <artifactId>cdap-authentication-client</artifactId>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-core</artifactId>
      <version>${logback.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>${logback.version}</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-all</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.4</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-dependencies</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/lib</outputDirectory>
              <overWriteReleases>false</overWriteReleases>
              <overWriteSnapshots>false</overWriteSnapshots>
              <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <classpathPrefix>lib/</classpathPrefix>
              <mainClass>${script.app.mainclass}</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>deb</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>jdeb</artifactId>
            <groupId>org.vafer</groupId>
            <version>1.1.1</version>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>jdeb</goal>
                </goals>
                <configuration>
                  <deb>${project.build.directory}/${project.artifactId}.deb</deb>
                  <controlDir>${project.basedir}/src/main/deb/control</controlDir>
                  <dataSet>
                    <data>
                      <src>${project.build.directory}/${project.build.finalName}.jar</src>
                      <type>file</type>
                      <mapper>
                        <type>perm</type>
                        <filemode>755</filemode>
                        <prefix>/usr/lib/${script.app.name}/lib</prefix>
                      </mapper>
                    </data>
                    <data>
                      <src>${project.build.directory}/lib</src>
                      <type>directory</type>
                      <mapper>
                        <type>perm</type>
                        <filemode>755</filemode>
                        <prefix>/usr/lib/${script.app.name}/lib</prefix>
                      </mapper>
                    </data>
                    <data>
                      <src>${project.basedir}/src/main/resources</src>
                      <type>directory</type>
                      <mapper>
                        <type>perm</type>
                        <filemode>755</filemode>
                        <prefix>/usr/lib/${script.app.name}/conf</prefix>
                      </mapper>
                    </data>
                    <data>
                      <src>${project.basedir}/src/main/deb/sh/bin</src>
                      <type>directory</type>
                      <mapper>
                        <type>perm</type>
                        <filemode>755</filemode>
                        <prefix>/usr/lib/${script.app.name}/bin</prefix>
                      </mapper>
                    </data>
                    <data>
                      <src>${project.basedir}/src/main/deb/init.d</src>
                      <type>directory</type>
                      <mapper>
                        <type>perm</type>
                        <filemode>755</filemode>
                        <prefix>/usr/lib/${script.app.name}/bin</prefix>
                      </mapper>
                    </data>
                  </dataSet>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>rpm</id>
      <build>
        <plugins>
          <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>rpm-maven-plugin</artifactId>
              <version>2.1-alpha-1</version>
              <extensions>true</extensions>
              <executions>
                <execution>
                  <phase>package</phase>
                  <goals>
                    <goal>attached-rpm</goal>
                  </goals>
                </execution>
              </executions>
              <configuration>
                <name>${project.artifactId}</name>
                <classifier></classifier>
                <copyright>Cask</copyright>
                <distribution>development</distribution>
                <group>Applications/File Tailer</group>
                <needarch>false</needarch>
                <packager>${user.name}</packager>
                <changelogFile>CHANGELOG</changelogFile>
                <defaultDirmode>500</defaultDirmode>
                <defaultFilemode>400</defaultFilemode>
                <defaultUsername>${script.app.user}</defaultUsername>
                <defaultGroupname>${script.app.user}</defaultGroupname>
                <mappings>
                  <mapping>
                    <directory>/usr/lib/${script.app.name}/lib</directory>
                    <filemode>755</filemode>
                    <username>${script.app.user}</username>
                    <groupname>${script.app.user}</groupname>
                    <sources>
                      <source>
                        <location>target/lib</location>
                      </source>
                      <source>
                        <location>target/${project.build.finalName}.jar</location>
                      </source>
                    </sources>
                  </mapping>
                  <mapping>
                    <directory>/usr/lib/${script.app.name}/conf</directory>
                    <filemode>755</filemode>
                    <username>${script.app.user}</username>
                    <groupname>${script.app.user}</groupname>
                    <sources>
                      <source>
                        <location>src/main/resources</location>
                      </source>
                    </sources>
                  </mapping>
                  <mapping>
                    <directory>/usr/lib/${script.app.name}/bin</directory>
                    <filemode>755</filemode>
                    <username>${script.app.user}</username>
                    <groupname>${script.app.user}</groupname>
                    <sources>
                      <source>
                        <location>${project.basedir}/src/main/deb/sh/bin</location>
                      </source>
                      <source>
                        <location>${project.basedir}/src/main/rpm/init.d</location>
                      </source>
                    </sources>
                  </mapping>
                </mappings>
                <preinstallScriptlet>
                  <scriptFile>${project.basedir}/src/main/rpm/control/preinst</scriptFile>
                  <fileEncoding>utf-8</fileEncoding>
                </preinstallScriptlet>
                <postinstallScriptlet>
                  <scriptFile>${project.basedir}/src/main/deb/control/postinst</scriptFile>
                  <fileEncoding>utf-8</fileEncoding>
                </postinstallScriptlet>
                <preremoveScriptlet>
                  <scriptFile>${project.basedir}/src/main/deb/control/prerm</scriptFile>
                  <fileEncoding>utf-8</fileEncoding>
                </preremoveScriptlet>
                <postremoveScriptlet>
                  <scriptFile>${project.basedir}/src/main/deb/control/postrm</scriptFile>
                  <fileEncoding>utf-8</fileEncoding>
                </postremoveScriptlet>
              </configuration>
            </plugin>
          </plugins>
      </build>
    </profile>
  </profiles>
</project>
