<?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.noise-planet</groupId>
        <artifactId>noisemodelling-parent</artifactId>
        <version>6.0.1</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>noisemodelling-scripts</artifactId>
    <name>NoiseModelling Scripts</name>
    <description>WebServer and groovy scripts of NoiseModelling</description>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <shell.executable />
        <shell.arg />
        <sphinx.command />
    </properties>
    <profiles>
        <profile>
            <id>unix-config</id>
            <activation>
                <os><family>unix</family></os>
            </activation>
            <properties>
                <shell.executable>sh</shell.executable>
                <shell.arg>-c</shell.arg>
                <!-- Check if python3 exists, if so run the commands, if not echo and exit 0 -->
                <sphinx.command>
                    command -v python3 &gt;/dev/null 2&gt;&amp;1 &amp;&amp; (
                    python3 -m venv target/venv &amp;&amp;
                    target/venv/bin/python -m pip install -r ../Docs/requirements.txt &amp;&amp;
                    target/venv/bin/sphinx-build -M html ../Docs target/sphinx
                    ) || echo "Python3 not found. Skipping documentation generation."
                </sphinx.command>
            </properties>
        </profile>
        <profile>
            <id>windows-config</id>
            <activation>
                <os><family>windows</family></os>
            </activation>
            <properties>
                <shell.executable>cmd</shell.executable>
                <shell.arg>/c</shell.arg>
                <sphinx.command>
                    where python &gt;nul 2&gt;nul &amp;&amp; ( python -m venv target/venv &amp;&amp; target\venv\Scripts\activate.bat &amp;&amp; pip install -r ..\Docs\requirements.txt &amp;&amp; sphinx-build -M html ..\Docs target\sphinx ) || echo Python not found. Skipping documentation generation.
                </sphinx.command>
            </properties>
        </profile>
        <profile>
            <id>macos-bundler</id>
            <activation>
                <os><family>mac</family></os>
            </activation>
            <build>
                <plugins>
                    <!-- 1. Sanitize the version string -->
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <version>3.5.0</version>
                        <executions>
                            <execution>
                                <id>regex-property</id>
                                <goals>
                                    <goal>regex-property</goal>
                                </goals>
                                <configuration>
                                    <name>macOS.version</name>
                                    <value>${project.version}</value>
                                    <!-- Regex to extract only the X.Y.Z part -->
                                    <regex>^([0-9]+(\.[0-9]+)*).*</regex>
                                    <replacement>$1</replacement>
                                    <failIfNoMatch>false</failIfNoMatch>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>3.6.0</version>
                        <executions>
                            <execution>
                                <id>copy-dependencies</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.directory}/macos-stage/lib</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- 2. Copy the Main JAR and the Scripts folder -->
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>3.3.1</version>
                        <executions>
                            <execution>
                                <id>copy-app-files</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.directory}/macos-stage/lib</outputDirectory>
                                    <resources>
                                        <!-- The Main JAR -->
                                        <resource>
                                            <directory>${project.build.directory}</directory>
                                            <includes>
                                                <include>${project.build.finalName}.jar</include>
                                                <include>help/**</include>
                                            </includes>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                            <execution>
                                <id>copy-help-files</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.directory}/macos-stage/help</outputDirectory>
                                    <resources>
                                        <!-- The help pages -->
                                        <resource>
                                            <directory>${project.build.directory}/sphinx/html/</directory>
                                            <includes>
                                                <include>**</include>
                                            </includes>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>create-macos-app</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>jpackage</executable>
                                    <arguments>
                                        <argument>--input</argument>
                                        <argument>${project.build.directory}/macos-stage</argument>
                                        <argument>--main-jar</argument>
                                        <argument>lib/${project.build.finalName}.jar</argument>
                                        <argument>--main-class</argument>
                                        <argument>org.noise_planet.noisemodelling.webserver.NoiseModellingServer</argument>
                                        <argument>--type</argument>
                                        <argument>dmg</argument>
                                        <argument>--dest</argument>
                                        <argument>${project.build.directory}</argument>
                                        <argument>--name</argument>
                                        <argument>NoiseModelling</argument>
                                        <argument>--icon</argument>
                                        <argument>../installer/Logo_noisemodelling_square.icns</argument>
                                        <argument>--vendor</argument>
                                        <argument>${parent.organization.name}</argument>
                                        <argument>--app-version</argument>
                                        <argument>${macOS.version}</argument>
                                        <argument>--mac-package-name</argument>
                                        <argument>NoiseModelling</argument>
                                        <argument>--mac-package-identifier</argument>
                                        <argument>org.noise-planet.noisemodelling</argument>
                                        <argument>--arguments</argument>
                                        <argument>-u -r ""</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>noisemodelling-jdbc</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>noisemodelling-emission</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>noisemodelling-pathfinder</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>noisemodelling-propagation</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.groovy</groupId>
            <artifactId>groovy-templates</artifactId>
        </dependency>
        <dependency>
            <groupId>org.geotools.ogc</groupId>
            <artifactId>net.opengis.wps</artifactId>
        </dependency>
        <dependency>
            <groupId>org.geotools.xsd</groupId>
            <artifactId>gt-xsd-wps</artifactId>
        </dependency>
        <dependency>
            <groupId>org.orbisgis</groupId>
            <artifactId>h2gis-utilities</artifactId>
        </dependency>
        <dependency>
            <groupId>org.orbisgis</groupId>
            <artifactId>h2gis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.orbisgis</groupId>
            <artifactId>postgis-jts</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-cli</groupId>
            <artifactId>commons-cli</artifactId>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.service.jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>com.opencsv</groupId>
            <artifactId>opencsv</artifactId>
        </dependency>
        <dependency>
            <groupId>io.javalin</groupId>
            <artifactId>javalin-bundle</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.groovy</groupId>
            <artifactId>groovy-sql</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.groovy</groupId>
            <artifactId>groovy-json</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.groovy</groupId>
            <artifactId>groovy</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-reload4j</artifactId>
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
        </dependency>
        <dependency>
            <groupId>com.auth0</groupId>
            <artifactId>java-jwt</artifactId>
        </dependency>
        <dependency>
            <groupId>io.javalin</groupId>
            <artifactId>javalin-rendering</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian</groupId>
            <artifactId>onetime</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>javase</artifactId>
        </dependency>
        <dependency>
            <groupId>org.openstreetmap.osmosis</groupId>
            <artifactId>osmosis-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.openstreetmap.osmosis</groupId>
            <artifactId>osmosis-pbf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.openstreetmap.osmosis</groupId>
            <artifactId>osmosis-xml</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jfree</groupId>
            <artifactId>jfreechart</artifactId>
        </dependency>
        <dependency>
            <groupId>org.matsim</groupId>
            <artifactId>matsim</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.geotools</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <!-- Exclude log4j 1.2 API to avoid conflicts with slf4j -->
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-1.2-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <!-- update version.properties -->
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
                <includes>
                    <include>org/noise_planet/noisemodelling/version.properties</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <!-- leave unchanged -->
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
                <excludes>
                    <exclude>org/noise_planet/noisemodelling/version.properties</exclude>
                </excludes>
                <filtering>false</filtering>
            </resource>
            <!-- Add groovy script source code as project resources -->
            <resource>
                <directory>${project.basedir}/src/main/groovy/org/noise_planet/noisemodelling/scripts</directory>
                <includes>
                    <include>**/*.groovy</include>
                </includes>
                <targetPath>scripts</targetPath>
                <filtering>false</filtering>
            </resource>
        </resources>
        <plugins>
            <!-- Maven plugin to generate the NoiseModelling documentation before packaging the distribution file -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.5.1</version>
                <executions>
                    <execution>
                        <id>generate-functions-docs</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${java.home}/bin/java</executable>
                            <arguments>
                                <argument>-classpath</argument>
                                <classpath />
                                <argument>org.noise_planet.noisemodelling.autodoc.GenerateFunctionsDocs</argument>
                                <argument>${project.parent.basedir}/Docs</argument>
                                <argument>${project.basedir}/src/main/groovy/org/noise_planet/noisemodelling/scripts</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>generate-cnossos-report</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${java.home}/bin/java</executable>
                            <arguments>
                                <argument>-classpath</argument>
                                <classpath />
                                <argument>org.noise_planet.noisemodelling.autodoc.GenerateReferenceDeviation</argument>
                                <argument>${project.parent.basedir}/Docs</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>generate-documentation</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <!-- We call 'sh' or 'cmd', which ALWAYS exist -->
                            <executable>${shell.executable}</executable>
                            <arguments>
                                <argument>${shell.arg}</argument>
                                <argument>${sphinx.command}</argument>
                            </arguments>
                            <inheritIo>true</inheritIo>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- GMavenPlus plugin for compiling Groovy -->
            <plugin>
                <groupId>org.codehaus.gmavenplus</groupId>
                <artifactId>gmavenplus-plugin</artifactId>
                <version>4.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>addSources</goal>
                            <goal>addTestSources</goal>
                            <goal>compile</goal>
                            <goal>compileTests</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <sources>
                        <source>
                            <directory>${project.basedir}/src/main/groovy</directory>
                            <includes>
                                <include>**/*.groovy</include>
                            </includes>
                        </source>
                    </sources>
                    <testSources>
                        <testSource>
                            <directory>${project.basedir}/src/test/groovy</directory>
                            <includes>
                                <include>**/*.groovy</include>
                            </includes>
                        </testSource>
                    </testSources>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <version>2.1.0</version>
                <executions>
                    <execution>
                        <id>assemble</id>
                        <phase>package</phase>
                        <goals>
                            <goal>assemble</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <programs>
                        <program>
                            <mainClass>org.noise_planet.noisemodelling.webserver.NoiseModellingServer</mainClass>
                            <id>WebServer</id>
                        </program>
                        <program>
                            <mainClass>org.noise_planet.noisemodelling.runner.Main</mainClass>
                            <id>ScriptRunner</id>
                        </program>
                    </programs>
                    <!-- This ensures all dependencies are included -->
                    <repositoryLayout>flat</repositoryLayout>
                    <useWildcardClassPath>true</useWildcardClassPath>
                    <repositoryName>lib</repositoryName>
                </configuration>
            </plugin>

            <!-- Assembly plugin runs after appassembler -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <id>create-distribution</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <finalName>NoiseModelling_${project.parent.version}</finalName>
                            <appendAssemblyId>false</appendAssemblyId>
                            <descriptors>
                                <descriptor>src/assembly/distribution.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <archive>
                        <!-- This points the JAR plugin to the file generated by the bundle plugin -->
                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>5.1.1</version>
                <extensions>true</extensions>
                <executions>
                    <execution>
                        <id>bundle-manifest</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>manifest</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <supportedProjectTypes>
                        <supportedProjectType>jar</supportedProjectType>
                        <supportedProjectType>bundle</supportedProjectType>
                        <supportedProjectType>war</supportedProjectType>
                    </supportedProjectTypes>
                    <instructions>
                        <Public-Package>org.noise_planet.noisemodelling.*</Public-Package>
                        <Bundle-Vendor>UMRAE team (Eiffel University), DECIDE team (Lab-STICC) </Bundle-Vendor>
                        <Import-Package>org.slf4j;version="[1.6.0,2)",!org.h2.*,*</Import-Package>
                        <Implementation-Build>${buildNumber}</Implementation-Build>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
