<?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/maven-v4_0_0.xsd">
  <parent>
    <groupId>org.n52.sensorweb.sos</groupId>
    <artifactId>i52n-sos</artifactId>
    <version>1.1</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>webapp-ioos</artifactId>
  <packaging>war</packaging>
  <name>IOOS 52North SOS IOOS</name>
  <description>52North Sensor Observation Service WAR Customized for IOOS</description>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  </properties>

  <build>
    <finalName>i52n-sos</finalName>
    <plugins>
      <!-- Run SOS-Test-Suite integration tests -->
      <!-- TODO: move to maven-failsafe-plugin? -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <includes>
            <include>**/*Suite*.java</include>
          </includes>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
          <failOnMissingWebXml>false</failOnMissingWebXml>
          <nonFilteredFileExtensions>
            <nonFilteredFileExtensions>db</nonFilteredFileExtensions>
          </nonFilteredFileExtensions>
          <overlays>
            <overlay>
              <groupId>${project.groupId}</groupId>
              <artifactId>webapp</artifactId>
              <excludes>
                <exclude>configuration.db</exclude>
                <exclude>WEB-INF/views/admin/index.jsp</exclude>
                <exclude>static/conf/client-config.json</exclude>
                <exclude>static/examples/**</exclude>
                <exclude>WEB-INF/classes/logback.xml</exclude>
                <!-- exclude dependencies (get from declared webapp pom dependency below -->
                <exclude>WEB-INF/lib/*.jar</exclude>
              </excludes>
            </overlay>
          </overlays>
          <webResources>
            <resource>
              <directory>src/main/webapp</directory>
              <filtering>true</filtering>
              <excludes>
                <exclude>configuration.db</exclude>
              </excludes>
            </resource>
            <resource>
              <directory>../misc/conf</directory>
              <filtering>false</filtering>
              <includes>
                <include>configuration.db</include>
              </includes>  
            </resource>
            <resource>
              <directory>src/main/resources</directory>
              <filtering>true</filtering>
              <targetPath>WEB-INF/classes</targetPath>
            </resource>
          </webResources>                    
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <!-- add upstream webapp overlay -->
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>webapp</artifactId>
      <version>${n52.sos.version}</version>
      <type>war</type>
    </dependency>
    <!-- add upstream webapps' transitive dependencies -->
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>webapp</artifactId>
      <version>${n52.sos.version}</version>
      <type>pom</type>
      <exclusions>
        <!-- exclude netcdf dependencies from upstream for now -->
        <!-- also exclude above in maven-war-plugin overlay -->
        <exclusion>
          <groupId>${project.groupId}</groupId>
          <artifactId>api-netcdf</artifactId>
        </exclusion>
        <exclusion>
          <groupId>${project.groupId}</groupId>
          <artifactId>coding-netcdf</artifactId>
        </exclusion>
        <exclusion>
          <groupId>${project.groupId}</groupId>
          <artifactId>coding-oceansites</artifactId>
        </exclusion>
        <exclusion>
          <groupId>${project.groupId}</groupId>
          <artifactId>netcdf</artifactId>
        </exclusion>
        <exclusion>
          <groupId>edu.ucar</groupId>
          <artifactId>netcdf</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <!-- upstream profile dependencies -->
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>hibernate-datasource-oracle</artifactId>
    </dependency>

    <!-- i52n dependencies -->
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>coding-ioos</artifactId>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>coding-ioos-netcdf</artifactId>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>test-data-ioos</artifactId>
    </dependency> 
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>ioos-controller</artifactId>
    </dependency>
    <dependency>
      <groupId>joda-time</groupId>
      <artifactId>joda-time-jsptags</artifactId>
      <version>1.1.1</version>
    </dependency>
    <dependency>
      <groupId>com.axiomalaska</groupId>
      <artifactId>ioos-sos-validator</artifactId>
      <scope>test</scope>
    </dependency>

    <!-- for query logging/performance tuning -->
    <!-- set hibernate.connection.driver_class to net.sf.log4jdbc.sql.jdbcapi.DriverSpy -->
    <!-- and prefix hibernate.connection.url with jdbc:log4 (e.g. jdbc:log4jdbc:postgresql://localhost:5432/sos -->
    <dependency>
      <groupId>org.bgee.log4jdbc-log4j2</groupId>
      <artifactId>log4jdbc-log4j2-jdbc4</artifactId>
      <version>1.16</version>
    </dependency>

    <!-- SOS-Test-Suite dependencies -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-core</artifactId>
      <version>1.3</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>hibernate-h2</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>test-suite-common</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>test-suite-sos-20</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>test-suite-sos-100</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>sqlite-config</artifactId>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <profiles>
    <profile>
      <id>configure-datasource-testdata</id>
      <activation>
        <property>
          <name>ioos-validate</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>configure-datasource-testdata</id>
                <phase>process-resources</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <tasks>
                    <copy file="../misc/testdata.datasource.properties" tofile="${project.build.directory}/${project.build.finalName}/WEB-INF/datasource.properties" />
                  </tasks>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <!-- validation testing is memory intensive, make sure to set MAVEN_OPTS to something like: -->
      <!-- "-Xmx1g -XX:PermSize=512m -XX:MaxPermSize=512m" or you will get memory errors -->
      <id>itest</id>
      <activation>
        <property>
          <name>ioos-validate</name>
        </property>
      </activation>      
      <properties>
        <jetty.port>9090</jetty.port>
        <jetty.version>9.2.18.v20160721</jetty.version>
      </properties>

      <dependencies>
        <dependency>
          <groupId>org.mortbay.jetty</groupId>
          <artifactId>jsp-2.1</artifactId>
          <version>6.0.0</version>
        </dependency>    
        <dependency>
          <groupId>org.eclipse.jetty</groupId>
          <artifactId>jetty-util</artifactId>
          <version>${jetty.version}</version>
        </dependency>
        <dependency>
          <groupId>org.hamcrest</groupId>
          <artifactId>hamcrest-all</artifactId>
          <scope>test</scope>
        </dependency>        
      </dependencies>

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <dependenciesToScan>
                <dependency>com.axiomalaska:ioos-sos-validator</dependency>
              </dependenciesToScan>        
              <includes>
                <include>**/AllTestsm1_0.java</include>
              </includes>
            </configuration>
            <dependencies>                
              <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.7.5</version>
              </dependency>
            </dependencies>                        
          </plugin>
          <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${jetty.version}</version>
            <configuration>
              <scanIntervalSeconds>10</scanIntervalSeconds>
              <stopPort>9999</stopPort>
              <stopKey>STOP</stopKey>
              <contextPath>/</contextPath>
              <httpConnector>
                <port>9090</port>
              </httpConnector>
              <webApp>
                <resourceBases>
                  <resoureBase>${project.build.directory}/i52n-sos</resoureBase>
                </resourceBases>
                <allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
              </webApp>
              <systemProperties>
                <systemProperty>
                  <name>logback.configurationFile</name>
                  <value>${project.build.outputDirectory}/logback.noop.xml</value>
                </systemProperty>
              </systemProperties>
            </configuration>
            <executions>
              <execution>
                <id>start-jetty</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
                <configuration>
                  <scanIntervalSeconds>0</scanIntervalSeconds>
                  <daemon>true</daemon>
                </configuration>
              </execution> 
              <execution>
                <id>stop-jetty</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>stop</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
