<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.sonarsource.scanner.maven</groupId>
    <artifactId>sonar-scanner-maven</artifactId>
    <version>5.6.0.6792</version>
  </parent>


  <artifactId>sonar-maven-plugin</artifactId>
  <name>SonarQube Scanner for Maven</name>
  <packaging>maven-plugin</packaging>

  <properties>
    <!--
      We can't update the Maven core dependencies unless we remove the dependency on SecDispatcher
      For more details see this ticket https://sonarsource.atlassian.net/browse/SCANMAVEN-222
    -->
    <mavenVersion>3.6.3</mavenVersion>
    <mojo.java.target>11</mojo.java.target>
    <maven.compiler.release>11</maven.compiler.release>
    <sonar.exclusions>src/main/java/org/apache/maven/shared/dependency/tree/DependencyTreeResolutionListener.java,target/generated-sources/**/*</sonar.exclusions>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>${mavenVersion}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-model</artifactId>
      <version>${mavenVersion}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-artifact</artifactId>
      <version>${mavenVersion}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-core</artifactId>
      <version>${mavenVersion}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.codehaus.plexus</groupId>
      <artifactId>plexus-sec-dispatcher</artifactId>
      <version>2.0</version>
    </dependency>

    <dependency>
      <groupId>org.apache.maven.plugin-tools</groupId>
      <artifactId>maven-plugin-annotations</artifactId>
      <version>3.5</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.sonarsource.scanner.lib</groupId>
      <artifactId>sonar-scanner-java-library</artifactId>
      <version>4.1.1.1633</version>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>3.18.0</version>
    </dependency>

    <dependency>
      <groupId>com.google.code.findbugs</groupId>
      <artifactId>jsr305</artifactId>
      <version>2.0.3</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>5.10.2</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.vintage</groupId>
      <artifactId>junit-vintage-engine</artifactId>
      <version>5.10.2</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <version>5.3.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <version>3.27.7</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.maven.plugin-testing</groupId>
      <artifactId>maven-plugin-testing-harness</artifactId>
      <version>4.0.0-alpha-1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <!-- Needed for the maven-plugin-testing-harness -->
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-compat</artifactId>
      <version>${mavenVersion}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-javadoc-plugin</artifactId>
          <configuration>
            <source>11</source>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-plugin-plugin</artifactId>
        <configuration>
          <!-- see http://jira.codehaus.org/browse/MNG-5346 -->
          <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
        </configuration>
        <executions>
          <execution>
            <id>mojo-descriptor</id>
            <goals>
              <goal>descriptor</goal>
            </goals>
          </execution>
          <!-- if you want to generate help goal -->
          <execution>
            <id>help-goal</id>
            <goals>
              <goal>helpmojo</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.plexus</groupId>
        <artifactId>plexus-component-metadata</artifactId>
        <version>2.2.0</version>
        <executions>
          <execution>
            <goals>
              <goal>generate-metadata</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>3.0.1</version>
        <configuration>
          <goals>deploy site site:stage</goals>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-scm-publish-plugin</artifactId>
        <version>3.2.1</version>
        <configuration>
          <scmBranch>gh-pages</scmBranch>
        </configuration>
        <executions>
          <execution>
            <id>scm-publish</id>
            <phase>site-deploy</phase>
            <goals>
              <goal>publish-scm</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.10</version>
        <executions>
          <execution>
            <id>pre-unit-test</id>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
          </execution>
          <execution>
            <id>post-unit-test</id>
            <phase>test</phase>
            <goals>
              <goal>report</goal>
            </goals>
          </execution>
          <execution>
            <id>pre-integration-test</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
            <configuration>
              <destFile>${project.build.directory}/jacoco-it.exec</destFile>
              <propertyName>invoker.mavenOpts</propertyName>
            </configuration>
          </execution>
          <execution>
            <id>post-integration-test</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>report</goal>
            </goals>
            <configuration>
              <dataFile>${project.build.directory}/jacoco-it.exec</dataFile>
              <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-invoker-plugin</artifactId>
        <version>3.9.1</version>
        <configuration>
          <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
          <settingsFile>src/it/default-settings.xml</settingsFile>
          <localRepositoryPath>target/local-repo</localRepositoryPath>
          <postBuildHookScript>verify</postBuildHookScript>
        </configuration>
        <executions>
          <execution>
            <id>integration-test</id>
            <goals>
              <goal>install</goal>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.cyclonedx</groupId>
        <artifactId>cyclonedx-maven-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>makeAggregateBom</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>license-maven-plugin</artifactId>
          <version>2.7.1</version>
          <configuration>
            <errorRemedy>xmlOutput</errorRemedy>
            <writeVersions>false</writeVersions>
            <socketTimeout>20000</socketTimeout>
            <licensesOutputDirectory>${project.build.directory}/temp-licenses/THIRD_PARTY_LICENSES</licensesOutputDirectory>
            <licensesOutputFile>${project.build.directory}/licenses.xml</licensesOutputFile>
            <organizeLicensesByDependencies>true</organizeLicensesByDependencies>
            <excludedGroups>com.sonarsource|org.sonarsource.scanner</excludedGroups>
            <licenseUrlReplacements>
               <licenseUrlReplacement>
                    <regexp>http://www.gnu.org/licenses/lgpl.txt</regexp>
                    <replacement>${project.baseUri}/license-resources/lgpl.txt</replacement>
                </licenseUrlReplacement>
                <licenseUrlReplacement>
                    <regexp>https://opensource.org/licenses/MIT</regexp>
                    <replacement>${project.baseUri}/license-resources/mit.txt</replacement>
                </licenseUrlReplacement>
              <licenseUrlReplacement>
                    <regexp>http://www.opensource.org/licenses/mit-license.php</regexp>
                    <replacement>${project.baseUri}/license-resources/mit.txt</replacement>
                </licenseUrlReplacement>
                <licenseUrlReplacement>
                    <regexp>https://www.bouncycastle.org/licence.html</regexp>
                    <replacement>${project.baseUri}/license-resources/bouncycastle.txt</replacement>
                </licenseUrlReplacement>
            </licenseUrlReplacements>
            <licenseUrlFileNameSanitizers>
              <LicenseUrlReplacement>
                <regexp>_.*\.txt</regexp>
              </LicenseUrlReplacement>
              <!--                 Append -LICENSE.txt -->
              <LicenseUrlReplacement>
                <regexp>$</regexp>
                <replacement>-LICENSE.txt</replacement>
              </LicenseUrlReplacement>
            </licenseUrlFileNameSanitizers>
          </configuration>
          <executions>
            <execution>
              <phase>generate-resources</phase>
              <id>download-licenses</id>
              <goals>
                <goal>download-licenses</goal>
              </goals>
            </execution>
          </executions>
        </plugin>


        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>exec-maven-plugin</artifactId>
          <version>3.6.3</version>
          <executions>
            <execution>
              <id>validate-license-files</id>
              <phase>verify</phase>
              <goals>
                <goal>exec</goal>
              </goals>
              <configuration>
                <executable>java</executable>
                <arguments>
                  <argument>${project.basedir}/license-resources/LicenseValidator.java</argument>
                  <argument>--temp_licenses=${project.build.directory}/temp-licenses</argument>
                  <argument>--committed_licenses=${project.basedir}/src/main/resources/licenses</argument>
                </arguments>
                <useMavenLogger>true</useMavenLogger>
              </configuration>
            </execution>
          </executions>
        </plugin>

       <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.4.0</version>
          <executions>
            <execution>
              <id>copy-main-license</id>
              <phase>generate-resources</phase>
              <goals>
                <goal>copy-resources</goal>
              </goals>
              <configuration>
                <resources>
                  <resource>
                    <directory>..</directory>
                    <includes>
                      <include>LICENSE.txt</include>
                    </includes>
                  </resource>
                </resources>
                <outputDirectory>${project.build.directory}/temp-licenses</outputDirectory>
              </configuration>
            </execution>
          </executions>
        </plugin>
    </plugins>
  </build>

  <profiles>
       <profile>
      <id>skip-license-validation</id>
      <activation>
        <property>
          <name>skipLicenseValidation</name>
        </property>
      </activation>
      <build>
        <plugins>
          <!-- Disable license generation when skipping validation -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>license-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>download-licenses</id>
                <phase>none</phase>
              </execution>
            </executions>
          </plugin>

          <!-- Disable license validation -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>validate-license-files</id>
                <phase>none</phase>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>updateLicenses</id>
      <build>
        <plugins>
          <!-- Clean existing licenses before regenerating -->
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>3.2.0</version>
            <executions>
              <!-- Clean licenses directory first -->
              <execution>
                <id>clean-licenses</id>
                <phase>initialize</phase>
                <configuration>
                  <target>
                    <echo message="Cleaning existing license files before regeneration..."/>
                    <delete dir="${project.basedir}/src/main/resources/licenses" failonerror="false"/>
                    <mkdir dir="${project.basedir}/src/main/resources/licenses"/>
                  </target>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <!-- Disable license validation when updating -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>validate-license-files</id>
                <phase>none</phase>
              </execution>
            </executions>
          </plugin>

          <!-- Override license-maven-plugin to write to actual resource directory -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>license-maven-plugin</artifactId>
            <configuration>
              <!-- Override to write directly to resources when updating -->
              <licensesOutputDirectory>${project.basedir}/src/main/resources/licenses/THIRD_PARTY_LICENSES</licensesOutputDirectory>
            </configuration>
          </plugin>

          <!-- Override maven-resources-plugin to write to actual resource directory -->
          <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
              <execution>
                <id>copy-main-license</id>
                <configuration>
                  <!-- Override to write directly to resources when updating -->
                  <outputDirectory>${project.basedir}/src/main/resources/licenses</outputDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-plugin-plugin</artifactId>
        <version>3.13.0</version>
        <configuration>
          <requirements>
            <jdk>${mojo.java.target}</jdk>
          </requirements>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <version>3.5.0</version>
        <reportSets>
          <reportSet>
            <reports>
              <report>dependency-info</report>
              <report>index</report>
              <report>issue-tracking</report>
              <report>project-team</report>
              <report>scm</report>
              <report>summary</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>
</project>
