<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~ Copyright The WildFly Authors
  ~ SPDX-License-Identifier: Apache-2.0
  -->

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <!--
        skip wildfly-feature-pack-parent and use wildfly-parent to avoid issues
        with dependencies imported with groupId ${project.groupId}
        -->
        <groupId>org.wildfly</groupId>
        <artifactId>wildfly-parent</artifactId>
        <!--
        Maintain separation between the artifact id and the version to help prevent
        merge conflicts between commits changing the GA and those changing the V.
        -->
        <version>33.0.0.Final</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>

    <groupId>org.wildfly.channels</groupId>
    <artifactId>wildfly-preview</artifactId>

    <name>WildFly: Preview Feature Pack Channel</name>
    <packaging>pom</packaging>

    <dependencies>

        <!-- We need the feature pack built first as that generates the manifest -->
        <dependency>
            <groupId>org.wildfly</groupId>
            <artifactId>wildfly-preview-feature-pack</artifactId>
            <version>${ee.maven.version}</version>
            <type>zip</type>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <!-- This module's artifact is currently not deployed -->
                    <skip>false</skip>
                </configuration>
            </plugin>
            <!-- Use the assembly plugin to copy and rename the manifest generated by the feature pack build.
                 (The resources plugin doesn't allow file renaming.)-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>assemble</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>${project.basedir}/assembly.xml</descriptor>
                            </descriptors>
                            <finalName>assembly</finalName>
                            <workDirectory>${project.build.directory}/assembly-src/work</workDirectory>
                            <attach>false</attach>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Use the resources plugin to apply expression replacement filtering to the channel.yaml -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-channel-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.basedir}/target/resources</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.basedir}/src/main/resources</directory>
                                    <includes>
                                        <include>wildfly-preview-channel.yaml</include>
                                    </includes>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <!-- Attach the manifest.yaml to the build -->
                    <execution>
                        <id>attach-manifest</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/assembly-manifest-rename/assembly/${project.artifactId}-${project.version}-manifest.yaml</file>
                                    <type>yaml</type>
                                    <classifier>manifest</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                    <!-- Attach the channel.yaml to the build.
                         NOTE: Commented out until we have a concrete need. -->
                    <!--<execution>
                        <id>attach-channel</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/resources/${project.artifactId}.yaml</file>
                                    <type>yaml</type>
                                    <classifier>channel</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>-->
                </executions>
            </plugin>
            <plugin>
                <groupId>org.wildfly</groupId>
                <artifactId>wildfly-channel-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>test</id>
                        <phase>package</phase>
                        <goals>
                            <goal>edit-manifest</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <manifestPath>${project.build.directory}/assembly-manifest-rename/assembly/${project.artifactId}-${project.version}-manifest.yaml</manifestPath>
                    <manifestName>WildFly preview manifest version ${project.version}</manifestName>
                    <manifestId>${project.groupId}:${project.artifactId}</manifestId>
                    <manifestDescription>Manifest for WildFly preview feature pack.</manifestDescription>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
