<?xml version="1.0" encoding="UTF-8"?>
<!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at

     https://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.
    
     SPDX-License-Identifier: Apache-2.0
-->

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <name>Apache Jena - Fuseki UI</name>
    <artifactId>jena-fuseki-ui</artifactId>

    <parent>
        <groupId>org.apache.jena</groupId>
        <artifactId>jena-fuseki</artifactId>
        <version>6.1.0</version>
    </parent>

    <properties>
        <node.version>v20.19.3</node.version>
        <yarn.version>v1.22.17</yarn.version>
        <automatic.module.name>org.apache.jena.fuseki.ui</automatic.module.name>

        <!-- 
             Allow for skipping the tests.
             The test frameworks need various software compoents to 
             be available on the host running maven. This isn't always 
             practical. This property allows the UI to be built on such machines
             by skipping the tests.
             It is set "true" by profile "ui-skip-tests"
        -->
        <skip.ui.tests>false</skip.ui.tests>

    </properties>
    <profiles>
      <profile>
        <id>ui-skip-tests</id>
        <properties>
          <skip.ui.tests>true</skip.ui.tests>
        </properties>
    </profile>
    </profiles>

    <build>
        <plugins>
            <!-- Allocate two network ports for Jena Fuseki UI and for Jena Fuseki -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.6.1</version>
                <executions>
                    <execution>
                        <id>reserve-network-port</id>
                        <goals>
                            <goal>reserve-network-port</goal>
                        </goals>
                        <phase>process-resources</phase>
                        <configuration>
                            <portNames>
                                <portName>org.apache.jena.fuseki.port</portName>
                                <portName>org.apache.jena.fuseki.ui.port</portName>
                            </portNames>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Run Yarn to build and run tests -->
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>2.0.0</version>
                <executions>
                    <execution>
                        <id>install node and yarn</id>
                        <goals>
                            <goal>install-node-and-yarn</goal>
                        </goals>
                        <configuration>
                            <nodeVersion>${node.version}</nodeVersion>
                            <yarnVersion>${yarn.version}</yarnVersion>
                        </configuration>
                    </execution>
                    <execution>
                        <id>yarn install</id>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <configuration>
                            <arguments>install --frozen-lockfile</arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>yarn run build</id>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <configuration>
                            <arguments>run build</arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>yarn run test:unit</id>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <phase>test</phase>
                        <configuration>
                            <skip>${skip.ui.tests}</skip>
                            <arguments>run test:unit</arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>yarn run test:e2e</id>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <phase>test</phase>
                        <configuration>
                            <skip>${skip.ui.tests}</skip>
                            <environmentVariables>
                                <PORT>${org.apache.jena.fuseki.ui.port}</PORT>
                                <FUSEKI_PORT>${org.apache.jena.fuseki.port}</FUSEKI_PORT>
                            </environmentVariables>
                            <arguments>run test:e2e</arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-jar-plugin</artifactId>
              <configuration>
                <classesDirectory>${project.build.directory}</classesDirectory>
                <includes>
                  <include>webapp/**</include>
                </includes>
              </configuration>
            </plugin>
        </plugins>
    </build>
</project>
