<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright (C) 2017-2025 Dominic Heutelbeck (dominic@heutelbeck.com)

    SPDX-License-Identifier: Apache-2.0

    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>io.sapl</groupId>
        <artifactId>sapl-policy-engine</artifactId>
        <version>3.0.0</version>
    </parent>

    <artifactId>sapl-vaadin-editor</artifactId>

    <name>SAPL Vaadin Code Editors</name>

    <description>SAPL and JSON Editor Components for Vaadin</description>

    <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <!-- Try to keep transitive dependencies in add-ons to minimum.
                 Usually flow-server is enough, but if you extend an existing
                 component, add that directly as well or change to
                 vaadin/vaadin-core (worse option)
            -->
            <artifactId>flow-server</artifactId>
        </dependency>
        <!-- Shouldn't be needed, probably a bug the flow-client is not brought in via flow-server-->
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>flow-client</artifactId>
        </dependency>

        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>sapl-web</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>sapl-test-web</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- The CSS and JS resources of the xtext web dependency have to copied
				to the matching frontend folder CSS and images are hard coded into the HTML
				template of the webcomponent JS file -->

            <!-- First unpack the files from the JAR -->
            <plugin>
				<?m2e ignore?>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-xtext</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.eclipse.xtext</groupId>
                                    <artifactId>org.eclipse.xtext.web</artifactId>
                                    <version>${xtext.version}</version>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.build.directory}/xtext</outputDirectory>
                                    <includes>META-INF/resources/xtext/${xtext.version}/**/*</includes>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-sapl</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>io.sapl</groupId>
                                    <artifactId>sapl-web</artifactId>
                                    <version>3.0.0</version>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.build.directory}/sapl</outputDirectory>
                                    <includes>static/**/*</includes>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>io.sapl</groupId>
                                    <artifactId>sapl-test-web</artifactId>
                                    <version>3.0.0</version>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.build.directory}/sapl-test</outputDirectory>
                                    <includes>static/**/*</includes>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Second, copy the files into the frontend folder to be accessible
                via vaadin tooling -->
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-resources-js</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/classes/META-INF/frontend</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.build.directory}/xtext/META-INF/resources/xtext/${xtext.version}</directory>
                                    <includes>
                                        <include>xtext-codemirror.js</include>
                                    </includes>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-resources-sapl</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/classes/META-INF/frontend/</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.build.directory}/sapl/static</directory>
                                    <includes>
                                        <include>sapl-mode.js</include>
                                    </includes>
                                    <filtering>false</filtering>
                                </resource>
                                <resource>
                                    <directory>${project.build.directory}/sapl-test/static</directory>
                                    <includes>
                                        <include>sapl-test-mode.js</include>
                                    </includes>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

           <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>io.sapl.converter.TransformFiles</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>io/sapl/converter/**</exclude>
                    </excludes>
                    <archive>
                        <index>true</index>
                        <manifest>
                            <addClasspath>false</addClasspath>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                        <manifestEntries>
                            <Vaadin-Package-Version>1</Vaadin-Package-Version>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>     
        </plugins>
    </build>
</project>
