<?xml version="1.0" encoding="UTF-8"?>
<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>
        <artifactId>gremlin-tools</artifactId>
        <groupId>org.apache.tinkerpop</groupId>
        <version>4.0.0-beta.3</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>gremlin-socket-server</artifactId>
    <name>Apache TinkerPop :: Gremlin Socket Server</name>
    <dependencies>
        <dependency>
            <groupId>org.apache.tinkerpop</groupId>
            <artifactId>gremlin-util</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tinkerpop</groupId>
            <artifactId>tinkergraph-gremlin</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
            <version>${netty.version}</version>
        </dependency>
        <dependency>
            <groupId>io.github.littleproxy</groupId>
            <artifactId>littleproxy</artifactId>
            <version>2.8.0</version>
            <exclusions>
                <!--
                littleproxy 2.8.0 pulls its own Netty modules at a different patch level (4.2.15) than
                the project-managed ${netty.version}. Exclude all of littleproxy's Netty so it runs
                against the project Netty, satisfying the enforcer DependencyConvergence rule. Both are
                Netty 4.2.x, so littleproxy is binary-compatible with the project version.
                -->
                <exclusion>
                    <groupId>io.netty</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- LOGGING -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.groovy</groupId>
            <artifactId>groovy</artifactId>
            <version>${groovy.version}</version>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <properties>
        <!--
        provides a way to convert maven.exec.skip value to skipImageBuild for use in skipping image building for testing
        under incompatible platforms
        -->
        <maven.exec.skip>false</maven.exec.skip> <!-- default -->
        <skipImageBuild>${maven.exec.skip}</skipImageBuild>
    </properties>

    <build>
        <directory>${basedir}/target</directory>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
        <resources>
            <resource>
                <directory>${basedir}/src/main/resources
                </directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>
                                ${project.build.directory}/libs
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>org.apache.tinkerpop.gremlin.socket.server.SocketServerRunner</mainClass>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>libs/</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
            </plugin>
            <!--
            gremlin socket server image will be generated on each build as language variants will need the latest to do
            their work.
            -->
            <plugin>
                <artifactId>exec-maven-plugin</artifactId>
                <groupId>org.codehaus.mojo</groupId>
                <version>3.5.0</version>
                <executions>
                    <execution>
                        <id>build-image</id>
                        <phase>install</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <skip>${skipImageBuild}</skip>
                            <executable>docker</executable>
                            <arguments>
                                <argument>build</argument>
                                <argument>-f</argument>
                                <argument>./Dockerfile</argument>
                                <argument>--build-arg</argument>
                                <argument>SOCKET_SERVER_DIR=target/</argument>
                                <argument>--build-arg</argument>
                                <argument>SOCKET_SERVER_VERSION=${project.version}</argument>
                                <argument>-t</argument>
                                <argument>tinkerpop/gremlin-socket-server:${project.version}</argument>
                                <argument>.</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>remove-dangling-images</id>
                        <phase>install</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <skip>${skipImageBuild}</skip>
                            <executable>docker</executable>
                            <arguments>
                                <argument>image</argument>
                                <argument>prune</argument>
                                <argument>--filter</argument>
                                <argument>label=maintainer=dev@tinkerpop.apache.org</argument>
                                <argument>-f</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <!-- Overrides the config from the gremlin-tools pom-->
                <configuration>
                    <skip>false</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
