<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright (C) 2023 - 2024, Ashley Scopes.

    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>

  <groupId>io.github.ascopes</groupId>
  <artifactId>protobuf-maven-plugin</artifactId>
  <version>0.3.2</version>

  <name>Protobuf Maven Plugin</name>
  <description>Generates compilable sources from Protobuf definitions.</description>
  <packaging>maven-plugin</packaging>

  <prerequisites>
    <maven>3.8.1</maven>
  </prerequisites>

  <inceptionYear>2023</inceptionYear>

  <licenses>
    <license>
      <name>The Apache Software License, Version 2.0</name>
      <url>https://github.com/ascopes/protobuf-maven-plugin/blob/main/LICENSE.txt</url>
    </license>
  </licenses>

  <developers>
    <developer>
      <id>ascopes</id>
      <name>Ashley Scopes</name>
      <email>73482956+ascopes@users.noreply.github.com</email>
      <url>https://github.com/ascopes</url>
      <organization>Ashley Scopes</organization>
      <organizationUrl>https://github.com/ascopes</organizationUrl>
      <roles>
        <role>Developer</role>
      </roles>
      <timezone>Europe/London</timezone>
    </developer>
  </developers>

  <contributors />

  <distributionManagement>
    <repository>
      <id>ossrh</id>
      <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
    </repository>
    <snapshotRepository>
      <id>ossrh</id>
      <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
    </snapshotRepository>
    <site>
      <id>github-pages</id>
      <name>github-pages</name>
      <url>https://ascopes.github.io/protobuf-maven-plugin</url>
    </site>
  </distributionManagement>

  <issueManagement>
    <system>GitHub Issues</system>
    <url>https://github.com/ascopes/protobuf-maven-plugin/issues</url>
  </issueManagement>

  <organization>
    <name>Ashley Scopes (GitHub)</name>
    <url>https://github.com/ascopes</url>
  </organization>

  <url>https://github.com/ascopes/protobuf-maven-plugin</url>

  <scm>
    <url>https://github.com/ascopes/protobuf-maven-plugin</url>
    <connection>scm:git:https://github.com/ascopes/protobuf-maven-plugin</connection>
    <developerConnection>scm:git:https://github.com/ascopes/protobuf-maven-plugin</developerConnection>
    <tag>v0.3.2</tag>
  </scm>

  <properties>
    <!-- Dependencies -->
    <assertj.version>3.25.3</assertj.version>
    <immutables.version>2.10.0</immutables.version>
    <jspecify.version>0.3.0</jspecify.version>
    <junit.version>5.10.2</junit.version>
    <maven-artifact-transfer.version>0.13.1</maven-artifact-transfer.version>
    <maven-core.version>3.9.6</maven-core.version>
    <maven-plugin-annotations.version>3.11.0</maven-plugin-annotations.version>
    <maven-plugin-api.version>3.9.6</maven-plugin-api.version>
    <memoryfilesystem.version>2.8.0</memoryfilesystem.version>
    <mockito.version>5.10.0</mockito.version>
    <slf4j.version>2.0.12</slf4j.version>

    <!-- Plugins -->
    <jacoco-maven-plugin.version>0.8.11</jacoco-maven-plugin.version>
    <license-maven-plugin.version>4.3</license-maven-plugin.version>
    <maven-checkstyle-plugin.version>3.3.1</maven-checkstyle-plugin.version>
    <maven-compiler-plugin.version>3.12.1</maven-compiler-plugin.version>
    <maven-gpg-plugin.version>3.1.0</maven-gpg-plugin.version>
    <maven-invoker-plugin.version>3.6.0</maven-invoker-plugin.version>
    <maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
    <maven-javadoc-plugin.version>3.6.3</maven-javadoc-plugin.version>
    <maven-plugin-plugin.version>3.11.0</maven-plugin-plugin.version>
    <maven-plugin-report-plugin.version>3.11.0</maven-plugin-report-plugin.version>
    <maven-project-info-reports-plugin.version>3.5.0</maven-project-info-reports-plugin.version>
    <maven-release-plugin.version>3.0.1</maven-release-plugin.version>
    <maven-site-plugin.version>4.0.0-M13</maven-site-plugin.version>
    <maven-source-plugin.version>3.3.0</maven-source-plugin.version>
    <maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
    <sisu-maven-plugin.version>0.3.5</sisu-maven-plugin.version>

    <!-- Plugin dependencies -->
    <checkstyle.version>10.13.0</checkstyle.version>
    <maven-surefire-junit5-tree-reporter.version>1.2.1</maven-surefire-junit5-tree-reporter.version>

    <!-- Other stuff -->
    <argLine>
      -Xshare:off
      -Dnet.bytebuddy.experimental=true
      -Dorg.slf4j.simpleLogger.log.io.github.ascopes=TRACE
    </argLine>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.junit</groupId>
        <artifactId>junit-bom</artifactId>
        <version>${junit.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>

      <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-bom</artifactId>
        <version>${mockito.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>${maven-plugin-api.version}</version>
      <!-- Provided by Maven at runtime -->
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.maven.plugin-tools</groupId>
      <artifactId>maven-plugin-annotations</artifactId>
      <version>${maven-plugin-annotations.version}</version>
      <!-- Provided by Maven at runtime -->
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-core</artifactId>
      <version>${maven-core.version}</version>
      <!-- Provided by Maven at runtime -->
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.maven.shared</groupId>
      <artifactId>maven-artifact-transfer</artifactId>
      <version>${maven-artifact-transfer.version}</version>
      <scope>compile</scope>

      <exclusions>
        <!-- These are pulled in with provided scope by other dependencies,
            so do not depend on them with compile scope as this will raise
            build warnings. -->
        <exclusion>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-artifact</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-model</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.jspecify</groupId>
      <artifactId>jspecify</artifactId>
      <version>${jspecify.version}</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${slf4j.version}</version>
      <!-- Provided by Maven at runtime, so don't bundle it. -->
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.immutables</groupId>
      <artifactId>value</artifactId>
      <version>${immutables.version}</version>
      <scope>provided</scope>
    </dependency>

    <!-- Test dependencies -->
    <dependency>
      <groupId>com.github.marschall</groupId>
      <artifactId>memoryfilesystem</artifactId>
      <version>${memoryfilesystem.version}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <version>${assertj.version}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-junit-jupiter</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>${slf4j.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <!-- Enforces our license header and allows adding it automatically to code. -->
        <groupId>com.mycila</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <version>${license-maven-plugin.version}</version>

        <configuration>
          <!-- Useful flags: https://mycila.carbou.me/license-maven-plugin/ -->
          <licenseSets>
            <licenseSet>
              <header>.mvn/license/license-header.txt</header>
              <includes>
                <include>src/**/*.groovy</include>
                <include>src/**/*.java</include>
                <include>src/**/*.proto</include>
                <include>**/*.xml</include>
              </includes>
              <excludes>
                <exclude>.mvn/checkstyle/checkstyle.xml</exclude>
              </excludes>
            </licenseSet>
          </licenseSets>
          <mapping>
            <java>SLASHSTAR_STYLE</java>
          </mapping>
          <properties>
            <currentYear>2024</currentYear>
            <inceptionYear>${project.inceptionYear}</inceptionYear>
          </properties>
          <strictCheck>true</strictCheck>
        </configuration>

        <executions>
          <execution>
            <id>validate-license-headers</id>
            <phase>validate</phase>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <!-- Checking style of code matches the Google code style. -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>${maven-checkstyle-plugin.version}</version>

        <configuration>
          <configLocation>.mvn/checkstyle/checkstyle.xml</configLocation>
          <consoleOutput>true</consoleOutput>
          <failsOnError>true</failsOnError>
          <includeResources>true</includeResources>
          <sourceDirectories>${project.basedir}/src</sourceDirectories>
          <suppressionsLocation>.mvn/checkstyle/suppressions.xml</suppressionsLocation>
          <violationSeverity>info</violationSeverity>
        </configuration>

        <dependencies>
          <dependency>
            <!-- Force the usage of checkstyle v10 rather than v8.28 -->
            <groupId>com.puppycrawl.tools</groupId>
            <artifactId>checkstyle</artifactId>
            <version>${checkstyle.version}</version>
          </dependency>
        </dependencies>
      </plugin>

      <plugin>
        <!-- Java compiler config. -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${maven-compiler-plugin.version}</version>

        <configuration>
          <compilerArgs>
            <compilerArg>-Xlint:all,-classfile,-processing,-serial</compilerArg>
          </compilerArgs>
          <failOnWarning>true</failOnWarning>
          <showDeprecation>true</showDeprecation>
          <release>11</release>
        </configuration>
      </plugin>

      <plugin>
        <!-- Runs integration tests. -->
        <!-- See documentation at https://maven.apache.org/plugins/maven-invoker-plugin/integration-test-mojo.html -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-invoker-plugin</artifactId>
        <version>${maven-invoker-plugin.version}</version>

        <configuration>
          <addTestClassPath>true</addTestClassPath>
          <failIfNoProjects>true</failIfNoProjects>
          <postBuildHookScript>test</postBuildHookScript>
          <showErrors>true</showErrors>
          <showVersion>true</showVersion>
          <streamLogsOnFailures>true</streamLogsOnFailures>
          <writeJunitReport>true</writeJunitReport>
        </configuration>

        <executions>
          <execution>
            <id>integration-test</id>
            <phase>integration-test</phase>
            <goals>
              <goal>install</goal>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <!-- Add additional entries to the JAR's MANIFEST.MF. -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>${maven-jar-plugin.version}</version>

        <configuration>
          <archive>
            <index>true</index>
            <manifest>
              <addBuildEnvironmentEntries>true</addBuildEnvironmentEntries>
              <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
              <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
              <addExtensions>true</addExtensions>
            </manifest>
            <manifestEntries>
              <Sealed>true</Sealed>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>

      <plugin>
        <!-- We disable JavaDoc generation entirely as we do not need it. -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>${maven-javadoc-plugin.version}</version>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>

      <plugin>
        <!-- Generate plugin descriptors. -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-plugin-plugin</artifactId>
        <version>${maven-plugin-plugin.version}</version>

        <executions>
          <execution>
            <!-- We already generate the main descriptor by default.
                The help mojo is then generated for us by this
                custom execution. -->
            <id>generate-help-mojo</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>helpmojo</goal>
            </goals>
            <configuration>
              <helpPackageName>io.github.ascopes.protobufmavenplugin</helpPackageName>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <!-- Create site info pages. -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <version>${maven-project-info-reports-plugin.version}</version>
      </plugin>

      <plugin>
        <!-- Deployments and version incrementing. -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>${maven-release-plugin.version}</version>
        <configuration>
          <!-- These are run in the prepare phase already so don't run them twice -->
          <arguments>-Dmaven.test.skip -Dinvoker.skip</arguments>
          <goals>deploy</goals>
          <releaseProfiles>gpg</releaseProfiles>
        </configuration>
      </plugin>


      <plugin>
        <!-- Generate the plugin site. -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <version>${maven-site-plugin.version}</version>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>${maven-source-plugin.version}</version>
      </plugin>

      <plugin>
        <!-- Unit testing. -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven-surefire-plugin.version}</version>

        <configuration>
          <consoleOutputReporter>
            <disable>true</disable>
          </consoleOutputReporter>
          <!--
            This block is needed to show @DisplayName and @ParameterizedTest
            in reports with the provided names.
          -->
          <statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
            <disable>false</disable>
            <version>3.0</version>
            <usePhrasedFileName>false</usePhrasedFileName>
            <usePhrasedTestSuiteClassName>true</usePhrasedTestSuiteClassName>
            <usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
            <usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
          </statelessTestsetReporter>
          <statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
            <disable>false</disable>
            <printStacktraceOnError>true</printStacktraceOnError>
            <printStacktraceOnFailure>true</printStacktraceOnFailure>
            <usePhrasedFileName>false</usePhrasedFileName>
            <usePhrasedClassNameInRunning>true</usePhrasedClassNameInRunning>
            <usePhrasedClassNameInTestCaseSummary>true</usePhrasedClassNameInTestCaseSummary>
          </statelessTestsetInfoReporter>
        </configuration>

        <dependencies>
          <dependency>
            <groupId>me.fabriciorby</groupId>
            <artifactId>maven-surefire-junit5-tree-reporter</artifactId>
            <version>${maven-surefire-junit5-tree-reporter.version}</version>
          </dependency>
        </dependencies>
      </plugin>

      <plugin>
        <!-- Generates JSR-330 CDI configuration data to enable using dependency injection -->
        <groupId>org.eclipse.sisu</groupId>
        <artifactId>sisu-maven-plugin</artifactId>
        <version>${sisu-maven-plugin.version}</version>
        <executions>
          <execution>
            <id>generate-index</id>
            <goals>
              <goal>main-index</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <!-- Code coverage. -->
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>${jacoco-maven-plugin.version}</version>

        <executions>
          <execution>
            <id>prepare-coverage-agent-surefire</id>
            <phase>initialize</phase>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
          </execution>

          <execution>
            <id>prepare-coverage-agent-invoker</id>
            <phase>initialize</phase>
            <goals>
              <goal>prepare-agent-integration</goal>
            </goals>
            <configuration>
              <!-- Append to ensure multiple invoker test calls are included -->
              <append>true</append>
              <!-- Ensure `${invoker.mavenOpts}` is set in the invoker.properties as well
                  if maven.argLine is overridden. -->
              <includes>io.github.ascopes.protobufmavenplugin.*</includes>
              <propertyName>invoker.mavenOpts</propertyName>
            </configuration>
          </execution>

          <execution>
            <id>generate-coverage-reports</id>
            <goals>
              <goal>report</goal>
              <goal>report-integration</goal>
              <goal>report-aggregate</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <reporting>
    <plugins>
      <plugin>
        <!-- Compile src/main/site and generate the goals site pages. -->
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-plugin-report-plugin</artifactId>
        <version>${maven-plugin-report-plugin.version}</version>
      </plugin>
    </plugins>
  </reporting>

  <profiles>
    <profile>
      <id>gpg</id>
      <build>
        <plugins>
          <plugin>
            <!-- GPG signing of build artifacts, required by Maven
                Central. We only enable this via a profile so that
                forks do not have to register GPG keys to be able
                to build. -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
            <version>${maven-gpg-plugin.version}</version>
            <executions>
              <execution>
                <id>sign-artifacts</id>
                <phase>verify</phase>
                <goals>
                  <goal>sign</goal>
                </goals>
                <configuration>
                  <gpgArguments>
                    <arg>--pinentry-mode</arg>
                    <arg>loopback</arg>
                  </gpgArguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
