<?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-parent</artifactId>
        <version>4.9.0-rc4</version>
    </parent>

    <artifactId>bitbucket-docs</artifactId>
    <name>Bitbucket Server - Documentation</name>

	<properties>
		<linkcheck.offline>true</linkcheck.offline>
		<linkcheck.extra.exclude>aLongCustomHackStringThatShouldNotMatchAURLInTheDocs</linkcheck.extra.exclude>
        <linkcheck.timeout>10000</linkcheck.timeout>
        <site.resources>${project.basedir}/src/site/resources</site.resources>

        <!-- allow Bamboo and users not to have to enter their credentials to get the bower repo-->
        <bower.registry.clone.url>ssh://git@stash.atlassian.com:7997/BOWER/bower-registry.git</bower.registry.clone.url>
        <bower.lib.dir>${project.basedir}/src/site/resources/bower_components</bower.lib.dir>
    </properties>

    <build>
        <resources>
            <resource>
                <directory>target/site</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.html</include>
                </includes>
            </resource>
            <resource>
                <directory>target/site</directory>
                <filtering>false</filtering>
                <excludes>
                    <exclude>**/*.html</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <templateFile>${basedir}/maven-site.vm</templateFile>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>doxia-module-markdown</artifactId>
                        <version>1.0.1</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <!-- Workaround for http://jira.codehaus.org/browse/MRESOURCES-104 -->
                    <delimiters>
                        <delimiter>${*}</delimiter>
                    </delimiters>
                    <useDefaultDelimiters>false</useDefaultDelimiters>
                </configuration>
            </plugin>
            <!-- NOTE: the order of the next 3 plugin configs must not be changed, as they are bound to the same phase
                 (pre-site) and are dependent upon each other - the compression/aggregation relies on AUI resources
                 already copied and moved to $site.resources beforehand -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <id>unpack-aui</id>
                        <phase>pre-site</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.atlassian.aui</groupId>
                                    <artifactId>aui-flat-pack</artifactId>
                                    <version>5.3.1-aui-soy-backport</version> <!-- TEMPORARY ONLY - should revert back to ${aui.version} once an AUI release in flat-pack form is available -->
                                    <type>zip</type>
                                    <includes>
                                        aui/aui/css/aui-all.css,
                                        aui/aui/css/aui-ie*.css,
                                        aui/aui/css/atlassian-icons.*,
                                        aui/aui/js/aui-all.js,
                                        aui/aui/js/aui-ie.js,
                                        aui/css/aui-ie*.css,
                                    </includes>
                                    <outputDirectory>${site.resources}</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-linkcheck-plugin</artifactId>
                <version>1.1</version>
                <configuration>
                    <excludedLinks>
                        <excludedLink>${linkcheck.extra.exclude}</excludedLink>
                        <excludedLink>http://www.microsoft.com/en-us/download/details.aspx?id=11774</excludedLink>
                        <excludedLink>http://localhost:7990/rest/api/1.0/projects/PROJ_KEY/repos/REPO/commits/</excludedLink>
                        <excludedLink>http://www.atlassian.com/feeds</excludedLink>
                        <excludedLink>http://localhost:7990/stash</excludedLink>
                        <excludedLink>http://localhost:7990/bitbucket</excludedLink>
                        <!-- Ignore links to line numbers - these are handled programmatically -->
                        <excludedLink>**.html#line-*</excludedLink>
                    </excludedLinks>
                    <excludedHttpStatusErrors>
                        <!-- ignore method not allowed -->
                        <excludedHttpStatusErrors>405</excludedHttpStatusErrors>
                    </excludedHttpStatusErrors>
                    <excludedPages>
                        <excludedPage>license.html</excludedPage>
                        <excludedPage>**/bower_components/**/*.html</excludedPage>
                    </excludedPages>
                    <!-- Links to bitbucket are slow to resolve, setting timeout does not seem to be enough -->
                    <timeout>${linkcheck.timeout}</timeout>
                    <!-- So set the httpclient params explicitly: http://maven.apache.org/plugins/maven-linkcheck-plugin/linkcheck-mojo.html#httpClientParameters -->
                    <httpClientParameters>
                        <property>
                            <name>http.socket.timeout</name>
                            <value>${linkcheck.timeout}</value>
                        </property>
                        <property>
                            <name>http.connection.timeout</name>
                            <value>${linkcheck.timeout}</value>
                        </property>
                        <property>
                            <name>http.connection-manager.timeout</name>
                            <value>${linkcheck.timeout}</value>
                        </property>
                        <property>
                            <name>http.protocol.head-body-timeout</name>
                            <value>${linkcheck.timeout}</value>
                        </property>
                    </httpClientParameters>
                </configuration>
            </plugin>
            <plugin>
                <!--
                    We are using the bower-maven plugin to take advantage of our internal Bower server.

                    When we have a dedicated Bower server that we can use BTF withouth authentication,
                    we can switch to simply using `bower install`.
                -->
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>bower-maven-plugin</artifactId>
                <version>0.3</version>
                <configuration>
                    <outputDirectory>${bower.lib.dir}</outputDirectory>
                    <registryCloneUrl>${bower.registry.clone.url}</registryCloneUrl>
                </configuration>
                <executions>
                    <execution>
                        <phase>pre-site</phase>
                        <goals>
                            <goal>fetch-modules</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Don't hate me, you can't do this in the dependency plugin -->
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <!-- Generate the JSDocs before moving the resources -->
                    <execution>
                        <phase>pre-site</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <echo>NPM INSTALL</echo>
                                <exec executable="npm.cmd" dir="${project.basedir}" osfamily="windows" failonerror="true">
                                    <arg line="install" />
                                </exec>
                                <exec executable="npm" dir="${project.basedir}" osfamily="unix" failonerror="true">
                                    <arg line="install" />
                                </exec>
                                <echo>Generate JSDoc</echo>
                                <exec executable="node_modules/.bin/jsdoc.cmd" dir="${project.basedir}" osfamily="windows" resultproperty="cmdresult" failonerror="true">
                                    <arg line="-c jsdoc-conf.json -t jsdoc-template -r" />
                                </exec>
                                <exec executable="node_modules/.bin/jsdoc" dir="${project.basedir}" osfamily="unix" resultproperty="cmdresult" failonerror="true">
                                    <arg line="-c jsdoc-conf.json -t jsdoc-template -r" />
                                </exec>
                            </target>
                        </configuration>
                    </execution>

                    <execution>
                        <id>move-resources</id>
                        <phase>pre-site</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <move failonerror="false" todir="${site.resources}">
                                    <fileset dir="${site.resources}/aui/aui" includes="**" />
                                </move>
                                <move failonerror="false" todir="${site.resources}/js/lib">
                                    <fileset dir="${site.resources}/js" includes="aui-*.js" />
                                </move>
                                <!-- Remove on newer versions of AUI -->
                                <move failonerror="false" todir="${site.resources}/css">
                                    <fileset dir="${site.resources}/aui/css" includes="**" />
                                </move>
                                <!-- Since we are not serving the JS files dynamically we need to do the i18n translation,
                                however there are currently no english i18n files in the flatpack.
                                See https://ecosystem.atlassian.net/browse/AUI-1602
                                -->
                                <replace token="aui.words.more" value="More..." dir="${site.resources}/js/lib">
                                    <include name="aui-*.js" />
                                </replace>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>yuicompressor-maven-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <id>aggregate-assets</id>
                        <goals>
                            <goal>compress</goal>
                        </goals>
                        <phase>pre-site</phase>
                    </execution>
                </executions>
                <configuration>
                    <excludes>
                        <exclude>*/*</exclude>
                    </excludes>
                    <force>true</force>
                    <nosuffix>true</nosuffix>
                    <removeIncluded>true</removeIncluded>
                    <insertNewLine>true</insertNewLine>
                    <aggregations>
                        <aggregation>
                            <output>${site.resources}/js/lib-combined.js</output>
                            <includes>
                                <!-- Order matters here - please include CodeMirror before its modes/addons -->
                                <include>${site.resources}/bower_components/CodeMirror/lib/codemirror.js</include>
                                <include>${site.resources}/bower_components/CodeMirror/mode/clike/clike.js</include>
                                <include>${site.resources}/bower_components/CodeMirror/mode/javascript/javascript.js</include>
                                <include>${site.resources}/bower_components/CodeMirror/mode/properties/properties.js</include>
                                <include>${site.resources}/bower_components/CodeMirror/mode/smarty/smarty.js</include>
                                <include>${site.resources}/bower_components/CodeMirror/mode/xml/xml.js</include>
                                <include>**/*.js</include>
                            </includes>
                            <excludes>
                                <exclude>**/aui-all.js</exclude>
                                <exclude>**/html5.js</exclude>
                            </excludes>
                        </aggregation>
                        <aggregation>
                            <output>${site.resources}/css/all-combined.css</output>
                            <includes>
                                <!--
                                    Order matters here - please include CodeMirror styles before other stylesheets
                                    so we can override if necessary
                                -->
                                <include>${site.resources}/bower_components/CodeMirror/lib/codemirror.css</include>
                                <include>**/*.css</include>
                            </includes>
                            <excludes>
                                <exclude>**/*-ie*.css</exclude>
                            </excludes>
                        </aggregation>
                    </aggregations>
                </configuration>
            </plugin>
            <!--
            This is a terrible plugin - but might be a place to start
            http://maven.40175.n5.nabble.com/Maven-Site-Indexer-plugin-td4986538.html
            -->
            <!--
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>index</artifactId>
                <version>0.0.1-SNAPSHOT</version>
                <executions>
                    <execution>
                        <phase>site</phase>
                        <goals>
                            <goal>index</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            -->
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>check</id>
            <properties>
                <linkcheck.extra.exclude>https://**/${project.version}/**</linkcheck.extra.exclude>
            </properties>
        </profile>
    </profiles>
</project>
