<?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>

    <groupId>com.atlassian.stash</groupId>
    <artifactId>stash-docs</artifactId>
    <name>Atlassian Stash Documentation</name>

    <parent>
        <artifactId>stash-parent</artifactId>
        <groupId>com.atlassian.stash</groupId>
        <version>2.8.0-m5</version>
    </parent>
	<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>
    </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>
            <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>${project.basedir}/src/site/resources/js/lib-combined.js</output>
                            <includes>
                                <include>**/*.js</include>
                            </includes>
                            <excludes>
                                <exclude>**/aui-all.js</exclude>
                                <exclude>**/html5.js</exclude>
                            </excludes>
                        </aggregation>
                        <aggregation>
                            <output>${project.basedir}/src/site/resources/css/all-combined.css</output>
                            <includes>
                                <include>**/*.css</include>
                            </includes>
                            <excludes>
                                <exclude>**/*-ie*.css</exclude>
                            </excludes>
                        </aggregation>
                    </aggregations>
                </configuration>
            </plugin>
            <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>${aui.version}</version>
                                    <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>
            <!-- Don't hate me, you can't do this in the dependency plugin -->
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <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>
            <!--
            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>

    <reporting>
        <plugins>
            <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>
                    </excludedLinks>
                    <excludedHttpStatusErrors>
                        <!-- ignore method not allowed -->
                        <excludedHttpStatusErrors>405</excludedHttpStatusErrors>
                    </excludedHttpStatusErrors>
					<excludedPages>
						<excludedPage>license.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>
        </plugins>
    </reporting>

</project>
