<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.composum.platform.features</groupId>
        <artifactId>composum-launcher-feature</artifactId>
        <version>1.5.2.1</version>
    </parent>

    <artifactId>composum-launcher-feature-nodesstarter</artifactId>

    <name>Composum Launcher Feature Nodes Starter</name>
    <description>
        Creates a feature set and a starter based on a Sling Starter 12 snapshot to start Sling and updating Composum
        Nodes.
        It produces a self contained feature archive that doesn't need network access to start. The starter contains that feature archive.
    </description>

    <dependencies>
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.feature.launcher</artifactId>
            <version>${org.apache.sling.feature.launcher.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.feature.extension.content</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.sling/org.apache.sling.jcr.packageinit -->
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.jcr.packageinit</artifactId>
            <version>${org.apache.sling.jcr.packageinit.version}</version>
            <scope>runtime</scope>
        </dependency>

        <!-- Content to be put into the internal repository in the JAR -->
        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.apache.felix.framework</artifactId>
            <version>${org.apache.felix.framework.version}</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.starter</artifactId>
            <version>${sling.starter.version}</version>
            <classifier>oak_tar</classifier>
            <type>slingosgifeature</type>
        </dependency>

        <!-- For integration tests -->
        <dependency>
            <groupId>com.composum.platform.features</groupId>
            <artifactId>composum-launcher-feature-integrationtest</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

        <plugins>

            <plugin>
                <groupId>org.apache.sling</groupId>
                <artifactId>slingfeature-maven-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <replacePropertyVariables>
                        org.apache.sling.jcr.packageinit.version,composum.platform.version,composum.assets.version,composum.pages.version,composum.pages.options.version,cpm.platform.htl.version
                    </replacePropertyVariables>
                    <framework>
                        <groupId>org.apache.felix</groupId>
                        <artifactId>org.apache.felix.framework</artifactId>
                        <version>${org.apache.felix.framework.version}</version>
                    </framework>
                    <aggregates>
                        <aggregate>
                            <classifier>composum</classifier>
                            <filesInclude>**/composum*.json</filesInclude>
                            <includeArtifact>
                                <groupId>com.composum.nodes.setup</groupId>
                                <artifactId>composum-nodes-slingfeature</artifactId>
                                <version>${composum.nodes.version}</version>
                                <type>slingosgifeature</type>
                            </includeArtifact>
                            <artifactsOverrides>
                                <artifactsOverride>com.composum.nodes:*:HIGHEST</artifactsOverride>
                            </artifactsOverrides>
                        </aggregate>
                        <aggregate>
                            <classifier>oak_tar</classifier>
                            <includeClassifier>composum</includeClassifier>
                            <filesInclude>common/*.json</filesInclude>
                            <includeArtifact>
                                <groupId>org.apache.sling</groupId>
                                <artifactId>org.apache.sling.starter</artifactId>
                                <version>${sling.starter.version}</version>
                                <classifier>oak_tar</classifier>
                                <type>slingosgifeature</type>
                            </includeArtifact>
                            <artifactsOverrides>
                                <artifactsOverride>com.composum.nodes:*:HIGHEST</artifactsOverride>
                            </artifactsOverrides>
                        </aggregate>
                        <aggregate>
                            <classifier>oak_mongo</classifier>
                            <includeClassifier>composum</includeClassifier>
                            <filesInclude>common/*.json</filesInclude>
                            <includeArtifact>
                                <groupId>org.apache.sling</groupId>
                                <artifactId>org.apache.sling.starter</artifactId>
                                <version>${sling.starter.version}</version>
                                <classifier>oak_mongo</classifier>
                                <type>slingosgifeature</type>
                            </includeArtifact>
                            <artifactsOverrides>
                                <artifactsOverride>com.composum.nodes:*:HIGHEST</artifactsOverride>
                            </artifactsOverrides>
                        </aggregate>
                    </aggregates>
                    <scans>
                        <scan>
                            <includeClassifier>oak_tar</includeClassifier>
                        </scan>
                        <scan>
                            <includeClassifier>oak_mongo</includeClassifier>
                        </scan>
                    </scans>
                    <archives>
                        <archive>
                            <classifier>oak_tar</classifier>
                            <includeClassifier>oak_tar</includeClassifier>
                        </archive>
                        <archive>
                            <classifier>oak_mongo</classifier>
                            <includeClassifier>oak_mongo</includeClassifier>
                        </archive>
                        <archive>
                            <classifier>composum</classifier>
                            <includeClassifier>composum</includeClassifier>
                        </archive>
                    </archives>
                </configuration>
                <executions>
                    <execution>
                        <id>aggregate-features</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>aggregate-features</goal>
                            <goal>analyse-features</goal>
                            <goal>attach-features</goal>
                            <goal>attach-featurearchives</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>oakTarLauncher</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>src/main/assembly/oakTarLauncher.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                    <execution>
                        <id>oakMongoLauncher</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>src/main/assembly/oakMongoLauncher.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                    <execution>
                        <id>starter</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>src/main/assembly/plainLauncher.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>
                                com.composum.platform.feature.nodesstarter.LaunchFromEmbeddedFAR
                            </mainClass>
                            <classpathPrefix>lib/</classpathPrefix>
                            <classpathLayoutType>repository</classpathLayoutType>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>${basedir}</directory>
                            <!-- Clean up remnants from test starts possibly done by the user. -->
                            <includes>
                                <include>sling/**</include>
                                <include>launcher/**</include>
                            </includes>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>

            <!-- reserve network ports for the integration tests -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>reserve-network-port</id>
                        <goals>
                            <goal>reserve-network-port</goal>
                        </goals>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <portNames>
                                <portName>http.port</portName>
                            </portNames>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Start a server for the integration test -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>startITserver</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>java</executable>
                            <arguments>
                                <argument>-jar</argument>
                                <argument>${project.build.directory}/${project.build.finalName}-oak_tar-launcher.jar
                                </argument>
                                <argument>-D</argument>
                                <argument>org.osgi.service.http.port=${http.port}</argument>
                                <argument>--pidfile=${project.build.directory}/pid.it.txt</argument>
                            </arguments>
                            <workingDirectory>${project.build.directory}/it</workingDirectory>
                            <async>true</async>
                            <asyncDestroyOnShutdown>true</asyncDestroyOnShutdown>
                            <successCodes>0,143</successCodes>
                            <timeout>180000</timeout>
                        </configuration>
                    </execution>
                    <execution>
                        <id>shutdownITserver</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>com.composum.platform.feature.nodesstarter.StopFromPid</mainClass>
                            <arguments>
                                <argument>stop</argument>
                                <argument>--pidfile=${project.build.directory}/pid.it.txt</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- run the ITs -->
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <dependenciesToScan>
                        com.composum.platform.features:composum-launcher-feature-integrationtest
                    </dependenciesToScan>
                    <systemPropertyVariables>
                        <starter.http.test.ports>false:${http.port}</starter.http.test.ports>
                        <starter.min.bundles.count>223</starter.min.bundles.count>
                        <!-- Comma-separated list of paths to check for 200 status -->
                        <starter.check.paths>
                            /starter.html,
                            /server/default/jcr:root/content CONTAINS sv:node,
                            /system/sling.js,
                            /content/starter/img/sling-logo.svg,
                            /system/console/bundles,
                            /bin/browser.html,
                            /bin/packages.html,
                            /bin/cpm/usermanagement.tree.json/home/users/system/sling,
                            /system/console/status-Bundlelist.txt CONTAINS com.composum.nodes.console.*active,
                        </starter.check.paths>
                        <!-- Uncomment if you want the test to sleep for a while so that the server is running for diagnostics if something fails. -->
                        <!-- <starter.waitonfailure>600000</starter.waitonfailure> -->
                    </systemPropertyVariables>
                </configuration>
            </plugin>

        </plugins>
    </build>

</project>
