<?xml version="1.0"?>
<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">

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        
    </properties>

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.libreccm</groupId>
        <artifactId>ccm-bundle-devel</artifactId>
        <relativePath>../ccm-bundle-devel</relativePath>
        <version>7.0.0-SNAPSHOT</version>
    </parent>

    <groupId>org.libreccm</groupId>
    <artifactId>ccm-bundle-devel-wildfly</artifactId>
    <!--<version>7.0.0-SNAPSHOT</version>-->
    <packaging>war</packaging>

    <name>LibreCCM Devel Bundle for Wildfly</name>
    <url>http://www.libreccm.org/modules/web/wildfly</url>
    
    <dependencies>
        <dependency>
            <groupId>org.libreccm</groupId>
            <artifactId>ccm-wildfly</artifactId>
            <version>7.0.0-SNAPSHOT</version>
        </dependency>
        
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>font-awesome</artifactId>
            <!--<version>4.7.0</version>-->
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>requirejs</artifactId>
            <!--<version>2.3.5</version>-->
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>requirejs-domready</artifactId>
            <!--<version>2.0.1-2</version>-->
        </dependency>
        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>tinymce</artifactId>
            <!--<version>4.8.2</version>-->
        </dependency>
        <!-- <dependency>
            <groupId>org.librecms</groupId>
            <artifactId>ccm-cms-js</artifactId>
            <version>7.0.0-SNAPSHOT</version>
        </dependency> -->
<!--        <dependency>
            <groupId>org.librecms</groupId>
            <artifactId>ccm-cms-pagemodelseditor</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <dependency>
            <groupId>org.librecms</groupId>
            <artifactId>ccm-cms-tinymce</artifactId>
            <version>${project.parent.version}</version>
        </dependency>-->
        
        <!--        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>provided</scope>
        </dependency>-->
    </dependencies>

    <build>
        <finalName>libreccm-web-wildfly</finalName>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <!--<resource>
                <directory>${project.build.directory}/generated-resources</directory>
            </resource>-->
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                    <optimize>true</optimize>
                    <debug>true</debug>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>

<!--            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>

                <configuration>
                    <installDirectory>../node</installDirectory>
                </configuration>

                <executions>
                    <execution>
                        <id>Install node.js and NPM</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                        <configuration>
                            <nodeVersion>v16.14.2</nodeVersion>
                        </configuration>
                    </execution>
                     <execution>
                        <id>npm link @libreccm/ccm-pagemodelseditor</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>link @libreccm/ccm-pagemodelseditor</arguments>
                        </configuration>
                    </execution> 
                    <execution>
                        <id>npm link @librecms/ccm-cms-pagemodelseditor</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>link @librecms/ccm-cms-pagemodelseditor</arguments>
                        </configuration>
                    </execution>
                                        <execution>
                        <id>npm link @librecms/ccm-cms-tinymce</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>link @librecms/ccm-cms-tinymce</arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>npm link @librecms/ccm-cms-js</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>link @librecms/ccm-cms-js</arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>npm install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>build</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>run build</arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>-->

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>

                    <webResources>
                        <resource>
                            <directory>src/main/resources</directory>
                        </resource>
                        <!--<resource>
                            <directory>${project.build.directory}/generated-resources</directory>
                        </resource>-->
                    </webResources>

                    <overlays>
                        <overlay>
                            <groupId>org.libreccm</groupId>
                            <artifactId>ccm-editor</artifactId>
                            <type>jar</type>
                        </overlay>
<!--                        <overlay>
                            <groupId>org.libreccm</groupId>
                            <artifactId>ccm-pagemodelseditor</artifactId>
                            <type>jar</type>
                        </overlay>-->
                        <overlay>
                            <groupId>org.libreccm</groupId>
                            <artifactId>ccm-theme-foundry</artifactId>
                            <type>jar</type>
                        </overlay>
                        <overlay>
                            <groupId>org.libreccm</groupId>
                            <artifactId>ccm-core</artifactId>
                            <type>jar</type>
                            <includes>
                                <include>assets/</include>
                            </includes>
                        </overlay>
                        <overlay>
                            <groupId>org.libreccm</groupId>
                            <artifactId>ccm-core</artifactId>
                            <type>jar</type>
                            <includes>
                                <include>themes/</include>
                            </includes>
                        </overlay>
                        <overlay>
                            <groupId>org.libreccm</groupId>
                            <artifactId>ccm-core</artifactId>
                            <type>jar</type>
                            <includes>
                                <include>WEB-INF/</include>
                            </includes>
                        </overlay>
<!--                        <overlay>
                            <groupId>org.libreccm</groupId>
                            <artifactId>ccm-shortcuts</artifactId>
                            <type>jar</type>
                            <includes>
                                <include>WEB-INF/</include>
                            </includes>
                        </overlay>-->
                        <overlay>
                            <groupId>org.libreccm</groupId>
                            <artifactId>ccm-core</artifactId>
                            <type>jar</type>
                            <includes>
                                <include>resources/</include>
                            </includes>
                        </overlay>
                        <overlay>
                            <groupId>org.librecms</groupId>
                            <artifactId>ccm-cms</artifactId>
                            <type>jar</type>
                            <includes>
                                <include>WEB-INF/</include>
                            </includes>
                        </overlay>
                        <overlay>
                            <groupId>org.librecms</groupId>
                            <artifactId>ccm-cms</artifactId>
                            <type>jar</type>
                            <includes>
                                <include>assets/</include>
                            </includes>
                        </overlay>
                        <overlay>
                            <groupId>org.librecms</groupId>
                            <artifactId>ccm-cms</artifactId>
                            <type>jar</type>
                            <includes>
                                <include>icons/</include>
                            </includes>
                        </overlay> 
                        <overlay>
                            <groupId>org.librecms</groupId>
                            <artifactId>ccm-cms</artifactId>
                            <type>jar</type>
                            <includes>
                                <include>templates/</include>
                            </includes>
                        </overlay>
<!--                        <overlay>
                            <groupId>org.librecms</groupId>
                            <artifactId>ccm-cms-tinymce</artifactId>
                            <type>jar</type>
                            <includes>
                                <include>scripts/</include>
                            </includes>
                        </overlay>-->
                        <!-- <overlay>
                            <groupId>org.librecms</groupId>
                            <artifactId>ccm-cms-default-theme</artifactId>
                            <type>jar</type>
                            <includes>
                                <include>themes/librecms/scripts/</include>
                            </includes>
                        </overlay> -->
                    </overlays>
                </configuration>
            </plugin>
            
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <configuration>
                    <excludeDefaultDirectories>true</excludeDefaultDirectories>
                    <filesets>
                        <fileset>
                            <directory>${project.build.directory}</directory>
                            <excludes>
                                <exclude>wildfly*/**</exclude>
                            </excludes>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>read-runtime-properties</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>read-project-properties</goal>
                        </goals>
                        <configuration>
                            <files>
                                <file>${project.basedir}/runtime.example.properties</file>
                                <file>${project.basedir}/runtime.properties</file>
                            </files>
                            <quiet>true</quiet>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <configuration>
                    <skip>false</skip>
                    <propertiesFile>${project.basedir}/wildfly.properties</propertiesFile>
                    <java-opts>
                        <java-opt>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8787</java-opt>
                    </java-opts>
                </configuration>
            </plugin>
            
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-jar-maven-plugin</artifactId>
                <configuration>
                    <jvmArguments>
                        <arg>-agentlib:jdwp=transport=dt_socket,server=y,suspend=${libreccm.debug.suspend},address=${libreccm.debug.port}</arg>
                    </jvmArguments>
                    <arguments>
                        -Dorg.wildfly.datasources.postgresql.database=${libreccm.database.name} 
                        -Dorg.wildfly.datasources.postgresql.host=${libreccm.database.host} 
                        -Dorg.wildfly.datasources.postgresql.jndi-name=java:/comp/env/jdbc/libreccm/db
                        -Dorg.wildfly.datasources.postgresql.password=${libreccm.database.password} 
                        -Dorg.wildfly.datasources.postgresql.port=${libreccm.database.port} 
                        -Dorg.wildfly.datasources.postgresql.user-name=${libreccm.database.user} 
                    </arguments>
                    <feature-packs>
                        <feature-pack>
                            <location>wildfly@maven(org.jboss.universe:community-universe)#24.0.1.Final</location>
                        </feature-pack>
                        <feature-pack>
                            <groupId>org.wildfly</groupId>
                            <artifactId>wildfly-datasources-galleon-pack</artifactId>
                            <version>2.0.2.Final</version>
                        </feature-pack>
                    </feature-packs>
                    <layers>
                        <layer>cdi</layer>
                        <layer>datasources</layer>
                        <layer>ejb</layer>
                        <layer>jaxrs</layer>
                        <layer>jpa</layer>
                        <layer>jsf</layer>
                        <layer>jsonp</layer>
                        <layer>logging</layer>
                        <layer>mail</layer>
                        <layer>management</layer>
                        <layer>postgresql-datasource</layer>
                    </layers>
<!--                    <excluded-layers>
                        <layer>deployment-scanner</layer>
                    </excluded-layers>-->
                    <skip>false</skip>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
    
    <profiles>
        <profile>
            <id>setup-runtime</id>
            <dependencies>
                <dependency>
                    <groupId>org.postgresql</groupId>
                    <artifactId>postgresql</artifactId>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>properties-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>read-datasource-properties</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>read-project-properties</goal>
                                </goals>
                                <configuration>
                                    <files>
                                        <file>${project.basedir}/datasource.properties</file>
                                    </files>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.wildfly.plugins</groupId>
                        <artifactId>wildfly-maven-plugin</artifactId>
                        <configuration>
                            <skip>false</skip>
                            <propertiesFile>${project.basedir}/wildfly.properties</propertiesFile>
                        </configuration>
                        <executions>
                            <execution>
                                <id>start-for-prepare</id>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                                <phase>package</phase>
                                <configuration>
                                    <stdout>System.out</stdout>
                                </configuration>
                            </execution>
                            <execution>
                                <id>deploy-jdbc-driver</id>
                                <configuration>
                                    <groupId>org.postgresql</groupId>
                                    <artifactId>postgresql</artifactId>
                                    <name>postgresql.jar</name>
                                    <force>true</force>
                                </configuration>
                                <phase>package</phase>
                                <goals>
                                    <goal>deploy-artifact</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>add-datasource</id>
                                <configuration>
                                    <address>subsystem=datasources,data-source=ccm-devel</address>
                                    <force>true</force>
                                    <resources>
                                        <resource>
                                            <properties>
                                                <connection-url>${libreccm.datasource.connectionUrl}</connection-url>
                                                <jndi-name>java:/comp/env/jdbc/libreccm/db</jndi-name>
                                                <enabled>true</enabled>
                                                <user-name>${libreccm.datasource.username}</user-name>
                                                <password>${libreccm.datasource.password}</password>
                                                <use-ccm>false</use-ccm>
                                                <driver-name>postgresql.jar</driver-name>
                                            </properties>
                                        </resource>
                                    </resources>
                                   
                                </configuration>
                                <phase>package</phase>
                                <goals>
                                    <goal>add-resource</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>deploy-libreccm-bundle-devel</id>
                                <configuration>
                                    <force>true</force>
                                </configuration>
                                <phase>package</phase>
                                <goals>
                                    <goal>deploy-only</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>shutdown-after-deploy</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>shutdown</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
       
    </profiles>
</project>
