<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>
    <groupId>org.neo4j.driver</groupId>
    <artifactId>neo4j-java-driver-parent</artifactId>
    <version>5.2.0</version>
    <relativePath>..</relativePath>
  </parent>

  <artifactId>neo4j-java-driver-all</artifactId>

  <packaging>jar</packaging>
  <name>Neo4j Java Driver (shaded package)</name>
  <description>Access to the Neo4j graph database through Java</description>

  <properties>
    <moduleName>org.neo4j.driver</moduleName>
    <rootDir>${project.basedir}/..</rootDir>
    <maven.compiler.xlint.extras>,-try</maven.compiler.xlint.extras>
    <maven.deploy.skip>false</maven.deploy.skip>
  </properties>

  <dependencies>
    <!-- The original driver that will be repackaged. -->
    <dependency>
      <groupId>org.neo4j.driver</groupId>
      <artifactId>neo4j-java-driver</artifactId>
      <version>${project.version}</version>
      <optional>true</optional>
    </dependency>

    <!-- Optional and / or provided dependencies, as they are not transitive to the original driver they must be declared again. -->
    <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-core</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.graalvm.nativeimage</groupId>
      <artifactId>svm</artifactId>
    </dependency>

    <!-- As we pretend the driver being provided only, we need be explicit about the one dependency we actually didn't shade. -->
    <dependency>
      <groupId>org.reactivestreams</groupId>
      <artifactId>reactive-streams</artifactId>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-javadoc-plugin</artifactId>
          <executions>
            <execution>
              <id>attach-javadocs</id>
              <goals>
                <goal>jar</goal>
              </goals>
              <configuration>
                <additionalOptions combine.children="append">
                  <option>--add-exports jdk.internal.vm.ci/jdk.vm.ci.code=org.graalvm.nativeimage.builder</option>
                  <option>--add-exports org.graalvm.nativeimage.builder/com.oracle.svm.core.annotate=org.neo4j.driver</option>
                  <option>--add-exports org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=org.neo4j.driver</option>
                </additionalOptions>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <!-- Extract the original sources again -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <id>copy-appCtx</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/generated-sources/neo4j-java-driver</outputDirectory>
              <overwrite>true</overwrite>
              <resources>
                <resource>
                  <directory>${rootDir}/driver/src/main/java</directory>
                  <includes>
                    <include>**\/*.java</include>
                  </includes>
                  <excludes>
                    <exclude>module-info.java</exclude>
                  </excludes>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- Attach them -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-original-sources</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${project.build.directory}/generated-sources/neo4j-java-driver</source>
              </sources>
            </configuration>
          </execution>
          <execution>
            <id>set-osgi-version</id>
            <phase>validate</phase>
            <goals>
              <goal>parse-version</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>test-jar</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <archive>
            <index>true</index>
            <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
            <manifest>
              <packageName>org/neo4j/driver</packageName>
            </manifest>
            <manifestEntries>
              <!-- This is used to programmatically determine the driver version -->
              <Implementation-Version>${project.version}-${build.revision}</Implementation-Version>
              <!-- Stable module name for JDK9 automatic modules -->
              <Automatic-Module-Name>${moduleName}</Automatic-Module-Name>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <artifactSet>
                <includes>
                  <include>io.netty:*</include>
                  <include>io.projectreactor:*</include>
                </includes>
              </artifactSet>
              <relocations>
                <relocation>
                  <pattern>io.netty</pattern>
                  <shadedPattern>org.neo4j.driver.internal.shaded.io.netty</shadedPattern>
                </relocation>
                <relocation>
                  <pattern>reactor</pattern>
                  <shadedPattern>org.neo4j.driver.internal.shaded.reactor</shadedPattern>
                </relocation>
              </relocations>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
              </transformers>
              <filters>
                <filter>
                  <artifact>io.netty:*</artifact>
                  <excludes>
                    <exclude>META-INF/native-image/**</exclude>
                  </excludes>
                </filter>
              </filters>
              <shadeTestJar>true</shadeTestJar>
              <createSourcesJar>true</createSourcesJar>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>
