<?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>flow-plugins</artifactId>
    <version>25.4.abort-hung-uidl-request-online-SNAPSHOT</version>
  </parent>

  <artifactId>flow-gradle-plugin</artifactId>
  <packaging>jar</packaging>
  <name>Flow Gradle Plugin</name>

  <description>This maven module act as a proxy to test, build, and release the flow gradle plugin,
        which is written in Kotlin and is built by gradle natively. This makes development
        and testing of the gradle plugin much easier against the changes of flow, especially
        the flow-plugin-base. However, publishing the vaadin-gradle-plugin to gradle plugin
        central repo is done within platform final releases.</description>

  <properties>
    <gradle.executable>./gradlew</gradle.executable>
    <!-- Excluded from the Gradle build below a second time, which is a no-op
         until the skip-tests profile turns it into the unit test task. -->
    <gradle.skipped.task>functionalTest</gradle.skipped.task>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.vaadin</groupId>
      <artifactId>flow-plugin-base</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <!-- execute Gradle command -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>gradle</id>
            <goals>
              <goal>exec</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <executable>${gradle.executable}</executable>
              <arguments>
                <argument>clean</argument>
                <argument>build</argument>
                <argument>javadocJar</argument>
                <argument>-x</argument>
                <argument>functionalTest</argument>
                <argument>-x</argument>
                <argument>${gradle.skipped.task}</argument>
                <argument>-S</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- copy generated JARs -->
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-gradle-jars</id>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <outputDirectory>${basedir}/target</outputDirectory>
              <resources>
                <resource>
                  <directory>build/libs/</directory>
                  <includes>
                    <include>**/*.jar</include>
                  </includes>
                </resource>
              </resources>
              <overwrite>true</overwrite>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- attach copied JARs to build -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-artifacts</id>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <artifacts>
                <artifact>
                  <file>target/${project.artifactId}-${project.version}-sources.jar</file>
                  <type>jar</type>
                  <classifier>sources</classifier>
                </artifact>
                <artifact>
                  <file>target/${project.artifactId}-${project.version}-javadoc.jar</file>
                  <type>jar</type>
                  <classifier>javadoc</classifier>
                </artifact>
              </artifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <!-- Gradle's build task runs the unit tests, so a Maven skip flag stopped
         at Maven and this module went on testing for a minute in a build that
         had asked for no tests. Excluding the task carries the flag across.
         Two profiles because profile activation takes one property, and both
         flags are in use: -DskipTests and -Dmaven.test.skip=true. -->
    <profile>
      <id>skip-tests</id>
      <activation>
        <property>
          <name>skipTests</name>
          <value>true</value>
        </property>
      </activation>
      <properties>
        <gradle.skipped.task>test</gradle.skipped.task>
      </properties>
    </profile>
    <profile>
      <id>maven-test-skip</id>
      <activation>
        <property>
          <name>maven.test.skip</name>
          <value>true</value>
        </property>
      </activation>
      <properties>
        <gradle.skipped.task>test</gradle.skipped.task>
      </properties>
    </profile>
    <profile>
      <id>windows_profile</id>
      <activation>
        <os>
          <family>Windows</family>
        </os>
      </activation>
      <properties>
        <gradle.executable>gradlew.bat</gradle.executable>
      </properties>
    </profile>
  </profiles>
</project>
