<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>6.0.2</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>
  <url>https://github.com/neo4j/neo4j-java-driver</url>

  <properties>
    <moduleName>org.neo4j.driver</moduleName>
    <rootDir>${project.basedir}/..</rootDir>
    <maven.compiler.xlint.extras>,-try,-module</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>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.graalvm.nativeimage</groupId>
      <artifactId>svm</artifactId>
    </dependency>
    <dependency>
      <groupId>io.projectreactor.tools</groupId>
      <artifactId>blockhound</artifactId>
      <optional>true</optional>
    </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>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>org.apache.felix</groupId>
          <artifactId>maven-bundle-plugin</artifactId>
          <configuration>
            <instructions combine.children="append">
              <_removeheaders>Bnd-*,Private-Package,Bundle-ClassPath,Embed-Dependency,Embed-Transitive,Embedded-Artifacts,Include-Resource</_removeheaders>
              <Embed-Dependency>neo4j-bolt-connection-netty,netty-handler,netty-tcnative-classes,reactor-core</Embed-Dependency>
            </instructions>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <!-- Extract the original sources again -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <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>
                </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>org.neo4j.bolt:neo4j-bolt-connection</include>
                  <include>org.neo4j.bolt:neo4j-bolt-connection-netty</include>
                  <include>org.neo4j.bolt:neo4j-bolt-connection-pooled</include>
                  <include>org.neo4j.bolt:neo4j-bolt-connection-routed</include>
                  <include>io.netty:*</include>
                  <include>io.projectreactor:*</include>
                </includes>
              </artifactSet>
              <relocations>
                <relocation>
                  <pattern>org.neo4j.bolt.connection</pattern>
                  <shadedPattern>org.neo4j.driver.internal.shaded.bolt.connection</shadedPattern>
                </relocation>
                <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"/>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <manifestEntries>
                    <Include-Resource>META-INF/native-image/org.neo4j.driver/neo4j-java-driver/native-image.properties=src/main/resources/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/native-image.properties,META-INF/native-image/org.neo4j.driver/neo4j-java-driver/reflect-config.json=src/main/resources/META-INF/native-image/org.neo4j.driver/neo4j-java-driver/reflect-config.json</Include-Resource>
                  </manifestEntries>
                </transformer>
              </transformers>
              <filters>
                <filter>
                  <artifact>io.netty:*</artifact>
                  <excludes>
                    <exclude>META-INF/native-image/**</exclude>
                  </excludes>
                </filter>
                <filter>
                  <artifact>*:*</artifact>
                  <excludes>
                    <exclude>module-info.java</exclude>
                    <exclude>module-info.yml</exclude>
                    <exclude>META-INF/maven/**</exclude>
                    <exclude>META-INF/versions/**</exclude>
                  </excludes>
                </filter>
              </filters>
              <shadeTestJar>true</shadeTestJar>
              <createSourcesJar>true</createSourcesJar>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>add-module-info-to-sources</id>
            <phase>package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <unzip src="${project.build.directory}/${project.artifactId}-${project.version}-sources.jar" dest="${project.build.directory}/sources-with-module"/>
                <copy file="${project.basedir}/src/main/jpms/module-info.java" tofile="${project.build.directory}/sources-with-module/module-info.java" overwrite="true"/>
                <zip basedir="${project.build.directory}/sources-with-module" destfile="${project.build.directory}/${project.artifactId}-${project.version}-sources.jar"/>
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.moditect</groupId>
        <artifactId>moditect-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>add-module-infos</id>
            <phase>package</phase>
            <goals>
              <goal>add-module-info</goal>
            </goals>
            <configuration>
              <overwriteExistingFiles>true</overwriteExistingFiles>
              <module>
                <moduleInfoFile>
                  ${basedir}/src/main/jpms/module-info.java
                </moduleInfoFile>
              </module>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <scm>
    <connection>scm:git:git://github.com/neo4j/neo4j-java-driver.git</connection>
    <developerConnection>scm:git:git@github.com:neo4j/neo4j-java-driver.git</developerConnection>
    <url>https://github.com/neo4j/neo4j-java-driver</url>
  </scm>

</project>
