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

  <parent>
    <groupId>org.aksw.graphql4sparql</groupId>
    <artifactId>graphql4sparql-pkg-parent</artifactId>
    <version>0.7.0-SNAPSHOT</version>
  </parent>

  <artifactId>graphql4sparql-pkg-fuseki-plugin</artifactId>
  <description>Graphql4Sparql - Fuseki Plugin Jar</description>

  <properties>
    <outputBaseName>graphql4sparql-fuseki-plugin-${project.version}</outputBaseName>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.aksw.graphql4sparql</groupId>
      <artifactId>graphql4sparql-fuseki-mod</artifactId>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j2-impl</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.jena</groupId>
      <artifactId>jena-tdb2</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins> 

      <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>
        <configuration>
          <windowtitle>GraphQL over SPARQL Fuseki Plugin</windowtitle>
          <doctitle>GraphQL over SPARQL Fuseki Plugin ${project.version}</doctitle>
        </configuration>
      </plugin>
     
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <configuration>
          <skip>false</skip>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <!-- Profile to build a "plugin jar bundle" that can be loaded with fuseki or any other jena-based app -->
  <profiles>
    <profile>
      <id>bundle</id>
      <dependencies>
        <dependency>
          <groupId>org.apache.jena</groupId>
          <artifactId>jena-arq</artifactId>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>org.apache.jena</groupId>
          <artifactId>jena-fuseki-server</artifactId>
          <scope>provided</scope>
        </dependency>
      </dependencies>
      <build>  
        <plugins>
          <!-- jar file produced with this configuration gets intensionally overwritten by the shade plugin -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
              <execution>
                <id>default-jar</id>
                <phase>package</phase>
              </execution>
            </executions>
            <configuration>
              <finalName>${outputBaseName}</finalName>
              <!-- Skip manifest as shade will overwrite -->
<!--              <archive>-->
<!--                <manifest>-->
<!--                  <addDefaultImplementationEntries>false</addDefaultImplementationEntries>-->
<!--                  <addDefaultSpecificationEntries>false</addDefaultSpecificationEntries>-->
<!--                </manifest>-->
<!--              </archive>-->
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>shade</goal>
                </goals>
                <configuration>
                  <shadedArtifactAttached>false</shadedArtifactAttached>
                  <outputFile>${project.build.directory}/${outputBaseName}.jar</outputFile>
                  <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer">
                      <addHeader>false</addHeader>
                    </transformer>
                  </transformers>
                  <filters>
                    <filter>
                      <excludes>
                        <exclude>META-INF/*.SF</exclude>
                        <exclude>META-INF/*.DSA</exclude>
                        <exclude>META-INF/*.RSA</exclude>
                        <exclude>META-INF/DEPENDENCIES</exclude>
                        <exclude>META-INF/MANIFEST.MF</exclude>
                        <exclude>**/module-info.class</exclude>
                      </excludes>
                    </filter>
                  </filters>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <!-- Profile that unpacks the class files from the JAR release of this maven module. -->
    <!-- Use the command below to create a shaded Fuseki-Mod plugin jar from this pom.xml alone. -->
    <!-- The command execution will attempt to download the necessary JAR files and only operate on them. -->
    <!-- The Java source code does not have to be present. -->
    <!-- mvn -Punpack-own-classes,bundle -Dmaven.test.skip package -->
    <profile>
      <id>unpack-own-classes</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>unpack-own-classes</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>unpack</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>${project.artifactId}</artifactId>
                      <version>${project.version}</version>
                      <type>jar</type>
                      <overWrite>false</overWrite>
                      <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                    </artifactItem>
                  </artifactItems>
                  <!-- Skip if classes already exist (normal build with sources) -->
                  <overWriteIfNewer>false</overWriteIfNewer>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
