<?xml version="1.0"?>
<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>net.sf.ehcache</groupId>
    <artifactId>ehcache-ee-root</artifactId>
    <version>2.7.7</version>
  </parent>

  <artifactId>ehcache-ee-kit</artifactId>
  <packaging>pom</packaging>
  <name>ehcache-ee-kit</name>
  <description>project to build kit</description>
 
  <properties>
    <productName>ehcache-ee</productName>
    <kitFolder>${productName}-${project.version}</kitFolder>
    <tarballName>${kitFolder}-distribution</tarballName>
    <root.dir>${project.build.directory}/${kitFolder}</root.dir>
    <gmaven-plugin.version>1.3</gmaven-plugin.version>
    <tmc.version>1.1.7</tmc.version>
  </properties>
  
  <dependencies>
    <dependency>
      <groupId>net.sf.ehcache</groupId>
      <artifactId>ehcache-ee</artifactId>
      <version>${project.version}</version>
      <scope>provided</scope>
    </dependency> 
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>ehcache-kit</artifactId>
      <version>${project.version}</version>
      <classifier>distribution</classifier>
      <type>tar.gz</type>
    </dependency>
    <dependency>
      <groupId>com.terracotta</groupId>
      <artifactId>tmc-kit</artifactId>
      <version>${tmc.version}</version>
      <classifier>distribution</classifier>
      <type>tar.gz</type>
    </dependency>    
  </dependencies>

  <profiles>
    <profile>
      <id>includeJavadoc</id>
      <activation>
        <property>
          <name>!skipJavadoc</name>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>net.sf.ehcache</groupId>
          <artifactId>ehcache-ee</artifactId>
          <version>${project.version}</version>
          <classifier>javadoc</classifier>
          <scope>provided</scope>
        </dependency>  
      </dependencies>
    </profile>
  </profiles>
  
  <build>
    <plugins>
      <plugin>
        <groupId>com.github.goldin</groupId>
        <artifactId>copy-maven-plugin</artifactId>
        <version>0.2.3.8</version>
        <configuration>
          <verbose>false</verbose>
          <resources>
            <!-- clean up -->
            <resource>
              <runIf>{{ new File( project.build.directory, "${kitFolder}" ).isDirectory() }}</runIf>
              <directory>${root.dir}</directory>
              <includes>
                <include>**/**</include>
              </includes>
              <clean>true</clean>
              <cleanEmptyDirectories>true</cleanEmptyDirectories>
            </resource>
            <!-- exploded OS kit -->
            <resource>
              <targetPath>${project.build.directory}/tmp</targetPath>
              <dependency>
                <groupId>${project.groupId}</groupId>
                <artifactId>ehcache-kit</artifactId>
                <version>${project.version}</version>
                <classifier>distribution</classifier>
                <type>tar.gz</type>
              </dependency>
              <unpack>true</unpack>
            </resource>
            <resource>
              <targetPath>${root.dir}</targetPath>
              <directory>${project.build.directory}/tmp/ehcache-${project.version}</directory>
              <excludes>
                <exclude>**/lib/ehcache-${project.version}.jar</exclude>
                <exclude>**/src</exclude>
                <exclude>**/javadoc</exclude>
                <exclude>ehcache*.xml</exclude>
              </excludes>
              <preservePath>true</preservePath>
            </resource>
            <!-- rename sample Terracotta file from OS kit -->
            <resource>
              <targetPath>${root.dir}</targetPath>
              <file>${project.build.directory}/tmp/ehcache-${project.version}/ehcache-terracotta.xml</file>
              <destFileName>ehcache.xml</destFileName>
            </resource>
            <!-- skeleton -->                
            <resource>
              <targetPath>${root.dir}</targetPath>
              <directory>${basedir}/src/assembly/root</directory>
              <preservePath>true</preservePath>
            </resource>
            <!-- lib -->
            <resource>
              <targetPath>${root.dir}/lib</targetPath>
              <dependencies>
                <dependency>
                  <groupId>net.sf.ehcache</groupId>
                  <artifactId>ehcache-ee</artifactId>
                </dependency>
              </dependencies>
            </resource>
            <!-- src -->
            <resource>
              <targetPath>${root.dir}/src</targetPath>
              <dependencies>
                <dependency>
                  <groupId>net.sf.ehcache</groupId>
                  <artifactId>ehcache-ee</artifactId>
                  <classifier>sources</classifier>
                </dependency>
              </dependencies>
              <unpack>true</unpack>
            </resource>
            <!-- javadoc -->
            <resource>
              <failIfNotFound>false</failIfNotFound>
              <targetPath>${root.dir}/javadoc</targetPath>
              <dependencies>
                <dependency>
                  <groupId>net.sf.ehcache</groupId>
                  <artifactId>ehcache-ee</artifactId>
                  <classifier>javadoc</classifier>
                </dependency>
              </dependencies>
              <unpack>true</unpack>
            </resource>
            <!-- tmc -->
            <resource>
              <targetPath>${project.build.directory}</targetPath>
              <dependencies>   
                <dependency>
                  <groupId>com.terracotta</groupId>
                  <artifactId>tmc-kit</artifactId>
                  <classifier>distribution</classifier>
                  <type>tar.gz</type>
                </dependency>                  
              </dependencies>
              <unpack>true</unpack>
            </resource>
            <resource>
              <targetPath>${root.dir}/tmc</targetPath>
              <directory>${project.build.directory}/tmc-${tmc.version}</directory>
              <excludes>
                <exclude>**/LICENSE.txt</exclude>
              </excludes>
              <preservePath>true</preservePath>
            </resource>             
          </resources>
        </configuration>
        <executions>
          <execution>
            <id>prepare-packaging</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
          </execution>
        </executions>            
      </plugin>
      <plugin>
        <groupId>org.codehaus.gmaven</groupId>
        <artifactId>gmaven-plugin</artifactId>
        <version>${gmaven-plugin.version}</version>
        <executions>
          <execution>
            <id>create-tarball</id>
            <phase>package</phase>
            <goals>
              <goal>execute</goal>
            </goals>
            <configuration>         
              <source>
                def srcdir = new File(project.basedir, "target/${kitFolder}") 
                def destFile = new File(project.basedir, "target/${tarballName}.tar.gz") 
                ant.tar(destfile: "${destFile}", longfile: "gnu", compression: "gzip") {
                  tarfileset(dir: "${srcdir}", prefix: "${kitFolder}", excludes: "**/bin/**,**/lib/**,**/*.sh,**/*.bat")
                  tarfileset(dir: "${srcdir}", prefix: "${kitFolder}", includes: "**/bin/**,**/lib/**,**/*.sh,**/*.bat", filemode: "755")
                } 
              </source>
            </configuration>
          </execution>              
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.5</version>
        <executions>
          <execution>
            <id>attach-javadoc-sources</id>
            <phase>package</phase>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <configuration>
              <artifacts>
                <artifact>
                  <file>${project.build.directory}/${tarballName}.tar.gz</file>
                  <type>tar.gz</type>
                  <classifier>distribution</classifier>
                </artifact>                
              </artifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>      
    </plugins>
  </build>
  
  <repositories>
    <repository>
      <id>terracotta-snapshots</id>
      <url>http://www.terracotta.org/download/reflector/snapshots</url>
    </repository>  
    <repository>
      <id>terracotta-releases</id>
      <url>http://www.terracotta.org/download/reflector/releases</url>
    </repository>
  </repositories>
  
  <pluginRepositories>
    <pluginRepository>
      <id>terracotta-snapshots</id>
      <url>http://www.terracotta.org/download/reflector/snapshots</url>
    </pluginRepository>  
    <pluginRepository>
      <id>terracotta-releases</id>
      <url>http://www.terracotta.org/download/reflector/releases</url>
    </pluginRepository>
    <pluginRepository>
      <id>evgenyg.artifactoryonline.com</id>
      <url>http://evgenyg.artifactoryonline.com/evgenyg/repo/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </pluginRepository>    
  </pluginRepositories>
  
</project>
