<?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>
    <artifactId>scm</artifactId>
    <groupId>sonia.scm</groupId>
    <version>1.57</version>
  </parent>

  <groupId>sonia.scm</groupId>
  <artifactId>scm-server</artifactId>
  <version>1.57</version>
  <name>scm-server</name>
  <packaging>jar</packaging>

  <dependencies>

    <dependency>
      <groupId>commons-daemon</groupId>
      <artifactId>commons-daemon</artifactId>
      <version>${commons.daemon.version}</version>
    </dependency>

    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-server</artifactId>
      <version>${jetty.version}</version>
    </dependency>

    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-webapp</artifactId>
      <version>${jetty.version}</version>
    </dependency>

    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-jmx</artifactId>
      <version>${jetty.version}</version>
    </dependency>

    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-ajp</artifactId>
      <version>${jetty.version}</version>
    </dependency>

  </dependencies>

  <build>

    <plugins>

      <plugin>
        <groupId>sonia.maven</groupId>
        <artifactId>appassembler-maven-plugin</artifactId>
        <version>1.2.2.0</version>
        <executions>
          <execution>
            <id>scm-app</id>
            <phase>package</phase>
            <goals>
              <goal>create-repository</goal>
              <goal>generate-daemons</goal>
            </goals>
            <configuration>
              <target>${project.build.directory}/appassembler</target>
              <assembleDirectory>${exploded.directory}</assembleDirectory>
              <repoPath>lib</repoPath>
              <repositoryLayout>flat</repositoryLayout>
              <includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
              <daemons>
                <daemon>

                  <id>scm-server</id>
                  <version>${commons.daemon.native.version}</version>
                  <mainClass>sonia.scm.server.ScmServerDaemon</mainClass>
                  <platforms>
                    <platform>commons-daemon</platform>
                  </platforms>

                  <jvmSettings>
                    <systemProperties>
                      <arg>java.awt.headless=true</arg>
                      <arg>logback.configurationFile=logging.xml</arg>
                    </systemProperties>
                  </jvmSettings>

                  <generatorConfigurations>
                    <generatorConfiguration>

                      <generator>commons-daemon</generator>
                      <configuration>
                        <property>
                          <name>configuration.directory</name>
                          <value>conf</value>
                        </property>
                        <property>
                          <name>darwin.arch.enable</name>
                          <value>false</value>
                        </property>
                        <property>
                          <name>windows.service.dependencies</name>
                          <value>Tcpip</value>
                        </property>
                      </configuration>

                    </generatorConfiguration>
                  </generatorConfigurations>

                </daemon>
              </daemons>

            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.4</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>${project.groupId}</groupId>
                  <artifactId>scm-webapp</artifactId>
                  <version>${project.version}</version>
                  <type>war</type>
                  <outputDirectory>${exploded.directory}/var/webapp</outputDirectory>
                  <destFileName>scm-webapp.war</destFileName>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <descriptors>
            <descriptor>src/main/assembly/scm-server-app.xml</descriptor>
          </descriptors>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>

    <finalName>scm-server</finalName>
  </build>

  <profiles>
    <profile>
      <id>nativepkg</id>

      <build>
        <plugins>

          <plugin>
            <groupId>com.github.sdorra</groupId>
            <artifactId>nativepkg-maven-plugin</artifactId>
            <version>1.1.4</version>
            <executions>
              <execution>
                <goals>
                  <goal>deb</goal>
                  <goal>rpm</goal>
                </goals>
                <phase>package</phase>
              </execution>
            </executions>
            <configuration>
              <attach>true</attach>
              <classifier>all</classifier>
              <release>${maven.build.timestamp}</release>
              <section>devel</section>
              <group>Development/Tools</group>
              <vendor>SCM-Manager</vendor>
              <license>BSD 3-Clause</license>
              <url>www.scm-manager.org</url>
              <summary>${project.description}</summary>
              <packager>Sebastian Sdorra &lt;s.sdorra@gmail.com&gt;</packager>
              <platform>
                <architecture>noarch</architecture>
                <os>linux</os>
              </platform>
              <scripts>
                <preInstall>${project.basedir}/src/main/nativepkg/create-user</preInstall>
                <postInstall>${project.basedir}/src/main/nativepkg/clear-cache</postInstall>
              </scripts>
              <mappings>
                <files>
                  <file>
                    <path>/opt/scm-server/bin/scm-server</path>
                    <source>${exploded.directory}/bin/scm-server</source>
                    <mode>0744</mode>
                  </file>
                  <file>
                    <path>/opt/scm-server/conf/server-config.xml</path>
                    <source>${project.basedir}/src/main/conf/server-config.xml</source>
                    <config>true</config>
                  </file>
                  <file>
                    <path>/opt/scm-server/conf/logging.xml</path>
                    <source>${project.basedir}/src/main/nativepkg/logging.xml</source>
                    <config>true</config>
                  </file>
                  <file>
                    <path>/opt/scm-server/libexec/jsvc-linux-i686</path>
                    <source>${exploded.directory}/libexec/jsvc-linux-i686</source>
                    <mode>0744</mode>
                  </file>
                  <file>
                    <path>/opt/scm-server/libexec/jsvc-linux-x86_64</path>
                    <source>${exploded.directory}/libexec/jsvc-linux-x86_64</source>
                    <mode>0744</mode>
                  </file>
                  <file>
                    <path>/opt/scm-server/var/webapp/scm-webapp.war</path>
                    <source>${exploded.directory}/var/webapp/scm-webapp.war</source>
                  </file>
                  <file>
                    <path>/opt/scm-server/var/webapp/docroot/index.html</path>
                    <source>${basedir}/src/main/docroot/index.html</source>
                  </file>
                  <file>
                    <path>/etc/default/scm-server</path>
                    <source>${project.basedir}/src/main/nativepkg/default</source>
                    <mode>0644</mode>
                    <config>true</config>
                  </file>
                  <file>
                    <path>/etc/init.d/scm-server</path>
                    <source>${project.basedir}/src/main/nativepkg/init-script</source>
                    <mode>0755</mode>
                  </file>
                </files>
                <links>
                  <link>
                    <source>/opt/scm-server/var/log</source>
                    <target>/var/log/scm</target>
                  </link>
                  <link>
                    <source>/opt/scm-server/work</source>
                    <target>/var/cache/scm/work</target>
                  </link>
                </links>
                <directories>
                  <directory>
                    <path>/opt/scm-server/lib</path>
                    <source>${exploded.directory}/lib</source>
                  </directory>
                  <directory>
                    <path>/var/cache/scm</path>
                    <uname>scm</uname>
                    <gname>scm</gname>
                    <dirMode>0700</dirMode>
                    <addParents>false</addParents>
                  </directory>
                  <directory>
                    <path>/var/cache/scm/work</path>
                    <uname>scm</uname>
                    <gname>scm</gname>
                    <dirMode>0700</dirMode>
                    <addParents>false</addParents>
                  </directory>
                  <directory>
                    <path>/var/log/scm</path>
                    <uname>scm</uname>
                    <gname>scm</gname>
                    <dirMode>0770</dirMode>
                    <addParents>false</addParents>
                  </directory>
                  <directory>
                    <path>/var/lib/scm</path>
                    <uname>scm</uname>
                    <gname>scm</gname>
                    <dirMode>0700</dirMode>
                    <addParents>false</addParents>
                  </directory>
                </directories>
              </mappings>
            </configuration>
          </plugin>

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

  <properties>
    <commons.daemon.version>1.0.15</commons.daemon.version>
    <commons.daemon.native.version>1.0.15.1</commons.daemon.native.version>
    <exploded.directory>${project.build.directory}/appassembler/commons-daemon/scm-server</exploded.directory>
  </properties>

</project>
