<?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/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>io.github.mmhelloworld</groupId>
        <artifactId>idris-jvm</artifactId>
        <version>0.8.1</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>idris-jvm-compiler</artifactId>
    <name>Idris JVM Compiler</name>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <skipIdrisCompile>false</skipIdrisCompile>
        <skipIdrisInstallLibrary>false</skipIdrisInstallLibrary>
        <skipIdrisClean>false</skipIdrisClean>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-jar</id>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-install-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-install</id>
                        <goals>
                            <goal>install</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>initialize</phase>
                        <goals>
                            <goal>read-project-properties</goal>
                        </goals>
                        <configuration>
                            <files>
                                <file>${project.build.outputDirectory}/config.properties</file>
                            </files>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.parent.basedir}/src</source>
                                <source>${project.parent.basedir}/libs</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeScope>compile</includeScope>
                            <outputDirectory>${project.parent.basedir}/build/exec/idris2_app</outputDirectory>
                            <excludeArtifactIds>idris-jvm-runtime</excludeArtifactIds>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-runtime-jar</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>io.github.mmhelloworld</groupId>
                                    <artifactId>idris-jvm-runtime</artifactId>
                                    <version>${project.version}</version>
                                    <type>jar</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.parent.basedir}/build/exec/idris2_app</outputDirectory>
                                    <includes>**/*.class</includes>
                                </artifactItem>
                            </artifactItems>
                            <overWriteReleases>true</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <configuration>
                    <quietLogs>true</quietLogs>
                    <inheritIo>true</inheritIo>
                </configuration>
                <executions>
                    <execution>
                        <id>read-config</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>make</executable>
                            <workingDirectory>${project.parent.basedir}</workingDirectory>
                            <arguments>
                                <argument>maven-property</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>idris-compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <skip>${skipIdrisCompile}</skip>
                            <executable>make</executable>
                            <workingDirectory>${project.parent.basedir}</workingDirectory>
                            <environmentVariables>
                                <JAVA_OPTS>-Xss92m -Xms3g -Xmx3g</JAVA_OPTS>
                                <IDRIS2_CG>jvm</IDRIS2_CG>
                            </environmentVariables>
                        </configuration>
                    </execution>
                    <execution>
                        <id>idris-install-libs</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <skip>${skipIdrisInstallLibrary}</skip>
                            <executable>make</executable>
                            <workingDirectory>${project.parent.basedir}</workingDirectory>
                            <arguments>
                                <argument>install</argument>
                            </arguments>
                            <environmentVariables>
                                <IDRIS2_CG>jvm</IDRIS2_CG>
                                <JAVA_OPTS>-Xss92m -Xms3g -Xmx3g</JAVA_OPTS>
                            </environmentVariables>
                        </configuration>
                    </execution>
                    <execution>
                        <id>idris-clean</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <skip>${skipIdrisClean}</skip>
                            <executable>make</executable>
                            <workingDirectory>${project.parent.basedir}</workingDirectory>
                            <arguments>
                                <argument>clean</argument>
                            </arguments>
                            <environmentVariables>
                                <IDRIS2_CG>jvm</IDRIS2_CG>
                            </environmentVariables>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.parent.basedir}/build/exec/idris2_app</directory>
                                    <includes>
                                        <include>**/*.class</include>
                                    </includes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>delete-runtime-jar</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <failOnError>false</failOnError>
                            <target>
                                <!--
This is to remove bootstrap compiler runtime JAR under build/exec/idris2_app. This is only temporary as old Idris
JVM compiler copies runtime JAR into output directory. New compiler would copy the runtime classes instead of JAR
so when we have the newer bootstrap compiler, this can be removed.
                                -->
                                <delete failonerror="false">
                                    <fileset dir="${project.parent.basedir}/build/exec/idris2_app" includes="idris-jvm-runtime-*.jar" />
                                </delete>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>create-zip</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <appendAssemblyId>false</appendAssemblyId>
                            <descriptors>
                                <descriptor>src/assembly/bin.xml</descriptor>
                            </descriptors>
                            <finalName>idris2-${project.version}</finalName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                        <configuration>
                            <excludes>
                                <exclude>**/build/**</exclude>
                                <exclude>**/*.md</exclude>
                            </excludes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>io.github.mmhelloworld</groupId>
            <artifactId>idris-jvm-runtime</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>io.github.mmhelloworld</groupId>
            <artifactId>idris-jvm-assembler</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-artifact</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
