<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>org.terracotta.toolkit</groupId>
    <artifactId>terracotta-toolkit-root</artifactId>
    <version>3.2.0</version>
  </parent>

  <groupId>org.terracotta</groupId>
  <artifactId>terracotta-toolkit-${toolkit-api-version}-runtime</artifactId>
  <name>terracotta-toolkit-runtime</name>
  <packaging>jar</packaging>
  <description>Terracotta toolkit runtime</description>

  <properties>
    <terracotta-l1.artifactId>terracotta-l1</terracotta-l1.artifactId>
    <skipJavadoc>false</skipJavadoc>
  </properties>

  <dependencies>
    <!-- express impl -->
    <dependency>
      <groupId>org.terracotta.toolkit</groupId>
      <artifactId>express-impl</artifactId>
      <version>3.2.0</version>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.terracotta.toolkit</groupId>
      <artifactId>truezip-repkg</artifactId>
      <version>3.2.0</version>
      <optional>true</optional>
    </dependency>

    <!-- Stuff that goes into L1 -->
    <dependency>
      <groupId>org.terracotta</groupId>
      <artifactId>${terracotta-l1.artifactId}</artifactId>
      <version>${terracotta.core.version}</version>
      <optional>true</optional>
    </dependency>

    <!-- stuff that goes into TIMs -->
    <dependency>
      <groupId>org.terracotta.toolkit</groupId>
      <artifactId>terracotta-toolkit-${toolkit-api-version}</artifactId>
      <!-- I don't think this can be a range. 
           It needs to be a version that "works" with the terracotta version bundled here as well -->
      <version>${terracotta-toolkit.version}</version>
      <optional>true</optional>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>2.7</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
            <configuration>
              <skip>${skipJavadoc}</skip>
              <quiet>true</quiet>
              <sourcepath>${project.build.directory}/sources</sourcepath>
              <excludePackageNames>com.terracotta</excludePackageNames>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2</version>

        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>exec</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <executable>${java.home}/bin/java</executable>
          <arguments>
            <argument>-Dcom.tc.l1.modules.repositories=${settings.localRepository}</argument>
            <argument>-cp</argument>
            <classpath/>
            <argument>com.tc.object.tools.BootJarTool</argument>
            <argument>-w</argument>
            <argument>-o</argument>
            <argument>${project.build.directory}/dso-boot/dso-boot.jar</argument>
          </arguments>
        </configuration>
      </plugin>
        
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.3</version>

        <configuration>
          <tasks>
            <unzip src="${project.build.directory}/dso-boot/dso-boot.jar" dest="${project.build.directory}/dso-boot/unpacked">
              <patternset>
                <include name="META-INF/**"/>
                <include name="com/tc/**"/>
                <include name="com/tcclient/**"/>

                <!-- XXX: We can remove this if we ever stop using -->
                <!--      TLinkable in com.tc.object.cache.Cacheable -->
                <include name="gnu/**"/>
              </patternset>
            </unzip>

            <jar destfile="${project.build.directory}/dso-boot/dso-boot.jar" basedir="${project.build.directory}/dso-boot/unpacked" 
                 update="false" manifest="${project.build.directory}/dso-boot/unpacked/META-INF/MANIFEST.MF"/>
          </tasks>
        </configuration>

        <executions>
          <execution>
            <id>unjar-classes</id>
            <phase>package</phase>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack-dependencies</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <includeGroupIds>org.terracotta.toolkit</includeGroupIds>
              <excludeArtifactIds>truezip-repkg</excludeArtifactIds>
              <classifier>sources</classifier>
              <failOnMissingClassifierArtifact>true</failOnMissingClassifierArtifact>
              <outputDirectory>${project.build.directory}/sources</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.terracotta</groupId>
        <artifactId>maven-forge-plugin</artifactId>
        <configuration>
          <rootPath>${basedir}/..</rootPath>
          <manifestFile>${project.build.directory}/MANIFEST.MF</manifestFile>
          <manifestEntries>
            <Terracotta-Category>Product</Terracotta-Category>
            <Terracotta-DownloadPath>../../common</Terracotta-DownloadPath>
            <Terracotta-ArtifactCoordinates>${project.groupId}:${project.artifactId}:${project.version}</Terracotta-ArtifactCoordinates>
            <Terracotta-RequireVersion>${terracotta.core.version.base}</Terracotta-RequireVersion>
            <Terracotta-ProjectStatus>Supported</Terracotta-ProjectStatus>
            <Terracotta-InternalTIM>false</Terracotta-InternalTIM>
            <Terracotta-Name>${project.artifactId}</Terracotta-Name>
            <Terracotta-Description>${project.description}</Terracotta-Description>
            <Terracotta-Kit>open source</Terracotta-Kit>
          </manifestEntries>
        </configuration>
        <executions>
          <execution>
            <id>create-manifest</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>manifest</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-5</version>
        <configuration>
          <finalName>${project.artifactId}-${project.version}</finalName>
          <appendAssemblyId>false</appendAssemblyId>
          <attach>true</attach>
          <descriptors>
            <descriptor>${basedir}/src/main/assembly/bin.xml</descriptor>
          </descriptors>
          <archive>
            <!-- pick up MANIFEST.MF created by maven-forge-plugin -->
            <manifestFile>${project.build.directory}/MANIFEST.MF</manifestFile>
          </archive>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>skip-javadoc</id>
      <activation>
        <file>
          <exists>${user.home}/.skipjavadoc</exists>
        </file>
      </activation>
      <properties>
        <skipJavadoc>true</skipJavadoc>
      </properties>
    </profile>
  </profiles>
  
  <repositories>
    <repository>
      <id>terracotta-releases</id>
      <url>http://www.terracotta.org/download/reflector/releases</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <id>terracotta-releases</id>
      <url>http://www.terracotta.org/download/reflector/releases</url>
    </pluginRepository>
  </pluginRepositories>

</project>
