Skip to content
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

Fix prettier for java files #4986

Merged
merged 2 commits into from
Dec 4, 2024
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

# Prettified everything
091f56fa8f2375ad3eaed5db2507f030ff8806c7
ef9bceeb2285424851af178a7d0cdd9104c1cbc2
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private static void compare(Collection<RunResult> baseline, Collection<RunResult
println("Baseline: " + baselineScore);
println("Candidate: " + candidateScore);
var delta = Math.abs(baselineScore - candidateScore);
var deltaPercent = delta / baselineScore * 100;
var deltaPercent = (delta / baselineScore) * 100;
printf("Delta: %.3f (%.3f %%)%n", delta, deltaPercent);
if (deltaPercent > MARGIN_PERCENT) {
println("Performance degradation is greater than " + MARGIN_PERCENT + "%");
Expand Down Expand Up @@ -217,17 +217,15 @@ private static Optional<String> getJsPluginVersion(Orchestrator orchestrator) {
.execute()
.getBodyAsString();
var plugins = new Gson().fromJson(installed, JsonObject.class).get("plugins").getAsJsonArray();
return StreamSupport
.stream(plugins.spliterator(), false)
return StreamSupport.stream(plugins.spliterator(), false)
.map(JsonElement::getAsJsonObject)
.filter(e -> "javascript".equals(e.get("key").getAsString()))
.map(e -> e.get("version").getAsString())
.findFirst();
}

private static Orchestrator orchestrator(Location pluginLocation) {
return OrchestratorExtension
.builderEnv()
return OrchestratorExtension.builderEnv()
.setSonarVersion("LATEST_RELEASE")
.setOrchestratorProperty("orchestrator.container.port", "9000")
.useDefaultAdminCredentialsForBuilds(true)
Expand All @@ -236,8 +234,7 @@ private static Orchestrator orchestrator(Location pluginLocation) {
}

private static BuildResult runScan(String token, String projectKey, int maxspace) {
var build = SonarScanner
.create(Path.of("../sources/jsts/projects/", projectKey).toFile())
var build = SonarScanner.create(Path.of("../sources/jsts/projects/", projectKey).toFile())
.setProjectKey(projectKey)
.setProjectName(projectKey)
.setProjectVersion("1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public class ConsumerPlugin implements Plugin {

@Override
public void define(Context context) {
context.addExtensions(
Consumer.class,
ConsumerSensor.class
);
context.addExtensions(Consumer.class, ConsumerSensor.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ class ConsumerTest {

@Test
void test() {
var consumer = new Consumer();
consumer.doneAnalysis();
assertTrue(consumer.isDone());
var consumer = new Consumer();
consumer.doneAnalysis();
assertTrue(consumer.isDone());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ void should_raise_issues() throws IOException {
.anyMatch(s ->
s.matches("Using Node\\.js executable .* from property sonar\\.nodejs\\.executable\\.")
)
)
.isTrue();
).isTrue();
}
}

Expand Down Expand Up @@ -179,10 +178,9 @@ void should_log_failure_only_once() throws IOException {
// we need to stop engine initialized in @BeforeEach prepare() method, because we need configuration with different node
sonarlintEngine.stop();
// version `42` will let us pass SonarLint check of version
sonarlintEngine =
new StandaloneSonarLintEngineImpl(
getSonarLintConfig(new File("invalid/path/node").toPath(), Version.create("42"))
);
sonarlintEngine = new StandaloneSonarLintEngineImpl(
getSonarLintConfig(new File("invalid/path/node").toPath(), Version.create("42"))
);
List<Issue> issues = analyze(FILE_PATH, "");
assertThat(logs).contains("Provided Node.js executable file does not exist.");
assertThat(issues).isEmpty();
Expand Down Expand Up @@ -300,8 +298,7 @@ private StandaloneGlobalConfiguration getSonarLintConfig(Path nodePath, Version
System.out.println(formattedMessage);
};

return StandaloneGlobalConfiguration
.builder()
return StandaloneGlobalConfiguration.builder()
.addEnabledLanguage(Language.JS)
.addEnabledLanguage(Language.TS)
.addEnabledLanguage(Language.CSS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ void sonarlint() throws Exception {
NodeJsHelper nodeJsHelper = new NodeJsHelper();
nodeJsHelper.detect(null);

StandaloneGlobalConfiguration globalConfig = StandaloneGlobalConfiguration
.builder()
StandaloneGlobalConfiguration globalConfig = StandaloneGlobalConfiguration.builder()
.addEnabledLanguage(Language.JS)
.addEnabledLanguage(Language.TS)
.addPlugin(TestUtils.JAVASCRIPT_PLUGIN_LOCATION)
Expand All @@ -65,8 +64,7 @@ void sonarlint() throws Exception {
TestUtils.sonarLintInputFile(testFile, Files.readString(testFile))
);

StandaloneAnalysisConfiguration analysisConfig = StandaloneAnalysisConfiguration
.builder()
StandaloneAnalysisConfiguration analysisConfig = StandaloneAnalysisConfiguration.builder()
.setBaseDir(baseDir)
.addInputFiles(inputFiles)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ public class TestUtils {

static final Path JAVASCRIPT_PLUGIN_LOCATION = artifact();

static final List<String> platformStrings = List.of("darwin-arm64", "darwin-x64", "linux-arm64", "linux-x64", "linux-x64-musl", "win-x64", "multi");
static final List<String> platformStrings = List.of(
"darwin-arm64",
"darwin-x64",
"linux-arm64",
"linux-x64",
"linux-x64-musl",
"win-x64",
"multi"
);

/**
* This is used to test artifact with and without embedded runtime during plugin QA integration tests
*
Expand All @@ -54,15 +63,18 @@ private static Path artifact() {

private static Pattern pluginFilenameMatcher() {
if (System.getenv("SONARJS_ARTIFACT") != null) {
return Pattern.compile(String.format("sonar-javascript-plugin-.*-%s\\.jar", System.getenv("SONARJS_ARTIFACT")));
return Pattern.compile(
String.format("sonar-javascript-plugin-.*-%s\\.jar", System.getenv("SONARJS_ARTIFACT"))
);
}

return Pattern.compile("sonar-javascript-plugin-[0-9.]*(?:-SNAPSHOT)?\\.jar");
}


static boolean usingEmbeddedNode() {
return platformStrings.stream().anyMatch(TestUtils.JAVASCRIPT_PLUGIN_LOCATION.toString()::contains);
return platformStrings
.stream()
.anyMatch(TestUtils.JAVASCRIPT_PLUGIN_LOCATION.toString()::contains);
}

public static Path projectDir(String projectName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
package com.sonar.javascript.it.plugin;

import static com.sonar.javascript.it.plugin.OrchestratorStarter.JAVASCRIPT_PLUGIN_LOCATION;
import static org.assertj.core.api.Assertions.assertThat;

import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.SonarScanner;
Expand All @@ -26,9 +29,6 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static com.sonar.javascript.it.plugin.OrchestratorStarter.JAVASCRIPT_PLUGIN_LOCATION;
import static org.assertj.core.api.Assertions.assertThat;

class ConsumerPluginTest {

private static final String PLUGIN_ARTIFACT_ID = "consumer-plugin";
Expand All @@ -46,8 +46,7 @@ public static void after() {
}

static OrchestratorExtension initOrchestrator(String customRulesArtifactId) {
var orchestrator = OrchestratorExtension
.builderEnv()
var orchestrator = OrchestratorExtension.builderEnv()
.useDefaultAdminCredentialsForBuilds(true)
.setSonarVersion(System.getProperty("sonar.runtimeVersion", "LATEST_RELEASE"))
.addPlugin(JAVASCRIPT_PLUGIN_LOCATION)
Expand All @@ -70,8 +69,7 @@ static OrchestratorExtension initOrchestrator(String customRulesArtifactId) {
}

static BuildResult runBuild(Orchestrator orchestrator) {
SonarScanner build = OrchestratorStarter
.createScanner()
SonarScanner build = OrchestratorStarter.createScanner()
.setProjectDir(TestUtils.projectDirNoCopy("custom_rules"))
.setProjectKey("custom-rules")
.setProjectName("Custom Rules")
Expand All @@ -93,7 +91,8 @@ static BuildResult runBuild(Orchestrator orchestrator) {
@Test
void test() {
var buildResult = runBuild(orchestrator);
var logMatch = ".*DEBUG: Registered JsAnalysisConsumers \\[org.sonar.samples.javascript.consumer.Consumer.*]";
var logMatch =
".*DEBUG: Registered JsAnalysisConsumers \\[org.sonar.samples.javascript.consumer.Consumer.*]";
assertThat(buildResult.getLogsLines(l -> l.matches(logMatch))).hasSize(1);

// TS file is not processed yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ class CoverageTest {
@Test
void LCOV_path_can_be_relative() {
final String projectKey = "LcovPathCanBeRelative";
SonarScanner build = OrchestratorStarter
.createScanner()
SonarScanner build = OrchestratorStarter.createScanner()
.setProjectDir(TestUtils.projectDir("lcov"))
.setProjectKey(projectKey)
.setProjectName(projectKey)
Expand All @@ -55,8 +54,7 @@ void LCOV_path_can_be_relative() {
@Test
void LCOV_path_can_be_absolute() {
final String projectKey = "LcovPathCanBeAbsolute";
SonarScanner build = OrchestratorStarter
.createScanner()
SonarScanner build = OrchestratorStarter.createScanner()
.setProjectDir(TestUtils.projectDir("lcov"))
.setProjectKey(projectKey)
.setProjectName(projectKey)
Expand All @@ -79,8 +77,7 @@ void LCOV_path_can_be_absolute() {
@Test
void LCOV_report_paths() {
final String projectKey = "LcovReportPaths";
SonarScanner build = OrchestratorStarter
.createScanner()
SonarScanner build = OrchestratorStarter.createScanner()
.setProjectDir(TestUtils.projectDir("lcov"))
.setProjectKey(projectKey)
.setProjectName(projectKey)
Expand All @@ -103,8 +100,7 @@ void LCOV_report_paths() {
@Test
void LCOV_report_paths_alias() {
final String projectKey = "LcovReportPathsAlias";
SonarScanner build = OrchestratorStarter
.createScanner()
SonarScanner build = OrchestratorStarter.createScanner()
.setProjectDir(TestUtils.projectDir("lcov"))
.setProjectKey(projectKey)
.setProjectName(projectKey)
Expand All @@ -124,8 +120,7 @@ void LCOV_report_paths_alias() {
@Test
void zero_coverage() {
final String projectKey = "ZeroCoverage";
SonarScanner build = OrchestratorStarter
.createScanner()
SonarScanner build = OrchestratorStarter.createScanner()
.setProjectDir(TestUtils.projectDir("lcov"))
.setProjectKey(projectKey)
.setProjectName(projectKey)
Expand All @@ -147,8 +142,7 @@ void zero_coverage() {
// SONARJS-301
public void print_log_for_not_found_resource() {
final String projectKey = "PrintLogForNotFoundResource";
SonarScanner build = OrchestratorStarter
.createScanner()
SonarScanner build = OrchestratorStarter.createScanner()
.setProjectDir(TestUtils.projectDir("lcov"))
.setProjectKey(projectKey)
.setProjectName(projectKey)
Expand Down Expand Up @@ -177,8 +171,7 @@ public void print_log_for_not_found_resource() {
// SONARJS-547
void wrong_line_in_report() {
final String projectKey = "WrongLineInReport";
SonarScanner build = OrchestratorStarter
.createScanner()
SonarScanner build = OrchestratorStarter.createScanner()
.setProjectDir(TestUtils.projectDir("lcov"))
.setProjectKey(projectKey)
.setProjectName(projectKey)
Expand Down Expand Up @@ -211,8 +204,7 @@ void wrong_line_in_report() {
@Test
void conditions_on_non_executable_lines() {
final String projectKey = "ConditionsOnNonExecutableLines";
SonarScanner build = OrchestratorStarter
.createScanner()
SonarScanner build = OrchestratorStarter.createScanner()
.setProjectDir(TestUtils.projectDir("lcov-jsx"))
.setProjectKey(projectKey)
.setProjectName(projectKey)
Expand All @@ -221,9 +213,9 @@ void conditions_on_non_executable_lines() {
.setDebugLogs(true)
.setProperty(
"sonar.javascript.lcov.reportPaths",
TestUtils
.file("projects/lcov-jsx/conditions-on-non-executable-lines.lcov")
.getAbsolutePath()
TestUtils.file(
"projects/lcov-jsx/conditions-on-non-executable-lines.lcov"
).getAbsolutePath()
);
OrchestratorStarter.setEmptyProfile(projectKey);
orchestrator.executeBuild(build);
Expand All @@ -237,8 +229,7 @@ void conditions_on_non_executable_lines() {
@Test
void wildcard_LCOV_report_paths() {
final String projectKey = "LcovWildcardReportPaths";
SonarScanner build = OrchestratorStarter
.createScanner()
SonarScanner build = OrchestratorStarter.createScanner()
.setProjectDir(TestUtils.projectDir("lcov-wildcard"))
.setProjectKey(projectKey)
.setProjectName(projectKey)
Expand All @@ -257,8 +248,7 @@ void wildcard_LCOV_report_paths() {
@Test
void LCOV_report_outside_module() {
final String projectKey = "LcovReportOutsideModule";
SonarScanner build = OrchestratorStarter
.createScanner()
SonarScanner build = OrchestratorStarter.createScanner()
.setProjectDir(TestUtils.projectDir("lcov"))
.setProperty("sonar.modules", "dir")
.setProjectKey(projectKey)
Expand Down
Loading
Loading