<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2000-2021, Board of Trustees of Leland Stanford Jr. University
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

-->

<!-- In order to build this parent pom, buildingParent must be defined -->

<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>

  <parent>
    <groupId>org.lockss</groupId>
    <artifactId>lockss-parent-pom</artifactId>
    <version>1.14.0</version>
    <relativePath/>
  </parent>

  <groupId>org.lockss</groupId>
  <artifactId>lockss-plugins-parent-pom</artifactId>
  <version>1.3.0</version>
  <packaging>pom</packaging>

  <name>lockss-plugins-parent-pom</name>
  <description>Maven infrastructure to build LOCKSS plugins and tdbs</description>
  <properties>

  </properties>

  <dependencies>
    <dependency>
      <groupId>org.lockss</groupId>
      <artifactId>lockss-core-bundle</artifactId>
      <version>${version.lockss.lockss-core-bundle}</version>
      <type>pom</type>
    </dependency>
    <dependency>
      <groupId>org.lockss</groupId>
      <artifactId>lockss-core-tests-bundle</artifactId>
      <version>${version.lockss.lockss-core-bundle}</version>
      <type>pom</type>
    </dependency>
    <dependency>
      <groupId>com.jayway.jsonpath</groupId>
      <artifactId>json-path</artifactId>
      <version>${version.dependency.json-path}</version>
    </dependency>
    <dependency>
      <groupId>org.lockss.laaws</groupId>
      <artifactId>lockss-plugin-compat</artifactId>
      <version>${version.lockss.lockss-plugin-compat}</version>
    </dependency>
    <dependency>
      <groupId>org.lockss</groupId>
      <artifactId>lockss-junit4-bundle</artifactId>
      <version>${version.lockss.lockss-junit4-bundle}</version>
      <type>pom</type>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.lockss</groupId>
      <artifactId>lockss-tdb-processor</artifactId>
      <version>${version.lockss.lockss-tdb-processor}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <!-- Process tdb files in src/main/tdb and src/test/java -->
      <plugin>
        <groupId>org.lockss.laaws</groupId>
        <artifactId>lockss-tdbxml-maven-plugin</artifactId>
        <version>${version.lockss.lockss-tdbxml-maven-plugin}</version>
        <executions>
	  <!-- src/main/tdb -->
          <execution>
            <id>processTdb</id>
            <phase>compile</phase>
            <goals>
              <goal>tdbxml</goal>
            </goals>
            <configuration>
              <skip>${buildingParent}</skip>
              <srcDir>${basedir}/src/main/tdb</srcDir>
              <dstDir>${project.build.directory}/tdbxml</dstDir>
              <recurse>true</recurse>
            </configuration>
          </execution>
          <execution>
            <id>processTestTdb</id>
            <phase>process-test-resources</phase>
            <goals>
              <goal>tdbxml</goal>
            </goals>
            <configuration>
              <skip>${buildingParent}</skip>
              <srcDir>${project.build.testSourceDirectory}</srcDir>
              <dstDir>${project.build.testOutputDirectory}</dstDir>
              <recurse>true</recurse>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Read signing keystore password if necessary -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>${version.plugin.maven-antrun-plugin}</version>
        <dependencies>
          <dependency>
            <groupId>ant-contrib</groupId>
            <artifactId>ant-contrib</artifactId>
            <version>${version.dependency.ant-contrib}</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <id>read-password</id>
            <goals>
              <goal>run</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <skip>${buildingParent}</skip>
              <target>
                <taskdef resource="net/sf/antcontrib/antcontrib.properties" />
		<if>
		  <and>
		    <isset property="keystore.file" />
		    <isset property="keystore.alias" />
		  </and>
		  <then>
                    <input message="Keystore password: "
			   addproperty="keystore.password">
                      <handler type="secure"/>
                    </input>
		  </then>
		  <else>
		    <echo message="keystore.file and keystore.alias must be defined" />
		    <fail message="keystore.file and keystore.alias must be defined" />
		  </else>
		</if>
              </target>
              <exportAntProperties>true</exportAntProperties>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Run PluginPackager -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>${version.plugin.exec-maven-plugin}</version>
        <executions>
          <execution>
            <id>package-plugins</id>
            <phase>package</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <skip>${buildingParent}</skip>
              <executable>java</executable>
              <arguments>
                <argument>-classpath</argument>
                <classpath/>
                <argument>-Dorg.lockss.defaultLogLevel=${loglevel}</argument>
                <argument>org.lockss.util.PluginPackager</argument>
                <argument>-pd</argument>
                <argument>${basedir}/target/classes</argument>
                <argument>-od</argument>
                <argument>${basedir}/target/pluginjars</argument>
                <argument>-keystore</argument>
                <argument>${keystore.file}</argument>
                <argument>-alias</argument>
                <argument>${keystore.alias}</argument>
                <argument>-storepass</argument>
                <argument>${keystore.password}</argument>
                <argument>-keypass</argument>
                <argument>${keystore.password}</argument>
                <argument>-explodelib</argument>
           </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>

    <!-- Copy support files needed by plugins and tests into target -->
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.xml</include>
          <include>**/*.dat</include>
          <include>**/*.dat.gz</include>
          <include>**/*.dtd</include>
          <include>**/*.props</include>
          <include>**/*.keystore</include>
          <include>**/lib/*.jar</include>
        </includes>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>src/test/resources</directory>
      </testResource>
      <testResource>
        <directory>src/test/java</directory>
        <excludes>
          <exclude>**/*.java</exclude>
          <exclude>**/*.tdb</exclude>
        </excludes>
      </testResource>
    </testResources>
  </build>

  <profiles>
    <profile>
      <!-- testing profile uses non-secret signing keystore in lockss-core
           test jar -->
      <id>testing</id>
      <activation>
	<property>
          <name>testing</name>
	</property>
      </activation>
      <properties>
	<keystore.file>resource:org/lockss/test/develop.keystore</keystore.file>
	<keystore.alias>develop</keystore.alias>
	<keystore.password>devpass</keystore.password>
      </properties>
    </profile>
  </profiles>

</project>
