<?xml version="1.0"?>
<!--

    Copyright 2017 ZTE Corporation.

    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>
        <groupId>org.onap.aai.esr-gui</groupId>
        <artifactId>aai-esr-gui</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>httpserver</artifactId>
    <name>httpserver</name>
    <packaging>pom</packaging>

    <properties>
        <packagename>httpserver</packagename>
        <tomcat.version>8.5.6</tomcat.version>
    </properties>

    <profiles>
        <profile>
            <id>env-windows</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
            </activation>
            <properties>
                <build-cmd>../build.bat</build-cmd>
            </properties>
        </profile>
        <profile>
            <id>env-unix</id>
            <activation>
                <os>
                    <family>unix</family>
                </os>
            </activation>
            <properties>
                <build-cmd>sh ../build.sh</build-cmd>
            </properties>
        </profile>
    </profiles>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-tomcat-to-temporary-dir</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.apache.tomcat</groupId>
                                    <artifactId>tomcat</artifactId>
                                    <type>zip</type>
                                    <outputDirectory>target/tomcat</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-tomcat-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/assembly/tomcat</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${basedir}/target/tomcat/apache-tomcat-${tomcat.version}</directory>
                                    <filtering>false</filtering>
                                    <includes>
                                        <include>**/*</include>
                                    </includes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <version>1.4</version>
                <configuration>
                    <timestampFormat>yyyyMMdd-HHmmss</timestampFormat>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>create-timestamp</goal>
                        </goals>
                    </execution>
                </executions>
                <inherited>false</inherited>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>zip</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks name="${project.artifactId}">
                                <delete file="target/assembly/tomcat/conf/server.xml"/>
								<delete file="target/assembly/tomcat/conf/logging.properties"/>
                                <delete file="target/assembly/tomcat/conf/web.xml"/>
								<delete file="target/assembly/tomcat/bin/catalina.bat"/>
                                <delete file="target/assembly/tomcat/bin/catalina.sh"/>
                                <copydir src="src/main/assembly/" dest="target/assembly" />
								<!--<copydir src="dist/" dest="target/assembly/tomcat/webapps/ROOT/esr-gui"></copydir>
                                <copy todir="target/assembly/tomcat/webapps/ROOT/esr-gui">
                                    <fileset dir="blueprint/">
                                        <include name="readme.txt" />  
                                    </fileset> 
									<fileset dir="dist/"></fileset>									
                                    <filterset>
                                        <filter token="VERSION" value="${project.version}"/>
                                        <filter token="TIME" value="${timestamp}"/>
                                    </filterset>
                                </copy>-->
                                <zip destfile="target/${packagename}-${project.version}.zip" update="true">
                                    <zipfileset dir="target/assembly" includes="**"/>
                                </zip>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>  
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>target/${packagename}-${project.version}.zip</file>
                                    <type>zip</type>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat</artifactId>
            <version>${tomcat.version}</version>
            <type>zip</type>
        </dependency>
    </dependencies>
</project>