<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.crowd</groupId>
        <artifactId>crowd-rest</artifactId>
        <version>3.4.4-m01-dacuploadtest-2</version>
    </parent>

    <artifactId>crowd-rest-documentation</artifactId>

    <packaging>jar</packaging>

    <name>Atlassian Crowd REST Documentation</name>

    <description>Generates user documentation for Crowd's REST resources</description>

    <dependencies>
        <!-- plugins with rest resources we document (see also src/main/resources/atlassian-plugin.xml -->
        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>crowd-rest-plugin</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!-- these define extra resources that should be documented -->
        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>crowd-rest-application-management</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!-- we don't inherit provided deps, so need the explicitly here -->
        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>crowd-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>crowd-integration-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>crowd-server-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>embedded-crowd-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>crowd-server-common</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>crowd-query-language</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.sal</groupId>
            <artifactId>sal-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>crowd-remote</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.scheduler</groupId>
            <artifactId>atlassian-scheduler-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.crowd</groupId>
            <artifactId>crowd-ldap</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </dependency>
        <!-- doclet/wadl deps -->
        <dependency>
            <groupId>com.atlassian.jersey</groupId>
            <artifactId>atlassian-jersey-restdoc</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins.rest</groupId>
            <artifactId>atlassian-rest-doclet</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins.rest</groupId>
            <artifactId>atlassian-rest-common</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.annotations</groupId>
            <artifactId>atlassian-annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>distribution</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-resources-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-xsl-resources</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${xsl.directory}</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>${basedir}/src/main/doc</directory>
                                            <filtering>true</filtering>
                                            <excludes>
                                                <exclude>static/**</exclude>
                                            </excludes>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                            <execution>
                                <id>copy-page-resources</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${restdoc.directory}</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>src/main/doc/static</directory>
                                            <filtering>true</filtering>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                            <execution>
                                <id>copy-combined-atlassian-plugin-xml</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>resources</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <!-- Generating REST API docs-->
                            <execution>
                                <id>schemaGen-plugin-description</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <tasks>
                                        <javadoc access="public" maxmemory="1024m" failonerror="true" useexternalfile="yes">
                                            <fileset dir="${project.basedir}/..">
                                                <include name="crowd-rest-plugin/src/main/**/*.java" />
                                                <include name="crowd-rest-application-management/src/main/**/*.java" />
                                            </fileset>
                                            <package name="com.atlassian.crowd.plugin.rest." />
                                            <!-- Uncomment the line below enable remote debugging. -->
                                            <!--<arg line="-J-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000" />-->
                                            <classpath>
                                                <path refid="maven.compile.classpath" />
                                                <pathelement location="${project.build.outputDirectory}" />
                                            </classpath>
                                            <doclet name="com.sun.jersey.wadl.resourcedoc.ResourceDocletJSON">
                                                <path>
                                                    <path refid="maven.plugin.classpath" />
                                                    <path refid="maven.compile.classpath" />
                                                    <path refid="maven.runtime.classpath" />
                                                    <pathelement location="${project.build.outputDirectory}" />
                                                </path>
                                                <param name="-output" value="${project.build.outputDirectory}/resourcedoc.xml" />
                                                <param name="-expand" value="attributes,group,user" />
                                            </doclet>
                                        </javadoc>
                                        <copy file="${project.build.outputDirectory}/resourcedoc.xml" tofile="${restdoc.directory}/resourcedoc.xml" />
                                    </tasks>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>com.sun.jersey.contribs</groupId>
                        <artifactId>maven-wadl-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>generate</id>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                                <phase>generate-resources</phase>
                            </execution>
                        </executions>

                        <dependencies>
                            <dependency>
                                <groupId>org.codehaus.jackson</groupId>
                                <artifactId>jackson-mapper-asl</artifactId>
                                <version>${jackson.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>com.fasterxml.jackson.core</groupId>
                                <artifactId>jackson-annotations</artifactId>
                                <version>2.8.0</version>
                            </dependency>
                            <dependency>
                                <groupId>org.reflections</groupId>
                                <artifactId>reflections</artifactId>
                                <version>0.9.10</version>
                            </dependency>
                        </dependencies>

                        <configuration>
                            <wadlFile>${restdoc.directory}/crowd-rest-plugin.wadl</wadlFile>
                            <formatWadlFile>true</formatWadlFile>
                            <baseUri>http://CROWD-SERVER:8095/rest/</baseUri>
                            <packagesResourceConfig>
                                <!-- from crowd-rest-plugin -->
                                <param>com.atlassian.crowd.plugin.rest.service.resource.usermanagement</param>
                                <!-- these come from crowd-rest-application-management, parts that are exposed as public api -->
                                <param>com.atlassian.crowd.plugin.rest.service.resource.admin</param>
                                <param>com.atlassian.crowd.plugin.rest.service.resource.audit</param>
                                <param>com.atlassian.crowd.plugin.rest.service.resource.memberships</param>
                                <param>com.atlassian.crowd.plugin.rest.service.resource.directory</param>
                                <param>com.atlassian.crowd.plugin.rest.service.resource.saml</param>
                            </packagesResourceConfig>
                            <wadlGenerators>
                                <wadlGeneratorDescription>
                                    <className>com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc
                                    </className>
                                    <properties>
                                        <property>
                                            <name>applicationDocsFile</name>
                                            <value>${xsl.directory}/application-doc.xml</value>
                                        </property>
                                    </properties>
                                </wadlGeneratorDescription>
                                <wadlGeneratorDescription>
                                    <className>com.sun.jersey.server.wadl.generators.WadlGeneratorGrammarsSupport
                                    </className>
                                    <properties>
                                        <property>
                                            <name>grammarsFile</name>
                                            <value>${xsl.directory}/application-grammars.xml</value>
                                        </property>
                                    </properties>
                                </wadlGeneratorDescription>
                                <wadlGeneratorDescription>
                                    <className>
                                        com.atlassian.plugins.rest.doclet.generators.resourcedoc.AtlassianWadlGeneratorResourceDocSupport
                                    </className>
                                    <properties>
                                        <property>
                                            <name>resourceDocFile</name>
                                            <value>${restdoc.directory}/resourcedoc.xml</value>
                                        </property>
                                    </properties>
                                </wadlGeneratorDescription>
                            </wadlGenerators>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>xml-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>transform</goal>
                                </goals>
                                <phase>generate-resources</phase>
                            </execution>
                        </executions>
                        <configuration>
                            <transformationSets>
                                <transformationSet>
                                    <dir>${restdoc.directory}</dir>
                                    <includes>
                                        <include>crowd-rest-plugin.wadl</include>
                                    </includes>
                                    <stylesheet>${xsl.directory}/wadl-documentation.xsl</stylesheet>
                                    <outputProperties>
                                        <outputProperty>
                                            <name>indent</name>
                                            <value>no</value>
                                        </outputProperty>
                                    </outputProperties>
                                    <outputDir>${restdoc.directory}</outputDir>
                                    <fileMappers>
                                        <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
                                            <pattern>crowd-rest-plugin.wadl</pattern>
                                            <replacement>index.html</replacement>
                                        </fileMapper>
                                    </fileMappers>
                                </transformationSet>
                            </transformationSets>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    <properties>
        <restdoc.directory>${project.build.outputDirectory}</restdoc.directory>
        <xsl.directory>${project.build.directory}/xsl</xsl.directory>
    </properties>
</project>
