<?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.1</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>

    <artifactId>kotlin-stdlib-common</artifactId>

    <properties>
        <kotlin-home>${kotlin-dist}/kotlinc</kotlin-home>
        <pp-profile>JS</pp-profile>
    </properties>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <testSourceDirectory>test</testSourceDirectory>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <id>common-sources</id>
                        <phase>process-sources</phase>
                        <configuration>
                            <target>
                                <delete dir="${basedir}/target/common-sources" failonerror="false"/>
                                <mkdir dir="${basedir}/target/common-sources"/>
                                <java classname="org.jetbrains.kotlin.preloading.Preloader" failonerror="true" fork="true">
                                    <classpath>
                                        <pathelement location="${kotlin-home}/lib/kotlin-preloader.jar"/>
                                    </classpath>
                                    <assertions>
                                        <enable/>
                                    </assertions>
                                    <arg value="-cp"/>
                                    <arg value="${kotlin-home}/lib/kotlin-compiler.jar"/>
                                    <arg value="org.jetbrains.kotlin.preprocessor.PreprocessorCLI"/>
                                    <arg value="${basedir}/../src/kotlin"/>
                                    <arg value="${basedir}/target/common-sources"/>
                                    <arg value="${pp-profile}"/>
                                </java>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>serialize-declarations</id>
                        <phase>compile</phase>
                        <configuration>
                            <target>
                                <delete dir="${basedir}/target/classes" failonerror="false"/>
                                <mkdir dir="${basedir}/target/classes"/>


                                <local name="src.line"/>

                                <path id="src.path">
                                    <union>
                                        <fileset dir="${basedir}/target/common-sources">
                                            <include name="**/*.kt" />
                                        </fileset>

                                        <fileset dir="${basedir}/src">
                                            <include name="**/*.kt" />
                                        </fileset>
                                    </union>
                                </path>

                                <pathconvert property="src.line" refid="src.path" pathsep=" "/>

                                <java classname="org.jetbrains.kotlin.preloading.Preloader" failonerror="true" fork="true">
                                    <classpath>
                                        <pathelement location="${kotlin-home}/lib/kotlin-preloader.jar"/>
                                    </classpath>
                                    <assertions>
                                        <enable/>
                                    </assertions>
                                    <!--
                                                <jvmarg value="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"/>
                                    -->
                                    <arg value="-cp"/>
                                    <arg value="${kotlin-home}/lib/kotlin-compiler.jar"/>
                                    <arg value="org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler"/>
                                    <arg value="-Xallow-kotlin-package" />
                                    <arg value="-d"/>
                                    <arg value="${basedir}/target/classes"/>
                                    <arg line="${src.line}"/>
                                </java>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </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>
        </plugins>
    </build>
</project>
