<?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.0</version>
    </parent>

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

    <name>Composum Launcher Feature Composum Starter (With Composum Public)</name>
    <description>
        Creates a feature set and a starter based on a Sling Starter 12 snapshot to start Sling, updating Composum Nodes
        and deploying all public parts of composum.
        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>com.composum.platform.features</groupId>
            <artifactId>composum-launcher-feature-nodesstarter</artifactId>
            <version>${project.version}</version>
            <classifier>oak_tar-launcher</classifier>
        </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>
        <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,composum.chatgpt.version,composum.dashboard.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.platform.features</groupId>
                                <artifactId>composum-launcher-feature-nodesstarter</artifactId>
                                <version>${project.version}</version>
                                <classifier>composum</classifier>
                                <type>slingosgifeature</type>
                            </includeArtifact>
                            <artifactsOverrides>
                                <artifactsOverride>com.composum.nodes:*:${composum.nodes.version}</artifactsOverride>
                            </artifactsOverrides>
                        </aggregate>
                        <aggregate>
                            <classifier>oak_tar</classifier>
                            <filesInclude>other/**/*.json</filesInclude>
                            <includeClassifier>composum</includeClassifier>
                            <includeArtifact>
                                <groupId>com.composum.platform.features</groupId>
                                <artifactId>composum-launcher-feature-nodesstarter</artifactId>
                                <version>${project.version}</version>
                                <classifier>oak_tar</classifier>
                                <type>slingosgifeature</type>
                            </includeArtifact>
                            <artifactsOverrides>
                                <artifactsOverride>com.composum.nodes:*:${composum.nodes.version}</artifactsOverride>
                            </artifactsOverrides>
                        </aggregate>
                        <aggregate>
                            <classifier>oak_mongo</classifier>
                            <filesInclude>other/**/*.json</filesInclude>
                            <includeClassifier>composum</includeClassifier>
                            <includeArtifact>
                                <groupId>com.composum.platform.features</groupId>
                                <artifactId>composum-launcher-feature-nodesstarter</artifactId>
                                <version>${project.version}</version>
                                <classifier>oak_mongo</classifier>
                                <type>slingosgifeature</type>
                            </includeArtifact>
                            <artifactsOverrides>
                                <artifactsOverride>com.composum.nodes:*:${composum.nodes.version}</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>
                    <reports>duplicates,exported-packages,contents</reports>
                </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>
                            <goal>info</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>
                            <mergeManifestMode>merge</mergeManifestMode>
                        </configuration>
                    </execution>
                    <execution>
                        <id>oakMongoLauncher</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>src/main/assembly/oakMongoLauncher.xml</descriptor>
                            </descriptors>
                            <mergeManifestMode>merge</mergeManifestMode>
                        </configuration>
                    </execution>
                </executions>
            </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 a network port 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>228</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,
                            /system/console/status-Bundlelist.txt CONTAINS com.composum.platform.htl,
                            /bin/cpm/usermanagement.tree.json/home/users/system/composum/platform CONTAINS composum-platform-service,
                            /system/console/healthcheck.txt?tags=*%2C-diskspace%2C-oak&amp;forceInstantExecution=true&amp;quiet=true CONTAINS HealthCheck executed. 0 failures,
                            /system/console/healthcheck.txt?tags=*%2C-diskspace%2C-oak CONTAINS bundles are started,
                            /system/console/healthcheck.txt?tags=*%2C-diskspace%2C-oak CONTAINS All . required services are available,
                        </starter.check.paths>
                    </systemPropertyVariables>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <!-- Generate .env file with our version to enable version independent scripting files -->
                        <id>copy-resources</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/env</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

</project>
