<?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">
    <!--
    Artifacts:

    1. codenameone-linux-8.0-SNAPSHOT.jar
        The src directory compiled (the GTK/Cairo platform implementation). No native
        compilation happens here; the C in nativeSources is compiled by ParparVM's
        "linux" clean-target build (CMake/Ninja + gcc/clang/zig) on Linux.
    2. codenameone-linux-8.0-SNAPSHOT-bundle.jar
        Zip with LinuxPort.jar and nativelinux.jar in the root, mirroring the
        Windows port bundle. Consumed by the build pipeline to supply the port
        classes and the native sources to the translator.
    -->
    <parent>
        <groupId>com.codenameone</groupId>
        <artifactId>codenameone</artifactId>
        <version>7.0.267</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.codenameone</groupId>
    <artifactId>codenameone-linux</artifactId>
    <version>7.0.267</version>
    <packaging>jar</packaging>

    <name>Codename One Linux Port</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>6</maven.compiler.source>
        <maven.compiler.target>6</maven.compiler.target>
        <src.dir>../../Ports/LinuxPort/src</src.dir>
        <codename1.nativelinux.dir>../../Ports/LinuxPort/nativeSources</codename1.nativelinux.dir>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.codenameone</groupId>
            <artifactId>codenameone-core</artifactId>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>${src.dir}</sourceDirectory>
        <resources>
            <resource>
                <directory>${src.dir}</directory>
                <excludes><exclude>**/*.java</exclude></excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <!-- Built for the -bundle step below / local use, but deliberately NOT
                                 attached: nothing consumes the published
                                 jar-with-dependencies classifier (verified across this repo
                                 plus BuildDaemon, BuildCloud, BuildClient, OfflineBuilder and
                                 Deploy - the builders use the -bundle classifier). It was
                                 ~44MB of shaded third-party bytes per release across the five
                                 ports. -->
                            <attach>false</attach>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <!-- The port has no built-in native look, so its native theme is
                         the full material theme (the same one Android ships). Stage it
                         as a classpath resource (linuxNativeTheme.res) so the linux
                         translator target embeds it into the binary and the
                         getResourceAsStream call in installNativeTheme() serves it
                         straight from the executable. Mirrors how the Windows port
                         carries windowsNativeTheme.res. Staged at prepare-package so it
                         is in target/classes before the jar is built (into LinuxPort.jar
                         for the build target) and visible to the screenshot harness,
                         which reads target/classes directly. -->
                    <execution>
                        <id>stage-native-theme</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <copy file="${project.basedir}/../../Themes/AndroidMaterialTheme.res"
                                      tofile="${project.build.outputDirectory}/linuxNativeTheme.res"
                                      overwrite="true" failonerror="true"/>
                            </target>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <mkdir dir="${project.build.directory}/codenameone/linuxport-bundle"/>
                                <!-- Stage the prebuilt libcn1ble shared
                                     libraries (from cn1-binaries) into the
                                     native bundle under ble/{arch}/, so the
                                     LinuxNativeBuilder can ship the arch-correct
                                     one next to a Bluetooth app's executable
                                     for the runtime dlopen in cn1_linux_ble.c.
                                     Tolerant of an absent ble/ dir. -->
                                <zip destfile="${project.build.directory}/codenameone/linuxport-bundle/nativelinux.jar">
                                    <fileset dir="${codename1.nativelinux.dir}"/>
                                    <zipfileset dir="${cn1.binaries}/ble/linux" prefix="ble" erroronmissingdir="false"/>
                                </zip>
                                <!--
                                  LinuxPort.jar inside the bundle is the
                                  fat jar: port classes plus every
                                  transitive dep including codenameone-core,
                                  matching the iOS port bundle. Without
                                  core inside, the ParparVM translator
                                  silently emits an empty C output because
                                  it cannot resolve classes like
                                  com.codename1.ui.events.ActionListener
                                  referenced by an app lambda body.
                                -->
                                <copy file="${project.build.directory}/${project.build.finalName}-jar-with-dependencies.jar" tofile="${project.build.directory}/codenameone/linuxport-bundle/LinuxPort.jar" overwrite="true"/>
                                <zip destfile="${project.build.directory}/${project.build.finalName}-bundle.jar">
                                    <fileset dir="${project.build.directory}/codenameone/linuxport-bundle"/>
                                </zip>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/${project.build.finalName}-bundle.jar</file>
                                    <type>jar</type>
                                    <classifier>bundle</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
