<?xml version="1.0" encoding="UTF-8"?>
<project
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
        xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-project</artifactId>
        <version>1.1.2</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>

    <artifactId>kotlin-runtime</artifactId>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>org.jetbrains</groupId>
            <artifactId>annotations</artifactId>
            <version>13.0</version>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>target/copied-sources</sourceDirectory>

        <resources>
            <resource>
                <directory>${basedir}/../../../dist/builtins</directory>
                <includes>
                    <include>**/*.kotlin_builtins</include>
                </includes>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>

                <executions>
                    <execution>
                        <id>copy-sources</id>
                        <phase>process-sources</phase>
                        <configuration>
                            <target>
                                <delete dir="${basedir}/target/copied-sources" failonerror="false"/>
                                <copy todir="${basedir}/target/copied-sources">
                                    <fileset dir="${basedir}/../../../core/builtins/src"/>
                                    <fileset dir="${basedir}/../../../core/runtime.jvm/src">
                                        <exclude name="org/jetbrains/annotations/**"/>
                                    </fileset>
                                </copy>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <id>attach-empty-javadoc</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <skipAttach>true</skipAttach>
                        </configuration>
                    </execution>
                    <execution>
                        <id>add-native-sources</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${basedir}/../../../core/builtins/native</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <Kotlin-Version>${kotlin.language.version}</Kotlin-Version>
                            <Kotlin-Runtime-Component>Main</Kotlin-Runtime-Component>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>${project.version}</version>

                <configuration>
                    <args>
                        <arg>-Xallow-kotlin-package</arg>
                    </args>
                </configuration>

                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <args combine.children="append">
                                <arg>-Xdump-declarations-to</arg>
                                <arg>${basedir}/target/runtime-declarations.json</arg>
                                <arg>-cp</arg>
                                <arg>${basedir}/../../../dist/builtins</arg>
                            </args>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
