<?xml version="1.0" encoding="UTF-8"?>
<!--
    Copyright 2014-2015 by Cloudsoft Corporation Limited

    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">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>brooklyn-clocker-parent</artifactId>
        <groupId>io.brooklyn.clocker</groupId>
        <version>1.2.0</version>  <!-- CLOCKER_VERSION -->
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>brooklyn-clocker-dist</artifactId>
    <name>Clocker Distribution</name>
    <description>
        Clocker distribution archive with example Brooklyn blueprints
    </description>

    <properties>
        <testLocation>jclouds:softlayer:ams01</testLocation>

        <!-- maven-brooklyn-plugin -->
        <brookyn.server>http://127.0.0.1:8081</brookyn.server>
        <brookyn.user>admin</brookyn.user>
        <brookyn.password>password</brookyn.password>
        <brookyn.timeout>50</brookyn.timeout>
        <brookyn.pollPeriod>30</brookyn.pollPeriod>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.brooklyn.clocker</groupId>
            <artifactId>brooklyn-clocker-extras</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <dependency>
            <groupId>io.brooklyn.clocker</groupId>
            <artifactId>brooklyn-clocker-patches</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <dependency>
            <groupId>io.brooklyn.clocker</groupId>
            <artifactId>brooklyn-clocker-docker</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <dependency>
            <groupId>io.brooklyn.clocker</groupId>
            <artifactId>brooklyn-clocker-mesos</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <dependency>
            <groupId>io.brooklyn.clocker</groupId>
            <artifactId>brooklyn-clocker-jsgui</artifactId>
            <version>${project.parent.version}</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>org.apache.brooklyn</groupId>
            <artifactId>brooklyn-jsgui</artifactId>
            <version>${brooklyn.version}</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>io.brooklyn.clocker</groupId>
            <artifactId>brooklyn-clocker-console</artifactId>
            <version>${project.parent.version}</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>org.apache.brooklyn</groupId>
            <artifactId>brooklyn-logback-xml</artifactId>
            <version>${brooklyn.version}</version>
            <scope>provided</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.apache.brooklyn</groupId>
            <artifactId>brooklyn-rest-client</artifactId>
            <version>${brooklyn.version}</version>
            <scope>test</scope>
            <!-- Exclusions added due to maven issue.
                 Whilst this is scope test, maven was still getting the versions from the children.
                 Excluding these dependencies solves this issue.
            -->
            <exclusions>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-databind</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-annotations</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.brooklyn</groupId>
            <artifactId>brooklyn-test-support</artifactId>
            <version>${brooklyn.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.brooklyn</groupId>
            <artifactId>brooklyn-core</artifactId>
            <version>${brooklyn.version}</version>
            <scope>test</scope>
            <classifier>tests</classifier>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**/*IntegrationTest.java</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/assembly/assembly.xml</descriptor>
                    </descriptors>
                    <finalName>brooklyn-clocker</finalName>
                </configuration>
                <executions>
                    <execution>
                        <id>build-distribution-archive</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <configuration>
                    <instructions>
                        <!-- OSGi specific instruction -->
                        <Import-Package>!io.airlift.command,*</Import-Package>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifestFile>
                            ${project.build.outputDirectory}/META-INF/MANIFEST.MF
                        </manifestFile>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>integration</id>
            <build>
                <resources>
                    <resource>
                        <directory>${project.basedir}/src/main/assembly/conf</directory>
                        <includes>
                            <include>*.pem</include>
                        </includes>
                    </resource>
                </resources>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>process-resources</id>
                                <phase>process-resources</phase>
                                <configuration>
                                    <target>
                                        <chmod file="${project.build.outputDirectory}/brooklyn.properties" perm="600"/>
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>io.brooklyn.maven</groupId>
                        <artifactId>brooklyn-maven-plugin</artifactId>
                        <version>0.3.0-SNAPSHOT</version>
                        <executions>
                            <execution>
                                <id>Start and deploy Clocker</id>
                                <goals>
                                    <goal>start-server</goal>
                                    <goal>deploy</goal>
                                    <goal>sensor</goal>
                                    <goal>stop</goal>
                                </goals>
                                <configuration>
                                    <mainClass>clocker.main.Main</mainClass>
                                    <bindPort>${bindPort}</bindPort>
                                    <pollPeriod>${brookyn.pollPeriod}</pollPeriod>
                                    <timeout>30</timeout><!--minutes-->
                                    <serverClasspathScope>runtime</serverClasspathScope>
                                    <bindAddress>localhost</bindAddress>
                                    <arguments>
                                        <argument>--catalogInitial</argument>
                                        <argument>${project.basedir}/src/main/assembly/conf/brooklyn/default.catalog.bom</argument>
                                        <argument>--localBrooklynProperties</argument>
                                        <argument>${project.build.outputDirectory}/brooklyn.properties</argument>
                                    </arguments>
                                    <blueprint>${project.basedir}/src/main/assembly/files/blueprints/docker-host.yaml</blueprint>
                                    <sensor>service.isUp</sensor>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>QA</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.bazaarvoice.maven.plugins</groupId>
                        <artifactId>s3-upload-maven-plugin</artifactId>
                        <version>1.2</version>
                        <executions>
                            <execution>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>s3-upload</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <bucketName>clocker-latest</bucketName>
                            <source>dist/target/brooklyn-clocker-dist.tar.gz</source>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>io.cloudsoft.amp</groupId>
                        <artifactId>test-framework-maven-plugin</artifactId>
                        <version>1.1-SNAPSHOT</version>
                        <inherited>false</inherited>
                        <executions>
                            <execution>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>brooklyn-test</goal>
                                </goals>
                                <configuration>
                                    <ampTestClusterUrl>http://169.50.81.105:8081</ampTestClusterUrl>
                                    <locationFolderURI>${project.build.testOutputDirectory}/quality_assurance/locations</locationFolderURI>
                                    <testAppFileURI>${project.build.testOutputDirectory}/quality_assurance/apps/nodejs_test.yaml</testAppFileURI>
                                    <testSpecFileURI>${project.build.testOutputDirectory}/quality_assurance/combined_test.yaml</testSpecFileURI>
                                    <noTearDownOnFailure>true</noTearDownOnFailure>
                                    <verbose>false</verbose>
                                    <maxTestDuration>80m</maxTestDuration>
                                    <ampTestClusterUsername>brooklyn</ampTestClusterUsername>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
