<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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>
        <artifactId>tinkerpop</artifactId>
        <groupId>org.apache.tinkerpop</groupId>
        <version>3.3.8</version>
    </parent>
    <artifactId>gremlin-console</artifactId>
    <name>Apache TinkerPop :: Gremlin Console</name>
    <dependencies>
        <dependency>
            <groupId>org.apache.tinkerpop</groupId>
            <artifactId>gremlin-groovy</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tinkerpop</groupId>
            <artifactId>tinkergraph-gremlin</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>
        <!-- commons-codec is a dependency of httpclient - excluded in root pom to bring all commons-codec versions inline -->
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-cli</groupId>
            <artifactId>commons-cli</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tinkerpop</groupId>
            <artifactId>gremlin-driver</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- TESTING -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tinkerpop</groupId>
            <artifactId>gremlin-server</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tinkerpop</groupId>
            <artifactId>gremlin-test</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.github.tomakehurst</groupId>
            <artifactId>wiremock</artifactId>
            <version>1.56</version>
            <scope>test</scope>
            <classifier>standalone</classifier>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.google.guava</groupId>
                    <artifactId>guava</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-annotations</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-databind</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpclient</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.skyscreamer</groupId>
                    <artifactId>jsonassert</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xmlunit</groupId>
                    <artifactId>xmlunit</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.jayway.jsonpath</groupId>
                    <artifactId>json-path</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>net.sf.jopt-simple</groupId>
                    <artifactId>jopt-simple</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    <build>
        <directory>${basedir}/target</directory>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <resources>
            <resource>
                <directory>${basedir}/src/main/resources
                </directory>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>${basedir}/src/test/resources
                </directory>
            </testResource>
        </testResources>
        <plugins>
            <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>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <attach>true</attach>
                    <descriptors>
                        <descriptor>src/assembly/standalone.xml</descriptor>
                        <descriptor>src/assembly/distribution.xml</descriptor>
                    </descriptors>
                    <finalName>apache-tinkerpop-${project.artifactId}-${project.version}</finalName>
                    <outputDirectory>target</outputDirectory>
                    <workDirectory>target/assembly/work</workDirectory>
                    <tarLongFileMode>warn</tarLongFileMode>
                    <archive>
                        <manifest>
                            <mainClass>org.apache.tinkerpop.gremlin.console.Console</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.gmavenplus</groupId>
                <artifactId>gmavenplus-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>addSources</goal>
                            <goal>addTestSources</goal>
                            <goal>generateStubs</goal>
                            <goal>compile</goal>
                            <goal>generateTestStubs</goal>
                            <goal>compileTests</goal>
                            <goal>removeStubs</goal>
                            <goal>removeTestStubs</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>uber</shadedClassifierName>
                            <shadeSourcesContent>true</shadeSourcesContent>
                            <createSourcesJar>true</createSourcesJar>
                            <relocations>
                                <relocation>
                                    <pattern>com.google.guava</pattern>
                                    <shadedPattern>com.shaded.google.guava</shadedPattern>
                                    <pattern>io.netty</pattern>
                                    <shadedPattern>io.shaded.netty</shadedPattern>
                                </relocation>
                            </relocations>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"></transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
                                    <resources>
                                        <resource>LICENSE.txt</resource>
                                        <resource>LICENSE</resource>
                                        <resource>NOTICE.txt</resource>
                                        <resource>NOTICE</resource>
                                        <resource>licenses</resource>
                                    </resources>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                                    <resource>META-INF/LICENSE</resource>
                                    <file>src/main/static/LICENSE</file>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                                    <resource>META-INF/NOTICE</resource>
                                    <file>src/main/static/NOTICE</file>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                                    <resource>META-INF/licenses/foundation</resource>
                                    <file>src/main/static/licenses/foundation</file>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                                    <resource>META-INF/licenses/jbcrypt</resource>
                                    <file>src/main/static/licenses/jbcrypt</file>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                                    <resource>META-INF/licenses/jcabi-log</resource>
                                    <file>src/main/static/licenses/jcabi-log</file>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                                    <resource>META-INF/licenses/jcabi-manifests</resource>
                                    <file>src/main/static/licenses/jcabi-manifests</file>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                                    <resource>META-INF/licenses/jline2</resource>
                                    <file>src/main/static/licenses/jline2</file>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                                    <resource>META-INF/licenses/kryo</resource>
                                    <file>src/main/static/licenses/kryo</file>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                                    <resource>META-INF/licenses/minlog</resource>
                                    <file>src/main/static/licenses/minlog</file>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                                    <resource>META-INF/licenses/normalize</resource>
                                    <file>src/main/static/licenses/normalize</file>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                                    <resource>META-INF/licenses/slf4j</resource>
                                    <file>src/main/static/licenses/slf4j</file>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <!-- activates the building of python components and requires that python be installed on the system. use
             the .glv file in gremlin-python as an indicator to activate -->
        <profile>
            <id>console-integration-tests</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <file>
                    <!-- can't use variable here - maven no likey -->
                    <exists>../gremlin-python/.glv</exists>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>create-python-reports-directory</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <skip>${skipIntegrationTests}</skip>
                                    <target>
                                        <mkdir dir="${project.build.directory}/python-reports"/>
                                        <mkdir dir="${project.build.directory}/python/env"/>
                                    </target>
                                </configuration>
                            </execution>
                            <!-- copy files in python directory to target/python and run virtual env to sandbox python.
                                 there is no need to "activate" the virtualenv because all calls to python occur
                                 directly from bin/ -->
                            <execution>
                                <id>setup-py-env</id>
                                <phase>process-resources</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <skip>${skipIntegrationTests}</skip>
                                    <tasks>
                                        <copy todir="${project.build.directory}/python">
                                            <fileset dir="src/test/python"/>
                                        </copy>
                                        <exec dir="${project.build.directory}/python" executable="virtualenv"
                                              failonerror="true">
                                            <arg line="--python=python env"/>
                                        </exec>
                                    </tasks>
                                </configuration>
                            </execution>
                            <execution>
                                <id>native-python-build</id>
                                <phase>compile</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <skip>${skipIntegrationTests}</skip>
                                    <target>
                                        <exec executable="env/bin/python" dir="${project.build.directory}/python"
                                              failonerror="true">
                                            <env key="PYTHONPATH" value=""/>
                                            <arg line="setup.py build --build-lib ${project.build.outputDirectory}/Lib"/>
                                        </exec>
                                    </target>
                                </configuration>
                            </execution>

                            <execution>
                                <id>copy-gremlinsh</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <skip>${skipIntegrationTests}</skip>
                                    <tasks>
                                        <copy todir="${project.build.directory}/python/gremlin-console">
                                            <fileset dir="${project.build.directory}/apache-tinkerpop-gremlin-console-${project.version}-standalone"/>
                                        </copy>
                                    </tasks>
                                </configuration>
                            </execution>

                            <!--
                            use pytest to execute native python tests - output of xunit output is configured in setup.cfg.
                            must run on integration tests because package phase has to execute to get the console binaries
                            available for testing
                            -->
                            <execution>
                                <id>native-python-test</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <skip>${skipIntegrationTests}</skip>
                                    <target>
                                        <exec executable="env/bin/python" dir="${project.build.directory}/python"
                                              failonerror="true">
                                            <env key="PYTHONPATH" value=""/>
                                            <arg line="setup.py test"/>
                                        </exec>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>docker-images</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property>
                    <name>dockerImages</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <!--
                    Deploying docker images will happen out of the normal jvm artifact deployment flow, so disable that
                    -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-deploy-plugin</artifactId>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>com.spotify</groupId>
                        <artifactId>dockerfile-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>docker-image-build</id>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <configuration>
                                    <tag>${project.version}</tag>
                                    <buildArgs>
                                        <GREMLIN_CONSOLE_DIR>target/apache-tinkerpop-${project.artifactId}-${project.version}-standalone</GREMLIN_CONSOLE_DIR>
                                    </buildArgs>
                                </configuration>
                            </execution>
                            <execution>
                                <id>docker-image-tag-minor-version</id>
                                <goals>
                                    <goal>tag</goal>
                                </goals>
                                <configuration>
                                    <tag>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}</tag>
                                    <skip>${only.when.is.prerelease.version}</skip>
                                </configuration>
                            </execution>
                            <execution>
                                <id>docker-image-push</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>push</goal>
                                </goals>
                                <configuration>
                                    <tag>${project.version}</tag>
                                    <skip>${only.when.is.snapshot.used}</skip>
                                </configuration>
                            </execution>
                            <execution>
                                <id>docker-image-push-minor-version</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>push</goal>
                                </goals>
                                <configuration>
                                    <tag>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}</tag>
                                    <skip>${only.when.is.prerelease.version}</skip>
                                </configuration>
                            </execution>
                        </executions>
                        <configuration>
                            <repository>tinkerpop/gremlin-console</repository>
                        </configuration>
                    </plugin>
                </plugins>                
            </build>
        </profile>
    </profiles>
</project>
