<?xml version="1.0"?>
<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>
  <packaging>jar</packaging>
  <groupId>com.cloudera.api</groupId>
  <artifactId>cloudera-manager-api</artifactId>
  <name>Cloudera Manager API</name>
  <version>7.13.2</version>
  <properties>
    <cxf.version>3.5.11</cxf.version>
    <google-gson.version>2.9.0</google-gson.version>
    <guava.version>32.0.1-jre</guava.version>
    <jackson2.version>2.15.0</jackson2.version>
    <joda.version>2.10.13</joda.version>
    <junit.version>4.12</junit.version>
    <hamcrest.version>2.2</hamcrest.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <test.redirectToFile>true</test.redirectToFile>
    <privateClassPath>com.cloudera.api.shaded</privateClassPath>
    <restapi.dir>${project.build.directory}/classes/restapi</restapi.dir>
    <!-- Update the apiVersion below whenever API version is updated in ApiRootResource.java -->
    <apiVersion>58</apiVersion>
    <!-- apiVersionString is referenced in enunciate2.xml -->
    <apiVersionString>v${apiVersion}</apiVersionString>
    <apiVersionFinalString>VFinal</apiVersionFinalString>
    <baseUrl>/api/${apiVersionString}</baseUrl>
    <javadocOptions>-Xdoclint:none</javadocOptions>
    <spotbugsVersion>4.9.3.0</spotbugsVersion>
  </properties>

  <distributionManagement>
    <repository>
      <id>cdh.releases.repo</id>
      <url>https://maven.jenkins.cloudera.com/artifactory/cdh-staging-local</url>
      <name>CDH Releases Repository</name>
    </repository>
    <snapshotRepository>
      <id>cdh.snapshots.repo</id>
      <url>https://maven.jenkins.cloudera.com/artifactory/libs-snapshot-local</url>
      <name>CDH Snapshots Repository</name>
    </snapshotRepository>
  </distributionManagement>

  <profiles>
    <profile>
      <!-- profile to use with Atlassian Clover for code coverage -->
      <id>clover</id>
      <properties>
        <clover.version>4.0.3</clover.version>
        <clover.generateHtml>true</clover.generateHtml>
        <clover.generateXml>true</clover.generateXml>
      </properties>
      <dependencies>
        <dependency>
          <groupId>com.atlassian.clover</groupId>
          <artifactId>clover</artifactId>
          <version>${clover.version}</version>
        </dependency>
      </dependencies>
      <build>
        <plugins>
          <plugin>
            <!-- Clover plugin to enable maven to create instantiated jars that will record code coverage -->
            <groupId>com.atlassian.maven.plugins</groupId>
            <artifactId>maven-clover2-plugin</artifactId>
            <version>${clover.version}</version>
            <configuration>
              <generateHtml>${clover.generateHtml}</generateHtml>
              <generateXml>${clover.generateXml}</generateXml>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

  <build>
    <resources>
      <resource>
        <directory>${project.basedir}</directory>
        <filtering>true</filtering>
        <includes>
          <include>openapi.fmt</include>
        </includes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>filter-openapi-template</id>
            <phase>generate-resources</phase>
            <goals><goal>copy-resources</goal></goals>
            <configuration>
              <outputDirectory>${project.build.directory}/generated-resources</outputDirectory>
              <resources>
                <resource>
                  <directory>${project.basedir}</directory>
                  <includes>
                    <include>openapi.fmt</include>
                  </includes>
                  <filtering>true</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <!-- Python API client version uses CM API version followed by maintenance release version -->
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.12</version>
        <executions>
          <execution>
            <id>regex-property</id>
            <goals>
              <goal>regex-property</goal>
            </goals>
            <configuration>
              <name>python_client.version</name>
              <value>${project.version}</value>
              <!-- Match any character as we use ".x" for development branches -->
              <regex>^(.+)\.(.+)\.(.+)$</regex>
              <replacement>${apiVersion}.0.$3</replacement>
              <failIfNoMatch>true</failIfNoMatch>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.cloudera.tools</groupId>
        <artifactId>api-flattener</artifactId>
        <version>${project.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <javaRelease>17</javaRelease>
              <sourceDirectory>${project.basedir}/src/main/java/com/cloudera/api</sourceDirectory>
              <targetDirectory>${project.build.directory}/generated-sources</targetDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.webcohesion.enunciate</groupId>
        <artifactId>enunciate-maven-plugin</artifactId>
        <version>2.15.0-cldr</version>
        <configuration>
          <configFile>enunciate2.xml</configFile>
          <docsDir>${restapi.dir}</docsDir>
          <enunciateArtifactId>Cloudera Manager API Docs</enunciateArtifactId>
          <sources>
            <source>${project.basedir}/src/main/java</source>
            <source>${project.build.directory}/generated-sources</source>
          </sources>
        </configuration>
        <executions>
          <execution>
            <id>enunciate-api</id>
            <goals>
              <goal>docs</goal>
            </goals>
            <phase>prepare-package</phase>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.6.0</version>
        <executions>
          <execution>
            <configuration>
              <executable>python</executable>
              <workingDirectory>${project.basedir}</workingDirectory>
              <arguments>
                <argument>swagger-utils.py</argument>
                <argument>${restapi.dir}/apidocs/ui/index.html</argument>
                <argument>${restapi.dir}/apidocs/ui/swagger-ui.css</argument>
                <argument>${restapi.dir}/apidocs/ui/swagger-ui-standalone-preset.js</argument>
                <argument>${project.basedir}/static/cms/icons/manager-logo.svg</argument>
                <argument>${restapi.dir}/apidocs/</argument>
              </arguments>
            </configuration>
            <id>update_index_html</id>
            <phase>package</phase>
            <goals>
              <goal>exec</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>io.swagger.codegen.v3</groupId>
        <artifactId>swagger-codegen-maven-plugin</artifactId>
        <version>3.0.71</version>
        <executions>
          <execution>
            <id>java-client</id>
            <goals>
              <goal>generate</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <templateDirectory>${project.basedir}/swagger/templates/java/</templateDirectory>
              <inputSpec>${restapi.dir}/apidocs/ui/openapi.json</inputSpec>
              <language>java</language>
              <library>okhttp4-gson</library>
              <typeMappings>
                <typeMapping>Integer=java.math.BigDecimal</typeMapping>
              </typeMappings>
              <output>${project.build.directory}/swagger/java</output>
              <!-- See language specific config options in the source code
              https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java -->
              <configOptions>
                <dateLibrary>java8</dateLibrary>
                <groupId>com.cloudera.api.swagger</groupId>
                <artifactId>cloudera-manager-api-swagger</artifactId>
                <artifactVersion>${project.version}</artifactVersion>
                <java11>true</java11>
              </configOptions>
              <apiPackage>com.cloudera.api.swagger</apiPackage>
              <modelPackage>com.cloudera.api.swagger.model</modelPackage>
              <invokerPackage>com.cloudera.api.swagger.client</invokerPackage>
              <environmentVariables>
                <maxYamlCodePoints>99999999</maxYamlCodePoints>
              </environmentVariables>
            </configuration>
          </execution>
          <execution>
            <id>python-client</id>
            <goals>
              <goal>generate</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <templateDirectory>${project.basedir}/swagger/templates/python/</templateDirectory>
              <inputSpec>${restapi.dir}/apidocs/ui/openapi.json</inputSpec>
              <language>python</language>
              <output>${project.build.directory}/swagger/python</output>
              <apiPackage>apis</apiPackage>
              <modelPackage>models</modelPackage>
              <configOptions>
                <packageName>cm_client</packageName>
                <packageVersion>${python_client.version}</packageVersion>
              </configOptions>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.ruleoftech</groupId>
        <artifactId>markdown-page-generator-plugin</artifactId>
        <version>2.1.0</version>
        <executions>
          <execution>
            <phase>prepare-package</phase>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <headerHtmlFile>${project.basedir}/swagger-client-sdk-header.html</headerHtmlFile>
          <inputDirectory>${project.build.directory}/swagger</inputDirectory>
          <outputDirectory>${project.build.directory}/swagger-html-sdk-docs</outputDirectory>
          <recursiveInput>true</recursiveInput>
          <transformRelativeMarkdownLinks>true</transformRelativeMarkdownLinks>
          <pegdownExtensions>TABLES,HARDWRAPS,FENCED_CODE_BLOCKS,AUTOLINKS,STRIKETHROUGH,ATXHEADERSPACE,TASKLISTITEMS,ANCHORLINKS</pegdownExtensions>
          <attributes>
            <attribute>TableBlock|class=table table-striped table-bordered</attribute>
          </attributes>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.11.0</version>
        <configuration>
          <release>17</release>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <shadedArtifactAttached>true</shadedArtifactAttached>
              <shadedClassifierName>shaded</shadedClassifierName>
              <artifactSet>
                <includes>
                  <include>com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider</include>
                  <include>com.fasterxml.jackson.core:*</include>
                  <include>com.fasterxml.jackson.databind:jackson-databind</include>
                  <include>com.fasterxml.jackson.module:jackson-module-jaxb-annotations</include>
                  <include>com.google.guava:guava</include>
                  <include>com.google.guava:failureaccess</include>
                  <include>joda-time:joda-time*</include>
                </includes>
              </artifactSet>
              <relocations>
                <relocation>
                  <pattern>com.</pattern>
                  <shadedPattern>${privateClassPath}.com.</shadedPattern>
                  <includes>
                    <include>com.google.common.**</include>
                    <!--include>com.fasterxml.jackson.**</include-->
                  </includes>
                </relocation>
                <relocation>
                  <pattern>org.</pattern>
                  <shadedPattern>${privateClassPath}.org.</shadedPattern>
                  <includes>
                    <include>org.joda.time.**</include>
                  </includes>
                </relocation>
              </relocations>
              <filters>
                <filter>
                  <artifact>com.fasterxml.jackson.core:jackson-core</artifact>
                  <excludes>
                    <exclude>**/module-info.class</exclude>
                    <exclude>META-INF/MANIFEST.MF</exclude>
                    <exclude>META-INF/services/**</exclude>
                    <exclude>META-INF/versions/**</exclude>
                  </excludes>
                </filter>
              </filters>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.1</version>
        <executions>
          <execution>
            <goals>
              <goal>test-jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12.4</version>
        <dependencies>
          <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>5.12.1</version>
          </dependency>
        </dependencies>
        <configuration>
          <systemProperties>
            <java.awt.headless>true</java.awt.headless>
          </systemProperties>
          <redirectTestOutputToFile>${test.redirectToFile}</redirectTestOutputToFile>
          <useFile>${test.redirectToFile}</useFile>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>2.2.1</version>
        <executions>
          <execution>
            <id>attach-sources</id>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.github.spotbugs</groupId>
        <artifactId>spotbugs-maven-plugin</artifactId>
        <version>${spotbugsVersion}</version>
        <configuration>
          <excludeFilterFile>findbugs-exclude.xml</excludeFilterFile>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.owasp</groupId>
        <artifactId>dependency-check-maven</artifactId>
        <version>1.4.3</version>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>${jackson2.version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <version>${jackson2.version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>${jackson2.version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.module</groupId>
      <artifactId>jackson-module-jaxb-annotations</artifactId>
      <version>${jackson2.version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.jaxrs</groupId>
      <artifactId>jackson-jaxrs-json-provider</artifactId>
      <version>${jackson2.version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.datatype</groupId>
      <artifactId>jackson-datatype-joda</artifactId>
      <version>${jackson2.version}</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-client</artifactId>
      <version>${cxf.version}</version>
      <exclusions>
        <exclusion>
          <groupId>com.fasterxml.woodstox</groupId>
          <artifactId>woodstox-core</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-features-logging</artifactId>
      <version>${cxf.version}</version>
    </dependency>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>${guava.version}</version>
    </dependency>
    <dependency>
      <groupId>javax.annotation</groupId>
      <artifactId>jsr250-api</artifactId>
      <version>1.0</version>
      <!-- Provided since this dependency is only needed by the CM server,
           which already provides it. We only use the security annotations,
           which are never processed by the client code. -->
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>joda-time</groupId>
      <artifactId>joda-time</artifactId>
      <version>${joda.version}</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.1</version>
    </dependency>
    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
      <version>2.6</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest</artifactId>
      <version>${hamcrest.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax.ws.rs</groupId>
      <artifactId>javax.ws.rs-api</artifactId>
      <version>2.1.1</version>
    </dependency>
    <dependency>
      <groupId>javax.xml.bind</groupId>
      <artifactId>jaxb-api</artifactId>
      <version>2.4.0-b180830.0359</version>
    </dependency>
    <dependency>
      <groupId>javax.annotation</groupId>
      <artifactId>javax.annotation-api</artifactId>
      <version>1.3.2</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.activation</groupId>
      <artifactId>activation</artifactId>
      <version>1.1.1</version>
    </dependency>
    <dependency>
      <groupId>com.webcohesion.enunciate</groupId>
      <artifactId>enunciate-core-annotations</artifactId>
      <version>2.15.0</version>
      <exclusions>
        <exclusion>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-configuration2</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-configuration2</artifactId>
      <version>2.10.1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-collections4</artifactId>
      <version>4.2</version>
    </dependency>
    <!-- Following dependencies are needed for the Swagger Java API client being generated -->
    <dependency>
      <groupId>io.swagger.core.v3</groupId>
      <artifactId>swagger-annotations</artifactId>
      <version>2.2.20</version>
    </dependency>
    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>${google-gson.version}</version>
    </dependency>
    <dependency>
      <groupId>com.squareup.okhttp3</groupId>
      <artifactId>okhttp</artifactId>
      <version>4.12.0</version>
    </dependency>
    <dependency>
      <groupId>com.squareup.okhttp3</groupId>
      <artifactId>logging-interceptor</artifactId>
      <version>4.12.0</version>
    </dependency>
    <dependency>
      <groupId>io.gsonfire</groupId>
      <artifactId>gson-fire</artifactId>
      <version>1.9.0</version>
    </dependency>
    <dependency>
      <groupId>com.cloudera.cmf</groupId>
      <artifactId>test-common</artifactId>
      <version>${project.version}</version>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>
      <!-- End of Swagger Java API client dependencies -->

      <!--
         Enunciate 2.15 does not recognize swagger-annotations v3
         So we need to add back swagger-annotations v1.6.9 to be able to
         apply @ApiOperation - eg. CommandsResourceV45.getCommandResultData
      -->
      <dependency>
          <groupId>io.swagger</groupId>
          <artifactId>swagger-annotations</artifactId>
          <version>1.6.9</version>
          <optional>true</optional>
      </dependency>

  </dependencies>
</project>
