<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>
    <groupId>software.amazon.awssdk.crt</groupId>
    <artifactId>aws-crt</artifactId>
    <packaging>jar</packaging>
    <version>0.3.21</version>
    <name>${project.groupId}:${project.artifactId}</name>
    <description>Java bindings for the AWS SDK Common Runtime</description>
    <url>https://github.com/awslabs/aws-crt-java</url>

    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>AWS SDK Common Runtime Team</name>
            <email>aws-sdk-common-runtime@amazon.com</email>
            <organization>Amazon Web Services</organization>
            <organizationUrl>https://aws.amazon.com</organizationUrl>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:git://github.com/awslabs/aws-crt-java.git</connection>
        <developerConnection>scm:git:ssh://github.com:awslabs/aws-crt-java.git</developerConnection>
        <url>http://github.com/awslabs/aws-crt-java/tree/master</url>
    </scm>

    <properties>
        <cmake.command>cmake</cmake.command>
        <cmake.buildtype>Release</cmake.buildtype>
        <cmake.binaries>target/cmake-build</cmake.binaries>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <profiles>
        <profile>
            <!-- Windows profile: find cmake generators and use ALL_BUILD target 
                NOTE: CMake generator will be cached to target/cmake-build/cmake.properties, delete or edit this
                file to change VS version
                -->
            <id>windows-vs</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
            </activation>
            <properties>
                <cmake.command>"${project.basedir}/vs_cmake.bat"</cmake.command>
                <cmake.target>ALL_BUILD</cmake.target>
                <cmake.cflags/>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.3.2</version>
                        <executions>
                            <execution>
                                <id>configure-visual-studio</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>"${project.basedir}/vs_config.bat"</executable>
                                    <arguments>
                                        <argument>${cmake.binaries}</argument>
                                    </arguments>
                                    <workingDirectory>.</workingDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>properties-maven-plugin</artifactId>
                        <version>1.0.0</version>
                        <executions>
                            <execution>
                                <id>read-cmake-vs-generator</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>read-project-properties</goal>
                                </goals>
                                <configuration>
                                    <files>
                                        <file>${cmake.binaries}/cmake.properties</file>
                                    </files>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <!-- Unix/Linux/OSX profiles: use makefiles and the "all" compile target -->
        <profile>
            <id>unix-make</id>
            <activation>
                <os>
                    <family>unix</family>
                </os>
            </activation>
            <properties>
                <cmake.generator>Unix Makefiles</cmake.generator>
                <cmake.target>all</cmake.target>
                <cmake.cflags/>
            </properties>
        </profile>
        <profile>
            <id>mac-make</id>
            <activation>
                <os>
                    <family>mac</family>
                </os>
            </activation>
            <properties>
                <cmake.generator>Unix Makefiles</cmake.generator>
                <cmake.target>all</cmake.target>
                <cmake.cflags/>
            </properties>
        </profile>
        <!-- 32-bit Unix -->
        <profile>
            <id>unix-x86</id>
            <activation>
                <os>
                    <family>unix</family>
                    <arch>i386</arch>
                </os>
            </activation>
            <properties>
                <cmake.cflags>-m32</cmake.cflags>
            </properties>
        </profile>
        <profile>
            <id>debug-native</id>
            <activation>
                <property>
                    <name>debug.native</name>
                </property>
            </activation>
            <properties>
                <cmake.buildtype>Debug</cmake.buildtype>
            </properties>
        </profile>
        <!-- native compilation -->
        <profile>
            <id>build-shared-lib</id>
            <activation>
                <property>
                    <name>!shared-lib.skip</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <!-- cmake configure and build -->
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.3.2</version>
                        <executions>
                            <!-- cmake configure -->
                            <execution>
                                <id>cmake-configure</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>${cmake.command}</executable>
                                    <workingDirectory>${cmake.binaries}</workingDirectory>
                                    <arguments>
                                        <argument>-G${cmake.generator}</argument>
                                        <argument>-DCMAKE_BUILD_TYPE=${cmake.buildtype}</argument>
                                        <argument>-DCMAKE_EXPORT_COMPILE_COMMANDS=ON</argument>
                                        <argument>-DBUILD_DEPS=ON</argument>
                                        <argument>-DCMAKE_C_FLAGS=${cmake.cflags}</argument>
                                        <argument>${project.basedir}</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                            <!-- cmake build -->
                            <execution>
                                <id>make</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>${cmake.command}</executable>
                                    <workingDirectory>${cmake.binaries}</workingDirectory>
                                    <arguments>
                                        <argument>--build</argument>
                                        <argument>.</argument>
                                        <argument>--target</argument>
                                        <argument>${cmake.target}</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>release</id>
            <distributionManagement>
                <snapshotRepository>
                    <id>ossrh</id>
                    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
                </snapshotRepository>
            </distributionManagement>
            <build>
                <plugins>
                    <!-- staging/release to Sonatype -->
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.8</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>false</autoReleaseAfterClose>
                        </configuration>
                    </plugin>
                    <!-- source jar -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>2.2.1</version>
                        <executions>
                            <execution>
                            <id>attach-sources</id>
                            <goals>
                                <goal>jar-no-fork</goal>
                            </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- javadoc jar -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.9.1</version>
                        <executions>
                            <execution>
                            <id>attach-javadocs</id>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- GPG signing -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.5</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                                <configuration>
                                    <keyname>${gpg.keyname}</keyname>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <!-- shared libs built via cmake -->
            <resource>
                <directory>${cmake.binaries}/lib</directory>
                <excludes>
                    <exclude>**/*.ilk</exclude><!-- no one needs incremental linker files in their jar -->
                    <exclude>**/*.pdb</exclude><!-- do not package pdbs, comment this out to debug C code -->
                </excludes>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- make build dir for cmake -->
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>create-build-dir</id>
                        <phase>initialize</phase>
                        <configuration>
                            <tasks>
                                <mkdir dir="${cmake.binaries}"/>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- unit test configuration -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.21.0</version>
                <configuration>
                    <systemPropertyVariables>
                        <certificate>${crt.test.certificate}</certificate>
                        <privatekey>${crt.test.privatekey}</privatekey>
                        <endpoint>${crt.test.endpoint}</endpoint>
                        <rootca>${crt.test.rootca}</rootca>
                    </systemPropertyVariables>
                    <shutdown>kill</shutdown>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
