<?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
  ~
  ~       http://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.
  -->
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.apache.hop</groupId>
        <artifactId>hop</artifactId>
        <version>2.18.1</version>
    </parent>

    <artifactId>hop-ui-rap</artifactId>
    <packaging>jar</packaging>
    <name>Hop GUI (RAP fragment)</name>

    <properties>
        <monaco.resources.dir>${project.build.directory}/generated-resources/org/apache/hop/ui/hopgui/monaco</monaco.resources.dir>
        <monaco.version>0.55.1</monaco.version>
        <rap.version>4.5.0</rap.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.eclipse.rap</groupId>
            <artifactId>org.eclipse.rap.rwt</artifactId>
            <version>${rap.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hop</groupId>
            <artifactId>hop-core</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.hop</groupId>
            <artifactId>hop-engine</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.hop</groupId>
            <artifactId>hop-ui</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- Download the Monaco Editor npm package at build time -->
            <plugin>
                <groupId>com.googlecode.maven-download-plugin</groupId>
                <artifactId>download-maven-plugin</artifactId>
                <version>1.9.0</version>
                <executions>
                    <execution>
                        <id>download-monaco-editor</id>
                        <goals>
                            <goal>wget</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <url>https://registry.npmjs.org/monaco-editor/-/monaco-editor-${monaco.version}.tgz</url>
                            <unpack>true</unpack>
                            <outputDirectory>${project.build.directory}/monaco-download</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Copy the AMD distribution files and generate monaco-files.list -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>prepare-monaco-resources</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <target>
                                <mkdir dir="${monaco.resources.dir}"></mkdir>
                                <copy todir="${monaco.resources.dir}">
                                    <fileset dir="${project.build.directory}/monaco-download/package/min">
                                        <include name="vs/**/*.js"></include>
                                        <include name="vs/**/*.css"></include>
                                    </fileset>
                                </copy>
                                <pathconvert dirsep="/" pathsep="${line.separator}" property="monaco.file.list">
                                    <fileset dir="${monaco.resources.dir}">
                                        <include name="vs/**"></include>
                                    </fileset>
                                    <map from="${monaco.resources.dir}${file.separator}" to=""></map>
                                </pathconvert>
                                <echo file="${monaco.resources.dir}/monaco-files.list" message="${monaco.file.list}"></echo>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Add the generated Monaco resources to the classpath -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-monaco-resources</id>
                        <goals>
                            <goal>add-resource</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>${project.build.directory}/generated-resources</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
