<?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">
  <!--
  /**
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  -->
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.apache.zookeeper</groupId>
    <artifactId>zookeeper-client</artifactId>
    <version>3.8.1</version>
  </parent>

  <artifactId>zookeeper-client-c</artifactId>
  <packaging>pom</packaging>
  <name>Apache ZooKeeper - Client - C</name>
  <description>ZooKeeper c client</description>

  <properties>
    <c-test-coverage-arg> </c-test-coverage-arg>
  </properties>

  <build>
    <plugins>
        <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>autoreconf</id>
            <phase>process-sources</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <workingDirectory>${project.basedir}</workingDirectory>
              <executable>autoreconf</executable>
              <environmentVariables>
                <ACLOCAL>aclocal -I /usr/share/aclocal</ACLOCAL>
              </environmentVariables>
              <arguments>
                <argument>-if</argument>
              </arguments>
            </configuration>
          </execution>
          <execution>
            <id>configure</id>
            <phase>process-sources</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <workingDirectory>${project.build.directory}/c</workingDirectory>
              <executable>${project.basedir}/configure</executable>
              <environmentVariables>
                <base_dir>${project.basedir}/../..</base_dir>
                <CALLER>ANT</CALLER>
              </environmentVariables>
              <arguments>
                <argument>--with-openssl=${c-client-openssl}</argument>
                <argument>--with-sasl=${c-client-sasl}</argument>
                <argument>--prefix=${project.build.directory}/c</argument>
                <argument>${c-test-coverage-arg}</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
              <target>
                <mkdir dir="target/c" />
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
          <execution>
            <id>build-c-client</id>
            <phase>compile</phase>
            <configuration>
              <target>
                <exec dir="${basedir}/target/c" executable="make" failonerror="true">
                  <env key="LD_LIBRARY_PATH" value="${env.LD_LIBRARY_PATH};/usr/lib" />
                  <env key="PATH" path="${env.PATH};${basedir};" />
                  <env key="CALLER" value="ANT" />
                  <env key="CLOVER_HOME" value="${basedir}/../../zookeeper-server/target" />
                  <env key="base_dir" value="${basedir}/../.." />
                  <arg line="clean install" />
                </exec>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
          <execution>
            <id>replace-cclient-files-during-release</id>
            <phase>none</phase>
            <goals>
               <goal>run</goal>
            </goals>
            <configuration>
               <target>
                  <replaceregexp file="include/zookeeper_version.h" match="project.*" replace="project(zookeeper VERSION ${project.version})" byline="true" />
                  <replace file="include/zookeeper_version.h" value="">
                      <replaceToken>-SNAPSHOT</replaceToken>
                  </replace>
                  <replaceregexp file="CMakeLists.txt" match="project.*" replace="project(zookeeper VERSION ${project.version})" byline="true" />
                  <replace file="CMakeLists.txt" value="">
                      <replaceToken>-SNAPSHOT</replaceToken>
                  </replace>
                  <replaceregexp file="configure.ac" match="AC_INIT.*" replace="AC_INIT([zookeeper C client],${project.version},[user@zookeeper.apache.org],[zookeeper])" byline="true" />
                  <replace file="configure.ac" value="">
                      <replaceToken>-SNAPSHOT</replaceToken>
                  </replace>
               </target>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>c-test-coverage</id>
      <properties>
        <c-test-coverage-arg>--enable-gcov</c-test-coverage-arg>
      </properties>
    </profile>
    <profile>
      <!-- can be skipped by deactivating the profile with -P!cppunit (may need to escape or quote exclamation on command-line) -->
      <id>cppunit</id>
      <activation>
        <property>
          <!-- can also be skipped by -DskipCppUnit or with -DskipTests (see below) -->
          <name>!skipCppUnit</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>test-cppunit</id>
                <phase>test</phase>
                <configuration>
                  <!-- do not run cpp tests if tests are globally skipped -->
                  <skip>${skipTests}</skip>
                  <target>
                    <exec dir="${basedir}/target/c" executable="make" failonerror="true">
                      <env key="LD_LIBRARY_PATH" value="${env.LD_LIBRARY_PATH};/usr/lib" />
                      <env key="PATH" path="${env.PATH};${basedir};" />
                      <env key="CALLER" value="ANT" />
                      <env key="CLOVER_HOME" value="${basedir}/../../zookeeper-server/target" />
                      <env key="base_dir" value="${basedir}/../.." />
                      <arg line="check" />
                    </exec>
                  </target>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
