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

    AET

    Copyright (C) 2013 Cognifide 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>aet-root</artifactId>
    <groupId>com.cognifide.aet</groupId>
    <version>3.2.2</version>
  </parent>

  <artifactId>zip</artifactId>
  <packaging>pom</packaging>

  <name>AET :: Zip</name>

  <description>This module collects all AET artifacts and zip them into one file.</description>

  <properties>
    <release.artifacts.dir>${project.build.directory}/packages-${project.version}
    </release.artifacts.dir>

    <!-- zip files for release -->
    <release.bundles>bundles.zip</release.bundles>
    <release.features>features.zip</release.features>
    <release.report>report.zip</release.report>
    <release.sample-site>sample-site.zip</release.sample-site>
    <release.configs>configs.zip</release.configs>
  </properties>

  <dependencyManagement>
    <dependencies>
      <!--
          core bundles
          dependencies configured here as they are needed only for release
      -->
      <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>cleaner</artifactId>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>communication</artifactId>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>proxy</artifactId>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>runner</artifactId>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>validation</artifactId>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>datastorage</artifactId>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>worker</artifactId>
        <version>${project.version}</version>
      </dependency>

      <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>jobs</artifactId>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>rest-endpoint</artifactId>
        <version>${project.version}</version>
      </dependency>

      <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>test-executor</artifactId>
        <version>${project.version}</version>
      </dependency>

      <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>report</artifactId>
        <version>${project.version}</version>
        <type>zip</type>
      </dependency>

      <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>configs</artifactId>
        <version>${project.version}</version>
        <type>zip</type>
      </dependency>
      <!--
          sample site is only available from local maven repo
          please build the module locally
      -->
      <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>sample-site</artifactId>
        <version>${project.version}</version>
        <type>war</type>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <!-- let Maven know that we depends on all AET artifacts -->
  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>cleaner</artifactId>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>communication</artifactId>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>proxy</artifactId>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>runner</artifactId>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>validation</artifactId>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>datastorage</artifactId>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>worker</artifactId>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>jobs</artifactId>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>rest-endpoint</artifactId>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>test-executor</artifactId>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>report</artifactId>
      <type>zip</type>
    </dependency>

    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>configs</artifactId>
      <type>zip</type>
    </dependency>
  </dependencies>

  <profiles>
    <profile>
      <id>zip</id>
      <build>
        <plugins>
          <!-- collect required resources in single directory -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
              <execution>
                <id>copy-features-xml-file</id>
                <phase>install</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}</outputDirectory>
                  <resources>
                    <resource>
                      <directory>${project.parent.basedir}/osgi-dependencies</directory>
                      <includes>
                        <include>aet-features.xml</include>
                        <include>aet-webconsole.xml</include>
                      </includes>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>get-bundles-from-local-repo</id>
                <phase>install</phase>
                <goals>
                  <goal>copy</goal>
                </goals>
                <configuration>
                  <!--
                    for bundles filenames see https://github.com/Cognifide/aet/issues/248
                  -->
                  <prependGroupId>true</prependGroupId>
                  <stripVersion>true</stripVersion>
                  <artifactItems>
                    <!-- dependencies wrapped for OSGi -->
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>selenium</artifactId>
                    </artifactItem>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>w3chtml5validator</artifactId>
                    </artifactItem>
                    <!-- APIs -->
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>communication-api</artifactId>
                    </artifactItem>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>datastorage-api</artifactId>
                    </artifactItem>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>jobs-api</artifactId>
                    </artifactItem>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>validation-api</artifactId>
                    </artifactItem>
                    <!-- core bundles -->
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>cleaner</artifactId>
                    </artifactItem>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>communication</artifactId>
                    </artifactItem>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>proxy</artifactId>
                    </artifactItem>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>runner</artifactId>
                    </artifactItem>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>validation</artifactId>
                    </artifactItem>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>datastorage</artifactId>
                    </artifactItem>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>worker</artifactId>
                    </artifactItem>

                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>jobs</artifactId>
                    </artifactItem>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>rest-endpoint</artifactId>
                    </artifactItem>

                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>test-executor</artifactId>
                    </artifactItem>

                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>report</artifactId>
                      <type>zip</type>
                    </artifactItem>

                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>configs</artifactId>
                      <type>zip</type>
                    </artifactItem>
                    <!--
                        sample site is only available from local maven repo
                        please build the module locally
                    -->
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>sample-site</artifactId>
                      <type>war</type>
                    </artifactItem>

                  </artifactItems>
                  <outputDirectory>${project.build.directory}</outputDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <!-- zip release resources -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>truezip-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>zip-features</id>
                <phase>install</phase>
                <goals>
                  <goal>copy</goal>
                </goals>
                <configuration>
                  <fileset>
                    <directory>${project.build.directory}</directory>
                    <includes>
                      <include>aet-features.xml</include>
                      <include>aet-webconsole.xml</include>
                    </includes>
                    <outputDirectory>${release.artifacts.dir}/${release.features}</outputDirectory>
                  </fileset>
                </configuration>
              </execution>
              <execution>
                <id>zip-bundles</id>
                <phase>install</phase>
                <goals>
                  <goal>copy</goal>
                </goals>
                <configuration>
                  <fileset>
                    <directory>${project.build.directory}</directory>
                    <includes>
                      <!-- dependencies wrapped for OSGi -->
                      <include>${project.groupId}.selenium.jar</include>
                      <include>${project.groupId}.w3chtml5validator.jar</include>
                      <!-- APIs -->
                      <include>${project.groupId}.communication-api.jar</include>
                      <include>${project.groupId}.datastorage-api.jar</include>
                      <include>${project.groupId}.jobs-api.jar</include>
                      <include>${project.groupId}.validation-api.jar</include>
                      <!-- core bundles -->
                      <include>${project.groupId}.cleaner.jar</include>
                      <include>${project.groupId}.communication.jar</include>
                      <include>${project.groupId}.proxy.jar</include>
                      <include>${project.groupId}.runner.jar</include>
                      <include>${project.groupId}.validation.jar</include>
                      <include>${project.groupId}.datastorage.jar</include>
                      <include>${project.groupId}.worker.jar</include>

                      <include>${project.groupId}.jobs.jar</include>
                      <include>${project.groupId}.rest-endpoint.jar</include>

                      <include>${project.groupId}.test-executor.jar</include>
                    </includes>
                    <outputDirectory>${release.artifacts.dir}/${release.bundles}</outputDirectory>
                  </fileset>
                </configuration>
              </execution>
              <execution>
                <id>repackage-sample-site</id>
                <phase>install</phase>
                <goals>
                  <goal>cp</goal>
                </goals>
                <configuration>
                  <from>
                    ${project.build.directory}/${project.groupId}.sample-site.war
                  </from>
                  <to>${project.build.directory}/sample-site.war</to>
                </configuration>
              </execution>
              <execution>
                <id>zip-sample-site</id>
                <phase>install</phase>
                <goals>
                  <goal>copy</goal>
                </goals>
                <configuration>
                  <fileset>
                    <directory>${project.build.directory}</directory>
                    <includes>
                      <include>sample-site.war</include>
                    </includes>
                    <outputDirectory>${release.artifacts.dir}/${release.sample-site}
                    </outputDirectory>
                  </fileset>
                </configuration>
              </execution>
              <execution>
                <id>repackage-configs</id>
                <phase>install</phase>
                <goals>
                  <goal>cp</goal>
                </goals>
                <configuration>
                  <from>
                    ${project.build.directory}/${project.groupId}.configs.zip
                  </from>
                  <to>${release.artifacts.dir}/${release.configs}</to>
                </configuration>
              </execution>
              <execution>
                <id>repackage-report-zip</id>
                <phase>install</phase>
                <goals>
                  <goal>cp</goal>
                </goals>
                <configuration>
                  <from>
                    ${project.build.directory}/${project.groupId}.report.zip
                  </from>
                  <to>${release.artifacts.dir}/${release.report}</to>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      <dependencies>
        <!--
            sample site is only available from local maven repo
            please build the module locally
            this dependency is moved to profile in order to not break builds
            if integration-tests module is not built yet
        -->
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>sample-site</artifactId>
          <type>war</type>
        </dependency>
      </dependencies>
    </profile>

    <profile>
      <id>upload</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>wagon-maven-plugin</artifactId>
            <executions>
              <!-- skip execution inherited from parent -->
              <execution>
                <id>upload-single-bundle-to-karaf</id>
                <phase>none</phase>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
