<?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.6.0-rc.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-compiler-plugin</artifactId>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-jar</id>
                        <phase>compile</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>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <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>
                            <arguments>
                                <argument>support</argument>
                                <argument>idris2-exec</argument>
                            </arguments>
                            <environmentVariables>
                                <JAVA_OPTS>-Xss70m -Xms3g -Xmx3g</JAVA_OPTS>
                                <IDRIS2_CG>jvm</IDRIS2_CG>
                            </environmentVariables>
                        </configuration>
                    </execution>
                    <execution>
                        <id>runtime-jar-cleanup</id>
                        <phase>process-test-classes</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <skip>${skipIdrisCompile}</skip>
                            <!--
                            This is a hack to remove bootstrap compiler runtime JAR under "build/exec/idris2_app".
                            Idris JVM compiler copies runtime JAR into application output directories so that we don't
                            have to setup the JAR explicitly in the classpath to run programs but for compiler code
                            itself, we want to use the runtime JAR from the current version, not of the compiler that
                            compiles the current code. This program compares the semantic versions of runtime JARs
                            and removes the old JAR. This is specifically inside "test" directory so that dependencies
                            for this class like "maven-artifact" dependency wouldn't be copied
                            into "build/exec/idris2_app" directory.
                            -->
                            <mainClass>
                                io.github.mmhelloworld.idrisjvm.compiler.RuntimeJarCleanup
                            </mainClass>
                            <classpathScope>test</classpathScope>
                            <arguments>
                                <argument>${project.parent.basedir}/build/exec/idris2_app</argument>
                            </arguments>
                        </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>-Xss70m -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-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-compiler-jar</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <copy file="../build/exec/idris2_app/idris2.jar" tofile="./target/idris-jvm-compiler-${project.version}.jar" overwrite="true" />
                            </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>
