<?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.5.1.2</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>
                <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>
                <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>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>process-resources</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.parent.basedir}/tests/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>
                        </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>
                        </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>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>version-compiler-jar</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <move file="../build/exec/idris2_app/idris2.jar" tofile="../build/exec/idris2_app/idris-jvm-compiler-${project.version}.jar" failonerror="false" overwrite="true" />
                            </target>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-compiler-jar</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <copy file="../build/exec/idris2_app/idris-jvm-compiler-${project.version}.jar" tofile="./target/idris-jvm-compiler-${project.version}.jar" overwrite="true" />
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>idrisOutputScripts</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>assemble</goal>
                        </goals>
                        <configuration>
                            <binFolder>exec</binFolder>
                            <repositoryName>exec/idris2_app</repositoryName>
                            <repositoryLayout>flat</repositoryLayout>
                            <assembleDirectory>${project.parent.basedir}/build</assembleDirectory>
                            <extraJvmArguments>-Xss70m -Xms3g -Xmx3g</extraJvmArguments>
                            <programs>
                                <program>
                                    <mainClass>idris2.Main</mainClass>
                                    <id>idris2</id>
                                </program>
                            </programs>
                        </configuration>
                    </execution>
                    <execution>
                        <id>package</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>assemble</goal>
                        </goals>
                        <configuration>
                            <repositoryName>lib</repositoryName>
                            <repositoryLayout>flat</repositoryLayout>
                            <assembleDirectory>${project.build.directory}/assembly</assembleDirectory>
                            <extraJvmArguments>-Xss70m -Xms3g -Xmx3g</extraJvmArguments>
                            <programs>
                                <program>
                                    <mainClass>idris2.Main</mainClass>
                                    <id>idris2</id>
                                </program>
                            </programs>
                        </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>
    </dependencies>
</project>
