<?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">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.sonatype.oss</groupId>
    <artifactId>oss-parent</artifactId>
    <version>9</version>
  </parent>

  <groupId>com.github.sevntu-checkstyle</groupId>
  <artifactId>sevntu-checks</artifactId>
  <version>1.24.2</version>

  <properties>
    <project.build.sourceEncoding>iso-8859-1</project.build.sourceEncoding>
    <!-- it is not compile dependency to checkstyle, this version is only for maven plugins -->
    <checkstyle.version>8.0</checkstyle.version>
    <checkstyle.configLocation>https://raw.githubusercontent.com/checkstyle/checkstyle/checkstyle-${checkstyle.version}/config/checkstyle_checks.xml</checkstyle.configLocation>
    <!-- It is compile dependency to checkstyle, this version has to be the same as eclispe-cs depends on -->
    <checkstyle.eclipse-cs.version>7.6</checkstyle.eclipse-cs.version>
    <checkstyle.plugin.version>2.17</checkstyle.plugin.version>
    <sevntu.maven.plugin>RELEASE</sevntu.maven.plugin>
  </properties>

  <licenses>
    <license>
      <name>LGPL-2.1+</name>
      <url>http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt</url>
    </license>
  </licenses>

  <dependencies>
    <dependency>
      <groupId>com.puppycrawl.tools</groupId>
      <artifactId>checkstyle</artifactId>
      <version>${checkstyle.eclipse-cs.version}</version>
    </dependency>
    <dependency>
      <groupId>com.puppycrawl.tools</groupId>
      <artifactId>checkstyle</artifactId>
      <type>test-jar</type>
      <scope>test</scope>
      <version>${checkstyle.eclipse-cs.version}</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.powermock</groupId>
      <artifactId>powermock-api-mockito</artifactId>
      <version>1.6.6</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.powermock</groupId>
      <artifactId>powermock-module-junit4</artifactId>
      <version>1.6.6</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jgit</groupId>
      <artifactId>org.eclipse.jgit</artifactId>
      <version> 4.5.0.201609210915-r</version>
      <scope>test</scope>
    </dependency>
    <!-- required for package/import test cases because creating dummy ones interferes with cobertura -->
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>1.7.21</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>2.2.1</version>
        <executions>
          <execution>
            <id>attach-sources</id>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-javadoc-plugin</artifactId>
          <version>2.10.4</version>
          <executions>
            <execution>
              <id>attach-javadocs</id>
              <phase>package</phase>
              <goals>
                <goal>jar</goal>
              </goals>
           </execution>
         </executions>
      </plugin>

      <plugin>
        <groupId>org.sonatype.plugins</groupId>
        <artifactId>nexus-staging-maven-plugin</artifactId>
        <version>1.6.8</version>
        <extensions>true</extensions>
        <configuration>
          <!-- serverId is ID of a <server> section from Maven's settings.xml
              to pick authentication information from
          -->
          <serverId>sonatype-nexus-staging</serverId>
          <nexusUrl>https://oss.sonatype.org/</nexusUrl>
          <autoReleaseAfterClose>false</autoReleaseAfterClose>
          <skipStaging>true</skipStaging>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.17</version>
        <configuration>
          <additionalClasspathElements>
            <additionalClasspathElement>src/test/resources-noncompilable</additionalClasspathElement>
          </additionalClasspathElements>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.9.1</version>
        <executions>
          <execution>
            <id>add-test-source</id>
            <phase>generate-test-sources</phase>
            <goals>
              <goal>add-test-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>src/test/resources</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>${checkstyle.plugin.version}</version>
        <dependencies>
          <dependency>
            <groupId>com.puppycrawl.tools</groupId>
            <artifactId>checkstyle</artifactId>
            <version>${checkstyle.version}</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <!-- https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference
                 to run checkstyle validation in terminal please use command "mvn process-classes"
            -->
            <phase>process-classes</phase>
            <goals>
              <goal>check</goal>
            </goals>
            <configuration>
              <configLocation>${checkstyle.configLocation}</configLocation>
              <failOnViolation>true</failOnViolation>
              <linkXRef>false</linkXRef>
              <propertiesLocation>checkstyle.properties</propertiesLocation>
              <sourceDirectory>${project.basedir}/src</sourceDirectory>
              <excludes>**/test/resources/**/*,**/test/resources-noncompilable/**/*</excludes>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.7</version>
        <configuration>
          <check>
            <haltOnFailure>true</haltOnFailure>
            <!-- only integer values are accepted, all values should 100 after all whole regexes group
              is removed -->
            <branchRate>100</branchRate>
            <lineRate>100</lineRate>
            <totalBranchRate>88</totalBranchRate>
            <totalLineRate>96</totalLineRate>
            <regexes>
              <regex><pattern>.*.checks.coding.CustomDeclarationOrderCheck.*</pattern><branchRate>81</branchRate><lineRate>83</lineRate></regex>
              <regex><pattern>.*.checks.coding.EitherLogOrThrowCheck</pattern><branchRate>88</branchRate><lineRate>99</lineRate></regex>
              <regex><pattern>.*.checks.coding.ForbidThrowAnonymousExceptionsCheck</pattern><branchRate>81</branchRate><lineRate>97</lineRate></regex>
              <regex><pattern>.*.checks.coding.MapIterationInForEachLoopCheck</pattern><branchRate>90</branchRate><lineRate>98</lineRate></regex>
              <regex><pattern>.*.checks.coding.NoNullForCollectionReturnCheck</pattern><branchRate>85</branchRate><lineRate>96</lineRate></regex>
              <regex><pattern>.*.checks.coding.OverridableMethodInConstructorCheck</pattern><branchRate>88</branchRate><lineRate>99</lineRate></regex>
              <regex><pattern>.*.checks.design.HideUtilityClassConstructorCheck</pattern><branchRate>94</branchRate><lineRate>100</lineRate></regex>
            </regexes>
          </check>
        </configuration>
        <executions>
          <execution>
            <goals>
              <!-- validation triggered with check goal -->
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>travis</id>
      <activation>
        <property>
          <name>env.TRAVIS</name>
          <value>true</value>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.1.201405082137</version>
            <executions>
              <execution>
                <id>prepare-agent</id>
                <goals>
                  <goal>prepare-agent</goal>
                </goals>
              </execution>
              <execution>
                <id>report</id>
                <goals>
                  <goal>report</goal>
                </goals>
                <phase>prepare-package</phase>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.eluder.coveralls</groupId>
            <artifactId>coveralls-maven-plugin</artifactId>
            <version>2.2.0</version>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>selftesting</id>
      <properties>
        <skipTests>true</skipTests>
        <linkcheck.skip>true</linkcheck.skip>
        <maven.javadoc.skip>true</maven.javadoc.skip>
        <pmd.skip>true</pmd.skip>
        <xml.skip>true</xml.skip>
        <forbiddenapis.skip>true</forbiddenapis.skip>
        <findbugs.skip>true</findbugs.skip>
        <cobertura.skip>true</cobertura.skip>
        <maven.site.skip>true</maven.site.skip>
      </properties>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>${checkstyle.plugin.version}</version>
            <dependencies>
              <dependency>
                <groupId>com.puppycrawl.tools</groupId>
                <artifactId>checkstyle</artifactId>
                <version>${checkstyle.version}</version>
              </dependency>
              <!-- atention here is self-referencing, so be sure you did "mvn install" before "mvn verify -Pselftesting" -->
              <dependency>
                <groupId>com.github.sevntu-checkstyle</groupId>
                <artifactId>sevntu-checks</artifactId>
                <version>${project.version}</version>
              </dependency>
            </dependencies>
            <executions>
              <execution>
                <!-- https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference
                     to run checkstyle validation in terminal please use command "mvn process-classes"
                -->
                <phase>process-classes</phase>
                <goals>
                  <goal>check</goal>
                </goals>
                <configuration>
                  <configLocation>sevntu-checks.xml</configLocation>
                  <failOnViolation>true</failOnViolation>
                  <linkXRef>false</linkXRef>
                  <sourceDirectory>${project.basedir}/src</sourceDirectory>
                  <excludes>**/test/resources/**/*,**/test/resources-noncompilable/**/*</excludes>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>local-deploy</id>
      <distributionManagement>
        <repository>
          <id>com.github.sevntu-checkstyle</id>
          <name>sevntu-checks</name>
          <url>file://${basedir}/../gh-pages/maven2/</url>
        </repository>
      </distributionManagement>
    </profile>

    <profile>
      <!-- first part of profile is in settings.xml with defined gpg.passphrase and gpg.keyname -->
      <id>gpg</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
            <version>1.6</version>
            <executions>
              <execution>
                <id>sign-artifacts</id>
                <phase>verify</phase>
                <goals>
                  <goal>sign</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

  </profiles>

  <pluginRepositories>
    <pluginRepository>
      <id>sevntu-maven</id>
      <name>sevntu-maven</name>
      <url>http://sevntu-checkstyle.github.io/sevntu.checkstyle/maven2</url>
    </pluginRepository>
  </pluginRepositories>

</project>
