dist: trusty
language: cpp

env:
  global:
      - secure: "kof5OhO8fMloYaFhXN0V6SPz5cn/PPAs7sX4e4qD/y9KFMYx7q3MS48cddVlNn1o6MuzydbUKAO6ZUQIKjRU5N0gljpcC4/UsBn+58EzyOymNdRsc+cdlX4kmENcqcLtH6emkigmJWlULsCnSHTB+CETglDXxCRsrS7Ib0MmsUXyFzZpOLteh+5WsOkpMxw+t1JTj06b36XWuihyhMc7/XcpXyDkLRy9GHyAO0CI/AdBJtBX0oS3l/Gmu52g8uiY/nc4680mhBuDcN7A9UMWsVCIttxOGU27vU2AckqZ60B+hBioc+W7I+WGPKIAw46+UyMB7G96M9kPo1F06qyvYJNypD+jFNns+PDGm4rj3xOTDskbohgpfjXZOz+mJgTL9Jd0bg60+tkAjTLjXx/s6FsqkLwqrCA1REPufKnM3zreXFQgJ0mY9139+bSpsRWg02A8fwo8G1Fe6oXaWaB6o3iAeG/baA2E/sQZvXnUSnms1X/KYtbFQuNKTOWDLDOxIcs5yz/OC8mLhGWKrofyOQY9dsuuu5HLD1gVqdo5cmSUc63gWWjRsnqVxHxouo3vRW/s/vgufW5SfMipzrfiMTh4tufDzHShlcOFqjq69lLedUaIax5zKUAlh5y9ZqWB90VI23LRCD/uknhjPcohGHvr6jpRKu3xYQiVWNVMc5Q="

matrix:
  include:
    - os: linux
      sudo: false
      addons:
        apt:
          packages:
            - libpcre3-dev
      compiler: gcc
    - os: linux
      sudo: false
      addons:
        apt:
          packages:
            - libpcre3-dev
      compiler: clang
    - os: osx
      osx_image: xcode6.4  # Mac OS X 10.10
      compiler: gcc
    - os: osx
      osx_image: xcode6.4  # Mac OS X 10.10
      compiler: clang

before_install:
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; brew install swig ; fi
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
      cd /tmp/;
      curl -s -J -O -k -L 'https://sourceforge.net/projects/swig/files/swig/swig-3.0.10/swig-3.0.10.tar.gz/download';
      tar zxf swig-3.0.10.tar.gz;
      cd swig-3.0.10;
      ./configure --prefix $HOME/swig/;
      make;
      make install;
      cd $TRAVIS_BUILD_DIR;
    fi

script:
  - set -e
# Set up our Maven and SWIG environment
  - mkdir -p $HOME/.m2
  - cat java/settings.xml | sed s/__MAVEN_SERVER_USERNAME__/$MAVEN_SERVER_USERNAME/g | sed s/__MAVEN_SERVER_PASSWORD__/$MAVEN_SERVER_PASSWORD/g > $HOME/.m2/settings.xml
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
      export SWIG=$HOME/swig/bin/swig;
      export LD_LIBRARY_PATH="$TRAVIS_BUILD_DIR/build";
    else
      export DYLD_LIBRARY_PATH="$TRAVIS_BUILD_DIR/build";
    fi
# Build native code
  - make clean swig all
# Prepare to run tests
  - cd build
  - mkdir -p transcoded/C/ transcoded/C++/ transcoded/Java/
# Test base jxrlib C library
  - for input in ../fixtures/first-tiles/*; do
      basename=${input##*/};
      basename=${bn%.jxr};
      ./JxrDecApp -i "$input" -o "transcoded/C/$basename.tif";
      ./jxrdecode "$input" "transcoded/C++/$basename.tif";
      ./jxrdecode --in-memory "$input";
    done
# Test jxrlib Java bindings (in memory and file to file)
  - mvn -f ../java/pom.xml test
# Testing was successful
  - cd $TRAVIS_BUILD_DIR
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
      mvn -f java/native-linux_64 package;
      if [[ "$TRAVIS_PULL_REQUEST" == "false" ]] && [[ "$CC" == "gcc" ]]; then
        mvn -f java/native-linux_64 deploy;
        mvn -f java/pom.xml deploy;
      fi
    else
      mvn -f java/native-osx_64 package;
      if [[ "$TRAVIS_PULL_REQUEST" == "false" ]] && [[ "$CC" == "clang" ]]; then
        mvn -f java/native-osx_64 deploy;
      fi
    fi

cache:
  directories:
# Don't repopulate the entire Maven repository every time we build
    - $HOME/.m2/repository
# Don't redownload the Gradle wrapper distributions
    - $HOME/.gradle/wrapper/dists
