<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>

  <groupId>io.armadaproject</groupId>
  <artifactId>java-client</artifactId>
  <version>0.0.2</version>
  <packaging>jar</packaging>
  <description>Java client library for the Armada project</description>
  <name>java-client</name>
  <url>https://github.com/armadaproject/java-client</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven-compiler-plugin.release>11</maven-compiler-plugin.release>
    <io.grpc.version>1.67.1</io.grpc.version>
    <protobuf-java.version>3.25.3</protobuf-java.version>
    <os-maven-plugin.version>1.7.1</os-maven-plugin.version>
    <maven-checkstyle-plugin.version>3.5.0</maven-checkstyle-plugin.version>
    <checkstyle.version>10.18.2</checkstyle.version>
    <maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
    <protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
    <annotation-api.version>6.0.53</annotation-api.version>
    <exec-maven-plugin.version>3.0.0</exec-maven-plugin.version>
    <org.junit.jupiter.version>5.11.1</org.junit.jupiter.version>
    <maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
  </properties>

  <licenses>
    <license>
      <name>Apache 2.0 License</name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
      <distribution>repo</distribution>
    </license>
  </licenses>

  <developers>
    <developer>
      <name>Mladjan Gadzic</name>
      <email>mladjan@gr-oss.io</email>
      <organization>G-Research</organization>
      <organizationUrl>https://www.gresearch.com/</organizationUrl>
    </developer>
  </developers>

  <scm>
    <connection>scm:git:git://github.com/armadaproject/java-client.git</connection>
    <developerConnection>scm:git:ssh://github.com:armadaproject/java-client.git
    </developerConnection>
    <url>http://github.com/armadaproject/java-client/tree/main</url>
    <tag/>
  </scm>

  <distributionManagement>
    <repository>
      <id>central</id>
      <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
    </repository>
  </distributionManagement>

  <profiles>
    <profile>
      <id>local</id>
      <properties>
        <env>local</env>
      </properties>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <!-- get proto files -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>${exec-maven-plugin.version}</version>
            <executions>
              <execution>
                <id>clone-armada-repo</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>git</executable>
                  <arguments>
                    <argument>clone</argument>
                    <argument>https://github.com/armadaproject/armada.git</argument>
                    <argument>${project.build.directory}/armada</argument>
                  </arguments>
                </configuration>
              </execution>
              <execution>
                <id>clone-api-repo</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>git</executable>
                  <arguments>
                    <argument>clone</argument>
                    <argument>https://github.com/kubernetes/api.git</argument>
                    <argument>${project.build.directory}/k8s.io/api</argument>
                  </arguments>
                </configuration>
              </execution>
              <execution>
                <id>clone-apimachinery-repo</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>git</executable>
                  <arguments>
                    <argument>clone</argument>
                    <argument>https://github.com/kubernetes/apimachinery.git</argument>
                    <argument>${project.build.directory}/k8s.io/apimachinery</argument>
                  </arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- copy proto files -->
          <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>${maven-resources-plugin.version}</version>
            <executions>
              <execution>
                <id>copy-protos</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.basedir}/src/main/proto</outputDirectory>
                  <resources>
                    <resource>
                      <directory>${project.build.directory}/armada</directory>
                      <includes>
                        <include>pkg/api/*.proto</include>
                        <include>pkg/api/binoculars/*.proto</include>
                      </includes>
                    </resource>
                    <resource>
                      <directory>${project.build.directory}</directory>
                      <includes>
                        <include>k8s.io/api/core/v1/generated.proto</include>
                        <include>k8s.io/api/networking/v1/generated.proto</include>
                        <include>k8s.io/apimachinery/pkg/api/resource/generated.proto</include>
                        <include>k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto</include>
                        <include>k8s.io/apimachinery/pkg/runtime/generated.proto</include>
                        <include>k8s.io/apimachinery/pkg/runtime/schema/generated.proto</include>
                        <include>k8s.io/apimachinery/pkg/util/intstr/generated.proto</include>
                      </includes>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- detect os -->
          <plugin>
            <groupId>kr.motd.maven</groupId>
            <artifactId>os-maven-plugin</artifactId>
            <version>${os-maven-plugin.version}</version>
            <executions>
              <execution>
                <goals>
                  <goal>detect</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <!-- checkstyle -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>${maven-checkstyle-plugin.version}</version>
            <dependencies>
              <dependency>
                <groupId>com.puppycrawl.tools</groupId>
                <artifactId>checkstyle</artifactId>
                <version>${checkstyle.version}</version>
              </dependency>
            </dependencies>
            <configuration>
              <configLocation>dev-support/google_checks.xml</configLocation>
              <suppressionsLocation>dev-support/checkstyle-suppressions.xml</suppressionsLocation>
              <consoleOutput>true</consoleOutput>
              <failsOnError>true</failsOnError>
              <failOnViolation>true</failOnViolation>
              <violationSeverity>warning</violationSeverity>
              <linkXRef>false</linkXRef>
            </configuration>
            <executions>
              <execution>
                <id>validate</id>
                <phase>validate</phase>
                <goals>
                  <goal>check</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <!-- generate java sources from proto -->
          <plugin>
            <groupId>org.xolstice.maven.plugins</groupId>
            <artifactId>protobuf-maven-plugin</artifactId>
            <version>${protobuf-maven-plugin.version}</version>
            <configuration>
              <protocArtifact>
                com.google.protobuf:protoc:${protobuf-java.version}:exe:${os.detected.classifier}
              </protocArtifact>
              <pluginId>grpc-java</pluginId>
              <pluginArtifact>
                io.grpc:protoc-gen-grpc-java:${io.grpc.version}:exe:${os.detected.classifier}
              </pluginArtifact>
            </configuration>
            <executions>
              <execution>
                <goals>
                  <goal>compile</goal>
                  <goal>compile-custom</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <!-- compile java -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin.version}</version>
            <configuration>
              <release>${maven-compiler-plugin.release}</release>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>ci</id>
      <properties>
        <env>ci</env>
      </properties>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>3.3.0</version>
            <executions>
              <execution>
                <id>attach-sources</id>
                <goals>
                  <goal>jar-no-fork</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>3.5.0</version>
            <executions>
              <execution>
                <id>attach-javadocs</id>
                <goals>
                  <goal>jar</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <!-- detect os -->
          <plugin>
            <groupId>kr.motd.maven</groupId>
            <artifactId>os-maven-plugin</artifactId>
            <version>${os-maven-plugin.version}</version>
            <executions>
              <execution>
                <goals>
                  <goal>detect</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.sonatype.central</groupId>
            <artifactId>central-publishing-maven-plugin</artifactId>
            <version>0.6.0</version>
            <extensions>true</extensions>
            <configuration>
              <publishingServerId>central</publishingServerId>
              <autoPublish>true</autoPublish>
            </configuration>
          </plugin>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
            <version>3.2.7</version>
            <executions>
              <execution>
                <id>sign-artifacts</id>
                <phase>verify</phase>
                <goals>
                  <goal>sign</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <!-- generate java sources from proto -->
          <plugin>
            <groupId>org.xolstice.maven.plugins</groupId>
            <artifactId>protobuf-maven-plugin</artifactId>
            <version>${protobuf-maven-plugin.version}</version>
            <configuration>
              <protocArtifact>
                com.google.protobuf:protoc:${protobuf-java.version}:exe:${os.detected.classifier}
              </protocArtifact>
              <pluginId>grpc-java</pluginId>
              <pluginArtifact>
                io.grpc:protoc-gen-grpc-java:${io.grpc.version}:exe:${os.detected.classifier}
              </pluginArtifact>
            </configuration>
            <executions>
              <execution>
                <goals>
                  <goal>compile</goal>
                  <goal>compile-custom</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <!-- compile java -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin.version}</version>
            <configuration>
              <release>${maven-compiler-plugin.release}</release>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

  <dependencies>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-netty-shaded</artifactId>
      <version>${io.grpc.version}</version>
      <scope>runtime</scope>
    </dependency>

    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-protobuf</artifactId>
      <version>${io.grpc.version}</version>
    </dependency>

    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-stub</artifactId>
      <version>${io.grpc.version}</version>
    </dependency>

    <dependency>
      <groupId>com.google.protobuf</groupId>
      <artifactId>protobuf-java</artifactId>
      <version>${protobuf-java.version}</version>
    </dependency>

    <!-- needed for javax.annotation.Generated -->
    <dependency>
      <groupId>org.apache.tomcat</groupId>
      <artifactId>annotations-api</artifactId>
      <version>${annotation-api.version}</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>${org.junit.jupiter.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>${org.junit.jupiter.version}</version>
      <scope>test</scope>
    </dependency>

  </dependencies>

</project>
