<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <name>CDAP Maven Plugin</name>
  <groupId>co.cask</groupId>
  <artifactId>cdap-maven-plugin</artifactId>
  <version>1.0.0</version>
  <packaging>maven-plugin</packaging>
  <description>CDAP Maven Plugin</description>
  <url>http://cask.co</url>

  <organization>
    <name>Cask Data, Inc.</name>
    <url>http://cask.co</url>
  </organization>

  <licenses>
    <license>
      <name>The Apache Software License, Version 2.0</name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
    </license>
  </licenses>

  <developers>
    <developer>
      <name>Cask Data</name>
      <email>cask-dev@googlegroups.com</email>
      <organization>Cask Data, Inc.</organization>
      <organizationUrl>http://www.cask.co</organizationUrl>
    </developer>
  </developers>

  <scm>
    <connection>scm:git:https://github.com/caskdata/cdap-maven-plugin.git</connection>
    <developerConnection>scm:git:git@github.com:caskdata/cdap-maven-plugin.git</developerConnection>
    <url>https://github.com/caskdata/cdap-maven-plugin.git</url>
    <tag>HEAD</tag>
  </scm>


  <distributionManagement>
    <repository>
      <id>sonatype.release</id>
      <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
    </repository>
    <snapshotRepository>
      <id>sonatype.snapshots</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </snapshotRepository>
    <site>
      <id>cask</id>
      <url>http://cask.co</url>
    </site>
  </distributionManagement>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <cask.packages.snapshot.repo>http://cask.invalid.snapshot.repo.co</cask.packages.snapshot.repo>
    <cask.packages.release.repo>http://cask.invalid.release.repo.co</cask.packages.release.repo>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>2.0</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven.plugin-tools</groupId>
      <artifactId>maven-plugin-annotations</artifactId>
      <version>3.2</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-project</artifactId>
      <version>2.2.1</version>
    </dependency>
    <dependency>
      <groupId>org.json</groupId>
      <artifactId>json</artifactId>
      <version>RELEASE</version>
    </dependency>
    <dependency>
      <groupId>commons-codec</groupId>
      <artifactId>commons-codec</artifactId>
      <version>1.6</version>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.5</version>
    </dependency>
  </dependencies>

  <profiles>
      <!-- Profile for release. Includes building of source and javadoc jars. -->
    <profile>
      <id>release</id>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-source-plugin</artifactId>
              <version>2.2.1</version>
              <configuration>
                <excludeResources>true</excludeResources>
              </configuration>
              <executions>
                <execution>
                  <id>attach-sources</id>
                  <phase>package</phase>
                  <goals>
                    <goal>jar-no-fork</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-plugin-plugin</artifactId>
              <version>3.4</version>
              <configuration>
                <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
              </configuration>
              <executions>
                <execution>
                  <id>mojo-descriptor</id>
                  <goals>
                    <goal>descriptor</goal>
                  </goals>
                 </execution>
                </executions>
            </plugin>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-javadoc-plugin</artifactId>
              <version>2.9.1</version>
              <configuration>
                <stylesheetfile>cdap-distributions/src/javadoc/stylesheet.css</stylesheetfile>
                <bottom>
                  <![CDATA[Copyright &#169; {currentYear} <a href="http://cask.co" target="_blank">Cask Data, Inc.</a> Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">Apache License, Version 2.0</a>.]]>
                </bottom>
                <doctitle>${project.name} ${project.version}</doctitle>
                <links>
                  <link>https://caskdata.github.io/docs-site/hosted-javadocs/jsr305-${findbugs.jsr305.version}-javadoc/</link>
                  <link>http://avro.apache.org/docs/${avro.version}/api/java/</link>
                  <link>http://docs.oracle.com/javaee/${jee.version}/api/</link>
                  <link>http://hadoop.apache.org/docs/r${hadoop.version}/api/</link>
                  <link>http://twill.incubator.apache.org/apidocs-${twill.version}/</link>
                  <link>http://twitter4j.org/javadoc/</link>
                </links>
                <quiet>true</quiet>
              </configuration>
              <executions>
                <execution>
                  <id>attach-javadoc</id>
                  <phase>package</phase>
                  <goals>
                    <goal>jar</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </pluginManagement>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-plugin-plugin</artifactId>
            <version>3.4</version>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
            <version>1.5</version>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.2.1</version>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.9.1</version>
          </plugin>
        </plugins>
      </build>
    </profile>
    <!-- Profile for dist -->
    <profile>
      <id>dist</id>
      <properties>
        <!--
          Service name before removing cdap- prefix.
          It's needed so that children pom can override it.
          The value is then get transformed into service.name by regex using the build-helper plugin
        -->
        <original.service.name>${project.artifactId}</original.service.name>
        <stage.dir>${project.build.directory}/stage-packaging</stage.dir>
        <stage.opt.dir>${stage.dir}/opt/cdap/${package.name}</stage.opt.dir>
        <stage.lib.dir>${stage.opt.dir}/lib</stage.lib.dir>
        <stage.plugins.dir>${stage.opt.dir}/plugins</stage.plugins.dir>
        <stage.coprocessor.dir>${stage.opt.dir}/coprocessor</stage.coprocessor.dir>
        <package.deb.depends>--depends cdap</package.deb.depends>
        <package.rpm.depends>--depends cdap</package.rpm.depends>
        <package.deb.arch>all</package.deb.arch>
        <package.rpm.arch>all</package.rpm.arch>
        <package.dirs>opt etc</package.dirs>
        <package.config.dirs>--config-files etc/cdap --config-files etc/logrotate.d --config-files etc/security</package.config.dirs>
      </properties>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-jar-plugin</artifactId>
              <version>2.4</version>
              <executions>
                <execution>
                  <id>jar</id>
                  <phase>prepare-package</phase>
                  <configuration>
                    <outputDirectory>${stage.lib.dir}</outputDirectory>
                    <finalName>${project.groupId}.${project.build.finalName}</finalName>
                  </configuration>
                  <goals>
                    <goal>jar</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </pluginManagement>

        <!-- Generate the package version. If it has -SNAPSHOT, replace it with build time. -->
        <plugins>
          <!-- Generate a timestamp property -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.3</version>
            <executions>
              <execution>
                <id>create-timestamp</id>
                <phase>validate</phase>
                <goals>
                  <goal>create-timestamp</goal>
                </goals>
                <configuration>
                  <timestampPropertyName>package.build.timestamp</timestampPropertyName>
                </configuration>
              </execution>
              <execution>
                <id>create-year</id>
                <phase>validate</phase>
                <goals>
                  <goal>create-timestamp</goal>
                </goals>
                <configuration>
                  <timestampPropertyName>package.build.year</timestampPropertyName>
                  <timestampFormat>yyyy</timestampFormat>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <!-- Generate the package.version property -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.9</version>
            <executions>
              <execution>
                <id>regex-properties</id>
                <phase>validate</phase>
                <goals>
                  <goal>regex-properties</goal>
                </goals>
                <configuration>
                  <regexPropertySettings>
                    <regexPropertySetting>
                      <name>package.name</name>
                      <value>${project.artifactId}</value>
                      <regex>cdap-</regex>
                      <replacement></replacement>
                      <failIfNoMatch>false</failIfNoMatch>
                    </regexPropertySetting>
                    <regexPropertySetting>
                      <name>service.name</name>
                      <value>${original.service.name}</value>
                      <regex>cdap-</regex>
                      <replacement></replacement>
                      <failIfNoMatch>false</failIfNoMatch>
                    </regexPropertySetting>
                    <regexPropertySetting>
                      <name>package.version</name>
                      <value>${project.version}</value>
                      <regex>-SNAPSHOT</regex>
                      <replacement>.${package.build.timestamp}</replacement>
                      <failIfNoMatch>false</failIfNoMatch>
                    </regexPropertySetting>
                  </regexPropertySettings>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <!-- Determine the deploy.url for non-standard (e.g. zip, rpm, deb) deployment -->
          <plugin>
            <groupId>org.codehaus.gmaven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <version>1.5</version>
            <dependencies>
              <dependency>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-all</artifactId>
                <version>1.5.8</version>
              </dependency>
            </dependencies>
            <executions>
              <execution>
                <id>choose-deploy-url</id>
                <phase>initialize</phase>
                <goals>
                  <goal>execute</goal>
                </goals>
                <configuration>
                  <source>
                    if (project.version.endsWith("-SNAPSHOT")){
                      project.properties['deploy.url'] = project.properties['cask.packages.snapshot.repo'];
                      project.properties['dist.deploy.groupId'] = "co.cask.cdap.distributions.snapshots";
                    } else {
                      project.properties['deploy.url'] = project.properties['cask.packages.release.repo'];
                      project.properties['dist.deploy.groupId'] = "co.cask.cdap.distributions.release";
                    }
                  </source>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.1</version>
          <configuration>
            <source>1.7</source>
            <target>1.7</target>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.14.1</version>
          <configuration>
            <argLine>-Xmx5000m -Djava.awt.headless=true -XX:MaxPermSize=256m -XX:+UseConcMarkSweepGC -XX:OnOutOfMemoryError="kill -9 %p" -XX:+HeapDumpOnOutOfMemoryError</argLine>
            <redirectTestOutputToFile>${surefire.redirectTestOutputToFile}</redirectTestOutputToFile>
            <reuseForks>false</reuseForks>
            <reportFormat>plain</reportFormat>
            <trimStackTrace>false</trimStackTrace>
            <systemPropertyVariables>
              <java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
            </systemPropertyVariables>
            <includes>
              <include>**/*TestsSuite.java</include>
              <include>**/*TestSuite.java</include>
              <include>**/Test*.java</include>
              <include>**/*Test.java</include>
              <include>**/*TestCase.java</include>
            </includes>
            <excludes>
              <exclude>**/*TestRun.java</exclude>
              <exclude>**/*TestBase.java</exclude>
            </excludes>
          </configuration>
          <dependencies>
            <dependency>
              <groupId>org.apache.maven.surefire</groupId>
              <artifactId>surefire-junit47</artifactId>
              <version>2.14</version>
            </dependency>
          </dependencies>
        </plugin>

        <!-- GPG signature -->
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-gpg-plugin</artifactId>
          <version>1.5</version>
          <configuration>
            <passphrase>${gpg.passphrase}</passphrase>
            <useAgent>${gpg.useagent}</useAgent>
          </configuration>
          <executions>
            <execution>
              <goals>
                <goal>sign</goal>
              </goals>
            </execution>
          </executions>
        </plugin>

        <!-- Nexus deploy plugin -->
        <plugin>
          <groupId>org.sonatype.plugins</groupId>
          <artifactId>nexus-staging-maven-plugin</artifactId>
          <version>1.6.2</version>
          <extensions>true</extensions>
          <configuration>
            <nexusUrl>https://oss.sonatype.org</nexusUrl>
            <serverId>sonatype.release</serverId>
            <stagingProfileId>655dc88dc770c3</stagingProfileId>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>

    <plugins>
      <plugin>
        <groupId>org.apache.rat</groupId>
        <artifactId>apache-rat-plugin</artifactId>
        <version>0.10</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>2.17</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.14.1</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.8</version>
      </plugin>
      <plugin>
        <groupId>org.sonatype.plugins</groupId>
        <artifactId>nexus-staging-maven-plugin</artifactId>
        <version>1.6.2</version>
      </plugin>
    </plugins>
  </build>
</project>
