Repository navigation
DO NOT MERGE SONARJAVA-7339 Test the SemSitter frontend with PVF #6548
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
Draft
rombirli
wants to merge
3
commits into
rombirli/semsitter-recorded-documents
from
rombirli/semsitter-frontend-default-on
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
4512b36
SONARJAVA-7339 DO NOT MERGE Use the SemSitter frontend whenever its e…
rombirli f5100fa
SONARJAVA-7339 DO NOT MERGE Bundle the Linux SemSitter server so PVF …
rombirli 6961f1a
SONARJAVA-7339 DO NOT MERGE Use the bundled SemSitter server only dur…
rombirli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/BundledServer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * 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 java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.StandardCopyOption; | ||
| import java.util.Locale; | ||
| import java.util.Optional; | ||
|
|
||
| /** | ||
| * The SemSitter server shipped inside this plugin for the performance-validation runners, which are Linux x64 and have | ||
| * no server installed. It is used only while the performance-validation benchmark is running. Every other analysis | ||
| * keeps the default frontend unless an executable is configured. | ||
| */ | ||
| final class BundledServer { | ||
|
|
||
| static final String RESOURCE = "udg-java-server-x86_64-unknown-linux-musl"; | ||
| static final String PERFORMANCE_VALIDATION_CONTEXT = "sonar.java.context"; | ||
|
|
||
| private BundledServer() { | ||
| } | ||
|
|
||
| static Optional<Path> extract() { | ||
| if (!performanceValidation() || !linuxAmd64()) { | ||
| return Optional.empty(); | ||
| } | ||
| try (InputStream in = BundledServer.class.getResourceAsStream(RESOURCE)) { | ||
| if (in == null) { | ||
| return Optional.empty(); | ||
| } | ||
| Path destination = Path.of(System.getProperty("java.io.tmpdir"), RESOURCE); | ||
| Path partial = Path.of(destination.toString() + ".part"); | ||
| Files.copy(in, partial, StandardCopyOption.REPLACE_EXISTING); | ||
| Files.move(partial, destination, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE); | ||
| if (!destination.toFile().setExecutable(true)) { | ||
| return Optional.empty(); | ||
| } | ||
| return Optional.of(destination); | ||
| } catch (IOException failure) { | ||
| return Optional.empty(); | ||
| } | ||
| } | ||
|
|
||
| private static boolean performanceValidation() { | ||
| return PERFORMANCE_VALIDATION_CONTEXT.equals(System.getProperty("sensor.context.key")); | ||
| } | ||
|
|
||
| private static boolean linuxAmd64() { | ||
| String os = System.getProperty("os.name", "").toLowerCase(Locale.ROOT); | ||
| String arch = System.getProperty("os.arch", "").toLowerCase(Locale.ROOT); | ||
| return os.contains("linux") && ("amd64".equals(arch) || "x86_64".equals(arch)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+19.2 MB
...ter/src/main/resources/org/sonar/java/semsitter/udg-java-server-x86_64-unknown-linux-musl
Binary file not shown.
55 changes: 55 additions & 0 deletions
55
java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/BundledServerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * 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 java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.Optional; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
|
|
||
| class BundledServerTest { | ||
|
|
||
| @TempDir | ||
| Path project; | ||
|
|
||
| @Test | ||
| void bundled_server_stays_unused_outside_performance_validation() { | ||
| System.clearProperty("sensor.context.key"); | ||
|
|
||
| assertThat(BundledServer.extract()).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void bundled_linux_server_speaks_the_protocol() throws Exception { | ||
| System.setProperty("sensor.context.key", BundledServer.PERFORMANCE_VALIDATION_CONTEXT); | ||
| try { | ||
| Optional<Path> server = BundledServer.extract(); | ||
| assumeTrue(server.isPresent()); | ||
|
|
||
| try (SemSitterClient client = SemSitterClient.start(server.get(), project)) { | ||
| assertThat(client).isNotNull(); | ||
| } | ||
| assertThat(Files.isExecutable(server.get())).isTrue(); | ||
| } finally { | ||
| System.clearProperty("sensor.context.key"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: Failure log and Javadoc still say the default frontend is used
Now that
FLAG_DEFAULTistrue,isFlagOnreturnstruewhen LaunchDarkly can't be reached (line 90), so SemSitter is the frontend that runs. The warning on line 89 still says "the default frontend is used", which is the opposite of what happens. The class Javadoc (line 35) also still says "Anything that goes wrong while asking leaves the default frontend in use". Anyone reading the logs or the docs during a ruling or CI run will get the wrong idea about which parser handled the analysis. The test namewithout_property_nor_client_id_the_default_frontend_stays(test line 111) has the same problem, since with no client id the provider now turns SemSitter on. Fix: build the log message and Javadoc fromFLAG_DEFAULT, or reword them to be neutral, and rename the test.Make the warning match what actually happens, whatever the default value is:
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎