<?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>
        <artifactId>diktat-parent</artifactId>
        <groupId>org.cqfn.diktat</groupId>
        <version>1.2.4.2</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>diktat-maven-plugin</artifactId>
    <packaging>maven-plugin</packaging>

    <properties>
        <maven.api.version>3.8.6</maven.api.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.itf.version>0.11.0</maven.itf.version>
    </properties>

    <dependencies>
        <!-- FixMe: Use this, when it's released: https://maven.apache.org/ref/4-LATEST/maven-bom/ -->
        <!-- <dependency> -->
        <!--     <groupId>org.apache.maven</groupId> -->
        <!--     <artifactId>maven-bom</artifactId> -->
        <!--     <version>${maven.api.version}</version> -->
        <!-- </dependency> -->
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-core</artifactId>
            <version>${maven.api.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-plugin-api</artifactId>
            <version>${maven.api.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugin-tools</groupId>
            <artifactId>maven-plugin-annotations</artifactId>
            <version>${maven-plugin-tools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jdk8</artifactId>
        </dependency>
        <dependency>
            <groupId>org.cqfn.diktat</groupId>
            <artifactId>diktat-rules</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.pinterest.ktlint</groupId>
            <artifactId>ktlint-reporter-plain</artifactId>
        </dependency>
        <dependency>
            <groupId>com.pinterest.ktlint</groupId>
            <artifactId>ktlint-reporter-sarif</artifactId>
        </dependency>
        <dependency>
            <groupId>com.pinterest.ktlint</groupId>
            <artifactId>ktlint-reporter-json</artifactId>
        </dependency>
        <dependency>
            <groupId>com.pinterest.ktlint</groupId>
            <artifactId>ktlint-reporter-html</artifactId>
        </dependency>
        <dependency>
            <groupId>com.pinterest.ktlint</groupId>
            <artifactId>ktlint-reporter-baseline</artifactId>
        </dependency>
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.soebes.itf.jupiter.extension</groupId>
            <artifactId>itf-jupiter-extension</artifactId>
            <version>${maven.itf.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugin-testing</groupId>
            <artifactId>maven-plugin-testing-harness</artifactId>
            <version>3.3.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <!-- to use org.apache.maven.repository.RepositorySystem in newer maven versions and maybe other classes -->
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-compat</artifactId>
            <version>${maven.api.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-cipher</artifactId>
            <version>2.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>src/main/kotlin</sourceDirectory>
        <testSourceDirectory>src/test/kotlin</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>process-test-sources</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                        <configuration>
                            <sourceDirs>
                                <!-- for some weird reason this is essential to compile kotlin test sources despite testSourceDirectory is set -->
                                <source>src/test/kotlin</source>
                            </sourceDirs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>*IntegrationTest*</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.soebes.itf.jupiter.extension</groupId>
                <artifactId>itf-maven-plugin</artifactId>
                <version>${maven.itf.version}</version>
                <executions>
                    <execution>
                        <id>installing</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>install</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <configuration>
                    <systemProperties>
                        <maven.version>${maven.version}</maven.version>
                        <maven.home>${maven.home}</maven.home>
                    </systemProperties>
                    <includes>
                        <include>**/*IntegrationTest*</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <!-- Jacoco configuration for report on integration test, doesn't override configuration for unit tests -->
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <!-- HelpMojo is generated automatically -->
                        <exclude>**/HelpMojo*</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <id>report-integration</id>
                        <goals>
                            <!-- Merge reports of individual maven invokations and build xml report -->
                            <goal>merge</goal>
                            <goal>report-integration</goal>
                        </goals>
                        <phase>post-integration-test</phase>
                        <configuration>
                            <fileSets>
                                <fileSet>
                                    <directory>${project.build.directory}</directory>
                                    <includes>
                                        <!-- Every test case runs maven process and therefore generates individual execution report -->
                                        <inlcude>jacoco-it*.exec</inlcude>
                                    </includes>
                                </fileSet>
                            </fileSets>
                            <destFile>${project.build.directory}/jacoco-it.exec</destFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <testResources>
            <testResource>
                <directory>../examples/maven</directory>
                <!-- setting filtering to false keeps unresolved properties, which in diktat-examples do not depend on diktat properties -->
                <filtering>false</filtering>
                <targetPath>${project.build.testOutputDirectory}/org/cqfn/diktat/plugin/maven/DiktatMavenPluginIntegrationTest/diktatCheck</targetPath>
            </testResource>
            <testResource>
                <directory>${project.basedir}/src/test/resources/.mvn</directory>
                <!-- Here we need to resolve actual maven properties -->
                <filtering>true</filtering>
                <targetPath>${project.build.testOutputDirectory}/org/cqfn/diktat/plugin/maven/DiktatMavenPluginIntegrationTest/diktatCheck/.mvn</targetPath>
            </testResource>
            <testResource>
                <directory>../examples/maven</directory>
                <filtering>false</filtering>
                <targetPath>${project.build.testOutputDirectory}/org/cqfn/diktat/plugin/maven/DiktatMavenPluginIntegrationTest/diktatFix</targetPath>
            </testResource>
            <testResource>
                <directory>${project.basedir}/src/test/resources/.mvn</directory>
                <filtering>true</filtering>
                <targetPath>${project.build.testOutputDirectory}/org/cqfn/diktat/plugin/maven/DiktatMavenPluginIntegrationTest/diktatFix/.mvn</targetPath>
            </testResource>
        </testResources>
    </build>

    <profiles>
        <profile>
            <!-- disable maven plugin documentation generation by default to speed up builds -->
            <id>default</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-plugin-plugin</artifactId>
                        <configuration>
                            <goalPrefix>diktat</goalPrefix>
                            <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
                        </configuration>
                        <executions>
                            <execution>
                                <id>mojo-descriptor</id>
                                <goals>
                                    <goal>descriptor</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>help-goal</id>
                                <goals>
                                    <goal>helpmojo</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <!-- enable maven plugin documentation generation only for release builds to speed up ordinary builds -->
            <id>release</id>
            <pluginRepositories>
                <pluginRepository>
                    <id>kotlin-maven-plugin-tools</id>
                    <name>GitHub Packages</name>
                    <url>https://maven.pkg.github.com/gantsign/kotlin-maven-plugin-tools</url>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-plugin-plugin</artifactId>
                        <configuration>
                            <goalPrefix>diktat</goalPrefix>
                            <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
                            <extractors>
                                <!-- Extractor from kotlin-maven-plugin-tools -->
                                <extractor>kotlin</extractor>
                            </extractors>
                        </configuration>
                        <executions>
                            <execution>
                                <id>mojo-descriptor</id>
                                <goals>
                                    <goal>descriptor</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>help-goal</id>
                                <goals>
                                    <goal>helpmojo</goal>
                                </goals>
                            </execution>
                        </executions>
                        <dependencies>
                            <dependency>
                                <groupId>com.github.gantsign.maven.plugin-tools</groupId>
                                <artifactId>kotlin-maven-plugin-tools</artifactId>
                                <version>0.9.26</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>properties-maven-plugin</artifactId>
                        <version>1.1.0</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>set-system-properties</goal>
                                </goals>
                                <configuration>
                                    <properties>
                                        <property>
                                            <name>idea.io.use.nio2</name>
                                            <value>true</value>
                                        </property>
                                        <property>
                                            <name>idea.io.use.fallback</name>
                                            <value>true</value>
                                        </property>
                                    </properties>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
