<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright 2015 herd contributors

  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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         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>org.finra.herd</groupId>
      <artifactId>herd-code</artifactId>
      <version>0.97.0</version>
   </parent>

   <properties>

      <maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>

      <!-- NOTE: This version number should be updated after EACH sprint at the same time as the herd snapshot version above. -->
      <herdsdk.version>0.90.0</herdsdk.version>

   </properties>

   <name>herd sdk</name>

   <!-- groupId and version are inherited from the parent and can be overridden here if needed. -->
   <artifactId>herd-sdk</artifactId>

   <description>This project contains swagger generated clients that invoke the herd REST API's.
   </description>
   <url>http://finraos.github.io/herd/</url>

   <dependencies>
      <dependency>
         <groupId>com.sun.jersey</groupId>
         <artifactId>jersey-client</artifactId>
      </dependency>
      <dependency>
         <groupId>com.sun.jersey.contribs</groupId>
         <artifactId>jersey-multipart</artifactId>
      </dependency>
      <dependency>
         <groupId>com.fasterxml.jackson.core</groupId>
         <artifactId>jackson-core</artifactId>
         <version>${apache.spark.jackson.version}</version>
      </dependency>
      <dependency>
         <groupId>com.fasterxml.jackson.core</groupId>
         <artifactId>jackson-annotations</artifactId>
         <version>${apache.spark.jackson.version}</version>
      </dependency>
      <dependency>
         <groupId>com.fasterxml.jackson.core</groupId>
         <artifactId>jackson-databind</artifactId>
         <version>${apache.spark.jackson.version}</version>
      </dependency>
      <dependency>
         <groupId>com.fasterxml.jackson.jaxrs</groupId>
         <artifactId>jackson-jaxrs-json-provider</artifactId>
         <version>${apache.spark.jackson.version}</version>
      </dependency>
      <dependency>
         <groupId>com.fasterxml.jackson.datatype</groupId>
         <artifactId>jackson-datatype-joda</artifactId>
         <version>${apache.spark.jackson.version}</version>
      </dependency>
      <dependency>
         <groupId>joda-time</groupId>
         <artifactId>joda-time</artifactId>
      </dependency>
      <dependency>
         <groupId>com.brsanthu</groupId>
         <artifactId>migbase64</artifactId>
      </dependency>
   </dependencies>

   <build>

      <!-- Add in the Swagger generated sources location as a resource so it can be correctly added with the maven-source-plugin. -->
      <resources>
         <resource>
            <directory>target/generated-sources/swagger/src/main/java</directory>
         </resource>
      </resources>

      <plugins>

         <!--
          Copy the generated YAML file from the herd-docs-swagger project to this one in the target directory so it can be picked up by the
          swagger-codegen-maven-plugin.
         -->
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
               <execution>
                  <id>unpack-shared-resources</id>
                  <goals>
                     <goal>unpack</goal>
                  </goals>
                  <phase>initialize</phase>
                  <configuration>
                     <artifactItems>
                        <artifactItem>
                           <groupId>${project.groupId}</groupId>
                           <artifactId>herd-docs-swagger</artifactId>
                           <version>${project.version}</version>
                           <type>zip</type>
                           <outputDirectory>${project.build.directory}/generated-resources</outputDirectory>
                           <includes>**/*.yaml</includes>
                        </artifactItem>
                     </artifactItems>
                  </configuration>
               </execution>
            </executions>
            <dependencies>
               <dependency>
                  <groupId>${project.groupId}</groupId>
                  <artifactId>herd-docs-swagger</artifactId>
                  <version>${project.version}</version>
               </dependency>
            </dependencies>
         </plugin>

         <!-- Generate the SDK files from the YAML file. -->
         <plugin>
            <groupId>org.openapitools</groupId>
            <artifactId>openapi-generator-maven-plugin</artifactId>
            <executions>
               <execution>
                  <goals>
                     <goal>generate</goal>
                  </goals>
                  <id>JAVA-Generation</id>
                  <phase>generate-resources</phase>
                  <configuration>
                     <inputSpec>${project.build.directory}/generated-resources/herd-docs-swagger-${project.version}/docs/rest/herd.swagger.yaml</inputSpec>
                     <output>${project.build.directory}/generated-sources/swagger</output>
                     <!-- Don't add the output directory to the project as a source root since we added it as a resource ourselves above. -->
                     <addCompileSourceRoot>false</addCompileSourceRoot>
                     <generatorName>java</generatorName>
                     <apiPackage>org.finra.herd.sdk.api</apiPackage>
                     <modelPackage>org.finra.herd.sdk.model</modelPackage>
                     <invokerPackage>org.finra.herd.sdk.invoker</invokerPackage>
                     <!--This generation can be refactored to generate its own tests and pom configuration-->
                     <!--When that happens these should be set to true and other config options need to be set-->
                     <generateApiTests>false</generateApiTests>
                     <generateModelTests>false</generateModelTests>
                     <generateApiDocumentation>false</generateApiDocumentation>
                     <generateModelDocumentation>false</generateModelDocumentation>
                     <!--uncomment next line in order to see all possible <configOptions> for the selected language-->
                     <!--<configHelp>true</configHelp>-->
                     <configOptions>
                        <!--these are the options specific to the java generation language-->
                        <licenseName>Apache-2.0</licenseName>
                        <licenseUrl>https://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
                        <library>jersey1</library>
                        <dateLibrary>joda</dateLibrary>
                     </configOptions>
                  </configuration>
               </execution>

               <execution>
                  <goals>
                     <goal>generate</goal>
                  </goals>
                  <id>Node-Generation</id>
                  <phase>prepare-package</phase>
                  <configuration>
                     <inputSpec>${project.build.directory}/generated-resources/herd-docs-swagger-${project.version}/docs/rest/herd.swagger.yaml</inputSpec>
                     <output>${project.build.directory}/node-client</output>
                     <generatorName>typescript-node</generatorName>
                  </configuration>
               </execution>

               <execution>
                  <goals>
                     <goal>generate</goal>
                  </goals>
                  <id>AngularJS-Generation</id>
                  <phase>prepare-package</phase>
                  <configuration>
                     <inputSpec>${project.build.directory}/generated-resources/herd-docs-swagger-${project.version}/docs/rest/herd.swagger.yaml</inputSpec>
                     <output>${project.build.directory}/angularjs-client</output>
                     <generatorName>typescript-angularjs</generatorName>
                  </configuration>
               </execution>

               <execution>
                  <goals>
                     <goal>generate</goal>
                  </goals>
                  <id>Angular-Generation</id>
                  <phase>prepare-package</phase>
                  <configuration>
                     <inputSpec>${project.build.directory}/generated-resources/herd-docs-swagger-${project.version}/docs/rest/herd.swagger.yaml</inputSpec>
                     <output>${project.build.directory}/angular-client</output>
                     <generatorName>typescript-angular</generatorName>
                     <configOptions>
                        <ngVersion>6.1.2</ngVersion>
                        <providedInRoot>true</providedInRoot>
                     </configOptions>
                  </configuration>
               </execution>

               <execution>
                  <goals>
                     <goal>generate</goal>
                  </goals>
                  <id>Python-Generation</id>
                  <phase>generate-resources</phase>
                  <configuration>
                     <inputSpec>${project.build.directory}/generated-resources/herd-docs-swagger-${project.version}/docs/rest/herd.swagger.yaml</inputSpec>
                     <output>${project.build.directory}/python-client</output>
                     <generatorName>python</generatorName>
                     <configOptions>
                        <packageName>herdsdk</packageName>
                        <projectName>herdsdk</projectName>
                        <packageVersion>${herdsdk.version}</packageVersion>
                     </configOptions>
                  </configuration>
               </execution>
            </executions>
         </plugin>

         <!-- Exclude the auto-generated java files from the main jar. -->
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
               <excludes>
                  <excludes>**/*.java</excludes>
               </excludes>
            </configuration>
         </plugin>

         <!-- Add in the sources. -->
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <executions>
               <execution>
                  <id>attach-sources</id>
                  <goals>
                     <goal>jar</goal>
                  </goals>
               </execution>
            </executions>
            <configuration>
               <!-- Include only the java files and not the other stuff the Swagger plug-in generates. -->
               <includes>
                  <include>**/*.java</include>
               </includes>
               <!-- Exclude the 2nd set of java code that the Swagger plug-in generates. -->
               <excludes>
                  <excludes>swagger/src/main/java/**</excludes>
               </excludes>
            </configuration>
         </plugin>

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <executions>
               <execution>
                  <id>jar</id>
                  <goals>
                     <goal>jar</goal>
                  </goals>
               </execution>
            </executions>
            <configuration>
               <!-- Specify the location where the swagger plugin generated the sources. -->
               <sourcepath>${project.build.directory}/generated-sources/swagger/src/main/java</sourcepath>
            </configuration>
         </plugin>

         <!-- Configure the Maven compiler to use JDK 1.5 to produce the appropriate class files that can be used with JDK 1.5 and up. -->
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
               <source>1.5</source>
               <target>1.5</target>
            </configuration>
         </plugin>


         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
               <execution>
                  <id>copy-angular-ts-config</id>
                  <phase>package</phase>
                  <configuration>
                     <target>
                        <copy overwrite="true" todir="${project.build.directory}/angular-client">
                           <fileset dir="${project.basedir}/src/tsconfig/angular"/>
                           <filterset>
                              <filter token="NPM_VERSION" value="${project.version}.${maven.build.timestamp}"/>
                           </filterset>
                        </copy>
                     </target>
                  </configuration>
                  <goals>
                     <goal>run</goal>
                  </goals>
               </execution>
               <execution>
                  <id>copy-angularjs-ts-config</id>
                  <phase>package</phase>
                  <configuration>
                     <target>
                        <copy overwrite="true" todir="${project.build.directory}/angularjs-client">
                           <fileset dir="${project.basedir}/src/tsconfig/angularjs"/>
                           <filterset>
                              <filter token="NPM_VERSION" value="${project.version}.${maven.build.timestamp}"/>
                           </filterset>
                        </copy>
                     </target>
                  </configuration>
                  <goals>
                     <goal>run</goal>
                  </goals>
               </execution>
               <execution>
                  <id>copy-node-ts-config</id>
                  <phase>package</phase>
                  <configuration>
                     <target>
                        <copy overwrite="true" todir="${project.build.directory}/node-client">
                           <fileset dir="${project.basedir}/src/tsconfig/node"/>
                           <filterset>
                              <filter token="NPM_VERSION" value="${project.version}.${maven.build.timestamp}"/>
                           </filterset>
                        </copy>
                     </target>
                  </configuration>
                  <goals>
                     <goal>run</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>


      </plugins>

   </build>

</project>
