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

<!--
Copyright (c) 2016 Red Hat, Inc.

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

<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.ovirt.engine.api</groupId>
    <artifactId>java-sdk-parent</artifactId>
    <version>4.1.6</version>
  </parent>

  <artifactId>sdk</artifactId>
  <packaging>jar</packaging>

  <name>oVirt Java SDK</name>

  <dependencies>

    <dependency>
      <groupId>com.sun.xml.txw2</groupId>
      <artifactId>txw2</artifactId>
      <version>20110809</version>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.7</version>
    </dependency>

    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-core-asl</artifactId>
      <version>1.9.13</version>
    </dependency>

    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-mapper-asl</artifactId>
      <version>1.9.13</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>io.undertow</groupId>
      <artifactId>undertow-core</artifactId>
      <version>1.3.21.Final</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.7.7</version>
      <scope>test</scope>
    </dependency>

  </dependencies>

  <build>
    <plugins>

      <!-- Make sure to always use Java 7: -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <!-- Copy model.jar to the target directory, so that it can be
          later loaded by the generator: -->
          <execution>
            <id>copy-model</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.ovirt.engine.api</groupId>
                  <artifactId>model</artifactId>
                  <version>${model.version}</version>
                  <type>jar</type>
                  <classifier>sources</classifier>
                  <outputDirectory>${project.basedir}/target</outputDirectory>
                  <destFileName>model.jar</destFileName>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>

          <!-- Copy needed metamodel sources, so that the SDK won't
            depend on the metamodel: -->
          <execution>
            <id>copy-metamodel</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.ovirt.engine.api</groupId>
                  <artifactId>metamodel-runtime</artifactId>
                  <version>${metamodel.version}</version>
                  <type>jar</type>
                  <classifier>sources</classifier>
                  <outputDirectory>${project.basedir}/target/generated-sources</outputDirectory>
                  <includes>**/xml/*.java,**/util/*.java</includes>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Run the code generator: -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <executions>
          <execution>
            <id>generate-code</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>java</goal>
            </goals>
            <configuration>
              <mainClass>org.ovirt.api.metamodel.tool.Main</mainClass>
              <arguments>
                <argument>org.ovirt.sdk.java.Tool</argument>
                <argument>--model</argument>
                <argument>${project.basedir}/target/model.jar</argument>
                <argument>--out</argument>
                <argument>${project.basedir}/target/generated-sources</argument>
                <argument>--resources</argument>
                <argument>${project.basedir}/src/main/resources</argument>
              </arguments>
              <includePluginDependencies>true</includePluginDependencies>
              <includeProjectDependencies>false</includeProjectDependencies>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>java-sdk-generator</artifactId>
            <version>${project.version}</version>
          </dependency>
        </dependencies>
      </plugin>

      <!-- Add the generated Java code directory to the source path: -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.10</version>
        <executions>
          <execution>
            <id>add-generated-sources</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${project.basedir}/target/generated-sources</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Attach the sources: -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
      </plugin>

      <!-- Make sure that we don't use different versions of the same
           dependency: -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.4.1</version>
        <executions>
          <execution>
            <id>enforce</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <dependencyConvergence />
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>

  <profiles>
    <profile>
      <id>httpclient45</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <executions>
              <execution>
                <id>execute-tests</id>
                <phase>test</phase>
                <goals>
                  <goal>test</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      <dependencies>
        <dependency>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpclient</artifactId>
          <version>4.5</version>
        </dependency>
        <dependency>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpcore</artifactId>
          <version>4.4.1</version>
        </dependency>
      </dependencies>
    </profile>

    <profile>
      <id>httpclient42</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
              <source>1.7</source>
              <target>1.7</target>
              <!-- Exclude classes for http client version 4.5: -->
              <excludes>
                <exclude>**/HttpClient45.java</exclude>
                <exclude>**/ConnectionBuilder45.java</exclude>
              </excludes>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <executions>
              <execution>
                <id>execute-tests</id>
                <phase>test</phase>
                <goals>
                  <goal>test</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      <dependencies>
        <dependency>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpclient</artifactId>
          <version>4.2.5</version>
        </dependency>
        <dependency>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpcore</artifactId>
          <version>4.2.4</version>
        </dependency>
      </dependencies>
    </profile>
  </profiles>

</project>
