<?xml version="1.0"?>
<!--
Copyright (C) 2013-2018 TU Dortmund
This file is part of LearnLib, http://www.learnlib.de/.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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>

    <artifactId>learnlib-build-parent</artifactId>
    <packaging>pom</packaging>

    <name>LearnLib :: Build Parent</name>
    <description>
        A utility parent, that defines certain plugin executions for the build process. May be used to define
        dependencies on the "build-tools" artifact without introducing cyclic dependencies with the general parent.
    </description>

    <parent>
        <groupId>de.learnlib</groupId>
        <artifactId>learnlib-parent</artifactId>
        <version>0.13.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <profiles>
        <profile>
            <id>code-analysis</id>
            <activation>
                <property>
                    <name>learnlib.release</name>
                    <value>true</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>findbugs-maven-plugin</artifactId>
                        <configuration>
                            <excludeFilterFile>/learnlib-findbugs-exclusions.xml</excludeFilterFile>
                            <effort>Max</effort>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>de.learnlib</groupId>
                                <artifactId>learnlib-build-tools</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <phase>verify</phase>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- TODO FIXME XXX oh boy, here we go:
                    Since the pmd-plugin (at least until now) reads its 'violation exclusion' file as a real file
                    (i.e. not as a resource from the classpath) we need to provide an actual file path. Since Maven
                    evaluates any variables such as ${basedir} in the context of the _active_ project it will change
                    for every child module (so we cannot specify an absolute path relative to the git checkout)

                    For now, we use the dependency plugin to extract our build-tools artifact (only the pmd-exclusions)
                    into the ${project.build.directory} for every module, where we can correctly reference it using
                    Maven variables again. Since this all happens in the 'verify' phase, this will not pollute the
                    contents of the jars (packaged in the 'package' phase).

                    This should be cleaned up as soon as the PMD plugins can read exclusion files from the classpath
                    -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>unpack-pmd</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifact>de.learnlib:learnlib-build-tools:${project.version}</artifact>
                                    <includes>learnlib-pmd-exclusions.properties</includes>
                                    <outputDirectory>${project.build.directory}/pmd/</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-pmd-plugin</artifactId>
                        <configuration>
                            <rulesets>
                                <ruleset>/learnlib-pmd-ruleset.xml</ruleset>
                            </rulesets>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>de.learnlib</groupId>
                                <artifactId>learnlib-build-tools</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>pmd</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                                <configuration>
                                    <!-- Path is loaded as a file, not as a resource, thus we need the absolute path -->
                                    <excludeFromFailureFile>
                                        ${project.build.directory}/pmd/learnlib-pmd-exclusions.properties
                                    </excludeFromFailureFile>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-checkstyle-plugin</artifactId>
                        <configuration>
                            <configLocation>/automatalib-learnlib-checkstyle.xml</configLocation>
                            <headerLocation>/license-header-java.txt</headerLocation>
                            <suppressionsLocation>/learnlib-checkstyle-suppressions.xml</suppressionsLocation>
                            <includeTestSourceDirectory>true</includeTestSourceDirectory>
                            <linkXRef>false</linkXRef>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>com.puppycrawl.tools</groupId>
                                <artifactId>checkstyle</artifactId>
                                <version>${checkstyle.version}</version>
                            </dependency>
                            <dependency>
                                <groupId>de.learnlib</groupId>
                                <artifactId>learnlib-build-tools</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <phase>verify</phase>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <pluginManagement>
            <plugins>
                <!-- If we run coverage analysis, skip generated sources -->
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <configuration>
                        <excludes>
                            <!-- generated builders for learning algorithms -->
                            <exclude>**/ADTLearnerBuilder.class</exclude>
                            <exclude>**/MealyDHCBuilder.class</exclude>
                            <exclude>**/DTLearner*Builder.class</exclude>
                            <exclude>**/DTLearnerVPDABuilder.class</exclude>
                            <exclude>**/KearnsVazirani*Builder.class</exclude>
                            <exclude>**/ClassicLStar*Builder.class</exclude>
                            <exclude>**/ExtensibleLStar*Builder.class</exclude>
                            <exclude>**/MalerPnueli*Builder.class</exclude>
                            <exclude>**/RivestSchapire*Builder.class</exclude>
                            <exclude>**/NLStarLearnerBuilder.class</exclude>
                            <exclude>**/TTTLearner*Builder.class</exclude>
                            <exclude>**/TTTLearnerVPDABuilder.class</exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>
