<?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/maven-v4_0_0.xsd">
  <parent>
    <artifactId>pathling</artifactId>
    <groupId>au.csiro.pathling</groupId>
    <version>9.2.0</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>library-runtime</artifactId>
  <name>Pathling Library Runtime</name>
  <description>A Spark package that bundles the Pathling Library API and its runtime dependencies for use in applications and clusters.</description>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <configuration>
          <filesets>
            <fileset>
              <directory>${project.basedir}</directory>
              <includes>
                <include>dependency-reduced-pom.xml</include>
              </includes>
            </fileset>
          </filesets>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <createDependencyReducedPom>true</createDependencyReducedPom>
          <shadedArtifactAttached>false</shadedArtifactAttached>
          <useDependencyReducedPomInJar>true</useDependencyReducedPomInJar>
          <filters>
            <filter>
              <artifact>*:*</artifact>
              <excludes>
                <exclude>META-INF/MANIFEST.MF</exclude>
                <exclude>META-INF/versions/**</exclude>
                <exclude>module-info.class</exclude>
                <exclude>META-INF/LICENSE</exclude>
                <exclude>META-INF/LICENSE.txt</exclude>
                <exclude>META-INF/LICENSE.md</exclude>
                <exclude>META-INF/NOTICE</exclude>
                <exclude>META-INF/NOTICE.txt</exclude>
                <exclude>META-INF/NOTICE.md</exclude>
                <exclude>META-INF/DEPENDENCIES</exclude>
                <exclude>META-INF/licenses.xml</exclude>
                <exclude>LICENSE</exclude>
              </excludes>
            </filter>
            <filter>
              <artifact>org.glassfish:javax.json</artifact>
              <excludes>
                <exclude>**</exclude>
              </excludes>
            </filter>
          </filters>
          <transformers>
            <transformer />
            <transformer />
            <transformer>
              <addHeader>false</addHeader>
            </transformer>
          </transformers>
          <relocations>
            <relocation>
              <pattern>com/</pattern>
              <shadedPattern>${shaded.dependency.prefix}.com.</shadedPattern>
              <includes>
                <include>com/github/benmanes/caffeine/**</include>
              </includes>
            </relocation>
            <relocation>
              <pattern>com/</pattern>
              <shadedPattern>${shaded.dependency.prefix}.com.</shadedPattern>
              <includes>
                <include>com/fasterxml/jackson/**</include>
              </includes>
            </relocation>
            <relocation>
              <pattern>org/</pattern>
              <shadedPattern>${shaded.dependency.prefix}.org.</shadedPattern>
              <includes>
                <include>org/hibernate/validator/**</include>
              </includes>
            </relocation>
          </relocations>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack-sources</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <includeGroupIds>au.csiro.pathling,au.csiro.fhir</includeGroupIds>
              <classifier>sources</classifier>
              <failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
              <outputDirectory>${project.build.directory}/dependency-sources</outputDirectory>
              <excludeTransitive>false</excludeTransitive>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-source-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-sources</id>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
            <configuration>
              <includes>
                <include>**/*.java</include>
              </includes>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <includePom>false</includePom>
          <archive>
            <manifest>
              <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
              <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
            </manifest>
          </archive>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>create-sources-jar</id>
            <phase>package</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>jar</executable>
              <workingDirectory>${project.build.directory}</workingDirectory>
              <arguments>
                <argument>cf</argument>
                <argument>${project.build.finalName}-sources.jar</argument>
                <argument>-C</argument>
                <argument>dependency-sources</argument>
                <argument>.</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-sources-jar</id>
            <phase>package</phase>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <configuration>
              <artifacts>
                <artifact>
                  <file>${project.build.directory}/${project.build.finalName}-sources.jar</file>
                  <type>jar</type>
                  <classifier>sources</classifier>
                </artifact>
              </artifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>docs</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>unpack-library-api-javadoc</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>unpack</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>au.csiro.pathling</groupId>
                      <artifactId>library-api</artifactId>
                      <version>${project.version}</version>
                      <classifier>javadoc</classifier>
                      <type>jar</type>
                      <outputDirectory>${project.build.directory}/unpacked-javadoc</outputDirectory>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
              <execution>
                <id>package-javadoc-jar</id>
                <phase>package</phase>
                <goals>
                  <goal>jar</goal>
                </goals>
                <configuration>
                  <classesDirectory>${project.build.directory}/unpacked-javadoc</classesDirectory>
                  <classifier>javadoc</classifier>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
  <properties>
    <shaded.dependency.prefix>au.csiro.pathling.shaded</shaded.dependency.prefix>
  </properties>
</project>
