<?xml version="1.0" encoding="UTF-8"?>
<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.spotify</groupId>
    <artifactId>helios-parent</artifactId>
    <version>0.8.781</version>
  </parent>

  <name>Helios Services</name>
  <artifactId>helios-services</artifactId>
  <packaging>jar</packaging>

  <properties>
    <masterImageName>helios-master:${project.version}</masterImageName>
    <agentImageName>helios-agent:${project.version}</agentImageName>
    <soloImageName>helios-solo:${project.version}</soloImageName>
  </properties>

  <profiles>
    <profile>
      <id>build-images</id>
      <activation>
        <property>
          <name>build-images</name>
        </property>
      </activation>
      <properties>
        <baseImage>java:8u66-jre</baseImage>
      </properties>
      <build>
        <plugins>
          <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.4.1</version>
            <configuration>
              <labels>
                <label>com.spotify.helios.version="${project.version}"</label>
              </labels>
            </configuration>
            <executions>
              <execution>
                <id>master</id>
                <phase>package</phase>
                <goals>
                  <goal>build</goal>
                </goals>
                <configuration>
                  <baseImage>${baseImage}</baseImage>
                  <resources>
                    <resource>
                      <targetPath>/usr/share/helios/lib/services/</targetPath>
                      <directory>${project.build.directory}</directory>
                      <include>${project.build.finalName}-shaded.jar</include>
                    </resource>
                    <resource>
                      <targetPath>/usr/bin/</targetPath>
                      <directory>${project.parent.basedir}/bin</directory>
                      <include>helios-*</include>
                    </resource>
                  </resources>
                  <imageName>${masterImageName}</imageName>
                  <entryPoint>["helios-master"]</entryPoint>
                  <tagInfoFile>${project.build.testOutputDirectory}/master-image.json</tagInfoFile>
                  <labels>
                    <label>com.spotify.helios.version="${project.version}"</label>
                  </labels>
                  <pullOnBuild>true</pullOnBuild>
                </configuration>
              </execution>
              <execution>
                <id>agent</id>
                <phase>package</phase>
                <goals>
                  <goal>build</goal>
                </goals>
                <configuration>
                  <baseImage>${baseImage}</baseImage>
                  <resources>
                    <resource>
                      <targetPath>/usr/share/helios/lib/services/</targetPath>
                      <directory>${project.build.directory}</directory>
                      <include>${project.build.finalName}-shaded.jar</include>
                    </resource>
                    <resource>
                      <targetPath>/usr/bin/</targetPath>
                      <directory>${project.parent.basedir}/bin</directory>
                      <include>helios-*</include>
                    </resource>
                  </resources>
                  <imageName>${agentImageName}</imageName>
                  <entryPoint>["helios-agent"]</entryPoint>
                  <tagInfoFile>${project.build.testOutputDirectory}/agent-image.json</tagInfoFile>
                  <labels>
                    <label>com.spotify.helios.version="${project.version}"</label>
                  </labels>
                  <pullOnBuild>true</pullOnBuild>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>build-solo</id>
      <build>
        <plugins>
          <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.4.1</version>
            <configuration>
              <labels>
                <label>com.spotify.helios.version="${project.version}"</label>
              </labels>
              <pullOnBuild>true</pullOnBuild>
            </configuration>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>build</goal>
                </goals>
                <configuration>
                  <dockerDirectory>solo/docker</dockerDirectory>
                  <imageName>${soloImageName}</imageName>
                  <tagInfoFile>${project.build.testOutputDirectory}/solo-image.json</tagInfoFile>
                  <resources>
                    <resource>
                      <targetPath>/</targetPath>
                      <directory>${project.build.directory}</directory>
                      <include>${project.build.finalName}-shaded.jar</include>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

  <dependencies>
    <dependency>
      <groupId>com.spotify.docgenerator</groupId>
      <artifactId>scanner</artifactId>
    </dependency>
    <!--compile deps -->
    <dependency>
      <groupId>io.dropwizard</groupId>
      <artifactId>dropwizard-core</artifactId>
      <version>0.7.1</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.jaxrs</groupId>
      <artifactId>jackson-jaxrs-json-provider</artifactId>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.dataformat</groupId>
      <artifactId>jackson-dataformat-yaml</artifactId>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.datatype</groupId>
      <artifactId>jackson-datatype-guava</artifactId>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
    </dependency>
    <dependency>
      <groupId>com.spotify</groupId>
      <artifactId>helios-service-registration</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>com.spotify</groupId>
      <artifactId>helios-tools</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>commons-codec</groupId>
      <artifactId>commons-codec</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>4.5</version>
    </dependency>
    <dependency>
      <groupId>joda-time</groupId>
      <artifactId>joda-time</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.zookeeper</groupId>
      <artifactId>zookeeper</artifactId>
      <version>3.5.0-alpha</version>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
        <exclusion>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.apache.curator</groupId>
      <artifactId>curator-recipes</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.kafka</groupId>
      <artifactId>kafka-clients</artifactId>
      <version>0.8.2.1</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-core</artifactId>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-access</artifactId>
    </dependency>
    <dependency>
      <groupId>net.logstash.logback</groupId>
      <artifactId>logstash-logback-encoder</artifactId>
      <version>4.5.1</version>
    </dependency>
    <dependency>
      <groupId>eu.toolchain.ffwd</groupId>
      <artifactId>ffwd-client</artifactId>
      <version>0.1.0</version>
    </dependency>
    <dependency>
      <groupId>net.kencochrane.raven</groupId>
      <artifactId>raven-logback</artifactId>
      <version>4.1.1</version>
    </dependency>
    <dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty</artifactId>
      <version>3.8.0.Final</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
      <groupId>net.sourceforge.argparse4j</groupId>
      <artifactId>argparse4j</artifactId>
    </dependency>
    <dependency>
      <groupId>com.readytalk</groupId>
      <artifactId>metrics3-statsd</artifactId>
      <version>4.1.0</version>
    </dependency>
    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-server</artifactId>
      <version>1.18.1</version>
    </dependency>
    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-client</artifactId>
      <version>1.18.1</version>
    </dependency>
    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-core</artifactId>
      <version>1.18.1</version>
    </dependency>
    <dependency>
      <groupId>com.spotify</groupId>
      <artifactId>docker-client</artifactId>
      <version>3.6.7</version>
      <classifier>shaded</classifier>
    </dependency>
    <dependency>
      <groupId>com.spotify</groupId>
      <artifactId>logging</artifactId>
      <version>2.0.17</version>
    </dependency>
    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
    </dependency>
    <dependency>
      <groupId>org.bouncycastle</groupId>
      <artifactId>bcpkix-jdk15on</artifactId>
      <version>1.53</version>
    </dependency>
    <dependency>
      <groupId>com.github.jnr</groupId>
      <artifactId>jnr-unixsocket</artifactId>
      <version>0.8</version>
    </dependency>

    <!--test deps-->
    <dependency>
      <groupId>com.spotify</groupId>
      <artifactId>helios-testing-common</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-all</artifactId>
    </dependency>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-library</artifactId>
    </dependency>
    <dependency>
      <groupId>com.aphyr</groupId>
      <artifactId>riemann-java-client</artifactId>
      <version>0.2.10</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <configuration>
          <createDependencyReducedPom>false</createDependencyReducedPom>
          <shadedArtifactAttached>true</shadedArtifactAttached>
          <shadedClassifierName>shaded</shadedClassifierName>
          <filters>
            <filter>
              <artifact>*:*</artifact>
              <excludes>
                <exclude>META-INF/*.SF</exclude>
                <exclude>META-INF/*.DSA</exclude>
                <exclude>META-INF/*.RSA</exclude>
              </excludes>
            </filter>
          </filters>
          <transformers>
            <!--The ServicesResourceTransformer is needed to make jersey happy-->
            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
          </transformers>
        </configuration>
      </plugin>

      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.5.3</version>
        <configuration>
          <descriptors>
            <descriptor>${project.basedir}/src/assembly/helios-solo.xml</descriptor>
          </descriptors>
          <finalName>helios-solo</finalName>
          <appendAssemblyId>false</appendAssemblyId>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>jdeb</artifactId>
        <groupId>org.vafer</groupId>
        <executions>

          <!--helios-master-->
          <execution>
            <id>helios-master</id>
            <phase>package</phase>
            <goals>
              <goal>jdeb</goal>
            </goals>
            <configuration>
              <deb>${project.build.directory}/helios-master_${project.version}_all.deb</deb>
              <controlDir>${project.parent.basedir}/src/deb/helios-master</controlDir>
              <dataSet>
                <data>
                  <src>${basedir}/../bin/helios-master</src>
                  <type>file</type>
                  <mapper>
                    <type>perm</type>
                    <prefix>/usr/bin/</prefix>
                    <filemode>755</filemode>
                  </mapper>
                </data>
                <data>
                  <src>${basedir}/../bin/helios-initialize-acl</src>
                  <type>file</type>
                  <mapper>
                    <type>perm</type>
                    <prefix>/usr/bin/</prefix>
                    <filemode>755</filemode>
                  </mapper>
                </data>
                <data>
                  <src>${project.parent.basedir}/src/deb/helios-master/default</src>
                  <type>file</type>
                  <dst>/etc/default/helios-master</dst>
                  <conffile>true</conffile>
                </data>
                <data>
                  <src>${project.parent.basedir}/src/deb/helios-master/upstart</src>
                  <type>file</type>
                  <dst>/etc/init/helios-master.conf</dst>
                  <conffile>true</conffile>
                </data>
                <data>
                  <src>${project.parent.basedir}/src/deb/helios-master/init</src>
                  <type>file</type>
                  <dst>/etc/init.d/helios-master</dst>
                  <mapper>
                    <type>perm</type>
                    <filemode>755</filemode>
                  </mapper>
                </data>
                <data>
                  <src>${basedir}/../bin/bootstrap.py</src>
                  <type>file</type>
                  <mapper>
                    <type>perm</type>
                    <prefix>/usr/share/helios/bin</prefix>
                    <filemode>755</filemode>
                  </mapper>
                </data>
              </dataSet>
            </configuration>
          </execution>

          <!--helios-agent-->
          <execution>
            <id>helios-agent</id>
            <phase>package</phase>
            <goals>
              <goal>jdeb</goal>
            </goals>
            <configuration>
              <deb>${project.build.directory}/helios-agent_${project.version}_all.deb</deb>
              <controlDir>${project.parent.basedir}/src/deb/helios-agent</controlDir>
              <dataSet>
                <data>
                  <src>${basedir}/../bin/helios-agent</src>
                  <type>file</type>
                  <mapper>
                    <type>perm</type>
                    <prefix>/usr/bin/</prefix>
                    <filemode>755</filemode>
                  </mapper>
                </data>
                <data>
                  <src>${project.parent.basedir}/src/deb/helios-agent/default</src>
                  <type>file</type>
                  <dst>/etc/default/helios-agent</dst>
                  <conffile>true</conffile>
                </data>
                <data>
                  <src>${project.parent.basedir}/src/deb/helios-agent/upstart</src>
                  <type>file</type>
                  <dst>/etc/init/helios-agent.conf</dst>
                  <conffile>true</conffile>
                </data>
                <data>
                  <src>${project.parent.basedir}/src/deb/helios-agent/init</src>
                  <type>file</type>
                  <dst>/etc/init.d/helios-agent</dst>
                  <mapper>
                    <type>perm</type>
                    <filemode>755</filemode>
                  </mapper>
                </data>
              </dataSet>
            </configuration>
          </execution>

          <!--helios-services-->
          <execution>
            <id>helios-services</id>
            <phase>package</phase>
            <goals>
              <goal>jdeb</goal>
            </goals>
            <configuration>
              <deb>${project.build.directory}/helios-services_${project.version}_all.deb</deb>
              <controlDir>${project.parent.basedir}/src/deb/helios-services</controlDir>
              <dataSet>
                <data>
                  <src>${project.build.directory}/${project.build.finalName}-shaded.jar</src>
                  <type>file</type>
                  <mapper>
                    <type>perm</type>
                    <prefix>/usr/share/helios/lib/services</prefix>
                  </mapper>
                </data>
              </dataSet>
            </configuration>
          </execution>

          <!--helios-solo-->
          <execution>
            <id>helios-solo</id>
            <phase>package</phase>
            <goals>
              <goal>jdeb</goal>
            </goals>
            <configuration>
              <deb>${project.build.directory}/helios-solo_${project.version}_all.deb</deb>
              <controlDir>${project.parent.basedir}/src/deb/helios-solo</controlDir>
              <dataSet>
                <data>
                  <type>files</type>
                  <paths>
                    <path>solo/helios-cleanup</path>
                    <path>solo/helios-down</path>
                    <path>solo/helios-env</path>
                    <path>solo/helios-restart</path>
                    <path>solo/helios-solo</path>
                    <path>solo/helios-up</path>
                    <path>solo/helios-use</path>
                  </paths>
                  <mapper>
                    <type>perm</type>
                    <prefix>/usr/bin</prefix>
                    <filemode>0755</filemode>
                    <strip>1</strip>
                  </mapper>
                </data>
              </dataSet>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>
</project>
