<?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-root</artifactId>
    <version>2.10.10.1.14</version>
  </parent>

  <artifactId>ehcache-kit</artifactId>
  <packaging>pom</packaging>
  <name>ehcache-kit</name>

  <description>project to build distribution kit</description>
  
  <modules>
    <module>colorcache</module>
    <module>events</module>
  </modules>
  
  <properties>
    <productName>ehcache</productName>
    <kitFolder>${productName}-${project.version}</kitFolder>
    <tarballName>${kitFolder}-distribution</tarballName>
    <root.dir>${project.build.directory}/${kitFolder}</root.dir>
    <terracotta.kit.path>${project.build.directory}/tmp/terracotta</terracotta.kit.path>
  </properties>

  <dependencies>
    <dependency>
      <groupId>net.sf.ehcache</groupId>
      <artifactId>ehcache</artifactId>
      <version>${project.version}</version>
      <scope>provided</scope>
    </dependency>   
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-jdk14</artifactId>
      <scope>provided</scope>
    </dependency>   
  </dependencies>
  
  <profiles>
    <profile>
      <id>includeJavadoc</id>
      <activation>
        <property>
          <name>!skipJavadoc</name>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>net.sf.ehcache</groupId>
          <artifactId>ehcache</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>
            <!-- skeleton -->                
            <resource>
              <targetPath>${root.dir}</targetPath>
              <directory>${basedir}/src/main/assembly/root</directory>
              <filtering>true</filtering>
              <preservePath>true</preservePath>
            </resource>
            <!-- ehcache.(xsd|xml) -->
            <resource>
              <targetPath>${root.dir}</targetPath>
              <directory>${basedir}/../ehcache-core/src/main/config</directory>
              <preservePath>true</preservePath>
            </resource>
            <!-- src -->
            <resource>
              <targetPath>${root.dir}/src</targetPath>
              <dependencies>
                <dependency>
                  <groupId>net.sf.ehcache</groupId>
                  <artifactId>ehcache</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</artifactId>
                  <classifier>javadoc</classifier>
                </dependency>
              </dependencies>
              <unpack>true</unpack>
            </resource> 
            <!-- clustered example -->                
            <resource>
              <runIf>{{ new File(project.properties['terracotta.kit.path']).isDirectory() }}</runIf>
              <targetPath>${root.dir}/samples</targetPath>
              <dependencies>
                <dependency>
                  <groupId>net.sf.ehcache.examples</groupId>
                  <artifactId>events</artifactId>
                  <version>${project.version}</version>
                  <classifier>distribution</classifier>
                  <type>tar.gz</type>
                </dependency>
                <dependency>
                  <groupId>net.sf.ehcache.examples</groupId>
                  <artifactId>colorcache</artifactId>
                  <version>${project.version}</version>
                  <classifier>distribution</classifier>
                  <type>tar.gz</type>
                </dependency>                
              </dependencies>
              <unpack>true</unpack>
            </resource>            
            <!-- terracotta -->                
            <resource>
              <runIf>{{ new File(project.properties['terracotta.kit.path']).isDirectory() }}</runIf>
              <targetPath>${root.dir}/terracotta</targetPath>
              <directory>${terracotta.kit.path}</directory>
              <excludes>
                <exclude>**/ehcache/**</exclude>
                <exclude>**/quartz/**</exclude>
                <exclude>**/sessions/**</exclude>
              </excludes>
              <preservePath>true</preservePath>
            </resource>
            <resource>
              <runIf>{{ new File(project.properties['terracotta.kit.path']).isDirectory() }}</runIf>
              <targetPath>${root.dir}/samples</targetPath>
              <directory>${terracotta.kit.path}/ehcache/samples</directory>
              <preservePath>true</preservePath>
            </resource>
            <resource>
              <runIf>{{ new File(project.properties['terracotta.kit.path']).isDirectory() }}</runIf>
              <targetPath>${root.dir}/samples/colorcache/bin</targetPath>
              <directory>${basedir}/src/main/assembly</directory>
              <includes>
                <include>relative-paths.*</include>
              </includes>
            </resource>
            <resource>
              <runIf>{{ new File(project.properties['terracotta.kit.path']).isDirectory() }}</runIf>
              <targetPath>${root.dir}/samples/events/bin</targetPath>
              <directory>${basedir}/src/main/assembly</directory>
              <includes>
                <include>relative-paths.*</include>
              </includes>
            </resource>             
          </resources>
        </configuration>
        <executions>
          <execution>
            <id>package-with-no-tc</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
          </execution>
        </executions>            
      </plugin>
      <!-- look up slf4j.version -->
      <plugin>
        <groupId>org.codehaus.gmavenplus</groupId>
        <artifactId>gmavenplus-plugin</artifactId>
      </plugin>
      <!-- package lib folder, use this plugin to get proper SNAPSHOT file name -->
      <plugin>
        <groupId>org.terracotta</groupId>
        <artifactId>maven-forge-plugin</artifactId>
        <executions>
          <execution>
            <id>package-lib</id>
            <phase>package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <outputDir>${root.dir}/lib</outputDir>
              <resolveTransitively>false</resolveTransitively>
              <artifacts>
                <param>net.sf.ehcache:ehcache:${project.version}</param>
                <param>org.slf4j:slf4j-api:${slf4j.version}</param>
                <param>org.slf4j:slf4j-jdk14:${slf4j.version}</param>
              </artifacts>
            </configuration>
          </execution>
        </executions>          
      </plugin>      
      <plugin>
        <groupId>org.codehaus.gmaven</groupId>
        <artifactId>groovy-maven-plugin</artifactId>
        <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-distribution</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>

</project>
