<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>2.10.5-j11</version>
    </parent>

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

    <packaging>pom</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 (including appmanagement, that are note currently 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>

        <!-- 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>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>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>

                <executions>
                    <execution>
                        <id>copy-combined-atlassian-plugin-xml</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>resources</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>copy-xsl-resources</id>
                        <phase>validate</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>validate</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>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <!-- Generating REST API docs-->
                    <execution>
                        <id>schemaGen-plugin-description</id>
                        <phase>process-classes</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>prepare-package</phase>
                    </execution>
                </executions>

                <configuration>
                    <wadlFile>${restdoc.directory}/crowd-rest-plugin.wadl</wadlFile>
                    <formatWadlFile>true</formatWadlFile>
                    <baseUri>http://CROWD-SERVER:8095/rest/</baseUri>
                    <packagesResourceConfig>
                        <param>com.atlassian.crowd.plugin.rest.service.resource.usermanagement</param>

                        <!-- these two come from crowd-rest-application-management, not public api at the moment -->
                        <param>com.atlassian.crowd.plugin.rest.service.resource.permission</param>
                        <param>com.atlassian.crowd.plugin.rest.service.resource.application</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>package</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>

    <properties>
        <restdoc.directory>${project.build.directory}/restapi</restdoc.directory>
        <xsl.directory>${project.build.directory}/xsl</xsl.directory>
    </properties>
</project>
