<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2024 REGnosys
  ~
  ~ Licensed 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.finos.rune</groupId>
        <artifactId>org.finos.rune.parent</artifactId>
        <version>10.0.0-dev.18</version>
    </parent>

    <name>Rune DSL Language Server</name>
    <artifactId>rune-ide</artifactId>

    <description>
        Responsibilities: adding support for developing Rosetta in an IDE, including
        - language server features (semantic highlighting, inlay hints, etc)
        - syntax highlighting
    </description>

    <dependencies>
        <!-- Inter-project dependencies -->
        <dependency>
            <groupId>org.finos.rune</groupId>
            <artifactId>rune-lang</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!-- External dependencies -->
        <dependency>
            <groupId>org.eclipse.xtext</groupId>
            <artifactId>org.eclipse.xtext.ide</artifactId>
        </dependency>
        <dependency>
            <groupId>org.yaml</groupId>
            <artifactId>snakeyaml</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.finos.rune</groupId>
            <artifactId>rune-testing</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>${project.basedir}/src-gen/main/java</directory>
                <includes>
                    <include>META-INF/services/org.eclipse.xtext.ISetup</include>
                </includes>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <configuration>
                    <filesets combine.children="append">
                        <!-- vscode -->
                        <fileset>
                            <directory>${basedir}/vscode/src/rosetta</directory>
                            <includes>
                                <include>**/*</include>
                            </includes>
                        </fileset>
                        <fileset>
                            <directory>${basedir}/vscode/syntaxes</directory>
                            <includes>
                                <include>**/*</include>
                            </includes>
                        </fileset>
                        <fileset>
                            <directory>${basedir}/vscode/out</directory>
                            <includes>
                                <include>**/*</include>
                            </includes>
                        </fileset>
                        <!-- xtend -->
                        <fileset>
                            <directory>${basedir}/xtend-gen</directory>
                            <includes>
                                <include>**/*</include>
                            </includes>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.eclipse.xtend</groupId>
                <artifactId>xtend-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>Generate TextMate grammar json file</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>com.regnosys.rosetta.ide.textmate.GenerateTmGrammar</mainClass>
                            <arguments>
                                <argument>${project.basedir}/rosetta.tmLanguage.yaml</argument>
                                <argument>${project.basedir}/src-gen/main/resources/syntaxes/rosetta.tmLanguage.json</argument>
                            </arguments>
                            <classpathScope>compile</classpathScope>
                            <cleanupDaemonThreads>false</cleanupDaemonThreads>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.outputDirectory}/syntaxes</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.basedir}/src-gen/main/resources/syntaxes</directory>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <excludeGroupIds>p2.eclipse-feature</excludeGroupIds>
                            <outputDirectory>${project.build.directory}/libs</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                            <excludeTransitive>true</excludeTransitive>
                            <excludeArtifactIds>
                                com.ibm.icu,
                                org.apache.ant,
                                org.apache.commons.lang,
                                org.apache.commons.logging,
                                org.eclipse.core.commands,
                                org.eclipse.core.contenttype,
                                org.eclipse.core.expressions,
                                org.eclipse.core.filesystem,
                                org.eclipse.core.jobs,
                                org.eclipse.core.resources,
                                org.eclipse.core.runtime,
                                org.eclipse.core.variables,
                                org.eclipse.debug.core,
                                org.eclipse.emf.codegen.ecore,
                                org.eclipse.emf.codegen,
                                org.eclipse.emf.mwe.core,
                                org.eclipse.emf.mwe.utils,
                                org.eclipse.emf.mwe2.lib,
                                org.eclipse.emf.mwe2.runtime,
                                org.eclipse.equinox.app,
                                org.eclipse.equinox.preferences,
                                org.eclipse.equinox.registry,
                                org.eclipse.jdt.core,
                                org.eclipse.jdt.debug,
                                org.eclipse.jdt.launching,
                                org.eclipse.text,
                            </excludeArtifactIds>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>assemble</goal>
                        </goals>
                        <configuration>
                            <assembleDirectory>${project.build.directory}/languageserver</assembleDirectory>
                            <repositoryLayout>flat</repositoryLayout>
                            <useWildcardClassPath>true</useWildcardClassPath>
                            <!--uncomment to enable remote debugging
                            <extraJvmArguments>-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000</extraJvmArguments>
                            -->
                            <programs>
                                <program>
                                    <id>rune-dsl-ls</id>
                                    <mainClass>com.regnosys.rosetta.ide.server.RosettaServerLauncher</mainClass>
                                    <!--uncomment to enable options
                                    <commandLineArguments>
                                        <commandLineArgument>-trace</commandLineArgument>
                                        <commandLineArgument>-log</commandLineArgument>
                                        <commandLineArgument>-noValidate</commandLineArgument>
                                    </commandLineArguments>
                                    -->
                                </program>
                            </programs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>install node and npm</id>
                        <phase>package</phase>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>npm install</id>
                        <phase>package</phase>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>install</arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>