<!--
  ~ Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
  ~
  ~ WSO2 Inc. licenses this file to you 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>
        <artifactId>awslambda-extension-parent</artifactId>
        <groupId>org.ballerinax.awslambda</groupId>
        <version>1.2.59</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>awslambda-extension-balo</artifactId>

    <packaging>pom</packaging>
    <name>Ballerinax - AWS Lambda Extension Balo</name>
    <url>https://ballerina.io</url>

    <profiles>
        <profile>
            <id>Windows</id>
            <activation>
                <os>
                    <family>Windows</family>
                </os>
            </activation>
            <properties>
                <script.extension>.bat</script.extension>
            </properties>
        </profile>
        <profile>
            <id>unix</id>
            <activation>
                <os>
                    <family>unix</family>
                </os>
            </activation>
            <properties>
                <script.extension>.sh</script.extension>
            </properties>
        </profile>
    </profiles>

    <dependencies>
        <dependency>
            <groupId>org.ballerinax.awslambda</groupId>
            <artifactId>awslambda-extension</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>exec-maven-plugin</artifactId>
                <groupId>org.codehaus.mojo</groupId>
                <executions>
                    <execution>
                        <id>GenerateBalo</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${project.basedir}/scripts/gen-balo${script.extension}</executable>
                            <arguments>
                                <argument>
                                    ${project.build.directory}/extracted-distribution/jballerina-tools-${ballerina.lang.version}
                                </argument>
                                <argument>
                                    ${project.basedir}
                                </argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.ballerinalang</groupId>
                                    <artifactId>jballerina-tools</artifactId>
                                    <version>${ballerina.lang.version}</version>
                                    <type>zip</type>
                                    <outputDirectory>${project.build.directory}/extracted-distribution/
                                    </outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.ballerinax.awslambda</groupId>
                                    <artifactId>awslambda-extension</artifactId>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>
                                ${project.build.directory}/extracted-distribution/jballerina-tools-${ballerina.lang.version}/bre/lib/
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>src/main/assembly/bin.xml</descriptor>
                            </descriptors>
                            <finalName>awslambda-artifacts</finalName>
                            <appendAssemblyId>false</appendAssemblyId>
                            <outputDirectory>${project.build.directory}/extracted-distribution/</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
