<?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.javascript</groupId>
    <artifactId>sonar-plugin</artifactId>
    <version>13.0.0.42526</version>
  </parent>

  <artifactId>javascript-checks</artifactId>

  <name>SonarQube JavaScript :: Checks</name>

  <properties>
    <rule.data.build.phase>none</rule.data.build.phase>
    <rspec.sha></rspec.sha>
    <rspec.javascript.sha>${rspec.sha}</rspec.javascript.sha>
    <rspec.css.sha>${rspec.sha}</rspec.css.sha>
    <rspec.branch>dogfood-automerge</rspec.branch>
    <rspec.javascript.branch>${rspec.branch}</rspec.javascript.branch>
    <rspec.css.branch>${rspec.branch}</rspec.css.branch>
    <sonar.coverage.jacoco.xmlReportPaths>${project.reporting.outputDirectory}/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
    <sonar.exclusions>src/main/java/org/sonar/javascript/checks/AllChecks.java,src/main/java/org/sonar/javascript/checks/S*.java</sonar.exclusions>
    <sonar.coverage.exclusions>src/main/java/org/sonar/javascript/checks/AllChecks.java,src/main/java/org/sonar/javascript/checks/S*.java</sonar.coverage.exclusions>
  </properties>

  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>api</artifactId>
    </dependency>
    <dependency>
      <groupId>org.sonarsource.api.plugin</groupId>
      <artifactId>sonar-plugin-api</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.code.findbugs</groupId>
      <artifactId>jsr305</artifactId>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>3.5.0</version>
        <configuration>
          <filesets>
            <fileset>
              <directory>${maven.multiModuleProjectDirectory}/resources/rule-data</directory>
            </fileset>
            <fileset>
              <directory>${project.basedir}/src/main/resources</directory>
              <includes>
                <include>org/sonar/l10n/javascript/rules/javascript/**</include>
                <include>rspec.sha</include>
              </includes>
            </fileset>
            <fileset>
              <directory>${project.basedir}/../css/src/main/resources</directory>
              <includes>
                <include>org/sonar/l10n/css/rules/css/**</include>
                <include>rspec.sha</include>
              </includes>
            </fileset>
            <fileset>
              <directory>${maven.multiModuleProjectDirectory}/packages/analysis/src/jsts/rules</directory>
              <includes>
                <include>**/generated-meta.ts</include>
                <include>metas.ts</include>
                <include>plugin-rules.ts</include>
                <include>rules.ts</include>
              </includes>
            </fileset>
          </filesets>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>${jacoco.version}</version>
        <configuration>
          <excludes>
            <exclude>org/sonar/javascript/checks/AllChecks*</exclude>
            <exclude>org/sonar/javascript/checks/S*</exclude>
          </excludes>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.sonarsource.rspec</groupId>
        <artifactId>rspec-maven-plugin</artifactId>
        <version>1.4.0.122</version>
        <configuration>
          <githubToken>${env.GITHUB_TOKEN}</githubToken>
        </configuration>
        <executions>
          <execution>
            <id>generate-rspec-javascript</id>
            <phase>${rule.data.build.phase}</phase>
            <goals>
              <goal>generate-rule-data</goal>
            </goals>
            <configuration>
              <ruleSubdirectory>javascript</ruleSubdirectory>
              <rspecSha>${rspec.javascript.sha}</rspecSha>
              <vcsBranchName>${rspec.javascript.branch}</vcsBranchName>
              <targetDirectory>${project.basedir}/../../resources/rule-data/javascript</targetDirectory>
            </configuration>
          </execution>
          <execution>
            <id>generate-rspec-css</id>
            <phase>${rule.data.build.phase}</phase>
            <goals>
              <goal>generate-rule-data</goal>
            </goals>
            <configuration>
              <ruleSubdirectory>css</ruleSubdirectory>
              <rspecSha>${rspec.css.sha}</rspecSha>
              <vcsBranchName>${rspec.css.branch}</vcsBranchName>
              <targetDirectory>${project.basedir}/../../resources/rule-data/css</targetDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>3.6.3</version>
        <executions>
          <execution>
            <id>deploy-rule-data</id>
            <phase>${rule.data.build.phase}</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>npm</executable>
              <workingDirectory>../..</workingDirectory>
              <arguments>
                <argument>run</argument>
                <argument>deploy-rule-data</argument>
              </arguments>
              <environmentVariables>
                <RSPEC_JAVASCRIPT_SHA>${rspec.javascript.sha}</RSPEC_JAVASCRIPT_SHA>
                <RSPEC_CSS_SHA>${rspec.css.sha}</RSPEC_CSS_SHA>
              </environmentVariables>
            </configuration>
          </execution>
          <execution>
            <id>Generate rule metadata</id>
            <phase>${node.build.phase}</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>npm</executable>
              <workingDirectory>../..</workingDirectory>
              <arguments>
                <argument>run</argument>
                <argument>generate-meta:raw</argument>
              </arguments>
            </configuration>
          </execution>
          <execution>
            <id>Generate the Java Check classes</id>
            <phase>${java.generation.phase}</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>npm</executable>
              <workingDirectory>../..</workingDirectory>
              <arguments>
                <argument>run</argument>
                <argument>generate-java-rule-classes</argument>
              </arguments>
            </configuration>
          </execution>
          <execution>
            <id>Update README with rule counts</id>
            <phase>${node.build.phase}</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>npm</executable>
              <workingDirectory>../..</workingDirectory>
              <arguments>
                <argument>run</argument>
                <argument>count-rules</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>generate-rule-data-from-rspec-sha</id>
      <activation>
        <property>
          <name>rspec.sha</name>
        </property>
      </activation>
      <properties>
        <rspec.javascript.branch></rspec.javascript.branch>
        <rspec.css.branch></rspec.css.branch>
      </properties>
    </profile>
    <profile>
      <id>generate-javascript-rule-data-from-rspec-sha</id>
      <activation>
        <property>
          <name>rspec.javascript.sha</name>
        </property>
      </activation>
      <properties>
        <rspec.javascript.branch></rspec.javascript.branch>
      </properties>
    </profile>
    <profile>
      <id>generate-css-rule-data-from-rspec-sha</id>
      <activation>
        <property>
          <name>rspec.css.sha</name>
        </property>
      </activation>
      <properties>
        <rspec.css.branch></rspec.css.branch>
      </properties>
    </profile>
    <profile>
      <id>generate-rule-data-when-javascript-rule-data-is-missing</id>
      <activation>
        <file>
          <missing>${project.basedir}/src/main/resources/org/sonar/l10n/javascript/rules/javascript</missing>
        </file>
      </activation>
      <properties>
        <rule.data.build.phase>${node.build.phase}</rule.data.build.phase>
      </properties>
    </profile>
    <profile>
      <id>generate-rule-data-when-css-rule-data-is-missing</id>
      <activation>
        <file>
          <missing>${project.basedir}/../css/src/main/resources/org/sonar/l10n/css/rules/css</missing>
        </file>
      </activation>
      <properties>
        <rule.data.build.phase>${node.build.phase}</rule.data.build.phase>
      </properties>
    </profile>
    <profile>
      <id>generate-rule-data-when-javascript-rspec-sha-is-missing</id>
      <activation>
        <file>
          <missing>${project.basedir}/src/main/resources/rspec.sha</missing>
        </file>
      </activation>
      <properties>
        <rule.data.build.phase>${node.build.phase}</rule.data.build.phase>
      </properties>
    </profile>
    <profile>
      <id>generate-rule-data-when-css-rspec-sha-is-missing</id>
      <activation>
        <file>
          <missing>${project.basedir}/../css/src/main/resources/rspec.sha</missing>
        </file>
      </activation>
      <properties>
        <rule.data.build.phase>${node.build.phase}</rule.data.build.phase>
      </properties>
    </profile>
  </profiles>

</project>
