<!--
  ~ Copyright (c) Microsoft. All rights reserved.
  ~ Licensed under the MIT license. See License.txt in the project root.
  -->

<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>

  <groupId>com.microsoft.alm</groupId>
  <artifactId>oauth2-useragent-parent</artifactId>
  <version>0.11.3</version>
  <packaging>pom</packaging>

  <name>Parent for Microsoft OAuth 2.0 User Agent library for Java</name>
  <description>This POM exists only to support the multi-module oauth2-useragent project and contains project metadata common to all modules.</description>
  <url>https://www.visualstudio.com/downloads/download-visual-studio-vs</url>

  <licenses>
    <license>
      <name>MIT License</name>
      <url>https://opensource.org/licenses/mit-license.php</url>
    </license>
  </licenses>

  <developers>
    <developer>
      <name>Oli Dagenais</name>
      <email>olivida@microsoft.com</email>
      <organization>Microsoft</organization>
      <organizationUrl>https://www.microsoft.com/</organizationUrl>
    </developer>
  </developers>

  <scm>
    <connection>scm:git:https://github.com/Microsoft/oauth2-useragent.git</connection>
    <developerConnection>scm:git:https://github.com/Microsoft/oauth2-useragent.git</developerConnection>
    <url>https://github.com/Microsoft/oauth2-useragent</url>
    <tag>oauth2-useragent-0.11.3</tag>
  </scm>

  <distributionManagement>
    <snapshotRepository>
      <id>ossrh</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </snapshotRepository>
    <repository>
      <id>ossrh</id>
      <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
    </repository>
  </distributionManagement>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <swt.version>4.4.2</swt.version>
    <!-- The following properties are set during the "initialize" phase by some Groovy code below.
    They must not be present in this element, even if the IDE says their use can't be resolved.
    <SWT_TEST_VM_OPTIONS />
    <SWT_DEPENDENCY_EXCLUDES />
    <SWT_RUNTIME_JAR />
    -->
  </properties>

  <modules>
    <module>oauth2-useragent-core</module>
    <module>oauth2-useragent-javafx</module>
    <module>oauth2-useragent-swt</module>
    <!-- The following module MUST go after core and the providers -->
    <module>oauth2-useragent</module>
    <module>oauth2-useragent-tester</module>
    <!-- This module MUST be last! -->
    <module>oauth2-useragent-dummy</module>
  </modules>

  <repositories>
    <repository>
      <id>maven-eclipse-repo</id>
      <url>https://maven-eclipse.github.io/maven</url>
    </repository>
  </repositories>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.microsoft.alm</groupId>
        <artifactId>oauth2-useragent</artifactId>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>com.microsoft.alm</groupId>
        <artifactId>oauth2-useragent-core</artifactId>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>com.microsoft.alm</groupId>
        <artifactId>oauth2-useragent-javafx</artifactId>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>com.microsoft.alm</groupId>
        <artifactId>oauth2-useragent-swt</artifactId>
        <version>${project.version}</version>
      </dependency>

      <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>1.7</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>com.github.tomakehurst</groupId>
        <artifactId>wiremock</artifactId>
        <version>1.57</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>org.littleshoot</groupId>
        <artifactId>littleproxy</artifactId>
        <version>1.1.0-beta1</version>
        <scope>test</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.5.1</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-enforcer-plugin</artifactId>
          <version>1.4.1</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.3</version>
        </plugin>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>animal-sniffer-maven-plugin</artifactId>
          <version>1.14</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-checkstyle-plugin</artifactId>
          <version>2.15</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <version>2.4</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-shade-plugin</artifactId>
          <version>2.4.1</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-javadoc-plugin</artifactId>
          <version>2.9.1</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.18.1</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-failsafe-plugin</artifactId>
          <version>2.18.1</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.6</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-gpg-plugin</artifactId>
          <version>1.6</version>
        </plugin>
        <plugin>
          <groupId>com.ruleoftech</groupId>
          <artifactId>markdown-page-generator-plugin</artifactId>
          <version>0.9</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-source-plugin</artifactId>
          <version>2.4</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.7</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.4</version>
        </plugin>
        <plugin>
          <groupId>org.sonatype.plugins</groupId>
          <artifactId>nexus-staging-maven-plugin</artifactId>
          <version>1.6.5</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.sonatype.plugins</groupId>
        <artifactId>nexus-staging-maven-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <serverId>ossrh</serverId>
          <nexusUrl>https://oss.sonatype.org/</nexusUrl>
          <autoReleaseAfterClose>true</autoReleaseAfterClose>
          <!-- The only artifacts we need are from the aggregator project, oauth2-useragent,
           and the parent POM, so enable deployment here -->
          <skipNexusStagingDeployMojo>false</skipNexusStagingDeployMojo>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-release-plugin</artifactId>
        <configuration>
          <goals>deploy</goals>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>2.15</version>
        <executions>
          <execution>
            <id>verify-style</id>
            <phase>process-classes</phase>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <checkstyleRules>
            <module name="Checker">
              <module name="Header">
                <property name="headerFile" value="config/checkstyle/java.header" />
                <property name="fileExtensions" value="java" />
              </module>
            </module>
          </checkstyleRules>
          <includeTestSourceDirectory>true</includeTestSourceDirectory>
          <logViolationsToConsole>true</logViolationsToConsole>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-install-plugin</artifactId>
        <!-- The only artifacts we need are from the aggregator project, oauth2-useragent,
         and the parent POM, so enable installation here -->
        <configuration>
          <skip>false</skip>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-javadoc-plugin</artifactId>
        <!-- The maven-javadoc-plugin is activated during release, through the use of `-D performRelease=true`
        ...but we don't want to use the maven-javadoc-plugin so we disable it altogether here.
         https://maven.apache.org/plugins/maven-javadoc-plugin/jar-mojo.html
         -->
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-source-plugin</artifactId>
        <!-- The maven-source-plugin is activated during release, through the use of `-D performRelease=true`
        ...but we don't want to use the maven-source-plugin so we disable it altogether.
         https://maven.apache.org/plugins/maven-source-plugin/jar-mojo.html
         -->
        <configuration>
          <skipSource>true</skipSource>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <dependencies>
          <dependency>
            <groupId>org.apache.maven.surefire</groupId>
            <artifactId>surefire-junit47</artifactId>
            <version>2.18.1</version>
          </dependency>
        </dependencies>
        <configuration>
          <excludedGroups>com.microsoft.alm.oauth2.useragent.IntegrationTests</excludedGroups>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.gmavenplus</groupId>
        <artifactId>gmavenplus-plugin</artifactId>
        <version>1.5</version>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.4.4</version>
            <scope>runtime</scope>
          </dependency>
          <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.0.13</version>
            <scope>runtime</scope>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <id>add-dynamic-properties</id>
            <phase>initialize</phase>
            <goals>
              <goal>execute</goal>
            </goals>
            <configuration>
              <scripts>
                <script>
                  <![CDATA[
                  import org.apache.maven.artifact.Artifact

                  def OS_NAME = System.properties['os.name']
                  boolean isWindows = OS_NAME.startsWith('Windows')
                  boolean isMac = OS_NAME.equals("Mac OS X")
                  boolean isLinux = OS_NAME.equals("Linux")

                  def swtTestVMOptions = ""
                  if (isMac) {
                      swtTestVMOptions += " -XstartOnFirstThread"
                  }

                  project.properties.setProperty("SWT_TEST_VM_OPTIONS", swtTestVMOptions)

                  boolean isx64 = System.getProperty("os.arch").contains("64")

                  def swtRuntime = "org.eclipse.swt."
                  if (isWindows) (
                      swtRuntime += "win32.win32"
                  ) else if (isMac) {
                      swtRuntime += "cocoa.macosx"
                  } else if (isLinux) {
                      swtRuntime += "gtk.linux"
                  }

                  if (isx64) {
                      swtRuntime += ".x86_64"
                  } else if (!isMac){
                      swtRuntime += ".x86"
                  }

                  for (Artifact d : project.artifacts) {
                      if (d.artifactId.equals(swtRuntime)) {
                          log.info("Using SWT Runtime jar at: " + d.file)
                          project.properties.setProperty("SWT_RUNTIME_JAR", d.file.absolutePath)
                          break
                      }
                  }

                  def excludes = []
                  for (Artifact d : project.artifacts) {
                      if (d.artifactId.startsWith("org.eclipse.swt")) {
                          excludes.add("org.eclipse.swt:" + d.artifactId)
                      }
                  }
                  final excludesValue = excludes.join(",")
                  project.properties.setProperty("SWT_DEPENDENCY_EXCLUDES", excludesValue)
                  ]]>
                </script>
              </scripts>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>integration_tests</id>
      <activation>
        <property>
          <name>integration_tests</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <dependencies>
              <dependency>
                <groupId>org.apache.maven.surefire</groupId>
                <artifactId>surefire-junit47</artifactId>
                <version>2.18.1</version>
              </dependency>
            </dependencies>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <includes>
                <include>**/*Test.java</include>
              </includes>
              <groups>com.microsoft.alm.oauth2.useragent.IntegrationTests</groups>
              <argLine>${SWT_TEST_VM_OPTIONS}</argLine>
              <classpathDependencyExcludes>${SWT_DEPENDENCY_EXCLUDES}</classpathDependencyExcludes>
              <additionalClasspathElements>
                <additionalClasspathElement>${SWT_RUNTIME_JAR}</additionalClasspathElement>
              </additionalClasspathElements>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>release</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-gpg-plugin</artifactId>
            <executions>
              <execution>
                <id>sign-artifacts</id>
                <phase>verify</phase>
                <goals>
                  <goal>sign</goal>
                </goals>
                <inherited>false</inherited>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
