<?xml version="1.0"?>
<!--

    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>pinot</artifactId>
    <groupId>org.apache.pinot</groupId>
    <version>1.3.0</version>
  </parent>
  <artifactId>pinot-common</artifactId>
  <name>Pinot Common</name>
  <url>https://pinot.apache.org/</url>
  <properties>
    <pinot.root>${basedir}/..</pinot.root>
  </properties>

  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration combine.children="override">
          <properties>
            <property>
              <name>usedefaultlisteners</name>
              <value>false</value>  <!-- This will disable all default listeners -->
            </property>
          </properties>
          <!--Disabling tests as Pinot currently uses Yammer and these tests fail for DropwizardMetricsFactory-->
          <excludes>
            <exclude>**/DropwizardBrokerPrometheusMetricsTest.java</exclude>
            <exclude>**/DropwizardServerPrometheusMetricsTest.java</exclude>
            <exclude>**/DropwizardMinionPrometheusMetricsTest.java</exclude>
            <exclude>**/DropwizardControllerPrometheusMetricsTest.java</exclude>
          </excludes>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.xolstice.maven.plugins</groupId>
        <artifactId>protobuf-maven-plugin</artifactId>
        <configuration>
          <checkStaleness>true</checkStaleness>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>com.diffplug.spotless</groupId>
        <artifactId>spotless-maven-plugin</artifactId>
        <configuration>
          <java>
            <excludes>
              <exclude>src/main/java/org/apache/pinot/common/request/*.java</exclude>
              <exclude>src/main/java/org/apache/pinot/common/response/ProcessingException.java</exclude>
            </excludes>
          </java>
        </configuration>
      </plugin>
      <!-- Creates a Java class for the custom parser from Parser.jj -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>javacc-maven-plugin</artifactId>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <id>javacc</id>
            <goals>
              <goal>javacc</goal>
            </goals>
            <configuration>
              <sourceDirectory>${project.build.directory}/generated-sources/javacc/</sourceDirectory>
              <includes>
                <include>Parser.jj</include>
              </includes>
              <lookAhead>2</lookAhead>
              <isStatic>false</isStatic>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>io.prometheus.jmx</groupId>
      <artifactId>jmx_prometheus_javaagent</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.pinot</groupId>
      <artifactId>pinot-segment-spi</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.pinot</groupId>
      <artifactId>pinot-timeseries-spi</artifactId>
    </dependency>

    <dependency>
      <groupId>org.apache.httpcomponents.client5</groupId>
      <artifactId>httpclient5</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.calcite</groupId>
      <artifactId>calcite-babel</artifactId>
    </dependency>
    <dependency>
      <groupId>org.immutables</groupId>
      <artifactId>value-annotations</artifactId>
    </dependency>

    <!-- Jersey Libraries -->
    <dependency>
      <groupId>org.glassfish.jersey.core</groupId>
      <artifactId>jersey-server</artifactId>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.containers</groupId>
      <artifactId>jersey-container-grizzly2-http</artifactId>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.media</groupId>
      <artifactId>jersey-media-multipart</artifactId>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.media</groupId>
      <artifactId>jersey-media-json-jackson</artifactId>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.inject</groupId>
      <artifactId>jersey-hk2</artifactId>
    </dependency>
    <dependency>
      <groupId>org.glassfish.hk2</groupId>
      <artifactId>hk2-metadata-generator</artifactId>
    </dependency>
    <dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-jersey2-jaxrs</artifactId>
    </dependency>
    <dependency>
      <groupId>org.webjars</groupId>
      <artifactId>swagger-ui</artifactId>
    </dependency>
    <dependency>
      <groupId>jakarta.servlet</groupId>
      <artifactId>jakarta.servlet-api</artifactId>
    </dependency>

    <dependency>
      <groupId>org.apache.thrift</groupId>
      <artifactId>libthrift</artifactId>
    </dependency>
    <dependency>
      <groupId>org.xerial.snappy</groupId>
      <artifactId>snappy-java</artifactId>
    </dependency>
    <dependency>
      <groupId>com.github.luben</groupId>
      <artifactId>zstd-jni</artifactId>
    </dependency>
    <dependency>
      <groupId>org.lz4</groupId>
      <artifactId>lz4-java</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-compress</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.helix</groupId>
      <artifactId>helix-core</artifactId>
    </dependency>
    <dependency>
      <groupId>net.sf.jopt-simple</groupId>
      <artifactId>jopt-simple</artifactId>
    </dependency>
    <dependency>
      <groupId>com.jayway.jsonpath</groupId>
      <artifactId>json-path</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.zookeeper</groupId>
      <artifactId>zookeeper</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.protobuf</groupId>
      <artifactId>protobuf-java</artifactId>
    </dependency>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-netty-shaded</artifactId>
    </dependency>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-protobuf</artifactId>
    </dependency>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-stub</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.yetus</groupId>
      <artifactId>audience-annotations</artifactId>
    </dependency>
    <dependency>
      <groupId>org.mindrot</groupId>
      <artifactId>jbcrypt</artifactId>
    </dependency>
    <dependency>
      <groupId>com.github.seancfoley</groupId>
      <artifactId>ipaddress</artifactId>
    </dependency>
    <dependency>
      <groupId>com.yscope.clp</groupId>
      <artifactId>clp-ffi</artifactId>
    </dependency>
    <dependency>
      <groupId>io.github.hakky54</groupId>
      <artifactId>sslcontext-kickstart-for-netty</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.re2j</groupId>
      <artifactId>re2j</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.auto.service</groupId>
      <artifactId>auto-service-annotations</artifactId>
    </dependency>

    <!-- Test -->
    <dependency>
      <groupId>org.apache.pinot</groupId>
      <artifactId>pinot-yammer</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>nl.jqno.equalsverifier</groupId>
      <artifactId>equalsverifier</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.pinot</groupId>
      <artifactId>pinot-dropwizard</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>net.sourceforge.fmpp</groupId>
      <artifactId>fmpp</artifactId>
    </dependency>
  </dependencies>
  <profiles>
    <profile>
      <id>profile-buildthrift</id>
      <activation>
        <file>
          <exists>/usr/local/bin/thrift</exists>
        </file>
        <property>
          <name>buildThrift</name>
          <value>true</value>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>generate-sources</id>
                <phase>generate-sources</phase>
                <configuration>
                  <target>
                    <delete dir="target/generated-sources/gen-javabean" />
                    <mkdir dir="target/generated-sources" />
                    <exec executable="/usr/local/bin/thrift">
                      <arg value="--gen" />
                      <arg value="java:beans" />
                      <arg value="-o" />
                      <arg value="target/generated-sources" />
                      <arg value="src/thrift/query.thrift" />
                    </exec>
                    <exec executable="/usr/local/bin/thrift">
                      <arg value="--gen" />
                      <arg value="java:beans" />
                      <arg value="-o" />
                      <arg value="target/generated-sources" />
                      <arg value="src/thrift/request.thrift" />
                    </exec>
                    <exec executable="/usr/local/bin/thrift">
                      <arg value="--gen" />
                      <arg value="java:beans" />
                      <arg value="-o" />
                      <arg value="target/generated-sources" />
                      <arg value="src/thrift/response.thrift" />
                    </exec>
                    <move todir="src/main/java/">
                      <fileset dir="target/generated-sources/gen-javabean" />
                    </move>
                    <delete dir="target/generated-sources/gen-javabean" />
                  </target>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>build-shaded-jar</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <shade.phase.prop>package</shade.phase.prop>
      </properties>
    </profile>
    <profile>
      <id>pinot-fastdev</id>
      <properties>
        <shade.phase.prop>none</shade.phase.prop>
      </properties>
    </profile>
    <profile>
      <!-- The Ant task doesn't care about unchanged (re)sources and will always generate.
      This causes the maven-compiler-plugin to detect changes and always recompile the Java sources.

      If there are changes in src/main/codegen, either enforcer activation of this profile by using -Psqlparser or by
      removing the generated-sources/javacc directory

      NOTICE: In Maven the profile activation is decided BEFORE plugin execution.
      When running clean+verify, the profile will not be activated (because the file still exists),
        clean will remove it and compiler-plugin will fail because of a missing class.
        Either run 'mvn clean && mvn verify' or 'mvn verify -Psqlparser'
       -->
      <id>sqlparser</id>
      <activation>
        <file>
          <missing>${project.build.directory}/generated-sources/javacc/Parser.jj</missing>
        </file>
      </activation>
      <build>
        <plugins>
          <!-- "Plugs in" the Calcite's Parser.jj with the variables present in config.fmpp. These contain the custom rules
     as well as the class to which the custom implementation will get generated -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>generate-fmpp-sources</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <target name="generate-code">
                    <taskdef name="fmpp" classname="fmpp.tools.AntTask" classpathref="maven.compile.classpath" />
                    <fmpp configuration="src/main/codegen/config.fmpp" sourceRoot="src/main/codegen/templates" outputRoot="${project.build.directory}/generated-sources/" />
                  </target>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin> <!-- Enforce javacc-maven-plugin executions after fmpp-maven-plugin -->
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>javacc-maven-plugin</artifactId>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
