<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.atlassian.jira</groupId>
    <artifactId>jira-plugins</artifactId>
    <version>4.3</version>
  </parent>
  <artifactId>jira-rest-plugin</artifactId>
  <name>JIRA REST Plugin</name>
  <description>Provides a REST interface for JIRA</description>
  <packaging>jar</packaging>
  <properties>
    <atlassian.plugin.key>com.atlassian.jira.rest</atlassian.plugin.key>
    <restdoc.directory>${project.build.directory}/restapi</restdoc.directory>
  </properties>
  <build>
    <plugins>
      <plugin>
        <groupId>org.twdata.maven</groupId>
        <artifactId>maven-cli-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>rest-apidocs</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
        <build>
          <plugins>
            <plugin>
              <groupId>org.twdata.maven</groupId>
              <artifactId>maven-cli-plugin</artifactId>
            </plugin>
            <plugin>
              <artifactId>maven-antrun-plugin</artifactId>
              <executions>
                <execution>
                  <id>schemaGen-plugin-description</id>
                  <phase>process-classes</phase>
                  <goals>
                    <goal>run</goal>
                  </goals>
                  <configuration>
                    <tasks>
                      <javadoc access="public" sourcepath="${project.build.sourceDirectory}" maxmemory="1024m" failonerror="true" useexternalfile="true">
                        <package name="com.atlassian.jira.rest.auth."/>
                        <package name="com.atlassian.jira.rest.v2."/>
                          <!-- Uncomment this line to enable remote debugging. <arg line="-J-Xdebug -J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"/>-->
                        <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"/>
                            <pathelement location="${project.build.outputDirectory}"/>
                          </path>
                          <param name="-output" value="${restdoc.directory}/resourcedoc.xml"/>
                          <param name="-expand" value="attachments,fields,comments.list,watchers.list,worklogs,groups"/>
                        </doclet>
                      </javadoc>
                    </tasks>
                  </configuration>
                </execution>
              </executions>
            </plugin>
            <plugin>
              <groupId>com.sun.jersey.contribs</groupId>
              <artifactId>maven-wadl-plugin</artifactId>
              <version>1.0.3</version>
              <executions>
                <execution>
                  <id>generate</id>
                  <goals>
                    <goal>generate</goal>
                  </goals>
                  <phase>process-classes</phase>
                </execution>
              </executions>
              <configuration>
                <wadlFile>${restdoc.directory}/jira-rest-plugin.wadl</wadlFile>
                <formatWadlFile>true</formatWadlFile>
                <baseUri>http://example.com:8080/jira/rest/</baseUri>
                <packagesResourceConfig>
                  <param>com.atlassian.jira.rest.auth</param>
                  <param>com.atlassian.jira.rest.v2</param>
                </packagesResourceConfig>
                <wadlGenerators>
                  <wadlGeneratorDescription>
                    <className>com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc</className>
                    <properties>
                      <property>
                        <name>applicationDocsFile</name>
                        <value>${basedir}/src/main/doc/application-doc.xml</value>
                      </property>
                    </properties>
                  </wadlGeneratorDescription>
                  <wadlGeneratorDescription>
                    <className>com.sun.jersey.server.wadl.generators.WadlGeneratorGrammarsSupport</className>
                    <properties>
                      <property>
                        <name>grammarsFile</name>
                        <value>${basedir}/src/main/doc/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>exec-maven-plugin</artifactId>
              <version>1.2</version>
              <executions>
                <execution>
                  <id>exec-xsltproc</id>
                  <goals>
                    <goal>exec</goal>
                  </goals>
                  <phase>package</phase>
                  <configuration>
                    <executable>xsltproc</executable>
                    <commandlineArgs>-o ${restdoc.directory}/index.html src/main/doc/wadl-documentation.xsl ${restdoc.directory}/jira-rest-plugin.wadl</commandlineArgs>
                  </configuration>
                </execution>
              </executions>
            </plugin>
            <plugin>
              <artifactId>maven-resources-plugin</artifactId>
              <version>2.4.3</version>
              <executions>
                <execution>
                  <id>copy-resources</id>
                  <phase>validate</phase>
                  <goals>
                    <goal>copy-resources</goal>
                  </goals>
                  <configuration>
                    <outputDirectory>${restdoc.directory}</outputDirectory>
                    <resources>
                      <resource>
                        <directory>src/main/js</directory>
                        <filtering>true</filtering>
                      </resource>
                    </resources>
                  </configuration>
                </execution>
              </executions>
            </plugin>
            <plugin>
              <artifactId>maven-assembly-plugin</artifactId>
              <executions>
                <execution>
                  <id>create-api-zip</id>
                  <phase>package</phase>
                  <goals>
                    <goal>single</goal>
                  </goals>
                  <configuration>
                    <descriptors>
                      <descriptor>src/main/assembly/api.xml</descriptor>
                    </descriptors>
                  </configuration>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </build>
    </profile>
    <!-- upload apidocs when performing a release, or when this profile is explicitly activated (e.g. in NIGHTLY) -->
    <profile>
      <id>rest-apidocs-deploy</id>
      <activation>
        <activeByDefault>false</activeByDefault>
        <property>
          <name>performRelease</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>com.atlassian.maven.plugins</groupId>
            <artifactId>maven-upload-plugin</artifactId>
            <version>1.1</version>
            <executions>
              <execution>
                <id>upload-api-to-docs</id>
                <phase>deploy</phase>
                <goals>
                  <goal>upload</goal>
                </goals>
                <configuration>
                  <resourceSrc>${restdoc.directory}/*</resourceSrc>
                  <serverId>atlassian-documentation</serverId>
                  <url>dav:https://docs.atlassian.com</url>
                  <resourceDest>jira/REST/${project.version}</resourceDest>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

  <dependencies>
    <!-- for some obscure reason it needs to be a module dep and not just a dep of the antrun plugin (ask Min'an) -->
    <dependency>
      <groupId>com.atlassian.plugins.rest</groupId>
      <artifactId>atlassian-rest-doclet</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.ws.rs</groupId>
      <artifactId>jsr311-api</artifactId>
    </dependency>
    <dependency>
      <groupId>javax.xml.bind</groupId>
      <artifactId>jaxb-api</artifactId>
    </dependency>
    <dependency>
      <groupId>com.atlassian.plugins.rest</groupId>
      <artifactId>atlassian-rest-common</artifactId>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.4</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aop</artifactId>
    </dependency>
  </dependencies>
</project>
