<?xml version="1.0"?>
<!--
Copyright (C) 2013-2020 TU Dortmund
This file is part of AutomataLib, http://www.automatalib.net/.

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>

    <parent>
        <groupId>net.automatalib</groupId>
        <artifactId>automata-parent</artifactId>
        <version>0.9.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

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

    <name>AutomataLib :: Build Parent</name>
    <description>
        A utility artifact, 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>

    <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 automata types -->
                            <exclude>net/automatalib/util/automata/builders/AutomatonBuilder.class</exclude>
                            <exclude>net/automatalib/util/automata/builders/AutomatonBuilder$*.class</exclude>
                            <exclude>net/automatalib/util/automata/builders/DFABuilder.class</exclude>
                            <exclude>net/automatalib/util/automata/builders/DFABuilder$*.class</exclude>
                            <exclude>net/automatalib/util/automata/builders/FSABuilder.class</exclude>
                            <exclude>net/automatalib/util/automata/builders/FSABuilder$*.class</exclude>
                            <exclude>net/automatalib/util/automata/builders/MealyBuilder.class</exclude>
                            <exclude>net/automatalib/util/automata/builders/MealyBuilder$*.class</exclude>
                            <exclude>net/automatalib/util/automata/builders/MooreBuilder.class</exclude>
                            <exclude>net/automatalib/util/automata/builders/MooreBuilder$*.class</exclude>

                            <!-- generated parser for TAF serialization -->
                            <exclude>net/automatalib/serialization/taf/parser/InternalTAFParser*.class</exclude>
                            <exclude>net/automatalib/serialization/taf/parser/ParseException.class</exclude>
                            <exclude>net/automatalib/serialization/taf/parser/SimpleCharStream.class</exclude>
                            <exclude>net/automatalib/serialization/taf/parser/Token.class</exclude>
                            <exclude>net/automatalib/serialization/taf/parser/TokenMgrError.class</exclude>

                            <!-- generated parser for LTSmin LTL parser -->
                            <exclude>net/automatalib/modelcheckers/ltsmin/InternalLTSminLTLParser*.class</exclude>
                            <exclude>net/automatalib/modelcheckers/ltsmin/ParseException.class</exclude>
                            <exclude>net/automatalib/modelcheckers/ltsmin/SimpleCharStream.class</exclude>
                            <exclude>net/automatalib/modelcheckers/ltsmin/Token.class</exclude>
                            <exclude>net/automatalib/modelcheckers/ltsmin/TokenMgrError.class</exclude>

                            <!-- generated builders for model checkers -->
                            <exclude>net/automatalib/modelcheckers/ltsmin/ltl/LTSminLTLAlternatingBuilder.class</exclude>
                            <exclude>net/automatalib/modelcheckers/ltsmin/ltl/LTSminLTLDFABuilder.class</exclude>
                            <exclude>net/automatalib/modelcheckers/ltsmin/ltl/LTSminLTLIOBuilder.class</exclude>

                            <exclude>net/automatalib/modelcheckers/ltsmin/monitor/LTSminMonitorAlternatingBuilder.class</exclude>
                            <exclude>net/automatalib/modelcheckers/ltsmin/monitor/LTSminMonitorDFABuilder.class</exclude>
                            <exclude>net/automatalib/modelcheckers/ltsmin/monitor/LTSminMonitorIOBuilder.class</exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <profiles>
        <profile>
            <id>code-analysis</id>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>com.github.spotbugs</groupId>
                            <artifactId>spotbugs-maven-plugin</artifactId>
                            <configuration>
                                <excludeFilterFile>/automatalib-spotbugs-exclusions.xml</excludeFilterFile>
                                <effort>Max</effort>
                            </configuration>
                            <dependencies>
                                <dependency>
                                    <groupId>net.automatalib</groupId>
                                    <artifactId>automata-build-tools</artifactId>
                                    <version>${project.version}</version>
                                </dependency>
                            </dependencies>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-pmd-plugin</artifactId>
                            <configuration>
                                <rulesets>
                                    <ruleset>/automatalib-pmd-ruleset.xml</ruleset>
                                </rulesets>
                            </configuration>
                            <dependencies>
                                <dependency>
                                    <groupId>net.automatalib</groupId>
                                    <artifactId>automata-build-tools</artifactId>
                                    <version>${project.version}</version>
                                </dependency>
                            </dependencies>
                        </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>/automatalib-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>net.automatalib</groupId>
                                    <artifactId>automata-build-tools</artifactId>
                                    <version>${project.version}</version>
                                </dependency>
                            </dependencies>
                        </plugin>
                    </plugins>
                </pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>com.github.spotbugs</groupId>
                        <artifactId>spotbugs-maven-plugin</artifactId>
                        <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>net.automatalib:automata-build-tools:${project.version}</artifact>
                                    <includes>automatalib-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>
                        <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/automatalib-pmd-exclusions.properties</excludeFromFailureFile>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-checkstyle-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>verify</phase>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>cf</id>
            <dependencies>
                <dependency>
                    <groupId>org.checkerframework</groupId>
                    <artifactId>checker</artifactId>
                    <version>${checkerframework.version}</version>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.checkerframework</groupId>
                    <artifactId>jdk8</artifactId>
                    <version>${checkerframework.version}</version>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>com.google.errorprone</groupId>
                    <artifactId>javac</artifactId>
                    <version>${error-prone.version}</version>
                </dependency>
                <!--dependency>
                    <groupId>org.checkerframework.annotatedlib</groupId>
                    <artifactId>guava</artifactId>
                    <version>${guava.version}</version>
                    <scope>provided</scope>
                </dependency-->
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>properties</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>cf-compile</id>
                                <phase>compile</phase>
                                <goals>
                                    <goal>compile</goal>
                                </goals>
                                <configuration>
                                    <skipMain>${automatalib.java9OrNewer}</skipMain>
                                    <failOnWarning>true</failOnWarning>
                                    <proc>only</proc>
                                    <fork>true</fork>
                                    <outputDirectory>${project.build.directory}/checkerframework</outputDirectory>
                                    <annotationProcessors>
                                        <annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
                                        <!--<annotationProcessor>org.checkerframework.checker.signedness.SignednessChecker</annotationProcessor>-->
                                    </annotationProcessors>
                                    <compilerArgs>
                                        <arg>-J-Xbootclasspath/p:${com.google.errorprone:javac:jar}</arg>
                                        <arg>-Xbootclasspath/p:${org.checkerframework:jdk8:jar}</arg>
                                        <!--<arg>-Xbootclasspath/a:${org.checkerframework.annotatedlib:guava:jar}</arg>-->
                                        <arg>-AskipDefs=net\.automatalib\.(serialization\.taf\.parser|modelcheckers\.ltsmin)\.(Internal.*|Token.*|SimpleCharStream)</arg> <!-- generated classes -->
                                        <!--<arg>-AonlyUses=^net\.automatalib</arg>-->
                                        <arg>-AskipUses=^com\.google|^java\.(awt|util\.Arrays|io\.StreamTokenizer)|^javax\.swing</arg>
                                        <arg>-AsuppressWarnings=uninitialized</arg>
                                        <arg>-AassumeAssertionsAreEnabled</arg>
                                        <!--<arg>-Alint=redundantNullComparison</arg>-->
                                    </compilerArgs>
                                </configuration>
                            </execution>
                            <execution>
                                <id>cf-test-compile</id>
                                <phase>test-compile</phase>
                                <goals>
                                    <goal>testCompile</goal>
                                </goals>
                                <configuration>
                                    <skip>${automatalib.java9OrNewer}</skip>
                                    <failOnWarning>true</failOnWarning>
                                    <proc>only</proc>
                                    <fork>true</fork>
                                    <outputDirectory>${project.build.directory}/checkerframework</outputDirectory>
                                    <annotationProcessors>
                                        <annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
                                    </annotationProcessors>
                                    <compilerArgs>
                                        <arg>-J-Xbootclasspath/p:${com.google.errorprone:javac:jar}</arg>
                                        <arg>-Xbootclasspath/p:${org.checkerframework:jdk8:jar}</arg>
                                        <arg>-AonlyDefs=^net\.automatalib</arg>
                                        <arg>-AskipUses=.*</arg>
                                        <arg>-AsuppressWarnings=uninitialized</arg>
                                        <arg>-AassumeAssertionsAreEnabled</arg>
                                        <arg>-Alint=redundantNullComparison</arg>
                                    </compilerArgs>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
