<?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.5</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>diktat-gradle-plugin</artifactId>
    <!-- not to generate default artifact jar and be able to also deploy plugin marker's pom as a module -->
    <packaging>pom</packaging>

    <properties>
        <gradle.workingDir>${project.basedir}</gradle.workingDir>
        <gradle.executable>gradlew</gradle.executable>
        <gradle.task>build</gradle.task>
        <gradle.builddir>build</gradle.builddir>
        <skip.gradle.build>false</skip.gradle.build>
        <skip.gradle.test>false</skip.gradle.test>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.cqfn.diktat</groupId>
            <artifactId>diktat-common</artifactId>
            <version>${project.version}</version>
            <exclusions>
                <exclusion>
                    <!-- Since we need diktat-common only for property name, we can exclude everything else -->
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.github.detekt.sarif4k</groupId>
            <artifactId>sarif4k-jvm</artifactId>
            <version>0.3.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <inherited>false</inherited>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>${project.basedir}/${gradle.builddir}</directory>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <inherited>false</inherited>
                <configuration>
                    <workingDirectory>${gradle.workingDir}</workingDirectory>
                    <executable>${gradle.workingDir}/${gradle.executable}</executable>
                </configuration>
                <executions>
                    <execution>
                        <id>gradle-test</id>
                        <phase>test</phase>
                        <configuration>
                            <arguments>
                                <argument>clean</argument>
                                <argument>test</argument>
                                <argument>functionalTest</argument>
                                <argument>-Pgroup=${project.groupId}</argument>
                                <argument>-Pversion=${project.version}</argument>
                                <argument>-Pdescription=${project.description}</argument>
                                <argument>-PktlintVersion=${ktlint.version}</argument>
                                <argument>-PjunitVersion=${junit.version}</argument>
                                <argument>-PjacocoVersion=${jacoco.version}</argument>
                                <argument>-S</argument>
                            </arguments>
                            <skip>${skip.gradle.test}</skip>
                        </configuration>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>gradle</id>
                        <phase>prepare-package</phase>
                        <configuration>
                            <arguments>
                                <argument>${gradle.task}</argument>
                                <argument>-Pgroup=${project.groupId}</argument>
                                <argument>-Pversion=${project.version}</argument>
                                <argument>-Pdescription=${project.description}</argument>
                                <argument>-PktlintVersion=${ktlint.version}</argument>
                                <argument>-PjunitVersion=${junit.version}</argument>
                                <argument>-PjacocoVersion=${jacoco.version}</argument>
                                <argument>-S</argument>
                                <!-- This argument can be set to excluded task in the specific build profile -->
<!--                                <argument></argument>-->
                            </arguments>
                            <skip>${skip.gradle.build}</skip>
                        </configuration>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <inherited>false</inherited>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${gradle.builddir}/libs/${project.artifactId}-${project.version}.jar</file>
                                    <type>jar</type>
                                </artifact>
                                <!-- Javadoc jar is generated by dokka from maven -->
                                <artifact>
                                    <file>${gradle.builddir}/libs/${project.artifactId}-${project.version}-sources.jar</file>
                                    <type>jar</type>
                                    <classifier>sources</classifier>
                                </artifact>
                            </artifacts>
                            <skipAttach>${skip.gradle.build}</skipAttach>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.github.ozsie</groupId>
                <artifactId>detekt-maven-plugin</artifactId>
                <version>${detekt.version}</version>
                <executions>
                    <execution>
                        <id>detekt</id>
                        <phase>none</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration combine.self="override">
                            <config>detekt-config.yml</config>
                            <!-- Do not use type resolution as dependencies in pom.xml are not accurate -->
                            <!--<classPath></classPath>-->
                            <languageVersion>1.3</languageVersion>
                            <jvmTarget>1.8</jvmTarget>
                            <excludes>**/resources/**/*.kt</excludes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- Do not include plugin marker module in builds where other modules are not installed -->
            <!-- Because otherwise plugin-marker won't have all dependencies -->
            <id>gradle-plugin-marker</id>
            <activation>
                <!-- Maven is awful so the only way to reliably have several profiles is activation by absence of property -->
                <property>
                    <name>!skipPluginMarker</name>
                </property>
            </activation>
            <modules>
                <module>gradle-plugin-marker</module>
            </modules>
        </profile>
        <profile>
            <id>local-win-build</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
            </activation>
            <properties>
                <gradle.executable>gradlew.bat</gradle.executable>
            </properties>
        </profile>
        <profile>
            <id>skip-gradle-tests</id>
            <activation>
                <property>
                    <name>skipTests</name>
                    <value>true</value>
                </property>
            </activation>
            <properties>
                <gradle.exclude.check>-xcheck</gradle.exclude.check>
                <skip.gradle.test>true</skip.gradle.test>
            </properties>
        </profile>
    </profiles>
</project>
