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

    Copyright (c) 2022 Contributors to the Eclipse Foundation. All rights reserved.
    Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.

    This program and the accompanying materials are made available under the
    terms of the Eclipse Public License v. 2.0, which is available at
    http://www.eclipse.org/legal/epl-2.0.

    This Source Code may also be made available under the following Secondary
    Licenses when the conditions for such availability set forth in the
    Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
    version 2 with the GNU Classpath Exception, which is available at
    https://www.gnu.org/software/classpath/license.html.

    SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.glassfish.main</groupId>
        <artifactId>glassfish-parent</artifactId>
        <version>9.0.0-M2</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>

    <groupId>org.glassfish.main.admingui</groupId>
    <artifactId>war</artifactId>
    <packaging>war</packaging>

    <name>Admin Console WAR</name>

    <developers>
        <!-- See parent POM -->
    </developers>

    <properties>
        <dependencies.extra.directory>${project.build.directory}/extra-dependencies</dependencies.extra.directory>
    </properties>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>console-core</artifactId>
            <version>${project.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>console-commandrecorder-plugin</artifactId>
            <version>${project.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- following provided scopes are to avoid maven-war-plugin's resolution of libs directory, -->
        <!-- because we need these dependencies in extra directory -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.woodstock.external</groupId>
            <artifactId>dojo</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.woodstock.dependlibs</groupId>
            <artifactId>json</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.woodstock.external</groupId>
            <artifactId>prototype</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.woodstock</groupId>
            <artifactId>woodstock-webui-jsf</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.woodstock</groupId>
            <artifactId>woodstock-webui-jsf-suntheme</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.faces</groupId>
            <artifactId>jakarta.faces-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.el</groupId>
            <artifactId>jakarta.el-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.cdi</groupId>
            <artifactId>jakarta.cdi-api</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>admingui</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>prepare-extra-dependencies</id>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <phase>prepare-package</phase>
                        <configuration>
                            <outputDirectory>${dependencies.extra.directory}</outputDirectory>
                            <includeArtifactIds>
                                commons-io,
                                dojo,json,prototype,
                                woodstock-webui-jsf,woodstock-webui-jsf-suntheme
                            </includeArtifactIds>
                            <includeScope>provided</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warSourceExcludes>WEB-INF/sun-web.xml</warSourceExcludes>
                    <webResources>
                        <resource>
                            <directory>src/main/webapp</directory>
                            <filtering>true</filtering>
                            <includes>
                                <include>WEB-INF/sun-web.xml</include>
                            </includes>
                        </resource>
                        <resource>
                            <directory>${dependencies.extra.directory}</directory>
                            <targetPath>WEB-INF/extra</targetPath>
                        </resource>
                    </webResources>
                    <archive>
                        <manifestEntries>
                            <Glassfish-require-services>org.glassfish.api.admingui.ConsoleProvider</Glassfish-require-services>
                            <HK2-Import-Bundles>
                                org.glassfish.main.admingui.console-common,
                                org.glassfish.hk2.hk2,
                                org.glassfish.main.admingui.console-plugin-service,
                                jakarta.servlet-api,
                                jakarta.servlet.jsp-api,
                                jakarta.el-api,
                                org.glassfish.expressly,
                                org.glassfish.jsftemplating,
                                org.glassfish.main.admingui.dataprovider
                            </HK2-Import-Bundles>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>dev</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-main-artifact</id>
                                <phase>package</phase>
                                <configuration>
                                    <target>
                                        <delete dir="${basedir}/../../../${glassfish.distribution.dir}/lib/install/applications/__admingui"/>
                                        <unzip src="${project.build.directory}/${project.build.finalName}.war" dest="${basedir}/../../../${glassfish.distribution.dir}/lib/install/applications/__admingui" />
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
