Skip to content
Open
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
14 changes: 5 additions & 9 deletions src/main/java/org/sonarsource/sonarlint/ls/java/JavaSdkUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
return new ArrayList<>(collectJars(home, isMac));
}

private static List<Path> collectJars(Path home, boolean isMac) {

Check failure on line 60 in src/main/java/org/sonarsource/sonarlint/ls/java/JavaSdkUtil.java

View check run for this annotation

SonarQube-Next / SonarQube Code Analysis

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.

[S3776] Cognitive Complexity of methods should not be too high See more on https://next.sonarqube.com/sonarqube/project/issues?id=org.sonarsource.sonarlint.ls%3Asonarlint-language-server&pullRequest=710&issues=800e040a-1875-4ca2-bc78-b928b20b9116&open=800e040a-1875-4ca2-bc78-b928b20b9116
var rootFiles = new ArrayList<Path>();

var jarDirs = collectJarDirs(home, isMac);
Expand All @@ -68,16 +68,12 @@
var jarFiles = listFiles(jarDir, p -> Files.isRegularFile(p) && p.getFileName().toString().endsWith(".jar"));
for (var jarFile: jarFiles) {
var jarFileName = jarFile.getFileName().toString();
if (jarFileName.equals("alt-rt.jar") || jarFileName.equals("alt-string.jar")) {
// filter out alternative implementations
continue;
if (!jarFileName.equals("alt-rt.jar") && !jarFileName.equals("alt-string.jar")) {
var realPath = toRealPathOrNull(jarFile);
if (realPath != null && duplicatePathFilter.add(realPath)) {
rootFiles.add(jarFile);
}
}
var realPath = toRealPathOrNull(jarFile);
if (realPath == null || !duplicatePathFilter.add(realPath)) {
// filter out duplicate (symbolically linked) .jar files commonly found in OS X JDK distributions
continue;
}
rootFiles.add(jarFile);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.net.SocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
Expand Down Expand Up @@ -264,7 +263,7 @@ static void cleanupProxyProperties() {
void openUrlInBrowserTest() throws MalformedURLException {
var params = new OpenUrlInBrowserParams("https://www.sonarsource.com");

underTest.openUrlInBrowser(new URL("https://www.sonarsource.com"));
underTest.openUrlInBrowser(URI.create("https://www.sonarsource.com").toURL());

verify(client).browseTo(params.getUrl());
}
Expand Down Expand Up @@ -872,7 +871,7 @@ protected PasswordAuthentication getPasswordAuthentication() {
});

var response = underTest.getProxyPasswordAuthentication("http://foo", 8085, "protocol",
"prompt", "scheme", new URL("http://targethost"));
"prompt", "scheme", URI.create("http://targethost").toURL());
assertThat(response.getProxyUser()).isEqualTo("username");
assertThat(response.getProxyPassword()).isEqualTo("password");

Expand All @@ -887,7 +886,7 @@ void shouldUseDefaultAuthenticatorWithSystemProperties() throws MalformedURLExce
System.setProperty("http.proxyPassword", "myPass");

var passwordAuth = Authenticator.requestPasswordAuthentication("localhost", null, 1234,
"http", "", "", new URL("http://localhost:9000"),
"http", "", "", URI.create("http://localhost:9000").toURL(),
Authenticator.RequestorType.PROXY);

assertThat(passwordAuth.getUserName()).isEqualTo("myUser");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import org.eclipse.lsp4j.WorkspaceFolder;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -101,7 +102,7 @@ void should_provide_all_main_files() {
var files = folderFileSystem.files();

assertThat(files)
.extracting(ClientInputFile::getPath, FolderFileSystemTests::getFileContents, ClientInputFile::isTest, ClientInputFile::getCharset, ClientInputFile::getClientObject,
.extracting(f -> Paths.get(f.uri()).toString(), FolderFileSystemTests::getFileContents, ClientInputFile::isTest, ClientInputFile::getCharset, ClientInputFile::getClientObject,
ClientInputFile::relativePath, ClientInputFile::uri)
.containsExactly(tuple(pythonFile.toAbsolutePath().toString(), "", false, StandardCharsets.UTF_8, pythonFile.toUri(), "file.py", pythonFile.toUri()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ class JavaMediumTests extends AbstractLanguageServerMediumTests {
private static Path module2Path;
private static Path analysisDir;

private static String MODULE_1_ROOT_URI;
private static String MODULE_2_ROOT_URI;
private static String module1RootUri;
private static String module2RootUri;

@BeforeAll
static void initialize() throws Exception {
analysisDir = makeStaticTempDir();
module1Path = makeStaticTempDir();
module2Path = makeStaticTempDir();
MODULE_1_ROOT_URI = module1Path.toUri().toString();
MODULE_2_ROOT_URI = module2Path.toUri().toString();
module1RootUri = module1Path.toUri().toString();
module2RootUri = module2Path.toUri().toString();

initialize(Map.of(
"telemetryStorage", "not/exists",
Expand Down Expand Up @@ -116,7 +116,7 @@ void analyzeSimpleJavaFileReuseCachedClasspath() throws Exception {
var uri = getUri("analyzeSimpleJavaFileOnOpen.java", analysisDir);

var javaConfigResponse = new GetJavaConfigResponse();
javaConfigResponse.setProjectRoot(MODULE_1_ROOT_URI);
javaConfigResponse.setProjectRoot(module1RootUri);
javaConfigResponse.setSourceLevel("1.8");
javaConfigResponse.setTest(false);
javaConfigResponse.setClasspath(new String[]{"/does/not/exist"});
Expand Down Expand Up @@ -158,7 +158,7 @@ void analyzeSimpleJavaFileWithFlows() throws Exception {
var uri = getUri("AnalyzeSimpleJavaFileWithFlows.java", analysisDir);

var javaConfigResponse = new GetJavaConfigResponse();
javaConfigResponse.setProjectRoot(MODULE_1_ROOT_URI);
javaConfigResponse.setProjectRoot(module1RootUri);
javaConfigResponse.setSourceLevel("1.8");
javaConfigResponse.setTest(false);
javaConfigResponse.setClasspath(new String[0]);
Expand Down Expand Up @@ -198,7 +198,7 @@ void analyzeSimpleJavaFilePassVmClasspath() throws Exception {
var uri = getUri("analyzeSimpleJavaFileOnOpen.java", analysisDir);

var javaConfigResponse = new GetJavaConfigResponse();
javaConfigResponse.setProjectRoot(MODULE_1_ROOT_URI);
javaConfigResponse.setProjectRoot(module1RootUri);
javaConfigResponse.setSourceLevel("1.8");
javaConfigResponse.setTest(false);
javaConfigResponse.setClasspath(new String[0]);
Expand Down Expand Up @@ -229,7 +229,7 @@ void analyzeSimpleJavaTestFileOnOpen() throws Exception {
var uri = getUri("analyzeSimpleJavaTestFileOnOpen.java", analysisDir);

var javaConfigResponse = new GetJavaConfigResponse();
javaConfigResponse.setProjectRoot(MODULE_1_ROOT_URI);
javaConfigResponse.setProjectRoot(module1RootUri);
javaConfigResponse.setSourceLevel("1.8");
javaConfigResponse.setTest(true);
javaConfigResponse.setClasspath(new String[]{Paths.get(this.getClass().getResource("/junit-4.12.jar").toURI()).toAbsolutePath().toString()});
Expand Down Expand Up @@ -309,7 +309,7 @@ void testJavaServerModeUpdateToStandardTriggersNewAnalysis() throws Exception {

// Prepare config response
var javaConfigResponse = new GetJavaConfigResponse();
javaConfigResponse.setProjectRoot(MODULE_1_ROOT_URI);
javaConfigResponse.setProjectRoot(module1RootUri);
javaConfigResponse.setSourceLevel("1.8");
javaConfigResponse.setTest(false);
javaConfigResponse.setClasspath(new String[0]);
Expand All @@ -336,7 +336,7 @@ void shouldBatchAnalysisFromTheSameModule() throws Exception {

// Prepare config response
var javaConfigResponse = new GetJavaConfigResponse();
javaConfigResponse.setProjectRoot(MODULE_1_ROOT_URI);
javaConfigResponse.setProjectRoot(module1RootUri);
javaConfigResponse.setSourceLevel("1.8");
javaConfigResponse.setTest(false);
javaConfigResponse.setClasspath(new String[0]);
Expand Down Expand Up @@ -415,14 +415,14 @@ void shouldNotBatchAnalysisFromDifferentModules() throws Exception {

// Prepare config response
var javaConfigResponse1 = new GetJavaConfigResponse();
javaConfigResponse1.setProjectRoot(MODULE_1_ROOT_URI);
javaConfigResponse1.setProjectRoot(module1RootUri);
javaConfigResponse1.setSourceLevel("1.8");
javaConfigResponse1.setTest(false);
javaConfigResponse1.setClasspath(new String[0]);
client.javaConfigs.put(file1module1, javaConfigResponse1);

var javaConfigResponse2 = new GetJavaConfigResponse();
javaConfigResponse2.setProjectRoot(MODULE_2_ROOT_URI);
javaConfigResponse2.setProjectRoot(module2RootUri);
javaConfigResponse2.setSourceLevel("1.8");
javaConfigResponse2.setTest(false);
javaConfigResponse2.setClasspath(new String[0]);
Expand Down
Loading