<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.atlassian.bitbucket.server</groupId>
        <artifactId>bitbucket-distribution-parent</artifactId>
        <version>5.2.0-rc4</version>
    </parent>

    <artifactId>bitbucket-distribution</artifactId>
    <packaging>pom</packaging>
    <name>Bitbucket Server - Distribution</name>

    <properties>
        <daemon.dir>${project.build.directory}/daemon</daemon.dir>
        <db.driver.dir>${project.build.directory}/db-drivers</db.driver.dir>
        <elasticsearch.dir>${project.build.directory}/elasticsearch</elasticsearch.dir>

        <bitbucket.context />
        <bitbucket.http.port>7990</bitbucket.http.port>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>strip-elasticsearch-version</id>
                        <!-- process-resources to run after ElasticSearch is unpacked in generate-resources -->
                        <phase>process-resources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <path id="elasticsearch_versioned_dir_path">
                                    <dirset dir="${project.build.directory}">
                                        <include name="elasticsearch-*" />
                                    </dirset>
                                </path>
                                <property name="elasticsearch_versioned_dir" refid="elasticsearch_versioned_dir_path" />
                                <move file="${elasticsearch_versioned_dir}" tofile="${elasticsearch.dir}" />
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>standalone</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <appendAssemblyId>false</appendAssemblyId>
                            <descriptors>
                                <descriptor>src/main/assembly/bin.xml</descriptor>
                            </descriptors>
                            <tarLongFileMode>posix</tarLongFileMode>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-db-drivers</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.microsoft.sqlserver</groupId>
                                    <artifactId>sqljdbc</artifactId>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.oracle</groupId>
                                    <artifactId>ojdbc7</artifactId>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.postgresql</groupId>
                                    <artifactId>postgresql</artifactId>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${db.driver.dir}</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-db-native-libs</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.microsoft.sqlserver</groupId>
                                    <artifactId>sqljdbc_auth</artifactId>
                                    <classifier>x64</classifier>
                                    <type>dll</type>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.microsoft.sqlserver</groupId>
                                    <artifactId>sqljdbc_auth</artifactId>
                                    <classifier>x86</classifier>
                                    <type>dll</type>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${db.driver.dir}</outputDirectory>
                            <stripVersion>true</stripVersion>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-commons-daemon</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>commons-daemon</groupId>
                                    <artifactId>commons-daemon</artifactId>
                                    <version>${commons.daemon.libversion}</version>
                                    <classifier>bin-windows</classifier>
                                    <type>zip</type>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${daemon.dir}</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-elasticsearch</id>
                        <!-- generate-resources to allow stripping the version in process-resources -->
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.elasticsearch.distribution.zip</groupId>
                                    <artifactId>elasticsearch</artifactId>
                                    <type>zip</type>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <!-- This import is here rather than in bitbucket-parent to avoid version conflicts; search references
                 a more recent version of com.fasterxml.jackson -->
            <dependency>
                <groupId>com.atlassian.bitbucket.search</groupId>
                <artifactId>bitbucket-search-parent</artifactId>
                <version>${bitbucket.search.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <!-- These dependencies are referenced from src/main/assembly/bin.xml and are unpacked into the distribution.
         Dependencies which are unpacked using maven-dependency-plugin:unpack don't need to be listed here. -->
    <dependencies>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-distribution-launcher</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-distribution-licenses</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-webapp</artifactId>
            <type>war</type>
        </dependency>

        <dependency>
            <groupId>com.atlassian.elasticsearch</groupId>
            <artifactId>buckler-plugin</artifactId>
            <type>zip</type>
        </dependency>
    </dependencies>
</project>
