<?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.atlassian.bitbucket.server</groupId>
        <artifactId>bitbucket-scm-parent</artifactId>
        <version>7.5.0-rc1</version>
    </parent>

    <artifactId>bitbucket-git</artifactId>

    <name>Bitbucket Server - Git SCM</name>
    <description>Provides support for the Git SCM</description>

    <dependencies>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-git-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-git-binary</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-git-common</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-model</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-platform</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-process-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-process</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-scm-cache</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-scm-common</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-spi</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-util</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-web-common</artifactId>
        </dependency>

        <dependency>
            <groupId>com.atlassian.event</groupId>
            <artifactId>atlassian-event</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.sal</groupId>
            <artifactId>sal-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.sal</groupId>
            <artifactId>sal-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.scheduler</groupId>
            <artifactId>atlassian-scheduler-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.soy</groupId>
            <artifactId>soy-template-renderer-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.support</groupId>
            <artifactId>stp-spi</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.util</groupId>
            <artifactId>content-cache</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.utils</groupId>
            <artifactId>atlassian-processutils</artifactId>
        </dependency>
        <dependency>
            <groupId>io.atlassian.fugue</groupId>
            <artifactId>fugue</artifactId>
        </dependency>
        <dependency>
            <groupId>io.atlassian.fugue</groupId>
            <artifactId>fugue-retry</artifactId>
        </dependency>
        <dependency>
            <groupId>io.atlassian.util.concurrent</groupId>
            <artifactId>atlassian-util-concurrent</artifactId>
        </dependency>

        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>nuprocess</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
        </dependency>

        <!-- Repositories with fixed test data -->
        <dependency>
            <groupId>com.atlassian.bitbucket.server.git</groupId>
            <artifactId>gpg-sanity</artifactId>
            <type>zip</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server.git</groupId>
            <artifactId>ref-sanity</artifactId>
            <type>zip</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.stash.git</groupId>
            <artifactId>binary-files-repository</artifactId>
            <type>zip</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.stash.git</groupId>
            <artifactId>comment-drift</artifactId>
            <type>zip</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.stash.git</groupId>
            <artifactId>default-repository</artifactId>
            <type>zip</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.stash.git</groupId>
            <artifactId>diff-tree</artifactId>
            <type>zip</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.stash.git</groupId>
            <artifactId>garbage</artifactId>
            <type>zip</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.stash.git</groupId>
            <artifactId>mailmap</artifactId>
            <type>zip</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.stash.git</groupId>
            <artifactId>merge</artifactId>
            <type>zip</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.stash.git</groupId>
            <artifactId>merge-commits</artifactId>
            <type>zip</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.stash.git</groupId>
            <artifactId>pull-requests</artifactId>
            <type>zip</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.stash.git</groupId>
            <artifactId>qa-resources</artifactId>
            <type>zip</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.stash.git</groupId>
            <artifactId>subrepositories</artifactId>
            <type>zip</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.stash.git</groupId>
            <artifactId>suggestion-drift</artifactId>
            <type>zip</type>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-branch</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-scm-test-util</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-service-impl</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-ssh</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-suggestions</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.bitbucket.server</groupId>
            <artifactId>bitbucket-test-util</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.atlassian.cache</groupId>
            <artifactId>atlassian-cache-memory</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.github.tomakehurst</groupId>
            <artifactId>wiremock</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>de.schlichtherle.truezip</groupId>
            <artifactId>truezip-file</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>de.schlichtherle.truezip</groupId>
            <artifactId>truezip-driver-zip</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>de.schlichtherle.truezip</groupId>
            <artifactId>truezip-driver-tar</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.el</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-text-patterns</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>log4j-over-slf4j</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>bitbucket-plugin.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <excludes>
                    <exclude>bitbucket-plugin.xml</exclude>
                </excludes>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
            </testResource>
            <testResource>
                <directory>src/main/templates</directory>
                <excludes>
                    <exclude>config</exclude>
                </excludes>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-scripts</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <appendAssemblyId>false</appendAssemblyId>
                            <attach>false</attach>
                            <descriptors>
                                <descriptor>src/main/assembly/scripts.xml</descriptor>
                            </descriptors>
                            <finalName>scripts</finalName>
                            <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>package-templates</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <appendAssemblyId>false</appendAssemblyId>
                            <attach>false</attach>
                            <descriptors>
                                <descriptor>src/main/assembly/templates.xml</descriptor>
                            </descriptors>
                            <finalName>templates</finalName>
                            <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <excludeArtifactIds>git</excludeArtifactIds>
                            <excludeTransitive>true</excludeTransitive>
                            <includeScope>test</includeScope>
                            <includeTypes>zip</includeTypes>
                            <outputDirectory>${project.build.testOutputDirectory}/git</outputDirectory>
                            <stripVersion>true</stripVersion>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <!-- DO NOT USE THIS PROFILE UNDER ANY OS BUT WINDOWS.
             - The git packages contain Windows binaries and will not run on Linux or MacOS
             - Unpacking uses the exec-maven-plugin to run "7za", which is a Windows binary
             - There are probably other issues lurking as well

             This profile exists to support git version matrix testing on BEAC, but it may also be used by developers
             who run Windows. -->
        <profile>
            <id>git-windows</id>
            <activation>
                <property>
                    <name>gfw.version</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <!-- Copy the Git distribution into the target directory. This is expected to be a
                                 "PortableGit" distribution packed using 7-zip compression. -->
                            <execution>
                                <id>copy-git</id>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                                <configuration>
                                    <excludeTransitive>true</excludeTransitive>
                                    <includeArtifactIds>git</includeArtifactIds>
                                    <includeScope>test</includeScope>
                                    <includeTypes>${git.artifact.type}</includeTypes>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                </configuration>
                            </execution>
                            <!-- Copy the 7za binary into the target directory. It will be used to unzip the
                                 "PortableGit" distribution copied above. -->
                            <execution>
                                <id>copy-7za</id>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                                <configuration>
                                    <excludeTransitive>true</excludeTransitive>
                                    <includeArtifactIds>7za</includeArtifactIds>
                                    <includeScope>test</includeScope>
                                    <includeTypes>exe</includeTypes>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                    <stripVersion>true</stripVersion>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- Since plexus-utils 3.1.0 (which is a transitive dependency of maven-dependency-plugin),
                         files are copied using Files.copy, also copying any file attributes. On some Windows
                         machines, this means copying the .exe without execute permissions. The following code
                         adds the executable permission again for the owner of the file. -->
                    <plugin>
                        <groupId>org.codehaus.gmavenplus</groupId>
                        <artifactId>gmavenplus-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>7za-set-executable</id>
                                <goals>
                                    <goal>execute</goal>
                                </goals>
                                <phase>generate-resources</phase>
                                <configuration>
                                    <scripts>
                                        <script><![CDATA[
                                            import java.nio.file.Files
                                            import java.nio.file.Paths
                                            import java.nio.file.attribute.AclEntry
                                            import java.nio.file.attribute.AclFileAttributeView

                                            import static java.nio.file.attribute.AclEntryPermission.EXECUTE
                                            import static java.nio.file.attribute.AclEntryPermission.READ_DATA
                                            import static java.nio.file.attribute.AclEntryType.ALLOW

                                            def view = Files.getFileAttributeView(Paths.get($/${project.build.directory}/$ + File.separator + '7za.exe'), AclFileAttributeView)
                                            def acl = view.getAcl()
                                            if (acl.find { view.getOwner() == it.principal() && it.permissions().contains(EXECUTE) } == null) {
                                                println 'File was missing EXECUTE permission, trying to add...'
                                                def entry = AclEntry.newBuilder()
                                                        .setType(ALLOW)
                                                        .setPrincipal(view.getOwner())
                                                        .setPermissions(EXECUTE, READ_DATA)
                                                        .build()
                                                acl.add(entry)
                                                view.setAcl(acl)
                                            }
                                            ]]></script>
                                    </scripts>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- Run 7za to unpack the "PortableGit" distribution into ${git.root}. As 7za is a Windows
                         executable, this will only work on Windows. -->
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>unzip-git</id>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <phase>generate-resources</phase>
                                <configuration>
                                    <arguments>
                                        <argument>x</argument>
                                        <argument>-o${git.root}</argument>
                                        <argument>${project.build.directory}/git-${gfw.version}-${git.artifact.classifier}.${git.artifact.type}</argument>
                                    </arguments>
                                    <executable>${project.build.directory}/7za</executable>
                                    <outputFile>NUL</outputFile>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            <dependencies>
                <dependency>
                    <groupId>com.atlassian.bitbucket.git</groupId>
                    <artifactId>git</artifactId>
                    <version>${gfw.version}</version>
                    <type>${git.artifact.type}</type>
                    <classifier>${git.artifact.classifier}</classifier>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.7zip</groupId>
                    <artifactId>7za</artifactId>
                    <version>9.20</version>
                    <type>exe</type>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <properties>
                <git.artifact.classifier>windows</git.artifact.classifier>
                <git.artifact.type>7z</git.artifact.type>
                <git.root>${project.build.directory}/git-${gfw.version}</git.root>
                <!-- Starting from 1.7.11, Git for Windows has a git.exe in cmd (earlier versions had git.cmd
                     instead). With the Git for Windows 2.x line, it is now _mandatory_ to run the Git tests
                     using cmd/git.exe rather than bin/git.exe. Using git.exe results in commands like clone
                     and init failing because they can't find the git-core commands. -->
                <git.cmd>${git.root}/cmd</git.cmd>
                <!-- Pass the path to the git executable to the forked Java process used by Surefire to execute
                     the unit tests. This will make the test run using the "PortableGit" distribution instead
                     of the installed git, allowing testing for specific versions. -->
                <surefire.git>-Dplugin.bitbucket-git.path.executable=${git.cmd}/git.exe</surefire.git>
                <surefire.argLine>${surefire.commonArgLine} ${surefire.git}</surefire.argLine>
            </properties>
        </profile>
        <!-- Adds a second surefire:test execution which enables BIO processes. This profile is active unless
             -DskipBio=true is specified. (Note that -DskipTests will also skip the BIO tests.) -->
        <profile>
            <id>bio</id>
            <activation>
                <property>
                    <name>skipBio</name>
                    <value>!true</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>bio-test</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <configuration>
                                    <!-- Only run Git tests; other tests are expected to be BIO/NIO agnostic -->
                                    <groups>com.atlassian.stash.internal.scm.git.AbstractGitTest</groups>
                                    <reportNameSuffix>${bioReportNameSuffix}</reportNameSuffix>
                                    <systemPropertyVariables>
                                        <spring.profiles.active>bio</spring.profiles.active>
                                    </systemPropertyVariables>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <bioReportNameSuffix>bio</bioReportNameSuffix>
            </properties>
        </profile>
    </profiles>
</project>
