<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <parent>
    <groupId>org.kie.kogito</groupId>
    <artifactId>kogito-apps</artifactId>
    <version>0.8.0</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  
  <artifactId>management-console</artifactId>
  <name>Kogito :: Management Console</name>

  <properties>
    <path.to.frontend.app>../packages/management-console</path.to.frontend.app>
  </properties>
  
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.kie.kogito</groupId>
        <artifactId>kogito-bom</artifactId>
        <version>${project.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-bom</artifactId>
        <version>${version.io.quarkus}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-vertx-web</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-junit5</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-maven-plugin</artifactId>
        <configuration>
          <uberJar>true</uberJar>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>build</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <systemProperties>
            <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
          </systemProperties>
        </configuration>
      </plugin>
      <!-- frontend related plugins-->
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <configuration>
          <workingDirectory>${path.to.frontend.app}</workingDirectory>
        </configuration>
      </plugin>
      <!-- Copy the built webapp to the directory used by Quarkus -->
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-resources</id>
            <phase>process-resources</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/classes/META-INF/resources/</outputDirectory>
              <resources>
                <resource>
                  <directory>${path.to.frontend.app}/dist</directory>
                  <filtering>false</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>native</id>
      <activation>
        <property>
          <name>native</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
                <configuration>
                  <systemProperties>
                    <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
                  </systemProperties>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      <properties>
        <quarkus.package.type>native</quarkus.package.type>
      </properties>
    </profile>
    <profile>
      <!--
        Installs node and yarn in the webapp's node and node_modules folders.
        Run 'mvn package -Dui.deps':
          * the first time you have checked out the source.
          * whenever the dependencies have been changed in package.json (delete the webapp's node_modules folder first!)
      -->
      <id>Install node and yarn</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <executions>
              <execution>
                <!--
                  Install node and yarn for the plugin to have a copy.
                -->
                <id>install node and yarn</id>
                <goals>
                  <goal>install-node-and-yarn</goal>
                </goals>
                <configuration>
                  <!-- Make sure these match the version you installed on your system -->
                  <nodeVersion>${version.node}</nodeVersion>
                  <yarnVersion>${version.yarn}</yarnVersion>
                </configuration>
              </execution>
              <execution>
                <!--
                  Run yarn install when having updated dependencies
                  -->
                <id>yarn install</id>
                <goals>
                  <goal>yarn</goal>
                </goals>
                <!-- Optional configuration which provides for running any yarn command -->
                <configuration>
                  <npmRegistryURL>${env.NPM_REGISTRY_URL}</npmRegistryURL>
                  <arguments>install</arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>Build the UI</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>yarn run build</id>
                <goals>
                  <goal>yarn</goal>
                </goals>
                <configuration>
                  <npmRegistryURL>${env.NPM_REGISTRY_URL}</npmRegistryURL>
                  <arguments>run build:prod</arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
