<?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.dotnet</groupId>
    <artifactId>sonar-dotnet</artifactId>
    <version>10.4-SNAPSHOT</version>
  </parent>

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

  <name>SonarC#</name>
  <description>Code Analyzer for C#</description>
  <url>http://redirect.sonarsource.com/plugins/csharp.html</url>
  <inceptionYear>2014</inceptionYear>

  <organization>
    <name>SonarSource</name>
    <url>http://www.sonarsource.com</url>
  </organization>

  <licenses>
    <license>
      <name>SSALv1</name>
      <url>https://sonarsource.com/license/ssal/</url>
      <distribution>repo</distribution>
    </license>
  </licenses>

  <scm>
    <connection>scm:git:git@github.com:SonarSource/sonar-dotnet.git</connection>
    <developerConnection>scm:git:git@github.com:SonarSource/sonar-dotnet.git</developerConnection>
    <url>https://github.com/SonarSource/sonar-dotnet</url>
    <tag>HEAD</tag>
  </scm>

  <properties>
    <maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
    <sonarAnalyzer.workDirectory>${project.build.directory}/analyzer</sonarAnalyzer.workDirectory>
    <rspec.directory>${project.build.directory}/../../analyzers/rspec</rspec.directory>
    <packaging.directory>${project.build.directory}/../../analyzers/packaging</packaging.directory>
    <maven.deploy.skip>false</maven.deploy.skip>
  </properties>

  <dependencies>
    <!-- provided at runtime -->
    <dependency>
      <groupId>org.sonarsource.api.plugin</groupId>
      <artifactId>sonar-plugin-api</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.code.findbugs</groupId>
      <artifactId>jsr305</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- compiled -->
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>sonar-dotnet-core</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>sonar-csharp-core</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.sonarsource.analyzer-commons</groupId>
      <artifactId>sonar-analyzer-commons</artifactId>
    </dependency>

    <!-- test dependencies -->
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
    </dependency>
    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.codehaus.woodstox</groupId>
      <artifactId>stax2-api</artifactId>
    </dependency>
    <dependency>
      <groupId>org.codehaus.staxmate</groupId>
      <artifactId>staxmate</artifactId>
      <exclusions>
        <exclusion>
          <groupId>org.codehaus.woodstox</groupId>
          <artifactId>woodstox-core-asl</artifactId>
        </exclusion>
        <exclusion>
          <groupId>stax</groupId>
          <artifactId>stax-api</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.codehaus.woodstox</groupId>
          <artifactId>stax2-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.sonarsource.sonarqube</groupId>
      <artifactId>sonar-plugin-api-impl</artifactId>
      <exclusions>
        <exclusion>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.sonarsource.api.plugin</groupId>
      <artifactId>sonar-plugin-api-test-fixtures</artifactId>
    </dependency>
  </dependencies>

  <build>
    <resources>
      <resource>
        <directory>${sonarAnalyzer.workDirectory}</directory>
        <includes>
          <include>org/sonar/plugins/csharp/*.json</include>
          <include>org/sonar/plugins/csharp/*.html</include>
          <include>static/SonarAnalyzer-csharp-${project.version}.zip</include>
        </includes>
      </resource>
    </resources>

    <plugins>
      <plugin>
        <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
        <artifactId>sonar-packaging-maven-plugin</artifactId>
        <configuration>
          <pluginName>C# Code Quality and Security</pluginName>
          <pluginClass>org.sonar.plugins.csharp.CSharpPlugin</pluginClass>
          <skipDependenciesPackaging>true</skipDependenciesPackaging>
          <sonarLintSupported>false</sonarLintSupported>
          <pluginApiMinVersion>${plugin.api.min.version}</pluginApiMinVersion>
          <requiredForLanguages>cs</requiredForLanguages>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-shade-plugin</artifactId>
        <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>
              </filters>
            </configuration>
          </execution>
        </executions>
      </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>5600000</maxsize>
                  <minsize>5400000</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-antrun-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
          <execution>
            <id>copy-analyzer-data</id>
            <phase>validate</phase>
            <configuration>
              <exportAntProperties>true</exportAntProperties>
              <target>
                <copy todir="${sonarAnalyzer.workDirectory}/SonarAnalyzer.CSharp">
                  <fileset dir="${packaging.directory}/binaries/SonarAnalyzer.CSharp/">
                    <include name="*.dll"/>
                  </fileset>
                  <fileset dir="${project.build.directory}/../..">
                    <include name="THIRD-PARTY-NOTICES.txt"/>
                  </fileset>
                </copy>
                <zip destfile="${sonarAnalyzer.workDirectory}/static/SonarAnalyzer-csharp-${project.version}.zip"
                     basedir="${sonarAnalyzer.workDirectory}/SonarAnalyzer.CSharp"/>
                <copy todir="${sonarAnalyzer.workDirectory}/org/sonar/plugins/csharp">
                  <fileset dir="${rspec.directory}/cs">
                    <include name="*.json"/>
                    <include name="*.html"/>
                  </fileset>
                </copy>
                <exec executable="dotnet"
                      failonerror="true"
                      dir="${packaging.directory}/binaries/RuleDescriptorGenerator">
                  <arg value="RuleDescriptorGenerator.dll"/>
                  <arg value="${sonarAnalyzer.workDirectory}/org/sonar/plugins/csharp/Rules.json"/>
                  <arg value="${packaging.directory}/binaries/SonarAnalyzer.CSharp/SonarAnalyzer.CSharp.dll"/>
                </exec>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
