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

    Copyright (c) 2012-2018 Red Hat, Inc.
    This program and the accompanying materials are made
    available under the terms of the Eclipse Public License 2.0
    which is available at https://www.eclipse.org/legal/epl-2.0/

    SPDX-License-Identifier: EPL-2.0

    Contributors:
      Red Hat, Inc. - initial API and implementation

-->
<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>che-agents-parent</artifactId>
        <groupId>org.eclipse.che</groupId>
        <version>6.10.0</version>
    </parent>
    <artifactId>terminal-agent</artifactId>
    <name>Agent :: Terminal</name>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-sources</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <!--To not use godep tool vendored dependencies are copied into correct place of GOPATH
                                by maven-->
                                <copy todir="${project.build.directory}/go-workspace/src">
                                    <fileset dir="${basedir}/../go-agents/vendor/" includes="**/*" />
                                </copy>
                                <copy todir="${project.build.directory}/go-workspace/src/github.com/eclipse/che/agents/go-agents">
                                    <fileset dir="${basedir}/../go-agents/">
                                        <exclude name="vendor/" />
                                        <exclude name="target/" />
                                        <include name="**/*.*go" />
                                    </fileset>
                                </copy>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.soebes.maven.plugins</groupId>
                <artifactId>iterator-maven-plugin</artifactId>
                <version>0.5.0</version>
                <executions>
                    <execution>
                        <id>compile-go-agents</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>iterator</goal>
                        </goals>
                        <configuration>
                            <itemsWithProperties>
                                <itemWithProperty>
                                    <name>linux_arm5</name>
                                    <properties>
                                        <go.target.os>linux</go.target.os>
                                        <go.target.architecture>arm</go.target.architecture>
                                        <go.target.arm.version>5</go.target.arm.version>
                                    </properties>
                                </itemWithProperty>
                                <itemWithProperty>
                                    <name>linux_arm6</name>
                                    <properties>
                                        <go.target.os>linux</go.target.os>
                                        <go.target.architecture>arm</go.target.architecture>
                                        <go.target.arm.version>6</go.target.arm.version>
                                    </properties>
                                </itemWithProperty>
                                <itemWithProperty>
                                    <name>linux_arm7</name>
                                    <properties>
                                        <go.target.os>linux</go.target.os>
                                        <go.target.architecture>arm</go.target.architecture>
                                        <go.target.arm.version>7</go.target.arm.version>
                                    </properties>
                                </itemWithProperty>
                                <itemWithProperty>
                                    <name>linux_amd64</name>
                                    <properties>
                                        <go.target.os>linux</go.target.os>
                                        <go.target.architecture>amd64</go.target.architecture>
                                    </properties>
                                </itemWithProperty>
                                <itemWithProperty>
                                    <name>linux_i386</name>
                                    <properties>
                                        <go.target.os>linux</go.target.os>
                                        <go.target.architecture>386</go.target.architecture>
                                    </properties>
                                </itemWithProperty>
                            </itemsWithProperties>
                            <pluginExecutors>
                                <pluginExecutor>
                                    <plugin>
                                        <groupId>org.codehaus.mojo</groupId>
                                        <artifactId>exec-maven-plugin</artifactId>
                                    </plugin>
                                    <goal>exec</goal>
                                    <configuration>
                                        <executable>go</executable>
                                        <workingDirectory>${project.build.directory}/go-workspace/src/github.com/eclipse/che/agents/go-agents/terminal-agent</workingDirectory>
                                        <arguments>
                                            <argument>build</argument>
                                            <argument>-a</argument>
                                            <argument>-installsuffix</argument>
                                            <argument>cgo</argument>
                                            <argument>-o</argument>
                                            <argument>${project.build.directory}/${item}/che-websocket-terminal</argument>
                                        </arguments>
                                        <environmentVariables>
                                            <CGO_ENABLED>0</CGO_ENABLED>
                                            <GOPATH>${project.build.directory}/go-workspace</GOPATH>
                                            <GOOS>${go.target.os}</GOOS>
                                            <GOARCH>${go.target.architecture}</GOARCH>
                                            <GOARM>${go.target.arm.version}</GOARM>
                                        </environmentVariables>
                                    </configuration>
                                </pluginExecutor>
                            </pluginExecutors>
                        </configuration>
                    </execution>
                    <execution>
                        <id>assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>iterator</goal>
                        </goals>
                        <configuration>
                            <items>
                                <item>linux_arm5</item>
                                <item>linux_arm6</item>
                                <item>linux_arm7</item>
                                <item>linux_amd64</item>
                                <item>linux_i386</item>
                            </items>
                            <pluginExecutors>
                                <pluginExecutor>
                                    <plugin>
                                        <artifactId>maven-assembly-plugin</artifactId>
                                    </plugin>
                                    <goal>single</goal>
                                    <configuration>
                                        <tarLongFileMode>posix</tarLongFileMode>
                                        <descriptors>
                                            <descriptor>${basedir}/src/assembly/assembly.xml</descriptor>
                                        </descriptors>
                                    </configuration>
                                </pluginExecutor>
                            </pluginExecutors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
