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

    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF 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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-salesforce-parent</artifactId>
    <version>3.0.0-M1</version>
  </parent>

  <artifactId>camel-salesforce</artifactId>
  <packaging>jar</packaging>
  <name>Camel :: Salesforce</name>
  <description>Camel Salesforce support</description>

  <properties>
    <camel.osgi.private.pkg>org.apache.camel.component.salesforce.internal.*</camel.osgi.private.pkg>
    <salesforce.component.root>..</salesforce.component.root>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-csv</artifactId>
      <version>${commons-csv-version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-client</artifactId>
      <version>${jetty9-version}</version>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-util</artifactId>
      <version>${jetty9-version}</version>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-util-ajax</artifactId>
      <version>${jetty9-version}</version>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-io</artifactId>
      <version>${jetty9-version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.datatype</groupId>
      <artifactId>jackson-datatype-jsr310</artifactId>
      <version>${jackson2-version}</version>
    </dependency>
    <!-- json schema -->
    <dependency>
      <groupId>com.fasterxml.jackson.jaxrs</groupId>
      <artifactId>jackson-jaxrs-json-provider</artifactId>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.module</groupId>
      <artifactId>jackson-module-jsonSchema</artifactId>
      <exclusions>
        <exclusion>
          <groupId>javax.validation</groupId>
          <artifactId>validation-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>com.thoughtworks.xstream</groupId>
      <artifactId>xstream</artifactId>
    </dependency>
    <dependency>
      <groupId>org.cometd.java</groupId>
      <artifactId>cometd-java-client</artifactId>
      <version>${cometd-java-client-version}</version>
      <exclusions>
        <exclusion>
          <groupId>org.eclipse.jetty</groupId>
          <artifactId>*</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <!-- logging -->
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>

    <!-- testing -->
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j-impl</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-csv</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-server</artifactId>
      <version>${jetty9-version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-servlet</artifactId>
      <version>${jetty9-version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-proxy</artifactId>
      <version>${jetty9-version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <version>${assertj-version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.googlecode.junit-toolbox</groupId>
      <artifactId>junit-toolbox</artifactId>
      <version>${junit-toolbox-version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.squareup.okhttp3</groupId>
      <artifactId>mockwebserver</artifactId>
      <version>${okclient-version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.awaitility</groupId>
      <artifactId>awaitility</artifactId>
      <version>${awaitility-version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.gmavenplus</groupId>
        <artifactId>gmavenplus-plugin</artifactId>
        <version>${gmavenplus-plugin-version}</version>
        <executions>
          <execution>
            <goals>
              <goal>addTestSources</goal>
              <goal>compileTests</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>integration</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-enforcer-plugin</artifactId>
            <executions>
              <execution>
                <id>salesforce-integration-test-prerequisites</id>
                <goals>
                  <goal>enforce</goal>
                </goals>
                <configuration>
                  <rules>
                    <requireFilesExist>
                      <files>
                        <file>${salesforce.component.root}/it/resources/migration-tool/ant-salesforce.jar</file>
                      </files>
                      <message><![CDATA[Salesforce Migration Tool required

You need to download the Salesforce Migration Tool (ZIP file) and 
extract the `ant-salesforce.jar` out of it to:

${salesforce.component.root}/it/resources/migration-tool/ant-salesforce.jar

It's needed by the integration tests to setup the Salesforce instance
with custom sObjects/fields that are required by the tests.

Have a look at:

${salesforce.component.root}/it/resources/salesforce

To see what will be done.

For information and download of the Salesforce Migration Tool consult:

https://developer.salesforce.com/page/Force.com_Migration_Tool]]></message>
                    </requireFilesExist>
                  </rules>
                  <fail>true</fail>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>${maven-resources-plugin-version}</version>
            <executions>
              <execution>
                <id>copy-test-salesforce-login-properties</id>
                <phase>generate-test-resources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/test-classes/</outputDirectory>
                  <resources>
                    <resource>
                      <directory>${salesforce.component.root}</directory>
                      <include>test-salesforce-login.properties</include>
                    </resource>
                  </resources>
                </configuration>
              </execution>
              <execution>
                <id>set-connected-app-client-id</id>
                <phase>generate-test-resources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${salesforce.component.root}/it/resources/salesforce/connectedApps</outputDirectory>
                  <overwrite>true</overwrite>
                  <filters>
                    <filter>${salesforce.component.root}/test-salesforce-login.properties</filter>
                  </filters>
                  <resources>
                    <resource>
                      <directory>${salesforce.component.root}/it/resources/</directory>
                      <include>CamelSalesforceIntegrationTests.connectedApp</include>
                      <filtering>true</filtering>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>setup-salesforce-instance</id>
                <goals>
                  <goal>run</goal>
                </goals>
                <phase>pre-integration-test</phase>
                <configuration>
                  <target xmlns:if="ant:if" xmlns:unless="ant:unless">
                    <taskdef resource="com/salesforce/antlib.xml" uri="antlib:com.salesforce">
                      <classpath>
                        <pathelement location="${salesforce.component.root}/it/resources/migration-tool/ant-salesforce.jar" />
                      </classpath>
                    </taskdef>

                    <property prefix="prop" file="${project.build.directory}/test-classes/test-salesforce-login.properties" />
                    <property environment="env" />

                    <property name="username" value="${prop.salesforce.username}" if:set="prop.salesforce.username" />
                    <property name="username" value="${env.SALESFORCE_USERNAME}" if:set="env.SALESFORCE_USERNAME" />

                    <property name="password" value="${prop.salesforce.password}" if:set="prop.salesforce.password" />
                    <property name="password" value="${env.SALESFORCE_PASSWORD}" if:set="env.SALESFORCE_PASSWORD" />

                    <fail unless:set="username" message="To run the migrations you need to specify either `salesforce.username` in: ${project.build.directory}/generated-resources/test-salesforce-login.properties or set SALESFORCE_USERNAME environment variable" />

                    <fail unless:set="password" message="To run the migrations you need to specify either `salesforce.password` in: ${project.build.directory}/generated-resources/test-salesforce-login.properties or set SALESFORCE_PASSWORD environment variable" />

                    <sf:deploy xmlns:sf="antlib:com.salesforce" username="${username}" password="${password}" deployRoot="${salesforce.component.root}/it/resources/salesforce" rollbackOnError="true" />
                  </target>
                </configuration>
              </execution>
            </executions>
            <dependencies>
              <dependency>
                <groupId>org.apache.ant</groupId>
                <artifactId>ant</artifactId>
                <version>1.10.1</version>
              </dependency>
            </dependencies>
          </plugin>
          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
              <execution>
                <phase>integration-test</phase>
                <goals>
                  <goal>integration-test</goal>
                </goals>
                <configuration>
                  <childDelegation>false</childDelegation>
                  <useFile>true</useFile>
                  <forkCount>3</forkCount>
                  <runOrder>random</runOrder>
                  <reuseForks>true</reuseForks>
                  <forkedProcessTimeoutInSeconds>300</forkedProcessTimeoutInSeconds>
                  <includes>
                    <include>**/*IntegrationTest.java</include>
                  </includes>
                  <excludedGroups>org.apache.camel.component.salesforce.Standalone</excludedGroups>
                </configuration>
              </execution>
              <execution>
                <id>standalone-integration-tests</id>
                <phase>integration-test</phase>
                <goals>
                  <goal>integration-test</goal>
                </goals>
                <configuration>
                  <childDelegation>false</childDelegation>
                  <useFile>true</useFile>
                  <includes>
                    <include>**/*IntegrationTest.java</include>
                  </includes>
                  <groups>org.apache.camel.component.salesforce.Standalone</groups>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
