<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.bamboo</groupId>
    <artifactId>atlassian-bamboo-plugins2-parent</artifactId>
    <version>4.3-M3</version>
  </parent>

  <groupId>com.atlassian.bamboo.plugins</groupId>
  <artifactId>atlassian-bamboo-plugin-rest</artifactId>
  <version>4.3-M3</version>
  <packaging>atlassian-plugin</packaging>

  <name>Atlassian Bamboo REST plugin</name>
  <description>REST API for Bamboo</description>

  <properties>
    <atlassian.plugin.key>com.atlassian.bamboo.plugins.rest</atlassian.plugin.key>
    <atlassian.product.version>${project.version}</atlassian.product.version>
    <atlassian.product.data.version>3.2.2</atlassian.product.data.version>
    <!--keep it as close as possible to ${atlassian.rest.jersey.version}-->
    <jersey-release-version>1.8</jersey-release-version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.atlassian.bamboo</groupId>
      <artifactId>atlassian-bamboo-web</artifactId>
    </dependency>

    <dependency>
      <groupId>com.atlassian.bamboo</groupId>
      <artifactId>atlassian-bamboo-charts</artifactId>
    </dependency>

    <dependency>
      <groupId>com.atlassian.plugins.rest</groupId>
      <artifactId>atlassian-rest-common</artifactId>
    </dependency>

    <dependency>
      <groupId>com.atlassian.fugue</groupId>
      <artifactId>fugue</artifactId>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <profiles>
    <profile>
      <id>restdoc</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>com.sun.tools.jxc.maven2</groupId>
            <artifactId>maven-jaxb-schemagen-plugin</artifactId>
            <version>1.2</version>
            <executions>
              <execution>
                <id>00</id>
                <phase>pre-site</phase>
                <goals>
                  <goal>generate</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <includes>
                <inclde>com/atlassian/bamboo/plugins/rest/model/*/*.java</inclde>
                <inclde>com/atlassian/bamboo/plugins/rest/resource/*.java</inclde>
              </includes>
              <excludes>
                <exclude>com/atlassian/bamboo/plugins/rest/common/*.java</exclude>
                <exclude>com/atlassian/bamboo/plugins/rest/model/documentation/*.java</exclude>
              </excludes>
              <schemas>
                <schema>
                  <namespace>http://atlassian.com/</namespace>
                  <file>schema-mvn.xsd</file>
                </schema>
              </schemas>
              <destdir>target/classes</destdir>
              <srcdir>src/main/java</srcdir>
              <verbose>true</verbose>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <executions>
              <execution>
                <phase>pre-site</phase>
                <goals>
                  <goal>compile</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>01-copy-docs-to-builddir</id>
                <goals>
                  <goal>exec</goal>
                </goals>
                <phase>pre-site</phase>
                <configuration>
                  <executable>cp</executable>
                  <commandlineArgs>src/main/doc/application-doc.xml src/main/doc/application-grammars.xml target/classes/</commandlineArgs>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.8.1</version>
            <executions>
              <execution>
                <id>02-schemaGen-plugin-description</id>
                <phase>pre-site</phase>
                <goals>
                  <goal>javadoc</goal>
                </goals>
                <configuration>
                  <verbose>false</verbose>
                  <show>public</show>
                  <subpackages>com</subpackages>
                  <doclet>com.sun.jersey.wadl.resourcedoc.ResourceDoclet</doclet>
                  <docletArtifacts>
                    <docletArtifact>
                      <groupId>com.sun.jersey.contribs</groupId>
                      <artifactId>wadl-resourcedoc-doclet</artifactId>
                      <version>1.8</version>
                    </docletArtifact>
                    <docletArtifact>
                      <groupId>com.sun.jersey.samples</groupId>
                      <artifactId>generate-wadl</artifactId>
                      <version>1.8</version>
                    </docletArtifact>
                    <docletArtifact>
                      <groupId>xerces</groupId>
                      <artifactId>xercesImpl</artifactId>
                      <version>${xerces.version}</version>
                    </docletArtifact>
                    <docletArtifact>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>${project.artifactId}</artifactId>
                      <version>4.3-M3</version>
                    </docletArtifact>
                  </docletArtifacts>
                  <additionalparam>-output ${project.build.outputDirectory}/resourcedoc.xml -processors com.sun.jersey.samples.generatewadl.util.ExampleDocProcessor</additionalparam>
                  <useStandardDocletOptions>false</useStandardDocletOptions>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>com.sun.jersey.contribs</groupId>
            <artifactId>maven-wadl-plugin</artifactId>
            <version>1.8</version>
            <executions>
              <execution>
                <id>03-generate</id>
                <goals>
                  <goal>generate</goal>
                </goals>
                <phase>pre-site</phase>
              </execution>
            </executions>
            <configuration>
              <wadlFile>${project.build.outputDirectory}/application.wadl</wadlFile>
              <formatWadlFile>true</formatWadlFile>
              <baseUri>http://myhost.com:8085/bamboo/rest/api/latest/</baseUri>
              <packagesResourceConfig>
                <param>com.atlassian.bamboo.plugins.rest.resource</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.sun.jersey.server.wadl.generators.resourcedoc.WadlGeneratorResourceDocSupport</className>
                  <properties>
                    <property>
                      <name>resourceDocFile</name>
                      <value>${project.build.outputDirectory}/resourcedoc.xml</value>
                    </property>
                  </properties>
                </wadlGeneratorDescription>
              </wadlGenerators>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xml-maven-plugin</artifactId>
            <version>1.0</version>
            <executions>
              <execution>
                <id>04-xsl transform target/application.html</id>
                <goals>
                  <goal>transform</goal>
                </goals>
                <phase>site</phase>
                <configuration>
                  <transformationSets>
                    <transformationSet>
                      <dir>target/classes</dir>
                      <includes>
                        <include>application.wadl</include>
                      </includes>
                      <stylesheet>src/main/doc/wadl-documentation.xsl</stylesheet>
                    </transformationSet>
                  </transformationSets>
                  <!-- the XSL above requires EXSLT node-set support, which xalan doesn't provide? -->
                  <transformerFactory>net.sf.saxon.TransformerFactoryImpl</transformerFactory>
                </configuration>
              </execution>
            </executions>
            <dependencies>
              <dependency>
                <groupId>net.sf.saxon</groupId>
                <artifactId>saxon</artifactId>
                <version>8.7</version>
              </dependency>
            </dependencies>
          </plugin>

          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>05-prepare-docs</id>
                <phase>site</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <tasks>
                    <mkdir dir="target/${version}" />
                    <copy file="target/generated-resources/xml/xslt/application.wadl" toFile="target/${version}/index.html" />
                    <copy file="target/classes/schema1.xsd" toFile="target/${version}/schema1.xsd" />
                  </tasks>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      <dependencies>
        <!-- override the scope in this profile because javadoc needs them at compile -->
        <dependency>
          <groupId>com.atlassian.bamboo</groupId>
          <artifactId>atlassian-bamboo-core</artifactId>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>com.atlassian.plugins.rest</groupId>
          <artifactId>atlassian-rest-common</artifactId>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>com.atlassian.plugins.rest</groupId>
          <artifactId>com.atlassian.jersey-library</artifactId>
          <type>pom</type>
          <scope>compile</scope>
        </dependency>
      </dependencies>
    </profile>

  </profiles>

  <reporting>
    <plugins>
      <plugin>
        <artifactId>maven-javadoc-plugin</artifactId>
        <configuration>
          <maxmemory>1024m</maxmemory>
        </configuration>
        <reportSets>
          <reportSet>
            <id>default</id>
            <reports>
              <report>aggregate</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <version>2.1.2</version>
      </plugin>
    </plugins>
  </reporting>


  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-site-plugin</artifactId>
          <version>2.0</version>
          <configuration>
            <inputDirectory>${project.reporting.outputDirectory}/apidocs</inputDirectory>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>com.atlassian.maven.plugins</groupId>
        <artifactId>maven-bamboo-plugin</artifactId>
        <version>${amps.version}</version>
        <extensions>true</extensions>
        <configuration>
          <productVersion>${atlassian.product.version}</productVersion>
          <productDataVersion>${atlassian.product.data.version}</productDataVersion>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>
