Repository navigation
SONARJAVA-7339 Add the SemSitter front-end module with its protobuf data model #6541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f123b53
e65e635
f9eee0f
60b09e7
0125202
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| id: build-maven | ||
| env: | ||
|
|
@@ -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 | ||
|
|
@@ -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: "" | ||
|
|
||
| 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()); | ||
| } | ||
| } |
There was a problem hiding this comment.
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.0in the URL and file names. The version Maven actually resolves is declared separately independencyManagement(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:
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎