Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/scripts/install-analyzer-wire.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -euo pipefail

base="${ARTIFACTORY_URL}/sonarsource-public-qa/org/sonarsource/semsitter/analyzer-wire/2.0.0"
dest="${RUNNER_TEMP}/analyzer-wire"
mkdir -p "$dest"
curl -fsS -u "${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}" \
-o "$dest/analyzer-wire-2.0.0.pom" "$base/analyzer-wire-2.0.0.pom"
curl -fsS -u "${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}" \
-o "$dest/analyzer-wire-2.0.0.jar" "$base/analyzer-wire-2.0.0.jar"

settings=()
if [[ ! -f "${MAVEN_CONFIG:-$HOME/.m2}/settings.xml" ]]; then
cat > "$dest/settings.xml" <<EOF
<settings>
<mirrors>
<mirror>
<id>sonarsource</id>
<url>${ARTIFACTORY_URL}/sonarsource-qa</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<servers>
<server>
<id>sonarsource</id>
<username>${ARTIFACTORY_USERNAME}</username>
<password>${ARTIFACTORY_ACCESS_TOKEN}</password>
</server>
</servers>
</settings>
EOF
settings=(-s "$dest/settings.xml")
fi
mvn -B "${settings[@]}" org.apache.maven.plugins:maven-install-plugin:3.1.2:install-file \
-Dfile="$dest/analyzer-wire-2.0.0.jar" \
-DpomFile="$dest/analyzer-wire-2.0.0.pom"
Comment on lines +4 to +36

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Quality: analyzer-wire version is hard-coded separately from pom.xml

The script hard-codes 2.0.0 in the URL and file names. The version Maven actually resolves is declared separately in dependencyManagement (pom.xml:344-346). If the pom version is bumped and the script is not, CI installs the stale 2.0.0 jar and the build still fails to resolve the new version. Fix: put the version in a single variable, or read it from the pom (e.g. mvn help:evaluate), and pass it to the script.

Parameterize the version so it can be passed in (or derived from the pom) in one place:

version="${ANALYZER_WIRE_VERSION:-2.0.0}"
base="${ARTIFACTORY_URL}/sonarsource-public-qa/org/sonarsource/semsitter/analyzer-wire/${version}"
dest="${RUNNER_TEMP}/analyzer-wire"
mkdir -p "$dest"
for ext in pom jar; do
  curl -fsS -u "${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}" \
    -o "$dest/analyzer-wire-${version}.${ext}" "$base/analyzer-wire-${version}.${ext}"
done
  • Apply fix

Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎

31 changes: 31 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ jobs:
- uses: jdx/mise-action@90f833d396d0cc3674b631d2d225e306476c303a # v5.2.10
with:
version: 2026.10.20
- name: Read Repox credentials
id: repox
uses: SonarSource/vault-action-wrapper@v3
with:
url: https://vault.dev.sonar.build
secrets: |
development/artifactory-edge-dev/token/{REPO_OWNER_NAME_DASH}-private-reader username | ARTIFACTORY_USERNAME;
development/artifactory-edge-dev/token/{REPO_OWNER_NAME_DASH}-private-reader access_token | ARTIFACTORY_ACCESS_TOKEN;
- name: Install analyzer-wire
env:
ARTIFACTORY_URL: https://repox-internal.dev.sonar.build/artifactory
ARTIFACTORY_USERNAME: ${{ fromJSON(steps.repox.outputs.vault).ARTIFACTORY_USERNAME }}
ARTIFACTORY_ACCESS_TOKEN: ${{ fromJSON(steps.repox.outputs.vault).ARTIFACTORY_ACCESS_TOKEN }}
run: bash ./.github/scripts/install-analyzer-wire.sh
- uses: SonarSource/ci-github-actions/build-maven@v2
Comment on lines +45 to 51

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Bug: Other full-reactor jobs still don't install analyzer-wire

This commit adds the install-analyzer-wire.sh step only to the build and qa-os-win jobs. Several other jobs also resolve the root reactor, which now includes java-frontend-semsitter (pom.xml:54) and depends on org.sonarsource.semsitter:analyzer-wire:2.0.0:

  • test-analyze runs build-maven@v2 on the whole project (build.yml:359).
  • custom-rules-license-check runs license-maven-plugin:aggregate-add-third-party from the repo root (build.yml:420), which resolves the dependencies of every module.
  • The scheduled unified-dogfooding.yml build runs build-maven@v2 on the full reactor (unified-dogfooding.yml:24).

The new step exists because Maven can't resolve the jar from the configured repositories. These jobs will hit the same dependency-resolution error, and since promote needs test-analyze and custom-rules-license-check, a PR build will fail to promote. Fix: add Install analyzer-wire to each of these jobs. In test-analyze and unified-dogfooding, add a config-maven step first so ARTIFACTORY_* is set, as done in build.

Add the install step to custom-rules-license-check (after config-maven), and add config-maven plus the install step before build-maven in test-analyze and unified-dogfooding:

- name: Configure Maven
  uses: SonarSource/ci-github-actions/config-maven@v2
  with:
    repox-url: https://repox-internal.dev.sonar.build
    artifactory-reader-role: private-reader
    use-develocity: ${{ env.USE_DEVELOCITY }}
    develocity-url: ${{ env.DEVELOCITY_URL }}
- name: Install analyzer-wire
  run: bash ./.github/scripts/install-analyzer-wire.sh
  • Apply fix

Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎

id: build-maven
env:
Expand Down Expand Up @@ -347,6 +361,20 @@ jobs:
secrets: |
development/kv/data/next url | SONAR_HOST_URL;
development/kv/data/next token | SONAR_TOKEN;
- name: Read Repox credentials
id: repox
uses: SonarSource/vault-action-wrapper@v3
with:
url: https://vault.dev.sonar.build
secrets: |
development/artifactory-edge-dev/token/{REPO_OWNER_NAME_DASH}-private-reader username | ARTIFACTORY_USERNAME;
development/artifactory-edge-dev/token/{REPO_OWNER_NAME_DASH}-private-reader access_token | ARTIFACTORY_ACCESS_TOKEN;
- name: Install analyzer-wire
env:
ARTIFACTORY_URL: https://repox-internal.dev.sonar.build/artifactory
ARTIFACTORY_USERNAME: ${{ fromJSON(steps.repox.outputs.vault).ARTIFACTORY_USERNAME }}
ARTIFACTORY_ACCESS_TOKEN: ${{ fromJSON(steps.repox.outputs.vault).ARTIFACTORY_ACCESS_TOKEN }}
run: bash ./.github/scripts/install-analyzer-wire.sh
- uses: SonarSource/ci-github-actions/build-maven@v2
with:
repox-url: https://repox-internal.dev.sonar.build
Expand Down Expand Up @@ -438,6 +466,9 @@ jobs:
use-develocity: ${{ env.USE_DEVELOCITY }}
develocity-url: ${{ env.DEVELOCITY_URL }}
disable-caching: 'true'
- name: Install analyzer-wire
shell: bash
run: bash ./.github/scripts/install-analyzer-wire.sh
- name: Run Maven
env:
JAVA_TOOL_OPTIONS: ""
Expand Down
32 changes: 32 additions & 0 deletions java-frontend-semsitter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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>9.0.0-SNAPSHOT</version>
</parent>

<artifactId>java-frontend-semsitter</artifactId>

<name>SonarQube Java :: SemSitter Front-end</name>
<description>Code Analyzer for Java :: Front-end based on SemSitter</description>

<dependencies>
<dependency>
<groupId>org.sonarsource.semsitter</groupId>
<artifactId>analyzer-wire</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* SonarQube Java
* Copyright (C) SonarSource Sàrl
* mailto:info AT sonarsource DOT com
*
* You can redistribute and/or modify this program under the terms of
* the Sonar Source-Available License Version 1, as published by SonarSource Sàrl.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Sonar Source-Available License for more details.
*
* You should have received a copy of the Sonar Source-Available License
* along with this program; if not, see https://sonarsource.com/license/ssal/
*/
package org.sonar.java.semsitter;

import com.google.protobuf.MessageLite;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.junit.jupiter.api.Test;
import org.sonarsource.semsitter.wire.Document;
import org.sonarsource.semsitter.wire.Fact;
import org.sonarsource.semsitter.wire.FactEntry;
import org.sonarsource.semsitter.wire.FactValue;
import org.sonarsource.semsitter.wire.Node;
import org.sonarsource.semsitter.wire.Place;
import org.sonarsource.semsitter.wire.Ref;
import org.sonarsource.semsitter.wire.StringList;
import org.sonarsource.semsitter.wire.Symbol;
import org.sonarsource.semsitter.wire.TypeRef;

import static org.assertj.core.api.Assertions.assertThat;

class ProtocolTest {

@Test
void document_round_trips() throws IOException {
TypeRef listOfString = TypeRef.newBuilder()
.setId("java.util.List")
.addArguments(TypeRef.newBuilder().setId("java.lang.String"))
.build();
Document document = Document.newBuilder()
.setPath("p/A.java")
.setSemantic(true)
.setTree(Node.newBuilder()
.setKind("program")
.addChildren(Node.newBuilder()
.setKind("identifier")
.setNamed(true)
.setStartLine(2)
.setText("xs")
.addDecls("p.A#xs")
.addRefs(Ref.newBuilder()
.setOutcome("resolved")
.setTarget("java.util.List")
.putFacts("type", FactValue.newBuilder().setType(listOfString).build()))))
.addSymbols(Symbol.newBuilder()
.setId("p.A#xs")
.setKind("field")
.setName("xs")
.setPlace(Place.newBuilder().setStartByte(30).setEndByte(32).setLine(2).setColumn(4))
.putFacts("final", FactValue.newBuilder().setFlag(true).build()))
.addFacts(FactEntry.newBuilder()
.setKey("p.A")
.setValue(Fact.newBuilder()
.setKind("class")
.addProps(org.sonarsource.semsitter.wire.Prop.newBuilder()
.setName("modifiers")
.addValues("public")
.build())
.build()))
.build();

Document read = Document.parseDelimitedFrom(roundTrip(document));

assertThat(read).isEqualTo(document);
assertThat(read.getTree().getChildren(0).getRefs(0).getFactsOrThrow("type").getType().getArguments(0).getId())
.isEqualTo("java.lang.String");
assertThat(read.getSymbols(0).getFactsOrThrow("final").getFlag()).isTrue();
}

@Test
void string_lists_round_trip() throws IOException {
StringList libraries = StringList.newBuilder().addValues("a.jar").addValues("b.jar").build();

StringList read = StringList.parseDelimitedFrom(roundTrip(libraries));

assertThat(read).isEqualTo(libraries);
}

private static InputStream roundTrip(MessageLite message) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
message.writeDelimitedTo(out);
return new ByteArrayInputStream(out.toByteArray());
}
}
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<modules>
<module>java-checks-test-sources</module>
<module>java-frontend</module>
<module>java-frontend-semsitter</module>
<module>java-checks-testkit</module>
<module>java-checks</module>
<module>java-checks-aws</module>
Expand Down Expand Up @@ -339,6 +340,11 @@
<version>2.15.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.semsitter</groupId>
<artifactId>analyzer-wire</artifactId>
<version>2.0.0</version>
</dependency>
<!-- staxmate is used by java-surefire -->
<dependency>
<groupId>com.fasterxml.staxmate</groupId>
Expand Down
Loading