<?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.8.1</version>
  <properties>
    <cxf.version>3.4.5</cxf.version>
    <guava.version>28.1-jre</guava.version>
    <jackson2.version>2.10.0</jackson2.version>
    <joda.version>2.1</joda.version>
    <junit.version>4.12</junit.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>50</apiVersion>
    <apiVersionString>v${apiVersion}</apiVersionString>
    <javadocOptions>-Xdoclint:none</javadocOptions>
    <findbugsVersion>3.0.1</findbugsVersion>
  </properties>

  <distributionManagement>
    <repository>
      <id>cdh.releases.repo</id>
      <url>http://maven.jenkins.cloudera.com:8081/artifactory/cdh-staging-local</url>
      <name>CDH Releases Repository</name>
    </repository>
    <snapshotRepository>
      <id>cdh.snapshots.repo</id>
      <url>http://maven.jenkins.cloudera.com:8081/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>
    <plugins>
      <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>
      <!-- Enunciate 1 doesn't work with Java 8; use Enunciate 2. -->
      <plugin>
        <groupId>com.webcohesion.enunciate</groupId>
        <artifactId>enunciate-maven-plugin</artifactId>
        <version>2.13.1</version>
        <configuration>
          <configFile>enunciate2.xml</configFile>
          <docsDir>${restapi.dir}</docsDir>
          <enunciateArtifactId>Cloudera Manager API Docs</enunciateArtifactId>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>docs</goal>
            </goals>
            <phase>prepare-package</phase>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <version>${java.version}</version>
            <scope>system</scope>
            <systemPath>${java.home}/../lib/tools.jar</systemPath>
          </dependency>
        </dependencies>
      </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-preprocessor.py</argument>
                <argument>-f</argument>
                <argument>${restapi.dir}/apidocs/ui/swagger.json</argument>
              </arguments>
            </configuration>
            <id>python_build</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>exec</goal>
            </goals>
          </execution>
          <execution>
            <!-- Overriding and replacing escaped chars in Python API package -->
            <configuration>
              <executable>bash</executable>
              <arguments>
                <argument>-c</argument>
                <argument>sed 'N;N;N;s/long_description=.*\n.*\n.*/long_description="Cloudera Manager API client ${python_client.version} for API version ${apiVersion} introduced in Cloudera Manager ${project.version}"/g' ${project.build.directory}/swagger/python/setup.py > ${project.build.directory}/swagger/python/setup.py.tmp ; mv ${project.build.directory}/swagger/python/setup.py.tmp ${project.build.directory}/swagger/python/setup.py</argument>
              </arguments>
            </configuration>
            <id>update_python_client_description</id>
            <phase>package</phase>
            <goals>
              <goal>exec</goal>
            </goals>
          </execution>
          <!-- OPSAPS 52807: swagger-utils.py adds cloudera branding to API Documentation/Explorer pages -->
          <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</groupId>
        <artifactId>swagger-codegen-maven-plugin</artifactId>
        <version>2.2.3</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/swagger.json</inputSpec>
              <language>java</language>
              <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>
              </configOptions>
              <apiPackage>com.cloudera.api.swagger</apiPackage>
              <modelPackage>com.cloudera.api.swagger.model</modelPackage>
              <invokerPackage>com.cloudera.api.swagger.client</invokerPackage>
            </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/swagger.json</inputSpec>
              <language>python</language>
              <output>${project.build.directory}/swagger/python</output>
              <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>2.3.2</version>
        <configuration>
          <compilerArgument>-Xlint</compilerArgument>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <shadedArtifactAttached>true</shadedArtifactAttached>
              <shadedClassifierName>shaded</shadedClassifierName>
              <artifactSet>
                <includes>
                  <include>com.fasterxml.jackson.*:*</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>
            </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>
        <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>org.codehaus.mojo</groupId>
        <artifactId>findbugs-maven-plugin</artifactId>
        <version>${findbugsVersion}</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>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-client</artifactId>
      <version>${cxf.version}</version>
    </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>com.webcohesion.enunciate</groupId>
      <artifactId>enunciate-core</artifactId>
      <version>2.13.1</version>
    </dependency>
    <!-- Following dependencies are needed for the Swagger Java API client being generated -->
    <dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-annotations</artifactId>
      <version>1.5.17</version>
    </dependency>
    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.8.2</version>
    </dependency>
    <dependency>
      <groupId>com.squareup.okhttp</groupId>
      <artifactId>okhttp</artifactId>
      <version>2.7.5</version>
    </dependency>
    <dependency>
      <groupId>com.squareup.okhttp</groupId>
      <artifactId>logging-interceptor</artifactId>
      <version>2.7.5</version>
    </dependency>
    <!-- End of Swagger Java API client dependencies -->
  </dependencies>
</project>
