<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>org.openmrs.maven.parents</groupId>
        <artifactId>maven-parent-openmrs-module</artifactId>
        <version>1.1.1</version>
    </parent>

    <groupId>io.github.abdi-icap</groupId>
    <artifactId>ethiohri-mamba</artifactId>
    <version>2.1.2</version>
    <packaging>pom</packaging>
    <name>Ethiori MambaETL Module</name>
    <description>MambaETL Module for ethiori reporting</description>

    <url>${nexus.url}/repository/maven-snapshots/</url>
    <organization>
        <name>ICAP At Columbia Unversity</name>
    </organization>
    <developers>
        <developer>
            <name>Samuel Ababeye</name>
        </developer>
    </developers>

    <licenses>
        <license>
            <name>Apache 2</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>


    <scm>
        <connection>scm:git:git@github.com:CDC-HIS/openmrs-module-ethiori-mamba</connection>
        <url>https://github.com/CDC-HIS/openmrs-module-ethiori-mamba</url>
        <developerConnection>scm:git:git@github.com:CDC-HIS/openmrs-module-ethiori-mamba.git</developerConnection>
        <tag>HEAD</tag>
    </scm>

    <modules>
        <module>api</module>
        <module>omod</module>
    </modules>

    <repositories>

        <repository>
            <id>openmrs-repo</id>
            <name>OpenMRS Nexus Repository</name>
            <url>https://mavenrepo.openmrs.org/nexus/content/repositories/public</url>
        </repository>
        <repository>
            <id>central</id>
            <name>Maven Repository Switchboard</name>
            <layout>default</layout>
            <url>https://repo1.maven.org/maven2</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>openmrs-repo</id>
            <name>OpenMRS Nexus Repository</name>
            <url>https://mavenrepo.openmrs.org/nexus/content/repositories/public</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <dependencyManagement>
        <dependencies>
            <!-- Begin OpenMRS core -->
            <dependency>
                <groupId>org.openmrs.api</groupId>
                <artifactId>openmrs-api</artifactId>
                <version>${openmrsPlatformVersion}</version>
                <type>jar</type>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.openmrs.web</groupId>
                <artifactId>openmrs-web</artifactId>
                <version>${openmrsPlatformVersion}</version>
                <type>jar</type>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.openmrs.module</groupId>
                <artifactId>mamba-core-api</artifactId>
                <version>${mambaETLCoreVersion}</version>
                <type>jar</type>
            </dependency>
            <dependency>
                <groupId>org.openmrs.api</groupId>
                <artifactId>openmrs-api</artifactId>
                <version>${openmrsPlatformVersion}</version>
                <type>test-jar</type>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>org.openmrs.web</groupId>
                <artifactId>openmrs-web</artifactId>
                <version>${openmrsPlatformVersion}</version>
                <type>test-jar</type>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>org.openmrs.test</groupId>
                <artifactId>openmrs-test</artifactId>
                <version>${openmrsPlatformVersion}</version>
                <type>pom</type>
                <scope>test</scope>
            </dependency>

            <!-- End OpenMRS core -->
            <dependency>
                <groupId>io.github.abdi-icap</groupId>
                <artifactId>reporting-api</artifactId>
                <version>${reportingVersion}</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.apache.maven</groupId>
                <artifactId>maven-artifact</artifactId>
                <version>3.0.3</version>
            </dependency>

            <dependency>
                <groupId>org.openmrs.module</groupId>
                <artifactId>cohort-api</artifactId>
                <version>${cohortVersion}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.annotation</groupId>
                <artifactId>javax.annotation-api</artifactId>
                <version>${javaxAnnotationVersion}</version>
                <scope>provided</scope>
            </dependency>

            <!-- Webservices Dependency -->
            <dependency>
                <groupId>org.openmrs.module</groupId>
                <artifactId>webservices.rest-omod-common</artifactId>
                <version>${webservicesRestVersion}</version>
                <type>jar</type>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.openmrs.module</groupId>
                <artifactId>webservices.rest-omod-common</artifactId>
                <version>${webservicesRestVersion}</version>
                <type>test-jar</type>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>org.openmrs.module</groupId>
                <artifactId>webservices.rest-omod-2.0</artifactId>
                <version>${webservicesRestVersion}</version>
                <type>jar</type>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>${jacksonCoreVersion}</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-dbcp2</artifactId>
                <version>${apache.commons.dbcp}</version>
                <exclusions>
                    <exclusion>
                        <groupId>commons-logging</groupId>
                        <artifactId>commons-logging</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>jakarta.transaction</groupId>
                        <artifactId>jakarta.transaction-api</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

        </dependencies>
    </dependencyManagement>

<!--    <distributionManagement>-->
<!--        <repository>-->
<!--            <id>nexus-releases</id>-->
<!--            <url>${nexus.url}/repository/maven-releases/</url>-->
<!--        </repository>-->
<!--        <snapshotRepository>-->
<!--            <id>nexus-snapshots</id>-->
<!--            <url>${nexus.url}/repository/maven-snapshots/</url>-->
<!--        </snapshotRepository>-->
<!--    </distributionManagement>-->


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <bestPractices>true</bestPractices>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.3.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>0.6.0</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>central</publishingServerId>
                    <autoPublish>true</autoPublish>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.6.3</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <failOnError>false</failOnError>
                </configuration>
            </plugin>
        </plugins>
        <pluginManagement>

            <plugins>

                <!-- 1. Unpack the dependency jar first -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>3.2.0</version>
                    <executions>
                        <execution>
                            <id>unpack-scripts</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>unpack</goal>
                            </goals>
                            <configuration>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>org.openmrs.module</groupId>
                                        <artifactId>mamba-core-api</artifactId>
                                        <outputDirectory>${project.build.directory}/mamba-etl</outputDirectory>
                                        <includes>_core/**</includes>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                        <execution>
                            <id>Expand resources</id>
                            <goals>
                                <goal>unpack-dependencies</goal>
                            </goals>
                            <phase>generate-resources</phase>
                            <configuration>
                                <includeGroupIds>${project.parent.groupId}</includeGroupIds>
                                <includeArtifactIds>${project.parent.artifactId}-api</includeArtifactIds>
                                <includeScope>compile</includeScope>
                                <includes>**\/*.xml,**\/*.properties</includes>
                                <outputDirectory>${project.build.directory}/classes</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <!-- Step 2 & the last step-->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.2.0</version>
                    <configuration>
                        <includeEmptyDirs>true</includeEmptyDirs>
                    </configuration>
                    <executions>

                        <!-- 2. Copy contents of the resources directory of the dependency jar to a target location -->
                        <execution>
                            <id>copy-scripts</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <resources>
                                    <resource>
                                        <directory>${project.basedir}/src/main/resources/_etl</directory>
                                        <filtering>true</filtering>
                                    </resource>
                                </resources>
                                <outputDirectory>${project.build.directory}/mamba-etl/_etl</outputDirectory>
                            </configuration>
                        </execution>

                        <!-- This should execute last - to copy the build script to a location liquibase.xml can access-->
                        <execution>
                            <id>copy-final-build-script</id>
                            <phase>install</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <resources>
                                    <resource>
                                        <directory>
                                            ${project.build.directory}/mamba-etl/_core/database/mysql/build
                                        </directory>
                                        <filtering>true</filtering>
                                    </resource>
                                </resources>
                                <outputDirectory>${project.parent.basedir}/api/src/main/resources/mamba
                                </outputDirectory>
                            </configuration>
                        </execution>

                    </executions>
                </plugin>

                <!-- 3. Make the compiler scripts executable & then run the compiler -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>3.0.0</version>
                    <executions>

                        <execution>
                            <id>set-executable-permission</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>exec</goal>
                            </goals>
                            <configuration>
                                <executable>/bin/sh</executable>
                                <arguments>
                                    <argument>-c</argument>
                                    <argument>chmod -R +x ${project.build.directory}/mamba-etl/_core/compiler</argument>
                                </arguments>
                            </configuration>
                        </execution>

                        <execution>
                            <id>run-script</id>
                            <phase>package</phase>
                            <goals>
                                <goal>exec</goal>
                            </goals>
                            <configuration>
                                <executable>/bin/sh</executable>
                                <workingDirectory>${project.build.directory}/mamba-etl/_core/compiler/linux
                                </workingDirectory>
                                <arguments>

                                    <argument>compile.sh</argument>

                                    <!-- The source database (OpenMRS database) -->
                                    <argument>-d openmrs</argument>

                                    <!-- The target or analysis Database where the ETL data is stored -->
                                    <argument>-a analytics_db</argument>

                                    <!-- File with a list of all files with stored procedures -->
                                    <!-- Remove this argument after automating core to auto-read this -->
                                    <argument>-s ../../database/mysql/sp_makefile</argument>

                                    <!-- a JSON configuration path/folder for all config files for db flattening -->
                                    <!-- Folder containing configs folder, derived folders and any other ETL related folders -->
                                    <argument>-t ${project.build.directory}/mamba-etl/_etl/config</argument>

                                    <!-- Database Vendor/Engine targeted in this ETL -->
                                    <argument>-n mysql</argument>

                                    <!-- Set 1 to recompile/build the scripts else 0 - not to. If 1 - don't forget to change the liquibase changeset ID -->
                                    <argument>-b 1</argument>

                                    <argument/>

                                    <argument/>

                                    <argument/>

                                </arguments>
                            </configuration>
                        </execution>

                        <execution>
                            <id>run-tests-after-install</id>
                            <phase>install</phase>
                            <goals>
                                <goal>exec</goal>
                            </goals>
                            <configuration>
                                <executable>mvn</executable>
                                <arguments>
                                    <argument>surefire:test</argument>
                                </arguments>
                            </configuration>
                        </execution>
                    </executions>

                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.15.0</version>
                    <configuration>
                        <release>21</release>
                        <encoding>UTF-8</encoding>
                    </configuration>
                    <executions>
                        <execution>
                            <id>default-testCompile</id>
                            <phase>test</phase>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.5.3</version>
                    <configuration>
                        <!--
                        <preparationGoals>clean install</preparationGoals>
                        <autoVersionSubmodules>true</autoVersionSubmodules>
                        <useReleaseProfile>false</useReleaseProfile>
                        <arguments>-Prelease</arguments>
                        -->
                        <autoVersionSubmodules>true</autoVersionSubmodules>
                        <tagNameFormat>v@{project.version}</tagNameFormat>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.4</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>3.2.5</version>
                    <configuration>
                        <includes>
                            <include>**/*Test.java</include>
                        </includes>
                        <argLine>
                            --add-opens java.base/java.lang=ALL-UNNAMED
                            --add-opens java.base/java.lang.reflect=ALL-UNNAMED
                            --add-opens java.base/java.util=ALL-UNNAMED
                            --add-opens java.base/java.util.concurrent=ALL-UNNAMED
                            --add-opens java.base/java.io=ALL-UNNAMED
                            --add-opens java.rmi/sun.rmi.transport=ALL-UNNAMED
                            --add-opens java.xml/com.sun.org.apache.xpath.internal=ALL-UNNAMED
                        </argLine>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.openmrs.maven.plugins</groupId>
                    <artifactId>maven-openmrs-plugin</artifactId>
                    <version>1.0.1</version>
                    <extensions>true</extensions>
                    <executions>
                        <execution>
                            <id>init</id>
                            <phase>initialize</phase>
                            <goals>
                                <goal>initialize-module</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>pack</id>
                            <phase>package</phase>
                            <goals>
                                <goal>package-module</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>versions-maven-plugin</artifactId>
                    <version>2.1</version>
                </plugin>

                <plugin>
                    <groupId>org.openmrs.maven.plugins</groupId>
                    <artifactId>openmrs-dependency-maven-plugin</artifactId>
                    <version>1.0.0</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>retrieve-versions</goal>
                                <goal>create-versions</goal>
                                <goal>compare-versions</goal>
                                <goal>attach-versions</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>3.1.0</version>
                    <executions>
                        <execution>
                            <phase>generate-test-resources</phase>
                            <goals>
                                <goal>parse-version</goal>
                            </goals>
                            <configuration>
                                <propertyPrefix>omrsVersion</propertyPrefix>
                                <versionString>${openmrsPlatformVersion}</versionString>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

            </plugins>

        </pluginManagement>
    </build>

    <properties>
        <javaCompilerSource>21</javaCompilerSource>
        <javaCompilerTarget>21</javaCompilerTarget>
        <openmrsPlatformVersion>2.8.6</openmrsPlatformVersion>
        <reportingVersion>2.2.2</reportingVersion>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <calculationVersion>1.1</calculationVersion>
        <serialization.xstreamVersion>0.3.0</serialization.xstreamVersion>
        <cohortVersion>3.5.0</cohortVersion>
        <javaxAnnotationVersion>1.3.2</javaxAnnotationVersion>
        <mambaETLCoreVersion>2.0.0</mambaETLCoreVersion>
        <webservicesRestVersion>2.42.0</webservicesRestVersion>
        <apache.commons.dbcp>2.11.0</apache.commons.dbcp>
        <jacksonCoreVersion>2.15.3</jacksonCoreVersion>

        <nexus.url>https://maven-repo.dh.moh.gov.et</nexus.url>
    </properties>

</project>
