<?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">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>fr.insee.trevas</groupId>
        <artifactId>trevas-parent</artifactId>
        <version>2.4.0</version>
    </parent>

    <artifactId>vtl-parser</artifactId>
    <name>VTL Parser</name>
    <description>Artifacts generated by Antlr from the VTL grammar files</description>
    <version>2.4.0</version>

    <!--    Warning: not lastest, align with version embedded by Spark-->
    <properties>
        <antlr4.version>4.9.3</antlr4.version>
        <sonar.coverage.jacoco.xmlReportPaths>
            ${project.basedir}/../coverage/target/site/jacoco-aggregate/jacoco.xml
        </sonar.coverage.jacoco.xmlReportPaths>
    </properties>

    <dependencies>
        <dependency>
            <groupId>fr.insee.trevas</groupId>
            <artifactId>vtl-antlr</artifactId>
            <version>2.4.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.antlr</groupId>
                <artifactId>antlr4-maven-plugin</artifactId>
                <version>${antlr4.version}</version>
                <executions>
                    <execution>
                        <id>antlr</id>
                        <goals>
                            <goal>antlr4</goal>
                        </goals>
                        <configuration>
                            <listener>true</listener>
                            <visitor>true</visitor>
                            <libDirectory>src/main/antlr4/fr/insee/vtl/parser</libDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <!-- ANTLR has no option to override the runtime import path; rewrite the
                     generated sources' imports to point at our relocated runtime (vtl-antlr)
                     so the compiled class files reference the shaded names from the start. -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>relocate-antlr-imports</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <replaceregexp match="org\.antlr\.v4" replace="fr.insee.vtl.antlr" flags="g">
                                    <fileset dir="${project.build.directory}/generated-sources/antlr4"
                                             includes="**/*.java"/>
                                </replaceregexp>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

        <!-- Needed so that the mvn test goal finds the ANTLR g4 files. -->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/antlr4</directory>
                <includes>
                    <include>**/*.g4</include>
                </includes>
            </resource>
        </resources>
    </build>

</project>
