apply plugin: 'groovy'
apply plugin: 'application'
apply plugin: PublishJarsPlugin


application {
  mainClass = "nz.org.riskscape.engine.cli.Main"
  applicationName = "riskscape"
}

publishJars {
  artifactId = 'engine-app'
}

configurations {
  // containers for the dist dirs for our plugins
  defaultPlugins
  optionalPlugins
}

dependencies {
  api project(':engine:core')
  api project(':engine:common')
  implementation project(':engine:i18n')
  testImplementation project(':test:shared')
  testImplementation group: 'org.geotools', name: 'gt-imagemosaic', version: project.property('geotoolsVersion')
  implementation group: 'org.jline', name: 'jline-terminal', version: project.property('jlineVersion')
  implementation group: 'org.jline', name: 'jline-terminal-jna', version: project.property('jlineVersion')
  implementation group: 'org.jline', name: 'jline-reader', version: project.property('jlineVersion')
  implementation group: 'ch.qos.logback', name: 'logback-classic', version: project.property('logbackVersion')

  defaultPlugins project(path: ':plugin:cpython', configuration: 'dist')
  defaultPlugins project(path: ':plugin:defaults', configuration: 'dist')
  defaultPlugins project(path: ':plugin:jython', configuration: 'dist')
  defaultPlugins project(path: ':plugin:postgis', configuration: 'dist')
  defaultPlugins project(path: ':plugin:wizard', configuration: 'dist')
  defaultPlugins project(path: ':plugin:wizard-cli', configuration: 'dist')

  optionalPlugins project(path: ':plugin:beta', configuration: 'dist')
  optionalPlugins project(path: ':plugin:hdf5', configuration: 'dist')
  optionalPlugins project(path: ':plugin:netcdf', configuration: 'dist')
  optionalPlugins project(path: ':plugin:ogr', configuration: 'dist')
  optionalPlugins project(path: ':plugin:openquake', configuration: 'dist')
  optionalPlugins project(path: ':plugin:usgs', configuration: 'dist')
}

def defaultScriptsTask = tasks['startScripts']
def unixScript = resources.text.fromFile('src/main/bin/unixStartScript.txt')
def windowsScript = resources.text.fromFile('src/main/bin/windowsStartScript.txt')
defaultScriptsTask.unixStartScriptGenerator.template = unixScript
defaultScriptsTask.windowsStartScriptGenerator.template = windowsScript

javadoc {
  exclude 'picocli/**'
}

test {
  // Set the RISKSCAPE_HOME varible to change the default home directory. These tests
  // require a clean settings.ini file. If we don't set this then if you have enabled
  // plugins etc in your setup ($HOME/.config/riskscape/settings.ini) then the tests may
  // break
  environment "RISKSCAPE_HOME", "src/test/resources/home-empty"
}

def cal = new GregorianCalendar()

distributions {
  main {
    contents {
      from("../core/src/main/i18n") {
        into "i18n"
        include "*.properties"
      }
      from("src/main/i18n") {
        into "i18n"
        include "*.properties"
      }

      from(project.configurations.defaultPlugins) {
        into 'plugins'
      }

      from(project.configurations.optionalPlugins) {
        into 'plugins-optional'
      }

      from("../..") {
        include "LICENSE"
        include "COPYRIGHT"
        expand([CURRENT_YEAR: cal.get(Calendar.YEAR)])
      }
    }
  }
}
