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

    Copyright (C) 2011 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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>me.snowdrop</groupId>
    <artifactId>istio-java-api</artifactId>
    <version>1.7.7.1</version>
  </parent>

  <artifactId>istio-model</artifactId>
  <packaging>jar</packaging>

  <name>Snowdrop :: Istio Java API :: Model</name>

  <properties>
    <schema.dir>${basedir}/src/main/resources/schema</schema.dir>
    <antlr4.version>4.7.1</antlr4.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>me.snowdrop</groupId>
      <artifactId>istio-common</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>joda-time</groupId>
      <artifactId>joda-time</artifactId>
      <version>2.9.9</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.joda/joda-convert -->
    <dependency>
      <groupId>org.joda</groupId>
      <artifactId>joda-convert</artifactId>
      <version>2.0.2</version>
    </dependency>
    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>kubernetes-model</artifactId>
    </dependency>
    <dependency>
      <groupId>org.antlr</groupId>
      <artifactId>antlr4-runtime</artifactId>
      <version>${antlr4.version}</version>
    </dependency>
    <dependency>
      <groupId>io.sundr</groupId>
      <artifactId>builder-annotations</artifactId>
      <scope>provided</scope>
      <exclusions>
        <exclusion>
          <groupId>com.sun</groupId>
          <artifactId>tools</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>io.sundr</groupId>
      <artifactId>transform-annotations</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.dataformat</groupId>
      <artifactId>jackson-dataformat-yaml</artifactId>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <profiles>
    <profile>
      <id>jdk9</id>
      <activation>
        <jdk>[1,1.9)</jdk>
      </activation>
      <dependencies>
        <dependency>
          <groupId>com.sun</groupId>
          <artifactId>tools</artifactId>
          <version>1.7</version>
          <scope>system</scope>
          <systemPath>${java.home}/../lib/tools.jar</systemPath>
        </dependency>
      </dependencies>
    </profile>
  </profiles>
  <build>
    <plugins>
      <plugin>
        <groupId>org.antlr</groupId>
        <artifactId>antlr4-maven-plugin</artifactId>
        <version>${antlr4.version}</version>
        <executions>
          <execution>
            <id>antlr</id>
            <goals>
              <goal>antlr4</goal>
            </goals>
            <!-- If we want to put the generated ANTLR classes in the proper package with other sources -->
            <!--<configuration>
              <outputDirectory>${project.build.sourceDirectory}/me/snowdrop/istio/api/cexl/parser</outputDirectory>
            </configuration>-->
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.jsonschema2pojo</groupId>
        <artifactId>jsonschema2pojo-maven-plugin</artifactId>
        <version>${jsonschema2pojo.version}</version>
        <configuration>
          <sourceDirectory>${schema.dir}</sourceDirectory>
          <targetPackage>me.snowdrop.istio.api</targetPackage>
          <includeConstructors>true</includeConstructors>
<!--          <includeJsr303Annotations>true</includeJsr303Annotations>-->
          <includeToString>false</includeToString>
          <serializable>true</serializable>
          <targetVersion>1.8</targetVersion>
          <includeHashcodeAndEquals>false</includeHashcodeAndEquals>
          <inclusionLevel>NON_EMPTY</inclusionLevel>
          <outputDirectory>${project.build.directory}/generated-sources/jsonschema2pojo</outputDirectory>
          <customAnnotator>me.snowdrop.istio.annotator.IstioTypeAnnotator</customAnnotator>
          <annotationStyle>none</annotationStyle>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>me.snowdrop</groupId>
            <artifactId>istio-model-annotator</artifactId>
            <version>${project.version}</version>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <id>remove-classes-pre-generation</id>
            <phase>generate-sources</phase>
            <configuration>
              <target>
                <echo>removing the duplicate / useless generated classes</echo>
                <delete file="${basedir}/target/generated-sources/jsonschema2pojo/me/snowdrop/istio/api/Duration.java" verbose="true" />
                <delete file="${basedir}/target/generated-sources/jsonschema2pojo/me/snowdrop/istio/api/IstioSchema.java" verbose="true" />
                <delete file="${basedir}/target/generated-sources/jsonschema2pojo/me/snowdrop/istio/api/TimeStamp.java" verbose="true" />
                <delete file="${basedir}/target/generated-sources/jsonschema2pojo/me/snowdrop/istio/api/cexl/TypedValue.java" verbose="true" />
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>attach-artifacts</id>
            <phase>package</phase>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <configuration>
              <artifacts>
                <artifact>
                  <file>${schema.dir}/istio-schema.json</file>
                  <type>json</type>
                  <classifier>schema</classifier>
                </artifact>
              </artifacts>
            </configuration>
          </execution>
          <execution>
            <!-- Add the generated sources as maven looked-at sources so that we can use them in tests -->
            <id>add-sources</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${project.build.directory}/generated-sources/annotations</source>
                <source>${project.build.directory}/generated-sources/jsonschema2pojo</source>
                <!--
                Useful when locally generating ANTLR parser classes (outside of maven) e.g. to work on CEXLTypeResolver.
                Note that project won't compile with locally generated classes since we then have duplicated classes with
                what is generated by the maven plugin.
                -->
                <source>${project.basedir}/gen/</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
