<?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>
    
    <groupId>com.github.phillip-kruger</groupId>
    <artifactId>javaee-servers-parent</artifactId>
    <version>javaee-7-v4</version>    
    <packaging>pom</packaging>
    
    <name>javaee-servers-parent</name>
    <url>https://github.com/phillip-kruger/javaee-servers-parent</url>
    <description>Some Java EE 7 application server functions from your maven script</description>
    
    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>
    
    <scm>
        <connection>scm:git:https://github.com/phillip-kruger/javaee-servers-parent.git</connection>
        <url>https://github.com/phillip-kruger/javaee-servers-parent</url>
    </scm>

    <distributionManagement>
        <site>
            <id>wiki</id>
            <url>https://github.com/phillip-kruger/javaee-servers-parent/wiki</url>
        </site>
        
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    
    </distributionManagement>

    <developers>
        <developer>
            <name>Phillip Kruger</name>
            <email>phillip.kruger@phillip-kruger.com</email>
            <organizationUrl>http://www.phillip-kruger.com</organizationUrl>
        </developer>
    </developers>
    
    <properties>
        <http.port>8080</http.port>
        <https.port>8443</https.port>
        <debug.port>5005</debug.port>
        
        <!-- Open Liberty properties -->
        <openliberty.version>17.0.0.4</openliberty.version>
        <openliberty.http.port>${http.port}</openliberty.http.port>
        <openliberty.https.port>${https.port}</openliberty.https.port>
        <openliberty.installDir>${java.io.tmpdir}${file.separator}${project.artifactId}${file.separator}openliberty</openliberty.installDir>
        <openliberty.configDir>${basedir}${file.separator}src${file.separator}main${file.separator}openliberty${file.separator}config</openliberty.configDir>
        <openliberty.logsDir>${openliberty.installDir}${file.separator}wlp${file.separator}usr${file.separator}servers${file.separator}defaultServer${file.separator}logs</openliberty.logsDir>
        <openliberty.maven.version>2.1.2</openliberty.maven.version>
        <openliberty.Xmx>512m</openliberty.Xmx>
        
        <!-- wildfly-swarm properties -->
        <wildfly-swarm.version>2018.3.3</wildfly-swarm.version>
        <wildfly-swarm.http.port>${http.port}</wildfly-swarm.http.port>
        <wildfly-swarm.https.port>${https.port}</wildfly-swarm.https.port>
        <wildfly-swarm.installDir>${java.io.tmpdir}${file.separator}${project.artifactId}${file.separator}wildfly-swarm</wildfly-swarm.installDir>
        <wildfly-swarm.deployDir>${wildfly-swarm.installDir}${file.separator}deployments</wildfly-swarm.deployDir>
        <wildfly-swarm.configDir>${basedir}${file.separator}src${file.separator}main${file.separator}wildfly-swarm${file.separator}config</wildfly-swarm.configDir>
        <wildfly-swarm.logsDir>${wildfly-swarm.installDir}${file.separator}logs</wildfly-swarm.logsDir>
        <wildfly-swarm.logfile>${wildfly-swarm.logsDir}${file.separator}server.log</wildfly-swarm.logfile>
        
        <!-- payara-micro properties -->
        <payara-micro.maven.version>1.0.0</payara-micro.maven.version>
        <payara-micro.version>4.1.2.174</payara-micro.version>
        <payara-micro.http.port>${http.port}</payara-micro.http.port>
        <payara-micro.https.port>${https.port}</payara-micro.https.port>
        <payara-micro.installDir>${java.io.tmpdir}${file.separator}${project.artifactId}${file.separator}payara-micro</payara-micro.installDir>
        <payara-micro.deployDir>${payara-micro.installDir}${file.separator}autodeploy</payara-micro.deployDir>
        <payara-micro.configDir>${basedir}${file.separator}src${file.separator}main${file.separator}payara-micro${file.separator}config</payara-micro.configDir>
        <payara-micro.logsDir>${payara-micro.installDir}${file.separator}logs</payara-micro.logsDir>
        <payara-micro.logfile>${payara-micro.logsDir}${file.separator}server.log</payara-micro.logfile>
    </properties>
    
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.wildfly.swarm</groupId>
                <artifactId>bom-all</artifactId>
                <version>${wildfly-swarm.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            
            <dependency>
                <groupId>fish.payara.extras</groupId>
                <artifactId>payara-micro</artifactId>
                <version>${payara-micro.version}</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
        
    </dependencyManagement>
    
    <build>
                
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>add-resource</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>add-resource</goal>
                        </goals>
                        <configuration>

                            <resources>
                                <!-- Open Liberty config -->
                                <resource>
                                    <directory>${openliberty.configDir}</directory>
                                    <targetPath>${project.build.directory}</targetPath>
                                    <filtering>true</filtering>
                                    <includes>
                                        <include>server.xml</include>
                                    </includes>
                                </resource>
                                <!-- Wildfly-swarm config -->
                                <resource>
                                    <directory>${wildfly-swarm.configDir}</directory>
                                    <targetPath>${project.build.directory}</targetPath>
                                    <filtering>true</filtering>
                                    <includes>
                                        <include>standalone.xml</include>
                                    </includes>
                                </resource>
                                <!-- Payara-micro config -->
                                <resource>
                                    <directory>${payara-micro.configDir}</directory>
                                    <targetPath>${project.build.directory}</targetPath>
                                    <filtering>true</filtering>
                                    <includes>
                                        <include>domain.xml</include>
                                    </includes>
                                </resource>
                            </resources>

                        </configuration>
                    </execution>
                </executions>
            </plugin>
            
            <!-- Open Liberty plugin -->
            <plugin>
                <groupId>net.wasdev.wlp.maven.plugins</groupId>
                <artifactId>liberty-maven-plugin</artifactId>
                <version>${openliberty.maven.version}</version>

                <configuration>
                    <assemblyArtifact>
                        <groupId>io.openliberty</groupId>
                        <artifactId>openliberty-runtime</artifactId>
                        <version>${openliberty.version}</version>
                        <type>zip</type>
                    </assemblyArtifact>
                </configuration>
            </plugin>
            
            <!-- Wildfly swarm plugin -->
            <plugin>
                <groupId>org.wildfly.swarm</groupId>
                <artifactId>wildfly-swarm-plugin</artifactId>
                <version>${wildfly-swarm.version}</version>
                
                <configuration>
                    <properties>
                        <swarm.context.path>/${project.artifactId}</swarm.context.path>
                        <swarm.http.port>${wildfly-swarm.http.port}</swarm.http.port>
                        <swarm.https.port>${wildfly-swarm.https.port}</swarm.https.port>
                        <swarm.management.http.port>2${wildfly-swarm.http.port}</swarm.management.http.port> 
                        <swarm.management.https.port>2${wildfly-swarm.https.port}</swarm.management.https.port>
                    </properties>
                </configuration>
            </plugin>
            
            <!-- Payara Micro plugin -->
            <plugin>
                <groupId>fish.payara.maven.plugins</groupId>
                <artifactId>payara-micro-maven-plugin</artifactId>
                <version>${payara-micro.maven.version}</version>
                <configuration>
                    <artifactItem>
                        <groupId>fish.payara.extras</groupId>
                        <artifactId>payara-micro</artifactId>
                        <version>${payara-micro.version}</version>
                    </artifactItem>
                    <payaraVersion>${payara-micro.version}</payaraVersion>
                    <commandLineOptions>
                        <option>
                            <key>--port</key>
                            <value>${payara-micro.http.port}</value>
                        </option>
                        <option>
                            <key>--sslport</key>
                            <value>${payara-micro.https.port}</value>
                        </option>
                        <option>
                            <key>--deploymentdir</key>
                            <value>${payara-micro.deployDir}</value>
                        </option>
                        
                        <option>
                            <key>--rootdir</key>
                            <value>${payara-micro.installDir}</value>
                        </option>
                        <option>
                            <key>--domainconfig</key>
                            <value>${project.build.directory}/domain.xml</value>
                        </option>
 
                    </commandLineOptions>
                    
                    <deployArtifacts>
                        <artifactItem>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                            <version>${project.version}</version>
                            <type>${project.packaging}</type>
                        </artifactItem>                       
                    </deployArtifacts>
                </configuration>
            </plugin>
            
        </plugins>
        
    </build>
    
    <profiles>
        <!-- ============================== PAYARA MICRO ============================== -->        
        <profile>
            <id>payara-micro-run</id>
            <activation>
                <property>
                    <name>payara-micro-run</name>
                </property>
            </activation>
            
            <build>
                <plugins>
<!--                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>generate-sources</id>
                                <phase>generate-sources</phase>
                                <configuration>
                                    <tasks>
                                        <mkdir dir="${payara-micro.deployDir}"/>
                                        <mkdir dir="${payara-micro.logsDir}"/>
                                    </tasks>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>-->
                
                    <plugin>
                        <groupId>fish.payara.maven.plugins</groupId>
                        <artifactId>payara-micro-maven-plugin</artifactId>
                        <configuration>
                            <useUberJar>false</useUberJar>
                            <daemon>false</daemon>
                            <deployWar>true</deployWar>
                        </configuration>
                        <executions>
                            <execution>
                                <id>1</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        
        <profile>
            <id>payara-micro-start</id>
            <activation>
                <property>
                    <name>payara-micro-start</name>
                </property>
            </activation>
            
            <build>
                <plugins>
                    
                    <!-- Create or merge domain.xml to add das-config -->
                    <plugin>
                        <groupId>org.codehaus.gmaven</groupId>
                        <artifactId>groovy-maven-plugin</artifactId>
                        <version>2.0</version>
                        <executions>
                            <execution>
                                <id>1</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>execute</goal>
                                </goals>
                                <configuration>
                                    <source>
                                        <![CDATA[
                                        String dasConfig = "<das-config autodeploy-enabled=\"true\" dynamic-reload-enabled=\"true\" deploy-xml-validation=\"full\" autodeploy-dir=\"${payara-micro.deployDir}\" />"
                                        
                                        println("==== Java EE servers parent maven (Payara Micro) ====");
                                        File deployDir = new File("${payara-micro.deployDir}");
                                        deployDir.mkdirs();

                                        println("Das config looking for deployments in ${payara-micro.deployDir}");
                                        File targetDir = new File("${project.build.directory}");
                                        if(targetDir.exists() && !targetDir.isDirectory()) {
                                            println("Target dir does not exist, wont create domain.xml !");
                                            return;
                                        }
                                        File domainXmlFile = new File(targetDir,"domain.xml");

                                        String content = null;
                                        if(domainXmlFile.exists() && !domainXmlFile.isDirectory()) {
                                            println("Enhancing existing domain.xml");
                                            BufferedReader reader = new BufferedReader(new FileReader (domainXmlFile));
                                            String line = null;
                                            StringBuilder stringBuilder = new StringBuilder();
                                            String ls = System.getProperty("line.separator");

                                            try {
                                                while((line = reader.readLine()) != null) {
                                                    stringBuilder.append(line);
                                                    stringBuilder.append(ls);
                                                }
                                                content = stringBuilder.toString();
                                            } finally {
                                                reader.close();
                                            }
                                        }else{
                                            String defaultUrl = "https://raw.githubusercontent.com/payara/Payara/master/appserver/extras/payara-micro/payara-micro-boot/src/main/resources/MICRO-INF/domain/domain.xml";
                                            println("Creating domain.xml from " + defaultUrl);
                                            content = new URL(defaultUrl).getText()
                                        }
                                        
                                        content = content.replaceAll("<das-config></das-config>", dasConfig);
                                        BufferedWriter writer = new BufferedWriter(new FileWriter(domainXmlFile));

                                        writer.write(content);
                                        writer.close();
                                        ]]>
                                    </source>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    
<!--                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>generate-sources</id>
                                <phase>generate-sources</phase>
                                <configuration>
                                    <tasks>
                                        <mkdir dir="${payara-micro.deployDir}"/>
                                        <mkdir dir="${payara-micro.logsDir}"/>
                                    </tasks>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>-->
                    
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>2</id>
                                <phase>install</phase>
                                <goals>
                                    <goal>copy</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>${project.artifactId}</artifactId>
                                            <version>${project.version}</version>
                                            <type>${project.packaging}</type>
                                        </artifactItem>
                                    </artifactItems>
                                    <outputDirectory>${payara-micro.deployDir}</outputDirectory>
                                    <stripVersion>true</stripVersion>
                                    <commandLineOptions>
                                        <option>
                                            <key>--deploymentdir</key>
                                            <value>${payara-micro.deployDir}</value>
                                        </option>
                                        <option>
                                            <key>--domainconfig</key>
                                            <value>${project.build.directory}/domain.xml</value>
                                        </option>
                                        <option>
                                            <key>--logtofile</key>
                                            <value>${payara-micro.logfile}</value>
                                        </option>
                                    </commandLineOptions>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    
                    <plugin>
                        <groupId>fish.payara.maven.plugins</groupId>
                        <artifactId>payara-micro-maven-plugin</artifactId>
                        <configuration>
                            <useUberJar>false</useUberJar>
                            <daemon>true</daemon>
                            <deployWar>false</deployWar>
                        </configuration>
                        <executions>
                            <execution>
                                <id>1</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>bundle</goal>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        
        <profile>
            <id>payara-micro-stop</id>
            <activation>
                <property>
                    <name>payara-micro-stop</name>
                </property>
            </activation>
            
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <id>1</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <exec executable="${JAVA_HOME}/bin/jps">
                                            <redirector outputproperty="process.pid">
                                                <outputfilterchain>
                                                    <linecontains>
                                                        <contains value="payara-micro-${payara-micro.version}.jar" />
                                                    </linecontains>
                                                    <replacestring from=" payara-micro-${payara-micro.version}.jar" />
                                                </outputfilterchain>
                                            </redirector>
                                        </exec>
                                        <exec executable="taskkill" osfamily="winnt">
                                            <arg value="/PID" />
                                            <arg value="${process.pid}" />
                                        </exec>
                                        <exec executable="kill" osfamily="unix">
                                            <arg value="-15" />
                                            <arg value="${process.pid}" />
                                        </exec>
                                    </target>
                                </configuration>
                            </execution>
                            
                        </executions>
                    </plugin>
                    
                </plugins>
            </build>
        </profile>
        
        <profile>
            <id>payara-micro-deploy</id>
            <activation>
                <property>
                    <name>payara-micro-deploy</name>
                </property>
            </activation>
            
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>2</id>
                                <phase>install</phase>
                                <goals>
                                    <goal>copy</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>${project.artifactId}</artifactId>
                                            <version>${project.version}</version>
                                            <type>${project.packaging}</type>
                                        </artifactItem>
                                    </artifactItems>
                                    <outputDirectory>${payara-micro.deployDir}</outputDirectory>
                                    <stripVersion>true</stripVersion>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <id>6</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>

                                <configuration>
                                    <target>
                                        <loadfile srcfile="${payara-micro.logfile}.0" property="serverlog" failonerror="false">
                                            <filterchain>
                                                <tailfilter lines="12"/>
                                            </filterchain>
                                        </loadfile>

                                        <echo message="${serverlog}"/>
                                    </target>

                                </configuration>

                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        
        <profile>
            <id>payara-micro-package</id>
            <activation>
                <property>
                    <name>payara-micro-package</name>
                </property>
            </activation>
            
            <build>
            
                <finalName>${project.artifactId}</finalName>
    
                <plugins>
                    
                    <plugin>
                        <groupId>fish.payara.maven.plugins</groupId>
                        <artifactId>payara-micro-maven-plugin</artifactId>
                        <configuration>
                            <autoDeployArtifact>false</autoDeployArtifact>
                        </configuration>
                        <executions>
                            <execution>
                                <id>1</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>bundle</goal>
                                </goals>
                            </execution>
                        </executions>
                        
                    </plugin>
                </plugins>
            </build>
        </profile>
        
        <profile>
            <id>payara-micro-log</id>
            <activation>
                <property>
                    <name>payara-micro-log</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.6.0</version>
                        <executions>
                            <execution>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <executable>tail</executable>
                            <arguments>
                                <argument>-F</argument>
                                <argument>${payara-micro.logfile}.0</argument>
                            </arguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        
<!-- ============================== WILDFLY SWARM ============================== -->        
        <profile>
            <id>wildfly-swarm-run</id>
            <activation>
                <property>
                    <name>wildfly-swarm-run</name>
                </property>
            </activation>
            
            <build>
                <plugins>
                    
                    <plugin>
                        <groupId>org.wildfly.swarm</groupId>
                        <artifactId>wildfly-swarm-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>1</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>package</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.6.0</version>
                        <executions>
                            <execution>
                                <id>1</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <executable>java</executable>
                            <arguments>
                                <argument>-jar</argument>
                                <argument>-Xdebug</argument>
                                <argument>-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${debug.port}</argument>
                                <argument>${project.build.directory}${file.separator}${project.artifactId}-swarm.jar</argument>
                                <argument>-c</argument>
                                <argument>${project.build.directory}${file.separator}standalone.xml</argument>
                            </arguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        
        <profile>
            <id>wildfly-swarm-start</id>
            <activation>
                <property>
                    <name>wildfly-swarm-start</name>
                </property>
            </activation>
            
            <build>
                <plugins>
                    <!-- Create or merge standalone.xml to add deployment scanner -->
                    <plugin>
                        <groupId>org.codehaus.gmaven</groupId>
                        <artifactId>groovy-maven-plugin</artifactId>
                        <version>2.0</version>
                        <executions>
                            <execution>
                                <id>1</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>execute</goal>
                                </goals>
                                <configuration>
                                    <source>
                                        <![CDATA[
                                        String scannerSubsystem = "\t<subsystem xmlns=\"urn:jboss:domain:deployment-scanner:2.0\">\n\t<deployment-scanner \n\t\tscan-enabled=\"true\"\n\t\tscan-interval=\"5000\" \n\t\tpath=\"${wildfly-swarm.deployDir}\" \n\t\tname=\"${project.artifactId}\" \n\t\tauto-deploy-xml=\"false\"/> \n\t</subsystem>";
                                        println("==== Java EE servers parent maven (Wildfly Swarm) ====");
                                        File deployDir = new File("${wildfly-swarm.deployDir}");
                                        deployDir.mkdirs();

                                        println("Scanner looking for deployments in ${wildfly-swarm.deployDir}");
                                        File targetDir = new File("${project.build.directory}");
                                        if(targetDir.exists() && !targetDir.isDirectory()) {
                                            println("Target dir does not exist, wont create standalone.xml !");
                                            return;
                                        }
                                        File standaloneXmlFile = new File(targetDir,"standalone.xml");

                                        String content = null;
                                        if(standaloneXmlFile.exists() && !standaloneXmlFile.isDirectory()) {
                                            println("Enhancing existing standalone.xml");
                                            BufferedReader reader = new BufferedReader(new FileReader (standaloneXmlFile));
                                            String line = null;
                                            StringBuilder stringBuilder = new StringBuilder();
                                            String ls = System.getProperty("line.separator");

                                            try {
                                                while((line = reader.readLine()) != null) {
                                                    stringBuilder.append(line);
                                                    stringBuilder.append(ls);
                                                }
                                                content = stringBuilder.toString();
                                            } finally {
                                                reader.close();
                                            }
                                        }else{
                                            println("Creating standalone.xml");
                                            content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
                                            content = content + "\n<profile>";
                                            content = content + "\n</profile>";
                                        }

                                        content = content.replaceAll("</profile>", scannerSubsystem + "\n\t</profile>");

                                        BufferedWriter writer = new BufferedWriter(new FileWriter(standaloneXmlFile));

                                        writer.write(content);
                                        writer.close();
                                        ]]>
                                    </source>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    
                    <plugin>
                        <groupId>org.wildfly.swarm</groupId>
                        <artifactId>wildfly-swarm-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>2</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>package</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <hollow>true</hollow>
                            <additionalFractions>scanner</additionalFractions>
                        </configuration>
                    </plugin>
                    
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <id>3</id>
                                <phase>integration-test</phase>
                                <configuration>
                                    <target name="copy wildfly-swarm distribution">
                                        <copy file="${project.build.directory}${file.separator}${project.artifactId}-hollow-swarm.jar" 
                                              tofile="${wildfly-swarm.installDir}${file.separator}${project.artifactId}-hollow-swarm.jar"
                                              overwrite="true" force="true" verbose="true"/>
                                        <copy file="${project.build.directory}${file.separator}standalone.xml" 
                                              tofile="${wildfly-swarm.installDir}${file.separator}standalone.xml" 
                                              overwrite="true" force="true" verbose="true"/>
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                            
                        </executions>
                    </plugin>
                    
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.6.0</version>
                        <executions>
                            <execution>
                                <id>4</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <executable>java</executable>
                            <async>true</async>
                            <asyncDestroyOnShutdown>false</asyncDestroyOnShutdown>
                            <arguments>
                                <argument>-jar</argument>
                                <argument>-Xdebug</argument>
                                <argument>-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${debug.port}</argument>
                                <argument>${wildfly-swarm.installDir}${file.separator}${project.artifactId}-hollow-swarm.jar</argument>
                                <argument>-c</argument>
                                <argument>${wildfly-swarm.installDir}${file.separator}standalone.xml</argument>
                            </arguments>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>5</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>copy</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>${project.artifactId}</artifactId>
                                            <version>${project.version}</version>
                                            <type>${project.packaging}</type>
                                        </artifactItem>
                                    </artifactItems>
                                    <outputDirectory>${wildfly-swarm.deployDir}</outputDirectory>
                                    <stripVersion>true</stripVersion>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                   
                </plugins>
            </build>
        </profile>
        
        <profile>
            <id>wildfly-swarm-stop</id>
            <activation>
                <property>
                    <name>wildfly-swarm-stop</name>
                </property>
            </activation>
            
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <id>1</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <exec executable="${JAVA_HOME}/bin/jps">
                                            <redirector outputproperty="process.pid">
                                                <outputfilterchain>
                                                    <linecontains>
                                                        <contains value="${project.artifactId}-hollow-swarm.jar" />
                                                    </linecontains>
                                                    <replacestring from=" ${project.artifactId}-hollow-swarm.jar" />
                                                </outputfilterchain>
                                            </redirector>
                                        </exec>
                                        <exec executable="taskkill" osfamily="winnt">
                                            <arg value="/PID" />
                                            <arg value="${process.pid}" />
                                        </exec>
                                        <exec executable="kill" osfamily="unix">
                                            <arg value="-9" />
                                            <arg value="${process.pid}" />
                                        </exec>
                                    </target>
                                </configuration>
                            </execution>
                            
                        </executions>
                    </plugin>
                    
                </plugins>
            </build>
        </profile>
        
        <profile>
            <id>wildfly-swarm-deploy</id>
            <activation>
                <property>
                    <name>wildfly-swarm-deploy</name>
                </property>
            </activation>
            
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>2</id>
                                <phase>install</phase>
                                <goals>
                                    <goal>copy</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>${project.artifactId}</artifactId>
                                            <version>${project.version}</version>
                                            <type>${project.packaging}</type>
                                        </artifactItem>
                                    </artifactItems>
                                    <outputDirectory>${wildfly-swarm.deployDir}</outputDirectory>
                                    <stripVersion>true</stripVersion>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <id>6</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>

                                <configuration>
                                    <target>
                                        <loadfile srcfile="${wildfly-swarm.logfile}" property="serverlog" failonerror="false">
                                            <filterchain>
                                                <tailfilter lines="12"/>
                                            </filterchain>
                                        </loadfile>

                                        <echo message="${serverlog}"/>
                                    </target>

                                </configuration>

                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            
        </profile>
        
        <profile>
            <id>wildfly-swarm-package</id>
            <activation>
                <property>
                    <name>wildfly-swarm-package</name>
                </property>
            </activation>
            
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.wildfly.swarm</groupId>
                        <artifactId>wildfly-swarm-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>1</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>package</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            
        </profile>
        
        <profile>
            <id>wildfly-swarm-log</id>
            <activation>
                <property>
                    <name>wildfly-swarm-log</name>
                </property>
            </activation>
            
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.6.0</version>
                        <executions>
                            <execution>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <executable>tail</executable>
                            <arguments>
                                <argument>-F</argument>
                                <argument>${wildfly-swarm.logfile}</argument>
                            </arguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            
        </profile>
        
<!-- ============================== OPENLIBERTY ============================== -->                
        
        <profile>
            <id>openliberty-run</id>
            <activation>
                <property>
                    <name>openliberty-run</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>net.wasdev.wlp.maven.plugins</groupId>
                        <artifactId>liberty-maven-plugin</artifactId>
                        
                        <executions>
                            <execution>
                                <phase>install</phase>
                                <goals>
                                    <goal>install-server</goal>
                                    <goal>create-server</goal>
                                    <goal>run-server</goal>    
                                </goals>

                                <configuration>
                                    <configFile>${project.build.directory}${file.separator}server.xml</configFile>
                                    <bootstrapProperties>
                                        <httpPort>${openliberty.http.port}</httpPort>
                                        <httpsPort>${openliberty.https.port}</httpsPort>
                                    </bootstrapProperties>
                                    <jvmOptions>
                                        <param>-Xmx${openliberty.Xmx}</param>
                                        <param>-Xdebug</param>
                                        <param>-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${debug.port}</param>
                                    </jvmOptions>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    
        <profile>
            <id>openliberty-start</id>
            <activation>
                <property>
                    <name>openliberty-start</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>net.wasdev.wlp.maven.plugins</groupId>
                        <artifactId>liberty-maven-plugin</artifactId>

                        <executions>
                            
                            <execution>
                                <id>1</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>install-server</goal>
                                </goals>
                                <configuration>
                                    <assemblyInstallDirectory>${openliberty.installDir}</assemblyInstallDirectory>
                                </configuration>
                            </execution>
                            
                            <execution>
                                <id>2</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>create-server</goal>
                                    <goal>start-server</goal>
                                </goals>
                                <configuration>
                                    <installDirectory>${openliberty.installDir}${file.separator}wlp</installDirectory>
                                    <configFile>${project.build.directory}${file.separator}server.xml</configFile>
                                    <bootstrapProperties>
                                        <httpPort>${openliberty.http.port}</httpPort>
                                        <httpsPort>${openliberty.https.port}</httpsPort>
                                    </bootstrapProperties> 
                                    <jvmOptions>
                                        <param>-Xmx${openliberty.Xmx}</param>
                                        <param>-Xdebug</param>
                                        <param>-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${debug.port}</param>
                                    </jvmOptions>
                                </configuration>
                            </execution>
                            
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <id>2</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>

                                <configuration>
                                    <target>
                                        <loadfile srcfile="${openliberty.logsDir}${file.separator}messages.log" property="serverlog" failonerror="false">
                                            <filterchain>
                                                <tailfilter lines="12"/>
                                            </filterchain>
                                        </loadfile>

                                        <echo message="${serverlog}"/>
                                    </target>

                                </configuration>

                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        
        <profile>
            <id>openliberty-stop</id>
            <activation>
                <property>
                    <name>openliberty-stop</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>net.wasdev.wlp.maven.plugins</groupId>
                        <artifactId>liberty-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>stop-server</goal>
                                </goals>
                                <configuration>
                                    <installDirectory>${openliberty.installDir}${file.separator}wlp</installDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <id>2</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>

                                <configuration>
                                    <target>
                                        <loadfile srcfile="${openliberty.logsDir}${file.separator}messages.log" property="serverlog" failonerror="false">
                                            <filterchain>
                                                <tailfilter lines="12"/>
                                            </filterchain>
                                        </loadfile>

                                        <echo message="${serverlog}"/>
                                    </target>

                                </configuration>

                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        
        <profile>
            <id>openliberty-deploy</id>
            <activation>
                <property>
                    <name>openliberty-deploy</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>net.wasdev.wlp.maven.plugins</groupId>
                        <artifactId>liberty-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>1</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>deploy</goal>
                                </goals>
                                <configuration>
                                    <appArchive>${project.build.directory}${file.separator}${project.artifactId}.war</appArchive>
                                    <installDirectory>${openliberty.installDir}${file.separator}wlp</installDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <id>2</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>

                                <configuration>
                                    <target>
                                        <loadfile srcfile="${openliberty.logsDir}${file.separator}messages.log" property="serverlog" failonerror="false">
                                            <filterchain>
                                                <tailfilter lines="12"/>
                                            </filterchain>
                                        </loadfile>

                                        <echo message="${serverlog}"/>
                                    </target>

                                </configuration>

                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        
        <profile>
            <id>openliberty-package</id>
            <activation>
                <property>
                    <name>openliberty-package</name>
                </property>
            </activation>
            
            <build>
                <plugins>
                    <plugin>
                        <groupId>net.wasdev.wlp.maven.plugins</groupId>
                        <artifactId>liberty-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>package-server</goal>
                                </goals>
                                <configuration>
                                    <packageFile>${project.build.directory}${file.separator}${project.artifactId}.jar</packageFile>
                                    <include>runnable</include>
                                    <installDirectory>${openliberty.installDir}${file.separator}wlp</installDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            
        </profile>
       
        <profile>
            <id>openliberty-log</id>
            <activation>
                <property>
                    <name>openliberty-log</name>
                </property>
            </activation>
            
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.6.0</version>
                        <executions>
                            <execution>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <executable>tail</executable>
                            <arguments>
                                <argument>-F</argument>
                                <argument>${openliberty.logsDir}${file.separator}trace.log</argument>
                            </arguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            
        </profile>
        
        
        
        <!-- Activate using the release property: mvn clean install -Prelease -->
        <profile>
            <id>release</id>
            <activation>
                <property>
                    <name>release</name>
                </property>
            </activation>
            
            <build>
                <plugins>
                    <!-- To release to Maven central -->
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.8</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>
                    <!-- To generate javadoc -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.0.1</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.10.4</version>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- To sign the artifacts -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.6</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>        

            </build>
        </profile>
    </profiles>
    
    <modules>
        <module>example</module>
    </modules>
</project>
