<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.vaadin</groupId>
    <artifactId>vaadin-swing-bridge</artifactId>
    <version>1.2-SNAPSHOT</version>
  </parent>

  <artifactId>swing-bridge-nb-playground</artifactId>
  <packaging>jar</packaging>
  <name>Vaadin Swing Bridge NB-RCP Playground</name>
  <description>Spring Boot host that demonstrates embedding a NetBeans Platform RCP application via SwingBridge. The example app's cluster is copied from `netbeans-rcp-app/application/target/swingcrm/` into `applibs/` during the build, so the bridge auto-discovers it through the standard `applibs/` convention.</description>

  <properties>
    <maven.compiler.source>21</maven.compiler.source>
    <maven.compiler.target>21</maven.compiler.target>
    <vaadin.version>25.2.0-beta1</vaadin.version>
    <spring-boot.version>4.0.4</spring-boot.version>
    <spotless.license-header>https://github.com/vaadin/flow/raw/main/eclipse/vaadin-commercial-license-header.txt</spotless.license-header>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${spring-boot.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-bom</artifactId>
        <version>${vaadin.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>com.vaadin</groupId>
      <artifactId>swing-bridge-graphics</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>com.vaadin</groupId>
      <artifactId>swing-bridge-flow</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>com.vaadin</groupId>
      <artifactId>vaadin-spring-boot-starter</artifactId>
      <!-- swing-bridge-flow already binds SLF4J to Log4j2 (log4j-core +
           log4j-slf4j2-impl). Drop Spring Boot's logback + log4j-to-slf4j so
           there is a single, non-cyclic logging backend; otherwise Log4j2
           aborts with "log4j-slf4j2-impl cannot be present with
           log4j-to-slf4j". -->
      <exclusions>
        <exclusion>
          <groupId>org.apache.logging.log4j</groupId>
          <artifactId>log4j-to-slf4j</artifactId>
        </exclusion>
        <exclusion>
          <groupId>ch.qos.logback</groupId>
          <artifactId>logback-classic</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>com.vaadin</groupId>
      <artifactId>vaadin-dev</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <exclusions>
        <exclusion>
          <groupId>org.apache.logging.log4j</groupId>
          <artifactId>log4j-to-slf4j</artifactId>
        </exclusion>
        <exclusion>
          <groupId>ch.qos.logback</groupId>
          <artifactId>logback-classic</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>com.microsoft.playwright</groupId>
      <artifactId>playwright</artifactId>
      <version>1.58.0</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
      <!-- This starter transitively re-introduces spring-boot-starter-logging
           (logback + log4j-to-slf4j) at compile scope via version management,
           which would re-trigger the Log4j2 binding conflict. Exclude it here
           too so the log4j2 backend stays the only one. -->
      <exclusions>
        <exclusion>
          <groupId>org.apache.logging.log4j</groupId>
          <artifactId>log4j-to-slf4j</artifactId>
        </exclusion>
        <exclusion>
          <groupId>ch.qos.logback</groupId>
          <artifactId>logback-classic</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <!--
        Self-bootstrap the demo: copy the example NetBeans RCP cluster
        (built by `netbeans-rcp-app/application` via the nbm-application
        packaging) into our applibs/ directory so the bridge auto-
        discovers it via the standard SwingBridge convention. This is
        what a customer would do manually for their own RCP build.
      -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-cluster-into-applibs</id>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
              <outputDirectory>${project.basedir}/applibs</outputDirectory>
              <overwrite>true</overwrite>
              <resources>
                <resource>
                  <directory>${project.parent.basedir}/netbeans-rcp-app/application/target/swingcrm</directory>
                  <filtering>false</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-clean-plugin</artifactId>
        <configuration>
          <filesets>
            <fileset>
              <directory>${project.basedir}/applibs</directory>
              <excludes>
                <exclude>.gitkeep</exclude>
                <exclude>README.md</exclude>
              </excludes>
              <followSymlinks>false</followSymlinks>
            </fileset>
          </filesets>
        </configuration>
      </plugin>
      <plugin>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-maven-plugin</artifactId>
        <version>${vaadin.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>prepare-frontend</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>${spring-boot.version}</version>
        <configuration>
          <jvmArguments>--patch-module java.desktop=../swing-bridge-patch/target/swing-bridge-patch-${project.version}.jar
            -Xbootclasspath/a:../swing-bridge-graphics/target/swing-bridge-graphics-${project.version}.jar
            --add-reads=java.desktop=ALL-UNNAMED
            --add-exports=java.desktop/sun.font=ALL-UNNAMED
            --add-exports=java.desktop/sun.awt=ALL-UNNAMED
            --add-exports=java.desktop/sun.awt.dnd=ALL-UNNAMED
            --add-exports=java.desktop/sun.awt.dnd.peer=ALL-UNNAMED
            --add-exports=java.base/sun.nio.cs=ALL-UNNAMED
            --add-exports=java.desktop/sun.java2d=ALL-UNNAMED
            --add-exports=java.desktop/sun.java2d.pipe=ALL-UNNAMED
            --add-exports=java.desktop/sun.awt.datatransfer=ALL-UNNAMED
            --add-exports=java.desktop/sun.awt.image=ALL-UNNAMED
            --add-exports=java.desktop/java.awt.peer=ALL-UNNAMED
            --add-exports=java.desktop/java.awt.dnd=ALL-UNNAMED
            --add-exports=java.desktop/java.awt.dnd.peer=ALL-UNNAMED
            --add-exports=java.desktop/sun.print=ALL-UNNAMED
            --add-exports=java.desktop/sun.swing=ALL-UNNAMED
            --add-opens=java.desktop/java.awt.event=ALL-UNNAMED
            --add-opens=java.desktop/sun.awt=ALL-UNNAMED
            --add-opens=java.desktop/java.awt.dnd=ALL-UNNAMED
            --add-opens=java.desktop/javax.swing.text=ALL-UNNAMED
            --add-opens=java.desktop/javax.swing=ALL-UNNAMED
            --add-opens=java.base/java.net=ALL-UNNAMED
            --add-opens=java.base/java.security=ALL-UNNAMED
            --add-opens=java.base/java.lang=ALL-UNNAMED
            -Djava.security.manager=allow</jvmArguments>
          <systemPropertyVariables>
            <java.awt.headless>false</java.awt.headless>
          </systemPropertyVariables>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <!--
        Integration-test profile: build the production frontend, start the
        Spring Boot host (with the same JDK module flags the dev run uses),
        run the Playwright *IT tests against the embedded NB-RCP shell, then
        stop the host. Mirrors swing-bridge-playground's `it` profile.
      -->
      <id>it</id>
      <dependencies>
        <dependency>
          <groupId>com.vaadin</groupId>
          <artifactId>vaadin-core</artifactId>
          <exclusions>
            <exclusion>
              <groupId>com.vaadin</groupId>
              <artifactId>vaadin-dev</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
      </dependencies>
      <build>
        <plugins>
          <plugin>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-maven-plugin</artifactId>
            <version>${vaadin.version}</version>
            <executions>
              <execution>
                <goals>
                  <goal>build-frontend</goal>
                </goals>
                <phase>compile</phase>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>3.6.0</version>
            <executions>
              <execution>
                <id>reserve-jmx-port</id>
                <goals>
                  <goal>reserve-network-port</goal>
                </goals>
                <phase>pre-integration-test</phase>
                <configuration>
                  <portNames>
                    <portName>jmx.port</portName>
                  </portNames>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>it-start</id>
                <goals>
                  <goal>start</goal>
                </goals>
                <phase>pre-integration-test</phase>
                <configuration>
                  <mainClass>com.swingcrm.playground.nb.Application</mainClass>
                  <!-- all JVM flags as one space-separated string; matches
                       the dev-run config above (NB-RCP needs the
                       java.base/java.lang open for IsolatedRootThreadGroup
                       and the security-manager allow for the platform boot) -->
                  <jvmArguments>--patch-module java.desktop=../swing-bridge-patch/target/swing-bridge-patch-${project.version}.jar
                                  -Xbootclasspath/a:../swing-bridge-graphics/target/swing-bridge-graphics-${project.version}.jar
                                  --add-reads=java.desktop=ALL-UNNAMED
                                  --add-exports=java.desktop/sun.font=ALL-UNNAMED
                                  --add-exports=java.desktop/sun.awt=ALL-UNNAMED
                                  --add-exports=java.desktop/sun.awt.dnd=ALL-UNNAMED
                                  --add-exports=java.desktop/sun.awt.dnd.peer=ALL-UNNAMED
                                  --add-exports=java.base/sun.nio.cs=ALL-UNNAMED
                                  --add-exports=java.desktop/sun.java2d=ALL-UNNAMED
                                  --add-exports=java.desktop/sun.java2d.pipe=ALL-UNNAMED
                                  --add-exports=java.desktop/sun.awt.datatransfer=ALL-UNNAMED
                                  --add-exports=java.desktop/sun.awt.image=ALL-UNNAMED
                                  --add-exports=java.desktop/java.awt.peer=ALL-UNNAMED
                                  --add-exports=java.desktop/java.awt.dnd=ALL-UNNAMED
                                  --add-exports=java.desktop/java.awt.dnd.peer=ALL-UNNAMED
                                  --add-exports=java.desktop/sun.print=ALL-UNNAMED
                                  --add-exports=java.desktop/sun.swing=ALL-UNNAMED
                                  --add-opens=java.desktop/java.awt.event=ALL-UNNAMED
                                  --add-opens=java.desktop/sun.awt=ALL-UNNAMED
                                  --add-opens=java.desktop/java.awt.dnd=ALL-UNNAMED
                                  --add-opens=java.desktop/javax.swing.text=ALL-UNNAMED
                                  --add-opens=java.desktop/javax.swing=ALL-UNNAMED
                                  --add-opens=java.base/java.net=ALL-UNNAMED
                                  --add-opens=java.base/java.security=ALL-UNNAMED
                                  --add-opens=java.base/java.lang=ALL-UNNAMED
                                  -Djava.security.manager=allow</jvmArguments>
                  <systemPropertyVariables>
                    <java.awt.headless>false</java.awt.headless>
                  </systemPropertyVariables>
                  <jmxPort>${jmx.port}</jmxPort>
                </configuration>
              </execution>
              <execution>
                <id>it-stop</id>
                <goals>
                  <goal>stop</goal>
                </goals>
                <phase>post-integration-test</phase>
                <configuration>
                  <jmxPort>${jmx.port}</jmxPort>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skipTests>true</skipTests>
            </configuration>
          </plugin>
          <!-- Runs the integration tests (*IT) after the server is started -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <configuration>
              <includes>
                <include>**/*IT.java</include>
              </includes>
              <trimStackTrace>false</trimStackTrace>
              <enableAssertions>true</enableAssertions>
              <useModulePath>false</useModulePath>
              <rerunFailingTestsCount>2</rerunFailingTestsCount>
            </configuration>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
