<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">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>jsignpdf-distribution</artifactId>
    <name>${project.artifactId}</name>
    <packaging>pom</packaging>

    <parent>
        <groupId>com.github.kwart.jsign</groupId>
        <artifactId>jsignpdf-root</artifactId>
        <version>3.1.0-RC-1</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <properties>
        <asciidoctor.maven.plugin.version>3.2.0</asciidoctor.maven.plugin.version>
        <asciidoctorj.pdf.version>2.3.23</asciidoctorj.pdf.version>
        <staging.dir>${project.build.directory}/appassembler</staging.dir>
    </properties>

    <build>
        <plugins>
            <!--
              Step 1: assemble bin/ launcher scripts + lib/ with every runtime dependency.
              The unix launcher and the .bat launcher use 'java -cp "lib/*" Bootstrap ...';
              the Bootstrap class then loads the platform-matching JavaFX classifier jars
              from lib/javafx/ via a URLClassLoader.
            -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>assemble</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>assemble</goal>
                        </goals>
                        <configuration>
                            <assembleDirectory>${staging.dir}</assembleDirectory>
                            <repositoryLayout>flat</repositoryLayout>
                            <repositoryName>lib</repositoryName>
                            <useWildcardClassPath>true</useWildcardClassPath>
                            <binFolder>bin</binFolder>
                            <binFileExtensions>
                                <unix>.sh</unix>
                                <windows>.cmd</windows>
                            </binFileExtensions>
                            <platforms>
                                <platform>unix</platform>
                                <platform>windows</platform>
                            </platforms>
                            <programs>
                                <program>
                                    <id>jsignpdf</id>
                                    <mainClass>com.intoolswetrust.jsignpdf.Bootstrap</mainClass>
                                </program>
                            </programs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!--
              Step 2: build two zips from the staging directory.
                * jsignpdf-VERSION-full.zip    — every JavaFX classifier jar, organised under
                                                 lib/javafx/ for Bootstrap to consume.
                * jsignpdf-VERSION-minimal.zip — every dependency *except* JavaFX (no JRE either);
                                                 Signer falls through to Swing when the GUI is
                                                 requested.
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>${maven.assembly.plugin.version}</version>
                <executions>
                    <execution>
                        <id>full-zip</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <finalName>jsignpdf-${project.version}-full</finalName>
                            <appendAssemblyId>false</appendAssemblyId>
                            <descriptors>
                                <descriptor>src/assembly/full.xml</descriptor>
                            </descriptors>
                            <tarLongFileMode>posix</tarLongFileMode>
                            <attach>false</attach>
                        </configuration>
                    </execution>
                    <execution>
                        <id>minimal-zip</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <finalName>jsignpdf-${project.version}-minimal</finalName>
                            <appendAssemblyId>false</appendAssemblyId>
                            <descriptors>
                                <descriptor>src/assembly/minimal.xml</descriptor>
                            </descriptors>
                            <tarLongFileMode>posix</tarLongFileMode>
                            <attach>false</attach>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!--
              Step 3: attach both zips as classified artifacts so the Maven
              release deploys them to Central (signed by maven-gpg-plugin at
              the later 'verify' phase), the same way the pre-3.0
              jsignpdf-distribution module published its single zip. The
              package-release workflow downloads these exact bits to drive the
              per-platform jpackage builds. The assembly executions keep
              <attach>false</attach>; build-helper does the attaching so the
              classifiers (full / minimal) are explicit.
            -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-distribution-zips</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/jsignpdf-${project.version}-full.zip</file>
                                    <type>zip</type>
                                    <classifier>full</classifier>
                                </artifact>
                                <artifact>
                                    <file>${project.build.directory}/jsignpdf-${project.version}-minimal.zip</file>
                                    <type>zip</type>
                                    <classifier>minimal</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <executions>
                    <execution>
                        <id>enforce-versions</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <rules>
                        <dependencyConvergence />
                    </rules>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.asciidoctor</groupId>
                <artifactId>asciidoctor-maven-plugin</artifactId>
                <version>${asciidoctor.maven.plugin.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>org.asciidoctor</groupId>
                        <artifactId>asciidoctorj-pdf</artifactId>
                        <version>${asciidoctorj.pdf.version}</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <sourceDirectory>../website/docs</sourceDirectory>
                    <attributes>
                        <sourcedir>${project.build.sourceDirectory}</sourcedir>
                        <jsignpdf-version>${project.version}</jsignpdf-version>
                    </attributes>
                </configuration>
                <executions>
                    <execution>
                        <id>generate-pdf-doc</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>process-asciidoc</goal>
                        </goals>
                        <configuration>
                            <backend>pdf</backend>
                            <attributes>
                                <source-highlighter>coderay</source-highlighter>
                                <icons>font</icons>
                                <pagenums />
                                <toc />
                                <idprefix />
                                <idseparator>-</idseparator>
                            </attributes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>jsignpdf-bootstrap</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>jsignpdf</artifactId>
            <version>${project.version}</version>
        </dependency>
        <!--
          Bundled signing engines. The main jsignpdf jar compile-depends only on the engine API;
          the concrete engine implementations are pulled in here (runtime) so their jars land in
          lib/ and are discovered via ServiceLoader. Additional engines (PDFBox, DSS) are added
          here in phase 2.
        -->
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>jsignpdf-engine-openpdf</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>jsignpdf-engine-dss</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>installcert</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!--
          Platform-specific JavaFX natives. Each classifier jar carries the native libraries for
          one OS/arch. The full ZIP relocates them to lib/javafx/ so Bootstrap can pick the right
          set at runtime; the minimal ZIP excludes them outright.
        -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-base</artifactId>
            <version>${openjfx.version}</version>
            <classifier>win</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-base</artifactId>
            <version>${openjfx.version}</version>
            <classifier>linux</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-base</artifactId>
            <version>${openjfx.version}</version>
            <classifier>mac</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-base</artifactId>
            <version>${openjfx.version}</version>
            <classifier>mac-aarch64</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>${openjfx.version}</version>
            <classifier>win</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>${openjfx.version}</version>
            <classifier>linux</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>${openjfx.version}</version>
            <classifier>mac</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>${openjfx.version}</version>
            <classifier>mac-aarch64</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${openjfx.version}</version>
            <classifier>win</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${openjfx.version}</version>
            <classifier>linux</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${openjfx.version}</version>
            <classifier>mac</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${openjfx.version}</version>
            <classifier>mac-aarch64</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>${openjfx.version}</version>
            <classifier>win</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>${openjfx.version}</version>
            <classifier>linux</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>${openjfx.version}</version>
            <classifier>mac</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>${openjfx.version}</version>
            <classifier>mac-aarch64</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-swing</artifactId>
            <version>${openjfx.version}</version>
            <classifier>win</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-swing</artifactId>
            <version>${openjfx.version}</version>
            <classifier>linux</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-swing</artifactId>
            <version>${openjfx.version}</version>
            <classifier>mac</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-swing</artifactId>
            <version>${openjfx.version}</version>
            <classifier>mac-aarch64</classifier>
        </dependency>
    </dependencies>
</project>
