<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>ch.so.agi.gretl</groupId>
    <artifactId>gretl-runtime-parent</artifactId>
    <version>0.1.0-SNAPSHOT</version>
  </parent>
  <artifactId>gretl-dist</artifactId>
  <packaging>jar</packaging>
  <name>GRETL Runtime Script Distribution</name>
  <description>Versioned script distribution with launcher, runtime, standard tasks, extensions and examples.</description>

  <repositories>
    <repository>
      <id>interlis-releases</id>
      <url>https://jars.interlis.ch</url>
      <releases><enabled>true</enabled><updatePolicy>never</updatePolicy></releases>
      <snapshots><enabled>true</enabled><updatePolicy>never</updatePolicy></snapshots>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
      <groupId>io.github.sogis</groupId>
      <artifactId>ilivalidator-custom-functions</artifactId>
      <version>${ilivalidator-custom-functions.version}</version>
      <scope>runtime</scope>
      <exclusions>
        <exclusion><groupId>javax.activation</groupId><artifactId>activation</artifactId></exclusion>
        <exclusion><groupId>com.sun.xml.bind</groupId><artifactId>jaxb-core</artifactId></exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>io.github.sogis</groupId>
      <artifactId>ilivalidator-custom-functions-geometries</artifactId>
      <version>${ilivalidator-custom-functions-geometries.version}</version>
      <scope>runtime</scope>
      <exclusions>
        <exclusion><groupId>javax.activation</groupId><artifactId>activation</artifactId></exclusion>
        <exclusion><groupId>com.sun.xml.bind</groupId><artifactId>jaxb-core</artifactId></exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>ch.geowerkstatt.ilivalidator.extensions.functions</groupId>
      <artifactId>geow-interlis-functions</artifactId>
      <version>${geow-interlis-functions.version}</version>
      <scope>runtime</scope>
      <exclusions>
        <exclusion><groupId>javax.activation</groupId><artifactId>activation</artifactId></exclusion>
        <exclusion><groupId>com.sun.xml.bind</groupId><artifactId>jaxb-core</artifactId></exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>ch.geowerkstatt.ilivalidator.extensions.functions</groupId>
      <artifactId>interlis-functions-ngk-so</artifactId>
      <version>${interlis-functions-ngk-so.version}</version>
      <scope>runtime</scope>
      <exclusions>
        <exclusion><groupId>javax.activation</groupId><artifactId>activation</artifactId></exclusion>
        <exclusion><groupId>com.sun.xml.bind</groupId><artifactId>jaxb-core</artifactId></exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId><artifactId>gretl-interlis-tasks</artifactId>
      <version>${project.version}</version><classifier>standard-functions</classifier>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-cli</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-database-tasks</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-io-tasks</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-ilivalidator</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-interlis-tasks</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl</groupId>
      <artifactId>gretl-job-runtime</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.so.agi.gretl.examples</groupId>
      <artifactId>file-size-extension</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <skipIfEmpty>true</skipIfEmpty>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>resolved-package-identities</id><phase>prepare-package</phase><goals><goal>tree</goal></goals>
            <configuration><scope>runtime</scope><outputType>json</outputType><verbose>false</verbose><outputFile>${project.build.directory}/package-resolved.json</outputFile></configuration>
          </execution>
          <execution>
            <id>resolved-package-edges</id><phase>prepare-package</phase><goals><goal>tree</goal></goals>
            <configuration><scope>runtime</scope><outputType>json</outputType><verbose>true</verbose><outputFile>${project.build.directory}/package-edges.json</outputFile></configuration>
          </execution>
          <execution>
            <id>copy-runtime-dependencies</id>
            <phase>prepare-package</phase>
            <goals><goal>copy-dependencies</goal></goals>
            <configuration>
              <outputDirectory>${project.build.directory}/dist/lib/runtime</outputDirectory>
              <includeScope>runtime</includeScope>
              <useBaseVersion>false</useBaseVersion>
              <excludeArtifactIds>gretl-database-tasks,gretl-io-tasks,gretl-ilivalidator,gretl-interlis-tasks</excludeArtifactIds>
            </configuration>
          </execution>
          <execution>
            <id>copy-task-jars</id>
            <phase>prepare-package</phase>
            <goals><goal>copy</goal></goals>
            <configuration>
              <outputDirectory>${project.build.directory}/dist/lib/tasks</outputDirectory>
              <artifactItems>
                <artifactItem>
                  <groupId>ch.so.agi.gretl</groupId>
                  <artifactId>gretl-database-tasks</artifactId>
                  <version>${project.version}</version>
                </artifactItem>
                <artifactItem>
                  <groupId>ch.so.agi.gretl</groupId>
                  <artifactId>gretl-io-tasks</artifactId>
                  <version>${project.version}</version>
                </artifactItem>
                <artifactItem>
                  <groupId>ch.so.agi.gretl</groupId>
                  <artifactId>gretl-ilivalidator</artifactId>
                  <version>${project.version}</version>
                </artifactItem>
                <artifactItem>
                  <groupId>ch.so.agi.gretl</groupId>
                  <artifactId>gretl-interlis-tasks</artifactId>
                  <version>${project.version}</version>
                </artifactItem>
                <artifactItem>
                  <groupId>ch.so.agi.gretl</groupId><artifactId>gretl-interlis-tasks</artifactId>
                  <version>${project.version}</version><classifier>standard-functions</classifier>
                  <outputDirectory>${project.build.directory}/dist/lib/extensions</outputDirectory>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-static-distribution</id>
            <phase>prepare-package</phase>
            <goals><goal>copy-resources</goal></goals>
            <configuration>
              <outputDirectory>${project.build.directory}/dist</outputDirectory>
              <resources>
                <resource>
                  <directory>src/main/dist</directory>
                  <filtering>false</filtering>
                  <excludes><exclude>inventory.json</exclude></excludes>
                </resource>
              </resources>
            </configuration>
          </execution>
          <execution>
            <id>copy-filtered-inventory</id>
            <phase>prepare-package</phase>
            <goals><goal>copy-resources</goal></goals>
            <configuration>
              <outputDirectory>${project.build.directory}/dist</outputDirectory>
              <resources>
                <resource>
                  <directory>src/main/dist</directory>
                  <filtering>true</filtering>
                  <includes><include>inventory.json</include></includes>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>checksums-and-launcher-mode</id>
            <phase>prepare-package</phase>
            <goals><goal>run</goal></goals>
            <configuration>
              <target>
                <chmod file="${project.build.directory}/dist/bin/gretl" perm="755"/>
                <java classname="ch.so.agi.gretl.dist.PackageCatalogGenerator" fork="true" failonerror="true">
                  <classpath><pathelement location="${project.build.outputDirectory}"/><path refid="maven.runtime.classpath"/></classpath>
                  <arg value="${project.build.directory}/dist"/>
                  <arg value="${project.build.directory}/package-resolved.json"/>
                  <arg value="${project.build.directory}/package-edges.json"/>
                  <arg value="${project.version}"/><arg value="${gretl.sourceRevision}"/>
                </java>
                <java classname="ch.so.agi.gretl.dist.ChecksumManifest" fork="true" failonerror="true">
                  <classpath>
                    <pathelement location="${project.build.outputDirectory}"/>
                  </classpath>
                  <arg value="${project.build.directory}/dist"/>
                </java>
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptors>
            <descriptor>src/main/assembly/dist.xml</descriptor>
          </descriptors>
          <appendAssemblyId>true</appendAssemblyId>
          <attach>false</attach>
          <finalName>gretl-runtime-${project.version}</finalName>
        </configuration>
        <executions>
          <execution>
            <id>make-distribution</id>
            <phase>package</phase>
            <goals><goal>single</goal></goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-distribution</id>
            <phase>verify</phase>
            <goals><goal>attach-artifact</goal></goals>
            <configuration>
              <artifacts>
                <artifact>
                  <file>${project.build.directory}/gretl-runtime-${project.version}-bin.zip</file>
                  <type>zip</type>
                  <classifier>bin</classifier>
                </artifact>
                <artifact>
                  <file>${project.build.directory}/gretl-runtime-${project.version}-bin.tar.gz</file>
                  <type>tar.gz</type>
                  <classifier>bin-tar-gz</classifier>
                </artifact>
              </artifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <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>
      </plugin>
    </plugins>
  </build>
  <profiles><profile><id>job-image</id><build><plugins><plugin>
    <groupId>org.apache.maven.plugins</groupId><artifactId>maven-antrun-plugin</artifactId>
    <executions><execution><id>build-generic-runtime-image</id><phase>pre-integration-test</phase><goals><goal>run</goal></goals>
      <configuration><target><exec executable="bash" failonerror="true">
        <arg value="${maven.multiModuleProjectDirectory}/scripts/build-runtime-image.sh"/>
        <arg value="--distribution"/><arg value="${project.build.directory}/dist"/>
        <arg value="--output"/><arg value="${project.build.directory}/image"/>
      </exec></target></configuration>
    </execution></executions>
  </plugin></plugins></build></profile></profiles>
</project>
