<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.ow2.mind</groupId>
        <artifactId>mind-compiler</artifactId>
        <version>1.0</version>
    </parent>

    <artifactId>mindc</artifactId>
    <name>Integration module</name>

    <properties>
        <ow2.file.deploy.dir>incoming</ow2.file.deploy.dir>
    </properties>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>adl-backend</artifactId>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>idl-backend</artifactId>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>fractal-runtime</artifactId>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>plugin-loader</artifactId>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>   
            <artifactId>annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>fractal-adl-bundle</artifactId>
            <type>bundle</type>
            <scope>test</scope>
        </dependency>

        <dependency>
			<groupId>org.testng</groupId>
			<artifactId>testng</artifactId>
			<classifier>jdk15</classifier>
		</dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <!-- Generates binary assemblies at package phase. -->
                    <execution>
                        <id>bin-packages</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>src/assemble/bin-release.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>

                    <!-- Generates directory assembly for integration test -->
                    <execution>
                        <id>bin-dir</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>directory-single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>src/assemble/bin-release.xml</descriptor>
                            </descriptors>
                            <outputDirectory>
                                ${project.build.directory}
							</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <configuration>
                    <executable>make</executable>
                    <workingDirectory>
                        ${project.build.directory}/${project.build.finalName}-bin/${project.build.finalName}/examples
					</workingDirectory>
                    <arguments>
                        <argument>MIND_ROOT=../../</argument>
                        <argument>clean</argument>
                        <argument>all</argument>
                    </arguments>
                </configuration>
                <executions>
                    <execution>
                        <id>test assembly (compile helloworld)</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>integration-test</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>src-packages</id>
            <activation>
                <property>
                    <name>performRelease</name>
                    <value>true</value>
                </property>
            </activation>

            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>src-packages</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                                <configuration>
                                    <descriptors>
                                        <descriptor>src/assemble/src-release.xml</descriptor>
                                    </descriptors>
                                    <tarLongFileMode>gnu</tarLongFileMode>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>local-install</id>
            <activation>
                <property>
                    <name>local-install</name>
                </property>
            </activation>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>install-local</id>
                                <phase>install</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>${project.artifactId}</artifactId>
                                            <version>${project.version}</version>
                                            <type>tar.gz</type>
                                            <classifier>bin</classifier>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>${local-install}</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>release</id>
            <activation>
                <property>
                    <name>performRelease</name>
                    <value>true</value>
                </property>
            </activation>

            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <inherited>false</inherited>
                        <executions>
                            <execution>
                                <id>upload assemblies</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <tasks>
                                        <!-- This Ant task will deploy assembly files 
                                            on the OW2 forge in order to release them on the "File" section of the forge. -->
                                        <scp todir="${ow2.username}@${ow2.hostname}:${ow2.file.deploy.dir}" verbose="true" passphrase="" keyfile="${user.home}/.ssh/id_rsa">
                                            <fileset dir="${project.build.directory}">
                                                <include name="*.tar.bz2" />
                                                <include name="*.tar.gz" />
                                                <include name="*.zip" />
                                            </fileset>
                                        </scp>
                                    </tasks>
                                </configuration>
                            </execution>
                        </executions>
                        <dependencies>
                            <dependency>
                                <groupId>org.apache.ant</groupId>
                                <artifactId>ant-jsch</artifactId>
                                <version>1.7.0</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>test-deploy</id>

            <properties>
                <ow2.file.deploy.dir>/tmp/mind/incomming</ow2.file.deploy.dir>
            </properties>
        </profile>

    </profiles>
</project>