<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.openmbee</groupId>
    <artifactId>opensysml-parent</artifactId>
    <version>0.12.1</version>
  </parent>

  <artifactId>opensysml</artifactId>
  <packaging>jar</packaging>

  <name>OpenSysML Java client</name>
  <description>Parse, inspect and evaluate SysML v2 models over the sysml-grpc service's Connect
    protocol, from inside a long-lived JVM host application.</description>
  <url>https://github.com/Open-MBEE/OpenSysML/tree/main/client/java</url>

  <dependencies>
    <dependency>
      <groupId>com.google.protobuf</groupId>
      <artifactId>protobuf-java</artifactId>
    </dependency>
    <!-- Only Encoding.JSON needs it, a debugging affordance rather than the
         default, so a host that never asks for JSON carries neither it nor gson. -->
    <dependency>
      <groupId>com.google.protobuf</groupId>
      <artifactId>protobuf-java-util</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <optional>true</optional>
    </dependency>
    <!-- Verifies the sigstore bundle over a release's SHA256SUMS.txt, which is what lets a
         release newer than this client's pinned digests install. -->
    <dependency>
      <groupId>dev.sigstore</groupId>
      <artifactId>sigstore-java</artifactId>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
    </dependency>
  </dependencies>

  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <includes>
          <include>opensysml-version.properties</include>
        </includes>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
        <excludes>
          <exclude>opensysml-version.properties</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <!-- The schema declares no Java file options, so the build appends the two the
           client's package layout needs to a copy of it; the repository's schema stays
           untouched and the committed Go stubs carry the same two options. -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>java-file-options</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <concat destfile="${project.build.directory}/proto/sysml.proto" fixlastline="yes">
                  <file file="${project.basedir}/../../../api/proto/sysml.proto"/>
                  <footer trimleading="yes">
                    option java_package = "org.openmbee.opensysml.proto";
                    option java_multiple_files = true;
                  </footer>
                </concat>
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- The message classes are generated into target/ by the protoc release that
           matches the protobuf-java runtime, so nothing generated is committed. -->
      <plugin>
        <groupId>io.github.ascopes</groupId>
        <artifactId>protobuf-maven-plugin</artifactId>
        <configuration>
          <protoc>${protobuf.version}</protoc>
          <sourceDirectories>
            <sourceDirectory>${project.build.directory}/proto</sourceDirectory>
          </sourceDirectories>
          <!-- sysml.proto imports nothing, so the dependencies' bundled .proto files
               have no part in the import path. -->
          <ignoreProjectDependencies>true</ignoreProjectDependencies>
          <!-- The jar ships classes, not the schema. -->
          <embedSourcesInClassOutputs>false</embedSourcesInClassOutputs>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <!-- The orphan-safety test starts a JVM of its own, so the test JVM
               must see its real classpath rather than a manifest-only jar. -->
          <useManifestOnlyJar>false</useManifestOnlyJar>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <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>
        <configuration>
          <!-- The generated message classes document the schema, which
               sysml.proto already does, and their javadoc is not the client's. -->
          <excludePackageNames>org.openmbee.opensysml.proto</excludePackageNames>
          <doclint>all,-missing</doclint>
          <notimestamp>true</notimestamp>
        </configuration>
        <executions>
          <execution>
            <id>attach-javadocs</id>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
