<?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>bridge</artifactId>
  <name>SonarQube JavaScript :: Bridge</name>
  <properties>
    <protobuf.version>4.35.1</protobuf.version>
    <sonar.coverage.jacoco.xmlReportPaths>${project.reporting.outputDirectory}/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
    <grpc.version>1.82.0</grpc.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>api</artifactId>
    </dependency>
    <!-- Build-order dependency: javascript-checks runs generate-meta before bridge compiles -->
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>javascript-checks</artifactId>
      <scope>provided</scope>
    </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>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-compress</artifactId>
    </dependency>
    <dependency>
      <groupId>org.tukaani</groupId>
      <artifactId>xz</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.protobuf</groupId>
      <artifactId>protobuf-java</artifactId>
      <version>${protobuf.version}</version>
    </dependency>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-okhttp</artifactId>
      <version>${grpc.version}</version>
    </dependency>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-protobuf</artifactId>
      <version>${grpc.version}</version>
    </dependency>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-stub</artifactId>
      <version>${grpc.version}</version>
    </dependency>
    <dependency>
      <groupId>javax.annotation</groupId>
      <artifactId>javax.annotation-api</artifactId>
      <version>1.3.2</version>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-params</artifactId>
      <scope>test</scope>
    </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>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.awaitility</groupId>
      <artifactId>awaitility</artifactId>
    </dependency>
    <dependency>
      <groupId>org.sonarsource.api.plugin</groupId>
      <artifactId>sonar-plugin-api-test-fixtures</artifactId>
    </dependency>
    <dependency>
      <groupId>org.sonarsource.sonarqube</groupId>
      <artifactId>sonar-plugin-api-impl</artifactId>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>
  </dependencies>
  <build>
    <extensions>
      <extension>
        <groupId>kr.motd.maven</groupId>
        <artifactId>os-maven-plugin</artifactId>
        <version>1.7.1</version>
      </extension>
    </extensions>
    <plugins>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>3.5.0</version>
        <configuration>
          <filesets>
            <fileset>
              <directory>${maven.multiModuleProjectDirectory}/lib</directory>
            </fileset>
            <fileset>
              <directory>${maven.multiModuleProjectDirectory}/bin</directory>
            </fileset>
            <fileset>
              <directory>${project.basedir}/src/main/resources</directory>
              <includes>
                <include>org/sonar/plugins/javascript/bridge/node-info.properties</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/plugins/javascript/bridge/protobuf/*</exclude>
            <exclude>org/sonar/plugins/javascript/analyzeproject/grpc/*</exclude>
          </excludes>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.6.1</version>
        <executions>
          <execution>
            <id>add-generated-sources</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${project.build.directory}/generated-sources</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.xolstice.maven.plugins</groupId>
        <artifactId>protobuf-maven-plugin</artifactId>
        <version>0.6.1</version>
        <executions>
          <execution>
            <id>Generate Protobuf Java Sources</id>
            <goals>
              <goal>compile</goal>
            </goals>
            <phase>${protobuf.generation.phase}</phase>
            <configuration>
              <protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}
              </protocArtifact>
              <protoSourceRoot>../../packages/analysis/src/jsts/parsers</protoSourceRoot>
              <outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
            </configuration>
          </execution>
          <execution>
            <id>Generate Analyze-Project Protobuf Java Sources</id>
            <goals>
              <goal>compile</goal>
              <goal>compile-custom</goal>
            </goals>
            <phase>${protobuf.generation.phase}</phase>
            <configuration>
              <protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}
              </protocArtifact>
              <pluginId>grpc-java</pluginId>
              <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
              <protoSourceRoot>../../packages</protoSourceRoot>
              <outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
              <clearOutputDirectory>false</clearOutputDirectory>
              <includes>
                <include>grpc/src/proto/analyze-project.proto</include>
              </includes>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protoc</artifactId>
            <version>${protobuf.version}</version>
            <type>exe</type>
            <classifier>${os.detected.classifier}</classifier>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>3.6.3</version>
        <executions>
          <execution>
            <id>Build the bridge</id>
            <phase>${node.build.phase}</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>npm</executable>
              <workingDirectory>../..</workingDirectory>
              <arguments>
                <argument>run</argument>
                <argument>bridge:compile</argument>
              </arguments>
            </configuration>
          </execution>
          <execution>
            <id>Bundle the bridge</id>
            <phase>${node.build.phase}</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>npm</executable>
              <workingDirectory>../..</workingDirectory>
              <arguments>
                <argument>run</argument>
                <argument>bridge:bundle</argument>
              </arguments>
            </configuration>
          </execution>
          <execution>
            <id>Pack the bridge</id>
            <phase>${node.build.phase}</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>npm</executable>
              <workingDirectory>../..</workingDirectory>
              <arguments>
                <argument>pack</argument>
              </arguments>
            </configuration>
          </execution>
          <execution>
            <id>Generate Node.js properties node-info.properties</id>
            <phase>${node.build.phase}</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>node</executable>
              <workingDirectory>../..</workingDirectory>
              <arguments>
                <argument>tools/sync-nodejs-versions.mjs</argument>
                <argument>sonar-plugin/bridge</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.5.0</version>
        <executions>
          <execution>
            <id>Copy the bridge to the package</id>
            <phase>${node.resources.phase}</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <resources>
                <resource>
                  <directory>../..</directory>
                  <includes>
                    <include>sonarjs-1.0.0.tgz</include>
                  </includes>
                </resource>
              </resources>
              <outputDirectory>${basedir}/target/classes</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
