<?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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.sonarsource.java</groupId>
    <artifactId>java</artifactId>
    <version>8.25.0.42802</version>
  </parent>

  <artifactId>sonar-java-plugin</artifactId>
  <packaging>sonar-plugin</packaging>

  <name>SonarQube Java :: Plugin</name>
  <description>Code Analyzer for Java</description>

  <!--
    Do not remove. Without <url> and <scm>, maven uses the values from the parent and wrongly appends
    "/sonar-java-plugin" at the end. The "sonar-packaging-maven-plugin" uses these values to define in
    META-INF/MANIFEST.MF "Plugin-Homepage" from <url> and "Plugin-SourcesUrl" from <scm><url>.
  -->
  <url>${project.parent.url}</url>
  <scm>
    <connection>${project.parent.scm.connection}</connection>
    <developerConnection>${project.parent.scm.developerConnection}</developerConnection>
    <url>${project.parent.scm.url}</url>
    <tag>${project.parent.scm.tag}</tag>
  </scm>

  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>java-surefire</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>java-frontend</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>java-checks</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>java-checks-aws</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>check-list</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>external-reports</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>java-jsp</artifactId>
      <version>${project.version}</version>
    </dependency>

    <dependency>
      <groupId>org.sonarsource.analyzer-commons</groupId>
      <artifactId>sonar-analyzer-commons</artifactId>
    </dependency>
    <dependency>
      <groupId>org.sonarsource.analyzer-commons</groupId>
      <artifactId>sonar-xml-parsing</artifactId>
    </dependency>
    <dependency>
      <groupId>org.sonarsource.analyzer-commons</groupId>
      <artifactId>sonar-performance-measure</artifactId>
    </dependency>

    <dependency>
      <groupId>org.sonarsource.api.plugin</groupId>
      <artifactId>sonar-plugin-api</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- unit tests -->
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-migrationsupport</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.sonarsource.api.plugin</groupId>
      <artifactId>sonar-plugin-api-test-fixtures</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.sonarsource.sonarqube</groupId>
      <artifactId>sonar-plugin-api-impl</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.sonarsource.java</groupId>
      <artifactId>test-classpath-reader</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>java-checks-testkit</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
        <artifactId>sonar-packaging-maven-plugin</artifactId>
        <configuration>
          <pluginName>Java Code Quality and Security</pluginName>
          <skipDependenciesPackaging>true</skipDependenciesPackaging>
          <pluginClass>org.sonar.plugins.java.JavaPlugin</pluginClass>
          <requiredForLanguages>java,jsp</requiredForLanguages>
          <sonarLintSupported>true</sonarLintSupported>
          <pluginApiMinVersion>9.14.0.375</pluginApiMinVersion>
          <jreMinVersion>17</jreMinVersion>
          <archive>
            <manifestEntries>
              <Implementation-Version>${project.version}</Implementation-Version>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <executions>
          <execution>
            <id>enforce-plugin-size</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <phase>verify</phase>
            <configuration>
              <rules>
                <requireFilesSize>
                  <maxsize>21000000</maxsize>
                  <minsize>19000000</minsize>
                  <files>
                    <file>${project.build.directory}/${project.build.finalName}.jar</file>
                  </files>
                </requireFilesSize>
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.5.1</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <shadedArtifactAttached>false</shadedArtifactAttached>
              <createDependencyReducedPom>false</createDependencyReducedPom>
              <minimizeJar>true</minimizeJar>
              <filters>
                <filter>
                  <artifact>*:*</artifact>
                  <excludes>
                    <exclude>META-INF/LICENSE*</exclude>
                    <exclude>META-INF/NOTICE*</exclude>
                    <exclude>META-INF/*.RSA</exclude>
                    <exclude>META-INF/*.SF</exclude>
                    <exclude>LICENSE*</exclude>
                    <exclude>NOTICE*</exclude>
                  </excludes>
                </filter>
                <filter>
                  <artifact>cglib:cglib-nodep</artifact>
                  <includes>
                    <include>**</include>
                  </includes>
                </filter>
                <filter>
                  <artifact>org.sonarsource.java:java-frontend</artifact>
                  <includes>
                    <include>**</include>
                  </includes>
                </filter>
                <filter>
                  <artifact>xerces:xercesImpl</artifact>
                  <includes>
                    <include>**</include>
                  </includes>
                </filter>
                <filter>
                  <artifact>xml-apis:xml-apis</artifact>
                  <includes>
                    <include>**</include>
                  </includes>
                </filter>
                <filter>
                  <artifact>org.apache.tomcat.embed:tomcat-embed-jasper</artifact>
                  <includes>
                    <include>**</include>
                  </includes>
                </filter>
                <!-- this is needed because org.apache.el.ExpressionFactoryImpl is instantiated with reflection -->
                <filter>
                  <artifact>org.apache.tomcat.embed:tomcat-embed-el</artifact>
                  <includes>
                    <include>**</include>
                  </includes>
                </filter>
              </filters>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>de.thetaphi</groupId>
        <artifactId>forbiddenapis</artifactId>
        <executions>
          <execution>
            <id>forbid-junit4</id>
            <goals>
              <goal>testCheck</goal>
            </goals>
            <configuration>
              <signaturesFiles>
                <signaturesFile>../forbid_junit4.txt</signaturesFile>
              </signaturesFiles>
            </configuration>
          </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.java</excludedGroups>
            <licenseUrlReplacements>
               <licenseUrlReplacement>
                    <regexp>http://www.gnu.org/licenses/lgpl.txt</regexp>
                    <replacement>${project.baseUri}/license-resources/lgpl.txt</replacement>
                </licenseUrlReplacement>
                <licenseUrlReplacement>
                    <regexp>https://www.eclipse.org/legal/epl-2.0/</regexp>
                    <replacement>${project.baseUri}/license-resources/epl.txt</replacement>
                </licenseUrlReplacement>
                <licenseUrlReplacement>
                    <regexp>http://www.opensource.org/licenses/bsd-license.php</regexp>
                    <replacement>${project.baseUri}/license-resources/bsd.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>sanity</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <systemProperties>
                <force.sanity.test>true</force.sanity.test>
              </systemProperties>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
       <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>
</project>
