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

    Copyright 2022-2023 Open Text.

    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>io.github.fileanalysissuite.adapters.rest.contract</groupId>
        <artifactId>adapter-rest-contract-aggregator</artifactId>
        <version>1.0.0-77</version>
    </parent>

    <artifactId>adapter-rest-dotnet-client</artifactId>
    <packaging>pom</packaging>

    <properties>
        <nugetOutputFolder>${project.build.directory}</nugetOutputFolder>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.github.fileanalysissuite.adapters.rest.contract</groupId>
            <artifactId>adapter-rest-contract</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <dependencies>
                    <dependency>
                        <groupId>io.github.fileanalysissuite.adapters.rest.contract</groupId>
                        <artifactId>adapter-rest-contract</artifactId>
                        <version>${project.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>generate-csharp-client-code</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>/io/github/fileanalysissuite/adapters/rest/contract/swagger.yaml</inputSpec>
                            <generatorName>csharp-netcore</generatorName>
                            <output>${project.build.directory}/openapi-codegen</output>
                            <gitUserId>FileAnalysisSuite</gitUserId>
                            <gitRepoId>adapter-rest-contract</gitRepoId>
                            <addCompileSourceRoot>false</addCompileSourceRoot>
                            <packageName>MicroFocus.FAS.Adapters.Rest.Client</packageName>
                            <library>httpclient</library>
                            <configOptions>
                                <packageVersion>${project.version}</packageVersion>
                                <packageGuid>{5CC863B4-F7B2-4565-909C-32E8C05B13E9}</packageGuid>
                                <licenseId>Apache-2.0</licenseId>
                                <releaseNote>See https://github.com/FileAnalysisSuite/adapter-rest-contract/releases</releaseNote>
                                <targetFramework>netstandard2.0</targetFramework>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.gmavenplus</groupId>
                <artifactId>gmavenplus-plugin</artifactId>
                <executions>
                    <execution>
                        <id>update-csproj-file</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <properties>
                                <property>
                                    <name>targetDir</name>
                                    <value>${project.build.directory}</value>
                                </property>
                                <property>
                                    <name>copyrightNotice</name>
                                    <value>${copyrightNotice}</value>
                                </property>
                                <property>
                                    <name>company</name>
                                    <value>${project.organization.name}</value>
                                </property>
                            </properties>
                            <scripts>
                                <script><![CDATA[
    def csprojFile = new File(
        targetDir + '/openapi-codegen/src/MicroFocus.FAS.Adapters.Rest.Client/MicroFocus.FAS.Adapters.Rest.Client.csproj')

    csprojFile.write(csprojFile.text
        .replaceAll('<Authors>.*</Authors>', '<Authors>Micro Focus FAS Development Team</Authors>')
        .replaceAll('<Copyright>.*</Copyright>', '<Copyright>' + groovy.xml.XmlUtil.escapeXml(copyrightNotice) + '</Copyright>')
        .replaceAll('<AssemblyTitle>.*</AssemblyTitle>', '<AssemblyTitle>REST Adapter Client Library</AssemblyTitle>')
        .replaceAll('<Description>.*</Description>', '<Description>Auto-generated REST Adapter Client Library</Description>')
        .replaceAll('<Company>.*</Company>', '<Company>' + groovy.xml.XmlUtil.escapeXml(company) + '</Company>'))
                                ]]>
                                </script>
                            </scripts>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-all</artifactId>
                        <version>2.4.21</version>
                        <scope>runtime</scope>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.2</version>
                <executions>
                    <execution>
                        <id>copy-swagger-codegen-files</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/generated-sources/csharp</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.build.directory}/openapi-codegen/src</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <configuration>
                    <environmentVariables>
                        <VERSION>${project.version}</VERSION>
                    </environmentVariables>
                    <workingDirectory>${project.build.directory}/openapi-codegen</workingDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>exec-dotnet-restore</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>dotnet</executable>
                            <arguments>
                                <argument>restore</argument>
                                <argument>--verbosity</argument>
                                <argument>normal</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>exec-dotnet-build</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>dotnet</executable>
                            <arguments>
                                <argument>build</argument>
                                <argument>--configuration</argument>
                                <argument>Release</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>exec-dotnet-pack</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>dotnet</executable>
                            <arguments>
                                <argument>pack</argument>
                                <argument>--configuration</argument>
                                <argument>Release</argument>
                                <argument>--no-build</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>exec-dotnet-pack-for-deploy</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>dotnet</executable>
                            <arguments>
                                <argument>pack</argument>
                                <argument>--configuration</argument>
                                <argument>Release</argument>
                                <argument>--no-build</argument>
                                <argument>--output</argument>
                                <argument>${nugetOutputFolder}</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
