<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.github.mcollovati.vertx</groupId>
        <artifactId>vertx-vaadin-root</artifactId>
        <version>0.4.1-SNAPSHOT</version>
    </parent>

    <artifactId>vaadin-flow-sockjs</artifactId>
    <packaging>jar</packaging>
    <name>vaadin-flow-sockjs</name>
    <version>0.1.0</version>
    <description>>Sockjs push connection implementation for Vaadin Flow</description>
    <url>https://github.com/mcollovati/vertx-vaadin</url>

    <properties>
        <bintray.package>vertx-vaadin-flow</bintray.package>
        <vaadin.version>10.0.6</vaadin.version>
        <flow.version>1.0.5</flow.version>
        <flow-client.version>${flow.version}</flow-client.version>

        <sockjs-client.version>1.1.4</sockjs-client.version>
        <checkstyle.skip>false</checkstyle.skip>

        <gwt.version>2.8.2</gwt.version>
        <gwt.module>com.github.mcollovati.vertx.vaadin.sockjs.SockjsClientEngine</gwt.module>
        <gwt.module.output>${project.build.outputDirectory}/META-INF/resources/VAADIN/static/</gwt.module.output>
        <gwt.module.style>OBF</gwt.module.style>
        <gwt.sdm.bindAddress>0.0.0.0</gwt.sdm.bindAddress>
        <flow-client-generated-sources>${project.build.directory}/generated-sources/flow-client
        </flow-client-generated-sources>
        <flow-overwritten-sources>${project.build.directory}/generated-sources/flow-overwrite</flow-overwritten-sources>

    </properties>

    <dependencies>

        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>flow-server</artifactId>
            <version>${flow.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>flow-client</artifactId>
            <version>${flow.version}</version>
            <type>jar</type>
            <classifier>sources</classifier>
            <scope>provided</scope>
        </dependency>


        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-user</artifactId>
            <version>${gwt.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-dev</artifactId>
            <version>${gwt.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-elemental</artifactId>
            <version>${gwt.version}</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <!-- This is needed for the sources required by the client-side compiler to be
            included in the produced JARs -->
        <resources>
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>${project.basedir}/src/main/java</directory>
                <includes>
                    <include>**/client/**</include>
                </includes>
            </resource>
        </resources>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**/vaadin/sockjs/client/*.java</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <id>compile-flow-client</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <compileSourceRoots>
                                <compileSourceRoot>${flow-client-generated-sources}</compileSourceRoot>
                            </compileSourceRoots>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- GWT Maven Plugin -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>gwt-maven-plugin</artifactId>
                <version>${gwt.version}</version>

                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test</goal>
                            <goal>generateAsync</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- Assertions should be disabled once we introduce
                        a separate production build -->
                    <enableAssertions>true</enableAssertions>
                    <failOnError>true</failOnError>
                    <persistentunitcache>false</persistentunitcache>
                    <gwtSdkFirstInClasspath></gwtSdkFirstInClasspath>
                    <webappDirectory>${gwt.module.output}</webappDirectory>
                    <launcherDir>${gwt.module.output}</launcherDir>
                    <compileReport>true</compileReport>
                    <bindAddress>${gwt.sdm.bindAddress}</bindAddress>
                    <modules>
                        <module>${gwt.module}</module>
                    </modules>
                    <webMode>true</webMode>
                    <style>${gwt.module.style}</style>
                    <htmlunit>FF38</htmlunit>
                    <testTimeOut>300</testTimeOut>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>${maven-jar-plugin.version}</version>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <Vaadin-Package-Version>1</Vaadin-Package-Version>
                            <Vaadin-Widgetsets>${gwt.module}</Vaadin-Widgetsets>
                        </manifestEntries>
                    </archive>
                    <!-- Exclude some unnecessary files generated by the
                        GWT compiler. -->
                    <excludes>
                        <exclude>VAADIN/gwt-unitCache/**</exclude>
                        <exclude>VAADIN/widgetsets/WEB-INF/**</exclude>
                        <exclude>com/vaadin/**</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <!-- Unpack flow-client sources for gwt compilation -->
                        <id>unpack-flow-client</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.vaadin</groupId>
                                    <artifactId>flow-client</artifactId>
                                    <version>${flow-client.version}</version>
                                    <type>jar</type>
                                    <classifier>sources</classifier>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>${flow-client-generated-sources}</outputDirectory>
                                    <includes>com/vaadin/flow/linker/**,com/vaadin/client/**</includes>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-sockjs</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.webjars.npm</groupId>
                                    <artifactId>sockjs-client</artifactId>
                                    <version>${sockjs-client.version}</version>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/sockjs-client</outputDirectory>
                            <includes>META-INF/resources/**/dist/sockjs.js</includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <useDefaultDelimiters>false</useDefaultDelimiters>
                    <delimiters>
                        <delimiter>@@*@@</delimiter>
                    </delimiters>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <id>default-cli</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <exportAntProperties>true</exportAntProperties>
                            <target>
                                <loadfile
                                        srcfile="${project.build.directory}/sockjs-client/META-INF/resources/webjars/sockjs-client/${sockjs-client.version}/dist/sockjs.js"
                                        property="sockjs-client.contents"/>
                            </target>
                        </configuration>
                    </execution>

                    <execution>
                        <id>compresspush</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <property name="vaadinPushSockJS.js"
                                          location="${project.build.outputDirectory}/META-INF/resources/VAADIN/static/push/vaadinPushSockJS.js"/>
                                <property name="vaadinPushSockJS-min.js"
                                          location="${project.build.outputDirectory}/META-INF/resources/VAADIN/static/push/vaadinPushSockJS-min.js"/>

                                <!-- Gzipped versions -->
                                <gzip src="${vaadinPushSockJS.js}" destfile="${vaadinPushSockJS.js}.gz"/>
                                <gzip src="${vaadinPushSockJS-min.js}" destfile="${vaadinPushSockJS-min.js}.gz"/>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.samaxes.maven</groupId>
                <artifactId>minify-maven-plugin</artifactId>
                <version>1.7.6</version>
                <executions>
                    <execution>
                        <id>default-minify</id>
                        <configuration>
                            <webappSourceDir>${project.build.outputDirectory}</webappSourceDir>
                            <webappTargetDir>${project.build.outputDirectory}</webappTargetDir>
                            <jsEngine>CLOSURE</jsEngine>
                            <jsSourceDir>META-INF/resources/VAADIN/static/push</jsSourceDir>
                            <jsSourceFiles>
                                <jsSourceFile>vaadinPushSockJS.js</jsSourceFile>
                            </jsSourceFiles>
                            <jsFinalFile>vaadinPushSockJS-min.js</jsFinalFile>
                            <nosuffix>true</nosuffix>
                            <verbose>true</verbose>
                        </configuration>
                        <goals>
                            <goal>minify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${flow-overwritten-sources}</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <pluginRepositories>
        <pluginRepository>
            <id>vaadin-prereleases</id>
            <url>https://maven.vaadin.com/vaadin-prereleases</url>
        </pluginRepository>
    </pluginRepositories>

    <repositories>
        <!--
        <repository>
            <id>vaadin-addons</id>
            <url>http://maven.vaadin.com/vaadin-addons</url>
        </repository>
        <repository>
            <id>webjars</id>
            <url>https://dl.bintray.com/webjars/maven</url>
        </repository>
        -->
        <repository>
            <id>vaadin-prereleases</id>
            <url>https://maven.vaadin.com/vaadin-prereleases</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
        <repository>
            <id>vaadin-snapshots</id>
            <url>https://oss.sonatype.org/content/repositories/vaadin-snapshots</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>

    <profiles>
        <profile>
            <id>do-release</id>
            <activation>
                <property>
                    <name>vertx-vaadin.release</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.vaadin</groupId>
                        <artifactId>vaadin-maven-plugin</artifactId>
                        <configuration>
                            <draftCompile>false</draftCompile>
                            <compileReport>false</compileReport>
                            <style>OBF</style>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
