<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>diktat-rules</artifactId>
    <name>diktat-rules</name>
    <description>The main diktat ruleset</description>

    <parent>
        <groupId>org.cqfn.diktat</groupId>
        <artifactId>diktat-parent</artifactId>
        <version>1.2.3</version>
    </parent>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <!-- kotlinpoet is needed only during build, but maven doesn't have such scope. -->
            <!-- If we ever move to gradle, it should be moved into a separate task. -->
            <!-- Also, we can't move it to test scope now, because Generation.kt has to be compiled before tests are compiled -->
            <groupId>com.squareup</groupId>
            <artifactId>kotlinpoet</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.cqfn.diktat</groupId>
            <artifactId>diktat-common</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.cqfn.diktat</groupId>
            <artifactId>diktat-test-framework</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.pinterest.ktlint</groupId>
            <artifactId>ktlint-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jdk8</artifactId>
        </dependency>
        <dependency>
            <!-- guava is used for string case utils -->
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </dependency>
        <dependency>
            <groupId>io.github.microutils</groupId>
            <artifactId>kotlin-logging-jvm</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-suite-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- is used for simplifying boolean expressions-->
        <dependency>
            <groupId>com.bpodgursky</groupId>
            <artifactId>jbool_expressions</artifactId>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
        <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>build-generated-code</id>
                        <phase>process-test-sources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <sourceDirs>
                                <source>${project.basedir}/src/main/kotlin/generated</source>
                            </sourceDirs>
                        </configuration>
                    </execution>
                    <execution>
                        <id>compile</id>
                        <phase>compile</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 if main sourceset is removed from here, syntax highlighting in idea an ability to launch tests is broken -->
                                <source>src/main/kotlin</source>
                                <source>src/test/kotlin</source>
                                <source>${project.basedir}/src/main/kotlin</source>
                                <source>${project.basedir}/src/test/kotlin</source>
                            </sourceDirs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>generate-warnings</id>
                        <phase>generate-test-sources</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>org.cqfn.diktat.ruleset.generation.GenerationKt</mainClass>
                    <arguments>
                        <argument>${project.build.sourceDirectory}</argument>
                        <argument>${project.basedir}/src/test/resources</argument>
                    </arguments>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**/DiktatSaveSmokeTest.*</exclude>
                    </excludes>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>**/DiktatSaveSmokeTest.*</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <!-- These executions complement those defined in the parent pom.xml. -->
                    <execution>
                        <id>default-prepare-agent-integration</id>
                        <goals>
                            <goal>prepare-agent-integration</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-merge</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>merge</goal>
                        </goals>
                        <configuration>
                            <fileSets>
                                <fileSet>
                                    <directory>${project.build.directory}</directory>
                                    <includes>
                                        <include>jacoco.exec</include>
                                        <include>jacoco-it.exec</include>
                                    </includes>
                                </fileSet>
                            </fileSets>
                            <destFile>${project.build.directory}/jacoco-merged.exec</destFile>
                        </configuration>
                    </execution>
                    <execution>
                        <id>default-report-merged</id>
                        <goals>
                            <goal>report-integration</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
                            <dataFile>${project.build.directory}/jacoco-merged.exec</dataFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Create a fat JAR to be used in smoke tests, removing the
                 circular dependency between `diktat-rules` and `diktat-ruleset`. -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <configuration>
                    <!-- Suppress the generation of `dependency-reduced-pom.xml`,
                         because it will also get installed under `~/.m2`,
                         resulting in the `diktat-maven-plugin` build failure
                         (the plug-in depends on `diktat-rules`). -->
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                    <!-- Should be `false`: otherwise, the generated JAR, even
                         with a custom classifier, will still be installed/deployed. -->
                    <shadedArtifactAttached>false</shadedArtifactAttached>
                    <!-- Necessary: otherwise, the artifact produced by the JAR
                         plug-in will be overwritten by the fat JAR. -->
                    <finalName>${project.name}-${project.version}-fat-jar-for-smoke-tests</finalName>
                    <artifactSet>
                        <excludes>
                            <exclude>com.squareup:kotlinpoet</exclude>
                            <exclude>net.java.dev.jna:jna</exclude>
                            <exclude>org.jetbrains.intellij.deps:trove4j</exclude>
                            <exclude>org.jetbrains.kotlin:kotlin-compiler-embeddable</exclude>
                            <exclude>org.jetbrains.kotlin:kotlin-daemon-embeddable</exclude>
                            <exclude>org.jetbrains.kotlin:kotlin-reflect</exclude>
                            <exclude>org.jetbrains.kotlin:kotlin-script-runtime</exclude>
                            <exclude>org.jetbrains.kotlin:kotlin-stdlib-common</exclude>
                            <exclude>org.jetbrains.kotlin:kotlin-stdlib-jdk7</exclude>
                            <exclude>org.jetbrains.kotlin:kotlin-stdlib-jdk8</exclude>
                            <exclude>org.jetbrains.kotlin:kotlin-stdlib</exclude>
                            <exclude>org.jetbrains:annotations</exclude>
                        </excludes>
                    </artifactSet>
                </configuration>
                <executions>
                    <execution>
                        <id>fat-jar-for-smoke-tests</id>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
