<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2015-2017 OpenCB
  ~
  ~ 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>org.opencb.opencga</groupId>
        <artifactId>opencga-storage</artifactId>
        <version>3.4.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>opencga-storage-app</artifactId>
    <packaging>jar</packaging>

    <properties>
        <build.dir>${project.basedir}/../build</build.dir>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.opencb.opencga</groupId>
            <artifactId>opencga-storage-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.opencb.opencga</groupId>
            <artifactId>opencga-storage-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.opencb.opencga</groupId>
            <artifactId>opencga-storage-benchmark</artifactId>
        </dependency>

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-webapp</artifactId>
        </dependency>

        <!--Added dependencies -->
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>

        </dependency>
        <dependency>
            <groupId>org.opencb.biodata</groupId>
            <artifactId>biodata-formats</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-api</artifactId>
            <version>1.28.1</version>
        </dependency>
        <dependency>
            <groupId>org.opencb.opencga</groupId>
            <artifactId>opencga-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.beust</groupId>
            <artifactId>jcommander</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.avro</groupId>
            <artifactId>avro</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>
        <dependency>
            <groupId>org.opencb.biodata</groupId>
            <artifactId>biodata-tools</artifactId>
        </dependency>
        <dependency>
            <groupId>org.opencb.biodata</groupId>
            <artifactId>biodata-models</artifactId>
        </dependency>
        <dependency>
            <groupId>org.opencb.commons</groupId>
            <artifactId>commons-lib</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.opencb.commons</groupId>
            <artifactId>commons-datastore-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <dependency>
            <groupId>jakarta.ws.rs</groupId>
            <artifactId>jakarta.ws.rs-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.samtools</groupId>
            <artifactId>htsjdk</artifactId>
        </dependency>

        <!-- TODO Review -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
        </dependency>

    </dependencies>

    <build>
        <finalName>opencga-app</finalName>
        <sourceDirectory>src/main/java</sourceDirectory>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <targetPath>${project.basedir}/target/conf</targetPath>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <version>1.10</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>assemble</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <repositoryName>libs</repositoryName>
                    <repositoryLayout>flat</repositoryLayout>
                    <useWildcardClassPath>false</useWildcardClassPath>
                    <!--By default, "etc".-->
                    <configurationDirectory>conf</configurationDirectory>
                    <extraJvmArguments>-Xms256m -Xmx16384m -Dfile.encoding=UTF-8</extraJvmArguments>
                    <includeConfigurationDirectoryInClasspath>false</includeConfigurationDirectoryInClasspath>
                    <environmentSetupFileName>../conf/${opencga.env.file}</environmentSetupFileName>
                    <programs>
                        <program>
                            <mainClass>org.opencb.opencga.storage.app.StorageMain</mainClass>
                            <name>opencga-storage.sh</name>
                            <platforms>
                                <platform>unix</platform>
                            </platforms>
                        </program>
                        <program>
                            <mainClass>org.opencb.opencga.storage.app.StorageAdminMain</mainClass>
                            <name>opencga-storage-admin.sh</name>
                            <platforms>
                                <platform>unix</platform>
                            </platforms>
                        </program>
                    </programs>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <id>clean-libs</id>
                        <phase>clean</phase>
                        <configuration>
                            <target>
                                <echo>Preparing ${build.dir} folder</echo>
                                <exec executable="rm">
                                    <arg value="-rf"/>
                                    <arg value="${build.dir}"/>
                                </exec>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>install-app</id>
                        <phase>install</phase>
                        <configuration>
                            <target>
                                <echo>Preparing ${build.dir} folder</echo>
                                <exec executable="rm">
                                    <arg value="-rf"/>
                                    <arg value="${build.dir}"/>
                                </exec>
                                <exec executable="mkdir">
                                    <arg value="${build.dir}"/>
                                    <arg value="${build.dir}/conf"/>
                                </exec>

                                <echo>Copying to ${build.dir}</echo>
                                <exec executable="cp">
                                    <arg value="-r"/>
                                    <arg value="${project.basedir}/target/appassembler/bin"/>
                                    <arg value="${project.basedir}/target/appassembler/libs"/>
                                    <arg value="${project.basedir}/target/conf"/>
                                    <arg value="${build.dir}"/>
                                </exec>

                                <echo>Coping configuration file</echo>
                                <exec executable="cp">
                                    <arg value="${project.basedir}/../opencga-storage-core/target/classes/${storage.configuration.file}"/>
                                    <arg value="${build.dir}/conf"/>
                                </exec>

                                <echo>Coping configuration file</echo>
                                <exec executable="cp">
                                    <arg value="-r"/>
                                    <arg value="${project.basedir}/../opencga-storage-benchmark/target/classes/benchmark"/>
                                    <arg value="${build.dir}"/>
                                </exec>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.6.0</version>
                <executions>
                    <execution>
                        <id>analyze</id>
                        <goals>
                            <goal>analyze-only</goal>
                        </goals>
                        <configuration>
                            <failOnWarning>true</failOnWarning>
                            <ignoredUnusedDeclaredDependencies>
                                <ignoredUnusedDeclaredDependency>*</ignoredUnusedDeclaredDependency>
                            </ignoredUnusedDeclaredDependencies>
                            <ignoredUsedUndeclaredDependencies>
                                <ignoredUsedUndeclaredDependency>
                                    javax.ws.rs:jsr311-api
                                </ignoredUsedUndeclaredDependency>
                            </ignoredUsedUndeclaredDependencies>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>

        <profile>
            <id>storage-hadoop</id>
            <activation>
                <property>
                    <name>!skipStorageHadoop</name>
                </property>
            </activation>

            <dependencies>
                <dependency>
                    <groupId>org.opencb.opencga</groupId>
                    <artifactId>opencga-storage-hadoop-core</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.opencb.opencga</groupId>
                    <artifactId>${opencga-hadoop-lib.artifactId}</artifactId>
                    <version>${project.parent.version}</version>
                    <optional>true</optional>
                </dependency>
            </dependencies>

            <build>
                <resources>
                    <resource>
                        <directory>../opencga-storage-hadoop/src/main/resources</directory>
                        <filtering>true</filtering>
                        <targetPath>${basedir}/build/conf</targetPath>
                    </resource>
                    <resource>
                        <directory>${basedir}/opencga-storage-hadoop/target</directory>
                        <includes>
                            <include>**/*-dependencies.jar</include>
                        </includes>
                        <targetPath>${basedir}/build/libs</targetPath>
                    </resource>
                </resources>
            </build>
        </profile>
    </profiles>

</project>
