<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  ~
  -->

<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">
    <parent>
        <artifactId>monitoring-dashboard-parent</artifactId>
        <groupId>org.wso2.ei</groupId>
        <version>1.2.0-beta</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>monitoring-dashboard-distribution</artifactId>
    <name>MI Monitoring Dashboard - Distribution</name>
    <packaging>pom</packaging>

    <dependencies>
        <!-- Carbon -->
        <dependency>
            <groupId>org.wso2.carbon</groupId>
            <artifactId>org.wso2.carbon.launcher</artifactId>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon</groupId>
            <artifactId>org.wso2.carbon.server.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon</groupId>
            <artifactId>org.wso2.carbon.osgi.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon</groupId>
            <artifactId>org.wso2.carbon.runtime.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.config</groupId>
            <artifactId>org.wso2.carbon.config.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.secvault</groupId>
            <artifactId>org.wso2.carbon.secvault.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.secvault</groupId>
            <artifactId>org.wso2.carbon.secvault.tools.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.utils</groupId>
            <artifactId>org.wso2.carbon.utils.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.touchpoint</groupId>
            <artifactId>org.wso2.carbon.touchpoint.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.deployment</groupId>
            <artifactId>org.wso2.carbon.deployment.engine.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.datasources</groupId>
            <artifactId>org.wso2.carbon.datasource.core.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.jndi</groupId>
            <artifactId>org.wso2.carbon.jndi.feature</artifactId>
            <type>zip</type>
        </dependency>

        <!-- OSGi -->
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
        </dependency>

        <!-- Metrics -->
        <dependency>
            <groupId>org.wso2.carbon.metrics</groupId>
            <artifactId>org.wso2.carbon.metrics.core.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.metrics</groupId>
            <artifactId>org.wso2.carbon.metrics.jdbc.core.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.metrics</groupId>
            <artifactId>org.wso2.carbon.metrics.das.core.feature</artifactId>
            <type>zip</type>
        </dependency>

        <!-- MSF4J-->
        <dependency>
            <groupId>org.wso2.msf4j</groupId>
            <artifactId>org.wso2.msf4j.feature</artifactId>
            <type>zip</type>
        </dependency>

        <!-- Databridge -->
        <dependency>
            <groupId>org.wso2.carbon.analytics-common</groupId>
            <artifactId>org.wso2.carbon.databridge.agent.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.analytics-common</groupId>
            <artifactId>org.wso2.carbon.databridge.commons.thrift.feature</artifactId>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>org.wso2.carbon.analytics-common</groupId>
            <artifactId>org.wso2.carbon.databridge.commons.feature</artifactId>
            <type>zip</type>
        </dependency>

        <!-- Carbon UI Server -->
        <dependency>
            <groupId>org.wso2.carbon.uiserver</groupId>
            <artifactId>org.wso2.carbon.uiserver.feature</artifactId>
            <type>zip</type>
        </dependency>

        <!-- Monitoring Dashboard -->
        <dependency>
            <groupId>org.wso2.ei</groupId>
            <artifactId>org.wso2.micro.integrator.dashboard.web.feature</artifactId>
            <version>${project.version}</version>
            <type>zip</type>
        </dependency>
        <dependency>
            <groupId>javax.annotation</groupId>
            <artifactId>javax.annotation-api</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <inherited>false</inherited>
                <executions>
                    <execution>
                        <id>1-unpack-p2-agent-distribution</id>
                        <phase>test</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.eclipse.equinox</groupId>
                                    <artifactId>org.eclipse.equinox.executable</artifactId>
                                    <version>3.5.0.v20110530-7P7NFUFFLWUl76mart</version>
                                    <type>zip</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>target</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-wso2carbon</id>
                        <phase>package</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.wso2.carbon</groupId>
                                    <artifactId>wso2carbon-core</artifactId>
                                    <version>${carbon.kernel4.version}</version>
                                    <type>zip</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>target</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.wso2.carbon.maven</groupId>
                <artifactId>carbon-feature-plugin</artifactId>
                <version>${carbon.feature.plugin.version}</version>
                <executions>
                    <execution>
                        <id>p2-repo-generation</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>generate-repo</goal>
                        </goals>
                        <configuration>
                            <targetRepository>file:${basedir}/target/p2-repo</targetRepository>
                            <features>
                                <!-- Carbon -->
                                <feature>
                                    <id>org.wso2.carbon.server.feature</id>
                                    <version>${carbon.kernel5.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.osgi.feature</id>
                                    <version>${carbon.kernel5.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.runtime.feature</id>
                                    <version>${carbon.kernel5.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.config.feature</id>
                                    <version>${carbon.config.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.secvault.feature</id>
                                    <version>${carbon.securevault.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.secvault.tools.feature</id>
                                    <version>${carbon.securevault.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.utils.feature</id>
                                    <version>${carbon.utils.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.touchpoint.feature</id>
                                    <version>${carbon.touchpoint.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.deployment.engine.feature</id>
                                    <version>${carbon.deployment.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.datasource.core.feature</id>
                                    <version>${carbon.datasources.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.jndi.feature</id>
                                    <version>${carbon.jndi.version}</version>
                                </feature>

                                <!-- Metrics -->
                                <feature>
                                    <id>org.wso2.carbon.metrics.core.feature</id>
                                    <version>${carbon.metrics.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.metrics.jdbc.core.feature</id>
                                    <version>${carbon.metrics.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.metrics.das.core.feature</id>
                                    <version>${carbon.metrics.version}</version>
                                </feature>

                                <!-- MSF4J -->
                                <feature>
                                    <id>org.wso2.msf4j.feature</id>
                                    <version>${msf4j.version}</version>
                                </feature>

                                <!-- Databridge -->
                                <feature>
                                    <id>org.wso2.carbon.databridge.agent.feature</id>
                                    <version>${carbon.analytics-common.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.databridge.commons.thrift.feature</id>
                                    <version>${carbon.analytics-common.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.databridge.commons.feature</id>
                                    <version>${carbon.analytics-common.version}</version>
                                </feature>

                                <!--Carbon UI Server-->
                                <feature>
                                    <id>org.wso2.carbon.uiserver.feature</id>
                                    <version>${carbon.uis.version}</version>
                                </feature>

                                <!-- Monitoring Dashboard -->
                                <feature>
                                    <id>org.wso2.micro.integrator.dashboard.web.feature</id>
                                    <version>${project.version}</version>
                                </feature>
                            </features>
                        </configuration>
                    </execution>
                    <execution>
                        <id>publishing products</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>publish-product</goal>
                        </goals>
                        <configuration>
                            <executable>
                                ${basedir}/target/org.eclipse.equinox.executable_3.5.0.v20110530-7P7NFUFFLWUl76mart
                            </executable>
                            <repositoryURL>file:${basedir}/target/p2-repo</repositoryURL>
                        </configuration>
                    </execution>
                    <execution>
                        <id>materialize-monitoring-dashboard</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>generate-runtime</goal>
                        </goals>
                        <configuration>
                            <repositoryURL>file:${basedir}/target/p2-repo</repositoryURL>
                            <targetPath>
                                file:${basedir}/target/wso2carbon-kernel-${carbon.kernel5.version}/wso2
                            </targetPath>
                            <runtime>server</runtime>
                        </configuration>
                    </execution>
                    <execution>
                        <id>feature-installation-monitoring-dashboard</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>install</goal>
                        </goals>
                        <configuration>
                            <runtime>server</runtime>
                            <repositoryURL>file:${basedir}/target/p2-repo</repositoryURL>
                            <destination>
                                ${basedir}/target/wso2carbon-kernel-${carbon.kernel5.version}/wso2
                            </destination>
                            <deleteOldRuntimeFiles>true</deleteOldRuntimeFiles>
                            <features>
                                <!-- Carbon -->
                                <feature>
                                    <id>org.wso2.carbon.server.feature.group</id>
                                    <version>${carbon.kernel5.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.osgi.feature.group</id>
                                    <version>${carbon.kernel5.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.runtime.feature.group</id>
                                    <version>${carbon.kernel5.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.config.feature.group</id>
                                    <version>${carbon.config.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.secvault.feature.group</id>
                                    <version>${carbon.securevault.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.secvault.tools.feature.group</id>
                                    <version>${carbon.securevault.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.utils.feature.group</id>
                                    <version>${carbon.utils.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.touchpoint.feature.group</id>
                                    <version>${carbon.touchpoint.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.datasource.core.feature.group</id>
                                    <version>${carbon.datasources.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.jndi.feature.group</id>
                                    <version>${carbon.jndi.version}</version>
                                </feature>

                                <!-- Metrics -->
                                <feature>
                                    <id>org.wso2.carbon.metrics.core.feature.group</id>
                                    <version>${carbon.metrics.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.metrics.jdbc.core.feature.group</id>
                                    <version>${carbon.metrics.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.metrics.das.core.feature.group</id>
                                    <version>${carbon.metrics.version}</version>
                                </feature>

                                <!-- MSF4J -->
                                <feature>
                                    <id>org.wso2.msf4j.feature.group</id>
                                    <version>${msf4j.version}</version>
                                </feature>

                                <!-- Databridge -->
                                <feature>
                                    <id>org.wso2.carbon.databridge.agent.feature.group</id>
                                    <version>${carbon.analytics-common.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.databridge.commons.thrift.feature.group</id>
                                    <version>${carbon.analytics-common.version}</version>
                                </feature>
                                <feature>
                                    <id>org.wso2.carbon.databridge.commons.feature.group</id>
                                    <version>${carbon.analytics-common.version}</version>
                                </feature>

                                <!-- Carbon UI Server -->
                                <feature>
                                    <id>org.wso2.carbon.uiserver.feature.group</id>
                                    <version>${carbon.uis.version}</version>
                                </feature>

                                <!-- Monitoring Dashboard -->
                                <feature>
                                    <id>org.wso2.micro.integrator.dashboard.web.feature</id>
                                    <version>${project.version}</version>
                                </feature>
                            </features>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.5.2</version>
                <executions>
                    <execution>
                        <id>distribution</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attached</goal>
                        </goals>
                        <configuration>
                            <filters>
                                <filter>${basedir}/src/assembly/filter.properties</filter>
                            </filters>
                            <descriptors>
                                <descriptor>${basedir}/src/assembly/bin.xml</descriptor>
                            </descriptors>
                            <finalName>wso2mi-monitoring-dashboard-${project.version}</finalName>
                            <appendAssemblyId>false</appendAssemblyId>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-in-place-tool</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <!-- download file -->
                                <get src="https://product-dist.wso2.com/downloads/in-place/release/update.zip" dest="${project.build.directory}/update.zip" verbose="false" usetimestamp="true" />
                                <unzip src="${project.build.directory}/update.zip" dest="${project.build.directory}" />
                            </target>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>prepare-package</phase>
                        <configuration>
                            <tasks>
                                <replace dir="target/wso2carbon-kernel-${carbon.kernel5.version}/wso2" token="false" value="true">
                                    <include name="**/bundles.info" />
                                </replace>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>prepare</id>
                        <phase>package</phase>
                        <configuration>
                            <skip>${docker.skip}</skip>
                            <target>
                                <echo message="prepare phase" />
                                <unzip src="${project.build.directory}/wso2mi-monitoring-dashboard-${project.version}.zip" dest="${project.build.directory}/docker" />
                                <move file="${project.build.directory}/docker/wso2mi-monitoring-dashboard-${project.version}" tofile="${project.build.directory}/docker/wso2mi-monitoring-dashboard" />
                                <chmod file="${project.build.directory}/docker/wso2mi-monitoring-dashboard/bin/*.sh" perm="+x" />
                                <chmod file="${project.build.directory}/docker/wso2mi-monitoring-dashboard/wso2/server/bin/*.sh" perm="+x" />
                                <chmod file="${project.build.directory}/docker/docker-entrypoint.sh" perm="+x" />
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>clean_target</id>
                        <phase>install</phase>
                        <configuration>
                            <tasks>
                                <delete dir="target/archive-tmp" />
                                <delete dir="target/dependency-maven-plugin-markers" />
                                <delete dir="target/org.eclipse.equinox.executable-3.5.0.v20110530-7P7NFUFFLWUl76mart" />
                                <delete dir="target/p2-repo" />
                                <delete file="target/tmp" />
                                <delete dir="target/wso2carbon-kernel-${carbon.kernel5.version}" />
                                <delete dir="target/antrun" />
                                <delete dir="target/maven-shared-archive-resources" />
                                <delete dir="target/findbugs" />
                                <delete file="target/checkstyle-cachefile" />
                                <delete file="target/checkstyle-checker.xml" />
                                <delete file="target/checkstyle-result.xml" />
                                <delete file="target/checkstyle-suppressions.xml" />
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>

                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>docker-entry-file</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>${basedir}/src/docker-distribution</directory>
                                    <filtering>true</filtering>
                                    <includes>
                                        <include>docker-entrypoint.sh</include>
                                    </includes>
                                </resource>
                            </resources>
                            <outputDirectory>${project.build.directory}/docker</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>build-image-alpine</id>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                        <configuration>
                            <skipDocker>${docker.skip}</skipDocker>
                            <imageName>wso2/micro-integrator-dashboard</imageName>
                            <imageTags>
                                <imageTag>${project.version}</imageTag>
                            </imageTags>
                            <dockerDirectory>${basedir}/src/docker-distribution/alpine</dockerDirectory>
                            <buildArgs>
                                <MICROESB_DASHBOARD_VERSION>${project.version}</MICROESB_DASHBOARD_VERSION>
                            </buildArgs>
                        </configuration>
                    </execution>
                    <execution>
                        <id>build-image-centos</id>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                        <configuration>
                            <skipDocker>${docker.skip}</skipDocker>
                            <imageName>wso2/micro-integrator-dashboard</imageName>
                            <imageTags>
                                <imageTag>${project.version}-centos7</imageTag>
                            </imageTags>
                            <dockerDirectory>${basedir}/src/docker-distribution/centos</dockerDirectory>
                            <buildArgs>
                                <MICROESB_DASHBOARD_VERSION>${project.version}</MICROESB_DASHBOARD_VERSION>
                            </buildArgs>
                        </configuration>
                    </execution>
                    <execution>
                        <id>build-image-ubuntu</id>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                        <configuration>
                            <skipDocker>${docker.skip}</skipDocker>
                            <imageName>wso2/micro-integrator-dashboard</imageName>
                            <imageTags>
                                <imageTag>${project.version}-ubuntu18.04</imageTag>
                            </imageTags>
                            <dockerDirectory>${basedir}/src/docker-distribution/ubuntu</dockerDirectory>
                            <buildArgs>
                                <MICROESB_DASHBOARD_VERSION>${project.version}</MICROESB_DASHBOARD_VERSION>
                            </buildArgs>
                        </configuration>
                    </execution>
                    <!-- TODO Enable after configuring Jenkins to push docker -->
                    <!--<execution>-->
                    <!--<id>push-image</id>-->
                    <!--<phase>deploy</phase>-->
                    <!--<goals>-->
                    <!--<goal>push</goal>-->
                    <!--</goals>-->
                    <!--<configuration>-->
                    <!--<configuration>-->
                    <!--<imageName>wso2/micro-integrator:${project.version}</imageName>-->
                    <!--</configuration>-->
                    <!--</execution>-->
                </executions>
            </plugin>
        </plugins>

        <resources>
            <resource>
                <directory>carbon-home/bin/</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/version.txt</include>
                </includes>
            </resource>
        </resources>
    </build>

    <properties>
        <docker.skip>true</docker.skip>
    </properties>
</project>
