<?xml version="1.0" encoding="UTF-8"?>
<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>com.vaadin</groupId>
        <artifactId>flow-project</artifactId>
        <version>24.10.preserve-on-refresh-app-shell-title-SNAPSHOT</version>
    </parent>
    <artifactId>flow-push</artifactId>
    <name>Flow Push</name>
    <description>${project.name}</description>
    <packaging>jar</packaging>

    <dependencies>
        <!-- Atmosphere -->
        <dependency>
            <groupId>com.vaadin.external.atmosphere</groupId>
            <artifactId>atmosphere-runtime</artifactId>
            <version>${atmosphere.runtime.version}</version>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>osgi.core</artifactId>
            <version>${osgi.core.version}</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <properties>
        <pushDirectory>${project.build.outputDirectory}/META-INF/resources/VAADIN/static/push</pushDirectory>
        <vaadinPush.js>${pushDirectory}/vaadinPush.js</vaadinPush.js>
        <vaadinPush-min.js>${pushDirectory}/vaadinPush-min.js</vaadinPush-min.js>
    </properties>

    <build>
        <plugins>
            <plugin>
                <!-- Create minified vaadin push js-->
                <groupId>net.alchim31.maven</groupId>
                <artifactId>yuicompressor-maven-plugin</artifactId>
                <version>1.5.1</version>
                <executions>
                    <execution>
                        <id>minifyjs</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>compress</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <sourceDirectory>${pushDirectory}</sourceDirectory>
                    <jswarn>false</jswarn>
                    <includes>
                        <include>vaadinPush.js</include>
                    </includes>
                    <outputDirectory>${pushDirectory}</outputDirectory>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.8.1</version>
                <executions>
                    <execution>
                        <id>unpack-atmosphere-js</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.atmosphere.client</groupId>
                                    <artifactId>javascript</artifactId>
                                    <version>${atmosphere.client.version}</version>
                                    <type>war</type>
                                    <outputDirectory>${project.build.directory}/temp</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>unpack-atmosphere-js</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <property name="javascript.unpack" location="${project.build.directory}/temp" />
                                <property name="templates.dir" location="${project.build.sourceDirectory}/../templates" />

                                <loadfile srcfile="${javascript.unpack}/javascript/atmosphere.js" property="atmosphere.js.contents" />

                                <loadfile srcfile="${templates.dir}/vaadinPush.js.tpl" property="vaadinPush.js.contents">
                                    <filterchain>
                                        <replacetokens begintoken="@" endtoken="@">
                                            <token key="atmosphere.js" value="${atmosphere.js.contents}" />
                                        </replacetokens>
                                    </filterchain>
                                </loadfile>
                                <echo file="${vaadinPush.js}">${vaadinPush.js.contents}</echo>
                            </target>
                        </configuration>
                    </execution>
                    <execution>
                        <id>compresspush</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <!-- Gzipped versions -->
                                <gzip src="${vaadinPush.js}" destfile="${vaadinPush.js}.gz" />
                                <gzip src="${vaadinPush-min.js}" destfile="${vaadinPush-min.js}.gz" />
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                        <index>false</index>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <!--This plugin's configuration is used to store Eclipse
                    m2e settings only. It has no influence on the Maven build itself. -->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>
                                            org.apache.maven.plugins
                                        </groupId>
                                        <artifactId>
                                            maven-antrun-plugin
                                        </artifactId>
                                        <versionRange>
                                            [1.8,)
                                        </versionRange>
                                        <goals>
                                            <goal>run</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

</project>
