<?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/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>com.atlassian.amps</groupId>
        <artifactId>atlassian-plugin-sdk-parent</artifactId>
        <version>5.1.2-7610039</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>sdk-installer</artifactId>
    <packaging>pom</packaging>
    <name>SDK Installer</name>

    <profiles>
        <profile>
            <id>installer-win</id>
            <build>
                <finalName>atlassian-plugin-sdk</finalName>

                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>unpack-for-windows</id>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <phase>generate-resources</phase>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>atlassian-plugin-sdk</artifactId>
                                            <version>${project.version}</version>
                                            <type>zip</type>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>${project.build.directory}/win-unzip</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.1</version>
                        <executions>
                            <execution>
                                <id>installbuilder-windows</id>
                                <phase>compile</phase>
                                <configuration>
                                    <executable>${installbuilder.builder}</executable>
                                    <outputFile>${project.build.directory}/installbuilder-out.txt</outputFile>
                                    <arguments>
                                        <argument>build</argument>
                                        <argument>amps-installbuilder.xml</argument>
                                        <argument>windows</argument>
                                        <argument>--license</argument>
                                        <argument>${project.basedir}/installbuilder-license.xml</argument>
                                        <argument>--setvars</argument>
                                        <argument>project.version=${project.version}</argument>
                                        <argument>project.outputDirectory=${project.build.directory}</argument>
                                        <argument>sdkUnzipDir=${project.build.directory}/win-unzip/atlassian-plugin-sdk-${project.version}/*</argument>
                                    </arguments>
                                </configuration>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <version>${buildhelper.version}</version>
                        <executions>
                            <execution>
                                <id>parse-win-version</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>parse-version</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>attach-win-installer</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>attach-artifact</goal>
                                </goals>
                                <configuration>
                                    <artifacts>
                                        <artifact>
                                            <file>${project.build.directory}/atlassian-plugin-sdk-${project.version}-windows.exe</file>
                                            <type>exe</type>
                                        </artifact>
                                    </artifacts>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>installer-win-install4j</id>
            <build>
                <finalName>atlassian-plugin-sdk</finalName>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>unpack-atlassian-keystore</id>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <phase>generate-resources</phase>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>com.atlassian.keystore</groupId>
                                            <artifactId>atlassian-keystore</artifactId>
                                            <version>1.4</version>
                                            <outputDirectory>${keystore.location}</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                            <execution>
                                <id>unpack-for-windows</id>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <phase>generate-resources</phase>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>atlassian-plugin-sdk</artifactId>
                                            <version>${project.version}</version>
                                            <type>zip</type>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>${project.build.directory}/win-unzip</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.sonatype.install4j</groupId>
                        <artifactId>install4j-maven-plugin</artifactId>
                        <version>1.0.7</version>
                        <executions>
                            <execution>
                                <id>install4j-windows</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>compile</goal>
                                </goals>
                                <configuration>
                                    <installDir>${install4j.home}</installDir>
                                    <projectFile>src/main/install4j/atlassian-plugin-sdk.install4j</projectFile>
                                    <mediaTypes>windows</mediaTypes>
                                    <release>${project.version}</release>
                                    <winKeystorePassword>${windows.keystore.password}</winKeystorePassword>
                                    <variables>
                                        <keystore.home>${keystore.location}/keystore/secure</keystore.home>
                                        <project.version>${project.version}</project.version>
                                        <project.build.directory>${project.build.directory}</project.build.directory>
                                        <project.basedir>${project.basedir}</project.basedir>
                                        <sdk.unzip.directory>${project.build.directory}/win-unzip/atlassian-plugin-sdk-${project.version}</sdk.unzip.directory>
                                    </variables>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <version>${buildhelper.version}</version>
                        <executions>
                            <execution>
                                <id>parse-win-version</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>parse-version</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>attach-win-installer</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>attach-artifact</goal>
                                </goals>
                                <configuration>
                                    <artifacts>
                                        <artifact>
                                            <file>${project.build.directory}/media/atlassian-plugin-sdk-${project.version}-windows.exe</file>
                                            <type>exe</type>
                                        </artifact>
                                    </artifacts>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>installer-osx-install4j</id>
            <build>
                <finalName>atlassian-plugin-sdk</finalName>

                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>unpack-for-osx</id>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <phase>generate-resources</phase>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>atlassian-plugin-sdk</artifactId>
                                            <version>${project.version}</version>
                                            <type>tar.gz</type>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>${project.build.directory}/osx-unzip</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.sonatype.install4j</groupId>
                        <artifactId>install4j-maven-plugin</artifactId>
                        <version>1.0.7</version>
                        <executions>
                            <execution>
                                <id>install4j-osx</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>compile</goal>
                                </goals>
                                <configuration>
                                    <installDir>${install4j.home}</installDir>
                                    <projectFile>src/main/install4j/atlassian-plugin-sdk.install4j</projectFile>
                                    <mediaTypes>macosFolder</mediaTypes>
                                    <release>${project.version}</release>
                                    <macKeystorePassword>${mac.keystore.password}</macKeystorePassword>
                                    <variables>
                                        <keystore.home>${keystore.location}/keystore/secure</keystore.home>
                                        <project.version>${project.version}</project.version>
                                        <project.build.directory>${project.build.directory}</project.build.directory>
                                        <project.basedir>${project.basedir}</project.basedir>
                                        <sdk.unzip.directory>${project.build.directory}/osx-unzip/atlassian-plugin-sdk-${project.version}</sdk.unzip.directory>
                                    </variables>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <version>${buildhelper.version}</version>
                        <executions>
                            <execution>
                                <id>attach-osx-installer</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>attach-artifact</goal>
                                </goals>
                                <configuration>
                                    <artifacts>
                                        <artifact>
                                            <file>${project.build.directory}/media/atlassian-plugin-sdk-${project.version}-macos.dmg</file>
                                            <type>dmg</type>
                                        </artifact>
                                    </artifacts>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>installer-linux</id>
            <build>
                <finalName>atlassian-plugin-sdk</finalName>

                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <version>${buildhelper.version}</version>
                        <executions>
                            <execution>
                                <id>parse-deb-version</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>parse-version</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>timestamp-property</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>timestamp-property</goal>
                                </goals>
                                <configuration>
                                    <name>snap.ts</name>
                                    <pattern>yyyyMMddHHmmss</pattern>
                                </configuration>
                            </execution>
                            <execution>
                                <id>deb-version</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>regex-property</goal>
                                </goals>
                                <configuration>
                                    <name>deb.version</name>
                                    <value>${project.version}</value>
                                    <regex>-SNAPSHOT</regex>
                                    <replacement>~${snap.ts}</replacement>
                                    <failIfNoMatch>false</failIfNoMatch>
                                </configuration>
                            </execution>
                        
                            <execution>
                                <id>rpm-snapshot-version</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>regex-property</goal>
                                </goals>
                                <configuration>
                                    <name>rpm.ts.version</name>
                                    <value>${project.version}</value>
                                    <regex>-SNAPSHOT</regex>
                                    <replacement>_${snap.ts}_SNAPSHOT</replacement>
                                    <failIfNoMatch>false</failIfNoMatch>
                                </configuration>
                            </execution>
                            <execution>
                                <id>rpm-version</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>regex-property</goal>
                                </goals>
                                <configuration>
                                    <name>rpm.version</name>
                                    <value>${rpm.ts.version}</value>
                                    <regex>[-]</regex>
                                    <replacement>_</replacement>
                                    <failIfNoMatch>false</failIfNoMatch>
                                </configuration>
                            </execution>
                            <execution>
                                <id>attach-linux-installers</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>attach-artifact</goal>
                                </goals>
                                <configuration>
                                    <artifacts>
                                        <artifact>
                                            <file>${project.build.directory}/atlassian-plugin-sdk-${deb.version}.deb</file>
                                            <type>deb</type>
                                        </artifact>
                                        <artifact>
                                            <file>${project.build.directory}/atlassian-plugin-sdk-${rpm.version}.noarch.rpm</file>
                                            <type>rpm</type>
                                        </artifact>
                                    </artifacts>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>unpack-for-deb</id>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <phase>generate-resources</phase>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>atlassian-plugin-sdk</artifactId>
                                            <version>${project.version}</version>
                                            <type>tar.gz</type>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>${project.build.directory}/deb-work/usr/share/</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                            <execution>
                                <id>unpack-for-rpm</id>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <phase>generate-resources</phase>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>atlassian-plugin-sdk</artifactId>
                                            <version>${project.version}</version>
                                            <type>tar.gz</type>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>${project.build.directory}/rpm-work/unzip/usr/share/</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-deb</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                                <configuration>
                                    <finalName>deb-work</finalName>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                    <appendAssemblyId>false</appendAssemblyId>
                                    <attach>false</attach>
                                    <descriptors>
                                        <descriptor>src/main/assembly/assembly-deb.xml</descriptor>
                                    </descriptors>
                                </configuration>
                            </execution>
                            <execution>
                                <id>copy-rpm</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                                <configuration>
                                    <finalName>rpm-work</finalName>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                    <appendAssemblyId>false</appendAssemblyId>
                                    <attach>false</attach>
                                    <descriptors>
                                        <descriptor>src/main/assembly/assembly-rpm.xml</descriptor>
                                    </descriptors>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.1</version>
                        <executions>
                            <execution>
                                <id>native-deb</id>
                                <phase>package</phase>
                                <configuration>
                                    <executable>${project.basedir}/deb-builder.sh</executable>
                                    <outputFile>${project.build.directory}/dpkg-out.txt</outputFile>
                                    <arguments>
                                        <argument>${project.version}</argument>
                                        <argument>${deb.version}</argument>
                                    </arguments>
                                </configuration>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>native-rpm</id>
                                <phase>package</phase>
                                <configuration>
                                    <executable>${project.basedir}/rpm-builder.sh</executable>
                                    <outputFile>${project.build.directory}/rpm-out.txt</outputFile>
                                    <arguments>
                                        <argument>${project.version}</argument>
                                        <argument>${rpm.version}</argument>
                                    </arguments>
                                </configuration>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>installer-osx</id>
            <build>
                <finalName>atlassian-plugin-sdk</finalName>

                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>unpack-for-osx</id>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <phase>generate-resources</phase>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>atlassian-plugin-sdk</artifactId>
                                            <version>${project.version}</version>
                                            <type>tar.gz</type>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>${project.build.directory}/osx-unzip</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.1</version>
                        <executions>
                            <execution>
                                <id>native-osx</id>
                                <phase>package</phase>
                                <configuration>
                                    <executable>${project.basedir}/osx-builder.sh</executable>
                                    <outputFile>${project.build.directory}/osx-out.txt</outputFile>
                                    <arguments>
                                        <argument>${project.version}</argument>
                                    </arguments>
                                </configuration>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-osx</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                                <configuration>
                                    <finalName>osx-work</finalName>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                    <appendAssemblyId>false</appendAssemblyId>
                                    <attach>false</attach>
                                    <descriptors>
                                        <descriptor>src/main/assembly/assembly-osx.xml</descriptor>
                                    </descriptors>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <version>${buildhelper.version}</version>
                        <executions>
                            <execution>
                                <id>attach-osx-installer</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>attach-artifact</goal>
                                </goals>
                                <configuration>
                                    <artifacts>
                                        <artifact>
                                            <file>${project.build.directory}/atlassian-plugin-sdk-${project.version}.pkg</file>
                                            <type>pkg</type>
                                        </artifact>
                                    </artifacts>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    <properties>
        <installbuilder.builder>/tools/installbuilder/bin/builder</installbuilder.builder>
        <keystore.location>${project.build.directory}/atlassian-keystore</keystore.location>
        <buildhelper.version>1.7</buildhelper.version>
        <sdk.scp.user>${user.name}</sdk.scp.user>
        <sdk.scp.host>plugin-sdk-repo-fe.internal.atlassian.com</sdk.scp.host>
        <sdk.scp.key>${user.home}/.ssh/id_rsa</sdk.scp.key>
    </properties>
</project>
