Get Started

Let’s start with a simple example: Download, unzip and validate an INTERLIS transfer file:

Java flavour

You need Java 1.8 and Gradle >= 5.1.1 (and < 6) installed on your machine.

Create a build.gradle file and paste the following code into the file:

import java.nio.file.Paths
import ch.so.agi.gretl.tasks.*
import ch.so.agi.gretl.api.*
import de.undercouch.gradle.tasks.download.Download

buildscript {
    repositories {
        maven { url "https://jars.interlis.ch" }
        maven { url "https://repo.osgeo.org/repository/release/" }
        maven { url "https://plugins.gradle.org/m2/" }
        maven { url "https://s01.oss.sonatype.org/service/local/repositories/releases/content/" }
        maven { url "https://s01.oss.sonatype.org/service/local/repositories/snapshots/content/" }
        mavenCentral()
    }
}

plugins {
  id "de.undercouch.download" version "4.1.2"
  id "ch.so.agi.gretl" version "2.3.426"
}

defaultTasks 'validateData'

tasks.register('downloadFile', Download) {
    src "https://files.geo.so.ch/ch.so.agi.av.dm01_ch/aktuell/2549.ch.so.agi.av.dm01_ch.itf.zip"
    dest file("2549.ch.so.agi.av.dm01_ch.itf.zip")
    overwrite true
}

tasks.register('unzipFile', Copy) {
    dependsOn 'downloadFile'
    from zipTree(Paths.get("2549.ch.so.agi.av.dm01_ch.itf.zip"))
    into file(".")
    include "**/*.itf"
}

tasks.register('validateData', IliValidator) {
    dependsOn 'unzipFile'
    dataFiles = ["2549.ch.so.agi.av.dm01_ch.itf"]
}

To run your first GRETL job just type gradle in the terminal - in the same directory where you saved the build.gradle file - and hit enter. On the first run, it will download a lot of dependencies (external libraries). Be patient and after downloading everything it will actually run the job and should finish with BUILD SUCCESSFUL.

If you want some more logging output, use gradle -i and you should see e.g. the well known output from ilivalidator.

Docker flavour

You can build your very own image or just use docker.io/sogis/gretl:latest. Since the image makes use of an init.gradle file, the build.gradle file looks a little bit different:

import java.nio.file.Paths
import ch.so.agi.gretl.tasks.*
import ch.so.agi.gretl.api.*
import de.undercouch.gradle.tasks.download.Download

apply plugin: 'ch.so.agi.gretl'
apply plugin: 'de.undercouch.download'

defaultTasks 'validateData'

tasks.register('downloadFile', Download) {
    src "https://files.geo.so.ch/ch.so.agi.av.dm01_ch/aktuell/2549.ch.so.agi.av.dm01_ch.itf.zip"
    dest file("2549.ch.so.agi.av.dm01_ch.itf.zip")
    overwrite true
}

tasks.register('unzipFile', Copy) {
    dependsOn 'downloadFile'
    from zipTree(Paths.get("2549.ch.so.agi.av.dm01_ch.itf.zip"))
    into file(".")
    include "**/*.itf"
}

tasks.register('validateData', IliValidator) {
    dependsOn 'unzipFile'
    dataFiles = ["2549.ch.so.agi.av.dm01_ch.itf"]
}

Run the following Docker command in the directory where the build.gradle file is stored:

docker run -i --rm --name gretl --entrypoint="/bin/sh" -v $PWD:/home/gradle/project sogis/gretl:latest -c 'gretl'

The most important part is the bind mount of the working directory ($PWD) to /home/gradle/project/ in the image. The image expects the build.gradle file in this specific directory.

If you want it a less verbose - especially if the run command gets more and more complex by adding more options - you can use e.g. a shell script.