<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>ch.sbb.polarion.extensions</groupId>
        <artifactId>ch.sbb.polarion.extension.generic</artifactId>
        <version>16.0.0</version>
    </parent>

    <artifactId>ch.sbb.polarion.extension.diff-tool</artifactId>
    <version>9.2.0</version>
    <packaging>jar</packaging>

    <name>Polarion ALM extension to diff/merge Documents/WorkItems</name>
    <description>This Polarion extension provides functionality to diff Polarion Documents/WorkItems with further possibility to merge selected diffs. This is an alternative to native Polarion's solution.</description>
    <url>https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.diff-tool</url>

    <licenses>
        <license>
            <name>The SBB License, Version 1.0</name>
            <url>https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.diff-tool/blob/main/LICENSES/SBB.txt</url>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>SBB Polarion Team</name>
            <email>polarion-opensource@sbb.ch</email>
            <organization>SBB AG</organization>
            <organizationUrl>https://www.sbb.ch</organizationUrl>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:git://github.com:SchweizerischeBundesbahnen/ch.sbb.polarion.extension.diff-tool.git</connection>
        <developerConnection>scm:git:ssh://github.com:SchweizerischeBundesbahnen/ch.sbb.polarion.extension.diff-tool.git</developerConnection>
        <url>https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.diff-tool/tree/main</url>
    </scm>

    <issueManagement>
        <system>GitHub</system>
        <url>https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.diff-tool/issues</url>
    </issueManagement>

    <properties>
        <maven-jar-plugin.Extension-Context>diff-tool</maven-jar-plugin.Extension-Context>
        <maven-jar-plugin.Automatic-Module-Name>ch.sbb.polarion.extension.diff_tool</maven-jar-plugin.Automatic-Module-Name>
        <maven-jar-plugin.Discover-Base-Package>ch.sbb.polarion.extension.diff_tool</maven-jar-plugin.Discover-Base-Package>
        <maven-jar-plugin.Configuration-Properties-Prefix>ch.sbb.polarion.extension.diff-tool.</maven-jar-plugin.Configuration-Properties-Prefix>

        <web.app.name>${maven-jar-plugin.Extension-Context}</web.app.name>

        <!-- Extension-specific Require-Bundle (in addition to common ones from parent POM):
            org.apache.commons.commons-collections4
            org.apache.commons.lang3
            com.polarion.subterra.persistence
            com.polarion.platform.jobs
            org.ehcache
            org.jsoup
            ch.sbb.polarion.extension.pdf-exporter;resolution:=optional
        -->
        <maven-jar-plugin.Require-Bundle.extension>org.apache.commons.commons-collections4,org.apache.commons.lang3,com.polarion.subterra.persistence,com.polarion.platform.jobs,org.ehcache,org.jsoup,ch.sbb.polarion.extension.pdf-exporter;resolution:=optional</maven-jar-plugin.Require-Bundle.extension>
        <maven-jar-plugin.Require-Bundle>${maven-jar-plugin.Require-Bundle.common},${maven-jar-plugin.Require-Bundle.extension}</maven-jar-plugin.Require-Bundle>

        <html5diff.version>1.4.5</html5diff.version>
        <ehcache.version>3.8.0</ehcache.version>

        <pdf-exporter.version>13.6.0</pdf-exporter.version>

        <awaitility.version>4.3.0</awaitility.version>



        <!-- Most of the UI build - node/npm, `npm ci`, `npm run build`, the dockerized Vitest run with
             its coverage gate in the `test` phase, and the copy into webapp/diff-tool-app - is inherited
             from the generic parent's `vite-ui` profile, which activates on the presence of
             ui/package.json. Its defaults (vite.sources.root, vite.destination.root, skipJsTests,
             jsTestCommand, jsTestExtraArgs) already match what this pom used to declare.

             What is diff-tool's own is the Playwright end-to-end suite in ui/e2e, which runs in the
             `test` phase alongside Vitest - as it has since before the React migration, so that a plain
             `mvn install` exercises the diff/merge viewer end to end. Skipping:
               -DskipJsE2eTests=true  drop only the e2e suite, keep Vitest and its coverage gate
               -DskipJsTests=true     drop both JS suites
               -DskipTests=true       drop the Java tests and, via frontend-maven-plugin's own skipTests
                                      parameter, both JS suites with them
             It needs the Playwright browsers present: `npx playwright install` once in ui/, or
             -DinstallPlaywright (from the parent) to have the build fetch them. -->
        <skipJsE2eTests>false</skipJsE2eTests>
    </properties>

    <profiles>
        <!-- -DskipJsTests=true has to turn off both JS suites, not just the parent's Vitest run, so it
             switches the e2e flag too. Matched on the exact value, so -DskipJsTests=false does not
             accidentally activate this (property activation fires on any value otherwise). -->
        <profile>
            <id>skip-js-e2e-tests-with-all-js-tests</id>
            <activation>
                <property>
                    <name>skipJsTests</name>
                    <value>true</value>
                </property>
            </activation>
            <properties>
                <skipJsE2eTests>true</skipJsE2eTests>
            </properties>
        </profile>
    </profiles>

    <dependencies>
        <dependency>
            <groupId>ch.sbb.polarion.extensions</groupId>
            <artifactId>ch.sbb.polarion.extension.generic.app</artifactId>
            <version>${project.parent.version}</version>
        </dependency>

        <dependency>
            <groupId>com.polarion.thirdparty</groupId>
            <artifactId>org.apache.commons.commons-collections4_4.4.0</artifactId>
            <version>${polarion.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.polarion.subterra.persistence</groupId>
            <artifactId>subterra-uniform-persistence</artifactId>
            <version>${polarion.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.polarion.thirdparty</groupId>
            <artifactId>org.apache.commons.lang3_3.12.0</artifactId>
            <version>${polarion.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>ch.sbb.polarion.extensions</groupId>
            <artifactId>ch.sbb.polarion.extension.pdf-exporter</artifactId>
            <version>${pdf-exporter.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>ch.sbb.html5diff</groupId>
            <artifactId>html5diff</artifactId>
            <version>${html5diff.version}</version>
        </dependency>

        <dependency>
            <groupId>org.ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>${ehcache.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.polarion.thirdparty</groupId>
            <artifactId>org.jsoup_1.21.2</artifactId>
            <version>${polarion.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>ch.sbb.polarion.extensions</groupId>
            <artifactId>ch.sbb.polarion.extension.generic.app</artifactId>
            <version>${project.parent.version}</version>
            <type>test-jar</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.awaitility</groupId>
            <artifactId>awaitility</artifactId>
            <version>${awaitility.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- The Playwright end-to-end suite, in the `test` phase next to the parent's Vitest run
                 (which is declared first, so the fast suite fails first). Not in a profile: a plain
                 `mvn install` has always run the viewer's e2e suite, and the migration must not quietly
                 take that away. CI's build job opts out with -DskipJsE2eTests=true, because its own
                 per-browser `e2e` job covers the same suite three times over. -->
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <executions>
                    <!-- The browsers the e2e suite needs, before it runs. The pre-migration pom did this
                         too, but unconditionally in generate-resources - so every build paid for it even
                         with the tests skipped, and on Linux the deps flag wanted root. Gated on the same
                         flag as the suite, and without the deps flag: the only consumers are developer
                         machines, since CI's Maven build skips e2e and its dedicated `e2e` job installs
                         the one browser it needs, with its OS deps, itself. A no-op once cached. -->
                    <execution>
                        <id>install-playwright-browsers</id>
                        <goals>
                            <goal>npx</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <arguments>playwright install</arguments>
                            <skip>${skipJsE2eTests}</skip>
                        </configuration>
                    </execution>
                    <execution>
                        <id>npm e2e</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <phase>test</phase>
                        <configuration>
                            <arguments>run e2e:headless</arguments>
                            <skip>${skipJsE2eTests}</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <executions>
                    <!-- Vite writes hash-named bundles into the gitignored webapp/diff-tool-app/app
                         dir. copy-resources only overwrites, never deletes, so stale bundles from
                         previous builds pile up there. Purge the dir both on `mvn clean` and right
                         before the copy in every build, so it never accumulates regardless of whether
                         `clean` was requested. excludeDefaultDirectories keeps these executions from
                         also wiping target/ (the default-clean execution owns that). -->
                    <execution>
                        <id>clean-generated-webapp</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                        <configuration>
                            <excludeDefaultDirectories>true</excludeDefaultDirectories>
                            <filesets>
                                <fileset>
                                    <directory>${markdown2html-maven-plugin.extensionContextAdminHtml}</directory>
                                    <includes>
                                        <include>${markdown2html-maven-plugin.outputFileName}</include>
                                    </includes>
                                    <followSymlinks>false</followSymlinks>
                                </fileset>
                                <fileset>
                                    <directory>${vite.destination.root}/app</directory>
                                    <followSymlinks>false</followSymlinks>
                                </fileset>
                            </filesets>
                        </configuration>
                    </execution>
                    <execution>
                        <id>purge-vite-output-before-copy</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                        <configuration>
                            <excludeDefaultDirectories>true</excludeDefaultDirectories>
                            <filesets>
                                <fileset>
                                    <directory>${vite.destination.root}/app</directory>
                                    <followSymlinks>false</followSymlinks>
                                </fileset>
                            </filesets>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>ch.sbb.maven.plugins</groupId>
                <artifactId>markdown2html-maven-plugin</artifactId>
            </plugin>

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

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

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

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
            </plugin>

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

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

            <plugin>
                <groupId>io.swagger.core.v3</groupId>
                <artifactId>swagger-maven-plugin-jakarta</artifactId>
                <configuration>
                    <outputFormat>JSON</outputFormat>
                    <!-- Stable ordering, so a rebuild does not reshuffle docs/openapi.json. -->
                    <resourcePackages>
                        <package>ch.sbb.polarion.extension.generic.rest.controller.info</package>
                        <package>ch.sbb.polarion.extension.generic.rest.controller.settings</package>
                        <package>ch.sbb.polarion.extension.generic.rest.controller.roles</package>
                        <package>ch.sbb.polarion.extension.generic.rest.model</package>
                        <package>ch.sbb.polarion.extension.diff_tool.rest.controller</package>
                        <package>ch.sbb.polarion.extension.diff_tool.rest.model</package>
                    </resourcePackages>
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.github.grigoriev</groupId>
                <artifactId>pre-commit-run-maven-plugin</artifactId>
            </plugin>

        </plugins>
    </build>

</project>
