<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>
    <artifactId>io.neba.neba-delivery-aem</artifactId>
    <name>NEBA delivery</name>
    <packaging>content-package</packaging>

    <description>Packages NEBA for deployment in Adobe AEM</description>

    <parent>
        <groupId>io.neba</groupId>
        <artifactId>io.neba.neba-parent</artifactId>
        <version>5.0.0</version>
    </parent>

    <properties>
        <neba.installation.path>/apps/neba/install</neba.installation.path>
        <spring.artifacts.sourcedir>${project.build.directory}/spring-artifacts</spring.artifacts.sourcedir>
        <spring.artifacts.targetdir>
            ${project.build.directory}/filefault-work-spring/jcr_root/${neba.installation.path}/17
        </spring.artifacts.targetdir>
    </properties>

    <dependencies>
        <!-- Internal dependencies -->
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>io.neba.neba-core</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>io.neba.neba-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>io.neba.neba-spring</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!-- External dependencies -->
        <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.spring-beans</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.spring-aop</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.spring-context-support</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.spring-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.aopalliance</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.spring-expression</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.spring-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.spring-webmvc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.eclipse.gemini.blueprint</groupId>
            <artifactId>gemini-blueprint-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.eclipse.gemini.blueprint</groupId>
            <artifactId>gemini-blueprint-io</artifactId>
        </dependency>
        <dependency>
            <groupId>org.eclipse.gemini.blueprint</groupId>
            <artifactId>gemini-blueprint-extender</artifactId>
        </dependency>
        <dependency>
            <groupId>org.eclipse.gemini.blueprint</groupId>
            <artifactId>gemini-blueprint-extensions</artifactId>
        </dependency>

        <!-- build dependencies -->
        <dependency>
            <groupId>biz.aQute.bnd</groupId>
            <artifactId>biz.aQute.bndlib</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <!-- Process and filter all .xml resources  -->
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <!-- Copy resources directly to target to add content to the content packgage plugin's "vault-work" directory -->
                <targetPath>${project.build.directory}</targetPath>
            </resource>
            <!-- Process and do not filter all non-xml resources (binaries)  -->
            <resource>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>**/*.xml</exclude>
                </excludes>
                <!-- Copy resources directly to target to add content to the content packgage plugin's "vault-work" directory -->
                <targetPath>${project.build.directory}</targetPath>
            </resource>
        </resources>
        <plugins>
            <!-- Omit the binary resources. They are shipped separately -->
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <configuration>
                    <excludeResources>true</excludeResources>
                </configuration>
            </plugin>

            <!-- Manifest customization: unpack all dependencies that require manifest transformation into a suitable directory -->
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-spring-dependencies</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeGroupIds>org.apache.servicemix.bundles</includeGroupIds>
                            <excludeArtifactIds>org.apache.servicemix.bundles.aopalliance</excludeArtifactIds>
                            <useSubDirectoryPerArtifact>true</useSubDirectoryPerArtifact>
                            <overWriteReleases>true</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                            <outputDirectory>${spring.artifacts.sourcedir}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- The JCR installer allows specifying the bundle start level via a path segment /install/<startlevel> -->
            <!-- Following, the bundles are packaged with start levels deemed optimal for dependency resolution -->

            <!-- Customize the manifests of the unpacked dependencies and re-package them -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>transform-javax-import-versions</id>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <phase>prepare-package</phase>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>io.neba.delivery.SpringBundlesTransformer</mainClass>
                    <!-- Spring bundles shall start after their dependencies at start level 17 -->
                    <arguments>
                        <!-- source directory -->
                        <argument>${spring.artifacts.sourcedir}</argument>
                        <!-- target directory -->
                        <argument>${spring.artifacts.targetdir}</argument>
                    </arguments>
                    <classpathScope>compile</classpathScope>
                </configuration>
            </plugin>

            <!-- Build the content package including bundles with customized manifests (those are already copied to the target/vault-work directory) -->
            <plugin>
                <groupId>org.apache.jackrabbit</groupId>
                <artifactId>filevault-package-maven-plugin</artifactId>
                <configuration>
                    <showImportPackageReport>false</showImportPackageReport>
                    <version>${project.version}</version>
                    <failOnMissingEmbed>true</failOnMissingEmbed>
                    <filters>
                        <filter>
                            <mode>replace</mode>
                            <root>/apps/neba</root>
                        </filter>
                    </filters>
                    <thumbnailImage>${project.build.directory}/filefault-work/META-INF/vault/definition/thumbnail.png
                    </thumbnailImage>
                </configuration>
                <executions>
                    <execution>
                        <id>default-package</id>
                        <phase>package</phase>
                        <goals>
                            <goal>package</goal>
                        </goals>
                        <configuration>
                            <packageType>container</packageType>
                            <finalName>${project.artifactId}-${project.version}-spring</finalName>
                            <workDirectory>${project.build.directory}/filefault-work-spring</workDirectory>
                            <properties>
                                <description>Packages NEBA along with the NEBA Spring integration and the Spring Framework.</description>
                            </properties>
                            <embeddeds>
                                <!-- Spring dependencies shall start first at start level 16 -->
                                <embedded>
                                    <groupId>org.apache.servicemix.bundles</groupId>
                                    <artifactId>org.apache.servicemix.bundles.aopalliance</artifactId>
                                    <target>${neba.installation.path}/16</target>
                                </embedded>

                                <!-- Gemini shall start after Spring has started at start level 18 -->
                                <embedded>
                                    <groupId>org.eclipse.gemini.blueprint</groupId>
                                    <artifactId>gemini-blueprint-core</artifactId>
                                    <target>${neba.installation.path}/18</target>
                                </embedded>
                                <embedded>
                                    <groupId>org.eclipse.gemini.blueprint</groupId>
                                    <artifactId>gemini-blueprint-io</artifactId>
                                    <target>${neba.installation.path}/18</target>
                                </embedded>
                                <embedded>
                                    <groupId>org.eclipse.gemini.blueprint</groupId>
                                    <artifactId>gemini-blueprint-extensions</artifactId>
                                    <target>${neba.installation.path}/18</target>
                                </embedded>
                                <embedded>
                                    <groupId>org.eclipse.gemini.blueprint</groupId>
                                    <artifactId>gemini-blueprint-extender</artifactId>
                                    <target>${neba.installation.path}/18</target>
                                </embedded>

                                <!-- Finally, NEBA shall start after gemini was started, but before the application
                                     bundles start, at start level 19. -->
                                <embedded>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>io.neba.neba-api</artifactId>
                                    <target>${neba.installation.path}/19</target>
                                </embedded>
                                <embedded>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>io.neba.neba-core</artifactId>
                                    <target>${neba.installation.path}/19</target>
                                </embedded>
                                <embedded>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>io.neba.neba-spring</artifactId>
                                    <target>${neba.installation.path}/19</target>
                                </embedded>
                            </embeddeds>
                        </configuration>
                    </execution>
                    <execution>
                        <id>create-core-aem-distribution</id>
                        <phase>package</phase>
                        <goals>
                            <goal>package</goal>
                        </goals>
                        <configuration>
                            <packageType>container</packageType>
                            <workDirectory>${project.build.directory}/filefault-work</workDirectory>
                            <embeddeds>
                                <embedded>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>io.neba.neba-api</artifactId>
                                    <target>${neba.installation.path}</target>
                                </embedded>
                                <embedded>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>io.neba.neba-core</artifactId>
                                    <target>${neba.installation.path}</target>
                                </embedded>
                            </embeddeds>
                        </configuration>
                    </execution>
                </executions>
                <extensions>true</extensions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>attach-aem-spring-package</id>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/${project.artifactId}-${project.version}-spring.zip</file>
                                    <type>zip</type>
                                    <classifier>spring</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
