<?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>de.neitzel</groupId>
        <artifactId>neitzelfx</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>neitzelfx-example</artifactId>

    <properties>
        <link.name>${project.artifactId}</link.name>
        <launcher>${project.artifactId}</launcher>
        <appName>${project.artifactId}</appName>
        <main.class>de.neitzel.neitzelfx.injectfx.example.Main</main.class>
        <jar.filename>${project.artifactId}-${project.version}</jar.filename>
    </properties>

    <dependencies>
        <!-- NeitzelFX dependency -->
        <dependency>
            <groupId>de.neitzel</groupId>
            <artifactId>neitzelfx-lib</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>${jar.filename}</finalName>
        <plugins>
            <plugin>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <profiles>

        <!-- Profile that adds JLink and JPackage runs.

             Add -Pimage or -Dimage to use this profile.
             -->
        <profile>
            <id>image</id>
            <activation>
                <property>
                    <name>image</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <!-- Copy dependencies -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>${maven.dependency.plugin}</version>
                        <executions>
                            <!-- erstmal Abhängigkeiten für den Class-Path kopieren -->
                            <execution>
                                <id>copy-dependencies</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.directory}/modules</outputDirectory>
                                    <includeScope>runtime</includeScope>
                                    <overWriteReleases>false</overWriteReleases>
                                    <overWriteSnapshots>false</overWriteSnapshots>
                                    <overWriteIfNewer>true</overWriteIfNewer>
                                </configuration>
                            </execution>

                            <!-- dazu noch das Projekt-JAR -->
                            <execution>
                                <id>copy</id>
                                <phase>install</phase>
                                <goals>
                                    <goal>copy</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.directory}/modules</outputDirectory>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>${project.artifactId}</artifactId>
                                            <version>${project.version}</version>
                                            <type>${project.packaging}</type>
                                            <destFileName>${project.build.finalName}.jar</destFileName>
                                        </artifactItem>
                                    </artifactItems>
                                    <overWriteIfNewer>true</overWriteIfNewer>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>com.github.akman</groupId>
                        <artifactId>jpackage-maven-plugin</artifactId>
                        <version>${jpackage.maven.plugin}</version>
                        <configuration>
                            <name>${appName}</name>
                            <type>IMAGE</type>
                            <modulepath>
                                <dependencysets>
                                    <dependencyset>
                                        <includenames>
                                            <includename>javafx\..*</includename>
                                        </includenames>
                                    </dependencyset>
                                </dependencysets>
                            </modulepath>
                            <addmodules>
                                <addmodule>javafx.controls</addmodule>
                                <addmodule>javafx.graphics</addmodule>
                                <addmodule>javafx.fxml</addmodule>
                                <addmodule>javafx.web</addmodule>
                            </addmodules>
                            <mainclass>${main.class}</mainclass>
                            <input>${project.build.directory}/modules</input>
                            <mainjar>${jar.filename}.jar</mainjar>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>install</phase>
                                <goals>
                                    <goal>jpackage</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- Profile to build a fat jar

             Add -Pfatjar or -Dfatjar to use this profile.
             -->
        <profile>
            <id>fatjar</id>
            <activation>
                <property>
                    <name>fatjar</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-shade-plugin</artifactId>
                        <version>${maven.shade.plugin}</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>shade</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>full</shadedClassifierName>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>
                                        <Main-Class>${main.class}</Main-Class>
                                        <Build-Version>1.0</Build-Version>
                                    </manifestEntries>
                                </transformer>
                            </transformers>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/MANIFEST.MF</exclude>
                                        <exclude>**/module-info.class</exclude>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
