<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~  Copyright 1999-2019 Seata.io Group.
  ~
  ~  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">
    <parent>
        <groupId>io.seata</groupId>
        <artifactId>seata-parent</artifactId>
        <version>${revision}</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>seata-server</artifactId>
    <packaging>jar</packaging>
    <name>seata-server ${project.version}</name>

    <properties>
        <logstash-logback-encoder.version>6.5</logstash-logback-encoder.version>
        <kafka-appender.version>0.2.0-RC2</kafka-appender.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>seata-core</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>seata-config-all</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>seata-discovery-all</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>seata-serializer-all</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>seata-compressor-all</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>seata-metrics-all</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!-- for database -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-dbcp2</artifactId>
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>
        <dependency>
            <groupId>com.beust</groupId>
            <artifactId>jcommander</artifactId>
        </dependency>

        <!-- only for event bus -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </dependency>

        <!-- logback -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </dependency>

        <!-- jedis -->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </dependency>

        <dependency>
            <groupId>com.github.fppt</groupId>
            <artifactId>jedis-mock</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
        </dependency>

        <dependency>
            <groupId>net.logstash.logback</groupId>
            <artifactId>logstash-logback-encoder</artifactId>
            <version>${logstash-logback-encoder.version}</version>
        </dependency>
        <dependency>
            <groupId>com.github.danielwegener</groupId>
            <artifactId>logback-kafka-appender</artifactId>
            <version>${kafka-appender.version}</version>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>release-seata</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-clean-plugin</artifactId>
                        <version>3.0.0</version>
                        <configuration>
                            <excludeDefaultDirectories>false</excludeDefaultDirectories>
                            <filesets>
                                <fileset>
                                    <directory>../distribution</directory>
                                    <includes>
                                        <include>bin/**</include>
                                        <include>conf/**</include>
                                        <include>logs/**</include>
                                        <include>lib/**</include>
                                        <include>seata-server-${revision}/**</include>
                                    </includes>
                                </fileset>
                            </filesets>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>appassembler-maven-plugin</artifactId>
                        <version>1.10</version>
                        <executions>
                            <execution>
                                <id>make-assembly</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>assemble</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <configurationDirectory>conf</configurationDirectory>
                            <configurationSourceDirectory>src/main/resources</configurationSourceDirectory>
                            <copyConfigurationDirectory>true</copyConfigurationDirectory>
                            <includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
                            <repositoryLayout>flat</repositoryLayout>
                            <repositoryName>lib</repositoryName>
                            <encoding>UTF-8</encoding>
                            <useWildcardClassPath>true</useWildcardClassPath>
                            <binFileExtensions>
                                <unix>.sh</unix>
                                <windows>.bat</windows>
                            </binFileExtensions>
                            <assembleDirectory>../distribution/seata-server-${revision}</assembleDirectory>
                            <logsDirectory>logs</logsDirectory>
                            <programs>
                                <program>
                                    <mainClass>io.seata.server.Server</mainClass>
                                    <name>seata-server</name>
                                    <jvmSettings>
                                        <extraArguments>
                                            <extraArgument>-server</extraArgument>
                                            <extraArgument>-Xmx2048m</extraArgument>
                                            <extraArgument>-Xms2048m</extraArgument>
                                            <extraArgument>-Xmn1024m</extraArgument>
                                            <extraArgument>-Xss512k</extraArgument>
                                            <extraArgument>-XX:SurvivorRatio=10</extraArgument>
                                            <extraArgument>-XX:MetaspaceSize=128m</extraArgument>
                                            <extraArgument>-XX:MaxMetaspaceSize=256m</extraArgument>
                                            <extraArgument>-XX:MaxDirectMemorySize=1024m</extraArgument>
                                            <extraArgument>-XX:-OmitStackTraceInFastThrow</extraArgument>
                                            <extraArgument>-XX:-UseAdaptiveSizePolicy</extraArgument>
                                            <extraArgument>-XX:+HeapDumpOnOutOfMemoryError</extraArgument>
                                            <extraArgument>-XX:HeapDumpPath=@BASEDIR@/logs/java_heapdump.hprof</extraArgument>
                                            <!--gc-->
                                            <extraArgument>-XX:+DisableExplicitGC</extraArgument>
                                            <extraArgument>-XX:+CMSParallelRemarkEnabled</extraArgument>
                                            <extraArgument>-XX:+UseCMSInitiatingOccupancyOnly</extraArgument>
                                            <extraArgument>-XX:CMSInitiatingOccupancyFraction=75</extraArgument>
                                            <extraArgument>-Xloggc:@BASEDIR@/logs/seata_gc.log</extraArgument>
                                            <extraArgument>-verbose:gc</extraArgument>
                                            <!--netty-->
                                            <extraArgument>-Dio.netty.leakDetectionLevel=advanced</extraArgument>
                                            <!--log-->
                                            <extraArgument>-Dlogback.color.disable-for-bat=true</extraArgument>
                                        </extraArguments>
                                    </jvmSettings>
                                    <platforms>
                                        <platform>windows</platform>
                                        <platform>unix</platform>
                                    </platforms>
                                </program>
                            </programs>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <id>copy-mysql</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>mysql</groupId>
                                    <artifactId>mysql-connector-java</artifactId>
                                    <version>${mysql.jdbc.version}</version>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>mysql</groupId>
                                    <artifactId>mysql-connector-java</artifactId>
                                    <version>${mysql8.jdbc.version}</version>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>
                                ${basedir}/target/lib/jdbc
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>jib-maven-plugin</artifactId>
                <version>2.3.0</version>
                <configuration>
                    <from>
                        <image>${IMAGE_NAME}</image>
                    </from>
                    <to>
                        <image>docker.io/seataio/seata-server</image>
                        <tags>
                            ${image.tags}
                        </tags>
                        <auth>
                            <username>${REGISTRY_USERNAME}</username>
                            <password>${REGISTRY_PASSWORD}</password>
                        </auth>
                    </to>
                    <container>
                        <appRoot>/seata-server</appRoot>
                        <workingDirectory>/seata-server</workingDirectory>
                        <mainClass>io.seata.server.Server</mainClass>
                        <ports>
                            <port>8091</port>
                        </ports>
                        <jvmFlags>
                            <jvmFlag>-Djava.security.egd=file:/dev/./urandom</jvmFlag>
                            <jvmFlag>-server</jvmFlag>
                            <jvmFlag>-Xss512k</jvmFlag>
                            <jvmFlag>-XX:+UnlockExperimentalVMOptions</jvmFlag>
                            <jvmFlag>-XX:+UseContainerSupport</jvmFlag>
                            <jvmFlag>-XX:SurvivorRatio=10</jvmFlag>
                            <jvmFlag>-XX:MetaspaceSize=128m</jvmFlag>
                            <jvmFlag>-XX:MaxMetaspaceSize=256m</jvmFlag>
                            <jvmFlag>-XX:MaxDirectMemorySize=1024m</jvmFlag>
                            <jvmFlag>-XX:-OmitStackTraceInFastThrow</jvmFlag>
                            <jvmFlag>-XX:-UseAdaptiveSizePolicy</jvmFlag>
                            <jvmFlag>-XX:+HeapDumpOnOutOfMemoryError</jvmFlag>
                            <jvmFlag>-XX:HeapDumpPath=/var/log/seata_heapdump.hprof</jvmFlag>
                            <!--gc-->
                            <jvmFlag>-XX:+DisableExplicitGC</jvmFlag>
                            <jvmFlag>-XX:+CMSParallelRemarkEnabled</jvmFlag>
                            <jvmFlag>-XX:+UseCMSInitiatingOccupancyOnly</jvmFlag>
                            <jvmFlag>-XX:CMSInitiatingOccupancyFraction=75</jvmFlag>
                            <jvmFlag>-Xloggc:/var/log/seata_gc.log</jvmFlag>
                            <jvmFlag>-verbose:gc</jvmFlag>
                            <!--netty-->
                            <jvmFlag>-Dio.netty.leakDetectionLevel=advanced</jvmFlag>
                            <!--log-->
                            <jvmFlag>-Dlogback.color.disable-for-bat=true</jvmFlag>
                        </jvmFlags>
                        <labels>
                            <name>seata-server</name>
                        </labels>
                        <creationTime>USE_CURRENT_TIMESTAMP</creationTime>
                    </container>
                    <extraDirectories>
                        <paths>
                            <path>
                                <from>target/lib/jdbc</from>
                                <into>/seata-server/libs/jdbc</into>
                            </path>
                        </paths>
                    </extraDirectories>
                    <skip>${image.publish.skip}</skip>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
