<?xml version="1.0" encoding="UTF-8"?>
<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.xipki.assembly</groupId>
    <artifactId>assemblies</artifactId>
    <version>5.3.14</version>
  </parent>
  <artifactId>xipki-cli</artifactId>
  <packaging>pom</packaging>
  <name>XiPKI :: assembly :: ${project.artifactId}</name>
  <properties>
    <app.name>cli</app.name>
    <shared.dir>${project.basedir}/../shared</shared.dir>
    <patchkaraf.repos>mvn:org.xipki.feature/cli/${project.version}/xml/features</patchkaraf.repos>
    <patchkaraf.features>(-jaas,-ssh,-config,aries-blueprint/${karaf.version},wrap),xipki-security,xipki-caclient,xipki-scepclient,xipki-ocspclient,xipki-camgmt,xipki-ocspmgmt</patchkaraf.features>
  </properties>
  <dependencies>
    <dependency>
      <!-- project base features -->
      <groupId>org.xipki.feature</groupId>
      <artifactId>cli</artifactId>
      <version>${project.version}</version>
      <classifier>features</classifier>
      <type>xml</type>
    </dependency>
  </dependencies>
  <build>
    <resources>
      <resource>
        <directory>src/main/filtered</directory>
        <filtering>true</filtering>
      </resource>
      <resource>
        <directory>src/main/unfiltered</directory>
        <filtering>false</filtering>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>filter</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>resources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <!--  include additional artifacts -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <!-- Uncompress the standard Karaf distribution -->
            <id>unpack</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.apache.karaf</groupId>
                  <artifactId>apache-karaf-minimal</artifactId>
                  <version>${karaf.version}</version>
                  <type>tar.gz</type>
                  <outputDirectory>${project.build.directory}</outputDirectory>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
          <execution>
            <!-- Copy the JDBC jars -->
            <id>jdbc</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <stripVersion>false</stripVersion>
              <outputDirectory>${project.build.directory}/classes/lib/ext</outputDirectory>
              <artifactItems>
                <artifactItem>
                  <groupId>org.mariadb.jdbc</groupId>
                  <artifactId>mariadb-java-client</artifactId>
                  <version>${jdbc.mariadb.version}</version>
                </artifactItem>
                <artifactItem>
                  <groupId>org.postgresql</groupId>
                  <artifactId>postgresql</artifactId>
                  <version>${jdbc.postgresql.version}</version>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
          <execution>
            <!-- Extract the TLS keys -->
            <id>unpack-tlskeys</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/classes/xipki/keycerts/tlskeys</outputDirectory>
              <artifactItems>
                <artifactItem>
                  <groupId>org.xipki.tools</groupId>
                  <artifactId>tlskeys-example</artifactId>
                  <classifier>ec</classifier>
                  <version>${xipki.tools.version}</version>
                  <type>zip</type>
                </artifactItem>
              </artifactItems>
              <includes>ca/tls-ca-cert.p12,server/tls-server-cert.der,server/tls-server.p12,client/*,client2/*,client3/*</includes>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.karaf.tooling</groupId>
        <artifactId>karaf-maven-plugin</artifactId>
        <extensions>true</extensions>
        <executions>
          <execution>
            <id>add-features-to-repo</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>features-add-to-repository</goal>
            </goals>
            <configuration>
              <repository>${project.build.directory}/classes/system</repository>
              <descriptors>
                <descriptor>mvn:org.xipki.feature/cli/${project.version}/xml/features</descriptor>
                <descriptor>mvn:org.apache.karaf.features/standard/${karaf.version}/xml/features</descriptor>
              </descriptors>
              <features>
                <feature>aries-blueprint</feature>
                <feature>wrap</feature>
                <!-- project-core features -->
                <feature>xipki-security</feature>
                <feature>xipki-caclient</feature>
                <feature>xipki-ocspclient</feature>
                <feature>xipki-scepclient</feature>
                <feature>xipki-camgmt</feature>
                <feature>xipki-ocspmgmt</feature>
              </features>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>prepare-package</phase>
            <configuration>
              <target>
                <java failonerror="true" classname="org.xipki.patchkaraf.PatchFeature">
                  <arg value="--backup"/>
                  <arg value="no"/>
                  <arg value="--file"/>
                  <arg file="${project.build.directory}/apache-karaf-minimal-${karaf.version}/etc/org.apache.karaf.features.cfg"/>
                  <arg value="--repos"/>
                  <arg value="${patchkaraf.repos}"/>
                  <arg value="--features"/>
                  <arg value="${patchkaraf.features}"/>
                </java>
                <java failonerror="true" classname="org.xipki.patchkaraf.PatchPaxUrlMvn">
                  <arg value="--backup"/>
                  <arg value="no"/>
                  <arg value="--file"/>
                  <arg file="${project.build.directory}/apache-karaf-minimal-${karaf.version}/etc/org.ops4j.pax.url.mvn.cfg"/>
                </java>
                <java failonerror="true" classname="org.xipki.patchkaraf.PatchPaxLogging">
                  <arg value="--backup"/>
                  <arg value="no"/>
                  <arg value="--file"/>
                  <arg file="${project.build.directory}/apache-karaf-minimal-${karaf.version}/etc/org.ops4j.pax.logging.cfg"/>
                </java>
                <java failonerror="true" classname="org.xipki.patchkaraf.PatchAppend">
                  <arg value="--backup"/>
                  <arg value="no"/>
                  <arg value="--file"/>
                  <arg file="${project.build.directory}/apache-karaf-minimal-${karaf.version}/etc/org.ops4j.pax.logging.cfg"/>
                  <arg value="--value-file"/>
                  <arg file="src/main/patchkaraf/org.ops4j.pax.logging.cfg.patch"/>
                </java>
                <replace
                    file="${project.build.directory}/apache-karaf-minimal-${karaf.version}/bin/inc"
                    token="-Dcom.sun.management.jmxremote"
                    value=""/>
                <replace
                        file="${project.build.directory}/apache-karaf-minimal-${karaf.version}/etc/jre.properties"
                        token="org.xml.sax.helpers"
                        value="org.xml.sax.helpers, com.ibm.db2.jcc, org.h2.jdbcx, org.hsqldb.jdbc, org.mariadb.jdbc, com.mysql.jdbc.jdbc2.optional, oracle.jdbc.pool, org.postgresql.ds"/>
                <replace
                        file="${project.build.directory}/apache-karaf-minimal-${karaf.version}/system/org/apache/karaf/features/standard/${karaf.version}/standard-${karaf.version}-features.xml"
                        token="bcpkix-jdk15on/${karaf.bc.version}"
                        value="bcpkix-jdk15on/${bc.version}"/>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <id>main</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <descriptors>
                <descriptor>src/main/descriptors/main.xml</descriptor>
              </descriptors>
              <appendAssemblyId>false</appendAssemblyId>
              <tarLongFileMode>posix</tarLongFileMode>
              <!-- Don't install/publish the result -->
              <attach>false</attach>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
