From 5a93a39205eefb07a7f3eb9ce5de24749b04b1af Mon Sep 17 00:00:00 2001 From: Yassin Kammoun <52890329+yassin-kammoun-sonarsource@users.noreply.github.com> Date: Mon, 4 Nov 2024 14:46:17 +0100 Subject: [PATCH] JS-389 Add missing license and clean up (#4890) --- .../javascript/bridge/TsConfigFile.java | 26 +++++++------------ .../bridge/BridgeServerImplTest.java | 10 +++---- .../analysis/AnalysisWithWatchProgram.java | 1 - .../javascript/analysis/TsConfigCache.java | 19 ++++++++++++++ .../analysis/TsConfigCacheImpl.java | 20 +++++++++++++- .../javascript/analysis/TsConfigOrigin.java | 20 +++++++++++++- 6 files changed, 72 insertions(+), 24 deletions(-) diff --git a/sonar-plugin/bridge/src/main/java/org/sonar/plugins/javascript/bridge/TsConfigFile.java b/sonar-plugin/bridge/src/main/java/org/sonar/plugins/javascript/bridge/TsConfigFile.java index c19a2942230..ed1d028c3c8 100644 --- a/sonar-plugin/bridge/src/main/java/org/sonar/plugins/javascript/bridge/TsConfigFile.java +++ b/sonar-plugin/bridge/src/main/java/org/sonar/plugins/javascript/bridge/TsConfigFile.java @@ -19,22 +19,16 @@ */ package org.sonar.plugins.javascript.bridge; -import java.io.IOException; -import java.nio.file.LinkOption; import java.nio.file.Path; import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class TsConfigFile { - private static final Logger LOG = LoggerFactory.getLogger(TsConfigFile.class); - - final String filename; - final Set files; - final List projectReferences; + private final String filename; + private final Set files; + private final List projectReferences; public TsConfigFile(String filename, List files, List projectReferences) { this.filename = filename; @@ -42,13 +36,6 @@ public TsConfigFile(String filename, List files, List projectRef this.projectReferences = projectReferences; } - public static String normalizePath(String path) { - return Path - .of(path) - .toString() - .replaceAll("[\\\\/]", "/"); - } - public List getProjectReferences() { return projectReferences; } @@ -65,4 +52,11 @@ public Set getFiles() { public String toString() { return filename; } + + private static String normalizePath(String path) { + return Path + .of(path) + .toString() + .replaceAll("[\\\\/]", "/"); + } } diff --git a/sonar-plugin/bridge/src/test/java/org/sonar/plugins/javascript/bridge/BridgeServerImplTest.java b/sonar-plugin/bridge/src/test/java/org/sonar/plugins/javascript/bridge/BridgeServerImplTest.java index 9b1c19edf83..b2deb43fde8 100644 --- a/sonar-plugin/bridge/src/test/java/org/sonar/plugins/javascript/bridge/BridgeServerImplTest.java +++ b/sonar-plugin/bridge/src/test/java/org/sonar/plugins/javascript/bridge/BridgeServerImplTest.java @@ -311,7 +311,7 @@ void should_create_tsconfig_files() throws IOException { bridgeServer.startServer(serverConfig, emptyList()); var tsConfig = bridgeServer.createTsConfigFile("{\"include\":[\"/path/to/project/**/*\"]}"); - assertThat(tsConfig.filename).isEqualTo("/path/to/tsconfig.json"); + assertThat(tsConfig.getFilename()).isEqualTo("/path/to/tsconfig.json"); } @Test @@ -555,8 +555,8 @@ void should_return_files_for_tsconfig() throws Exception { assertThat(tsConfigResponse.error).isNull(); TsConfigFile tsConfigFile = bridgeServer.loadTsConfig(tsconfig); - assertThat(tsConfigFile.files).contains("abs/path/file1", "abs/path/file2", "abs/path/file3"); - assertThat(tsConfigFile.filename).isEqualTo(tsconfig); + assertThat(tsConfigFile.getFiles()).contains("abs/path/file1", "abs/path/file2", "abs/path/file3"); + assertThat(tsConfigFile.getFilename()).isEqualTo(tsconfig); } @Test @@ -576,7 +576,7 @@ void should_return_no_files_for_tsconfig_no_response() throws Exception { bridgeServer.startServer(serverConfig, emptyList()); assertThat(bridgeServer.tsConfigFiles("path/to/tsconfig.json").files).isEmpty(); TsConfigFile tsConfigFile = bridgeServer.loadTsConfig("path/to/tsconfig.json"); - assertThat(tsConfigFile.files).isEmpty(); + assertThat(tsConfigFile.getFiles()).isEmpty(); } @Test @@ -585,7 +585,7 @@ void should_return_no_files_for_tsconfig_on_error() throws Exception { bridgeServer.startServer(serverConfig, emptyList()); TsConfigFile tsConfigFile = bridgeServer.loadTsConfig("path/to/tsconfig.json"); - assertThat(tsConfigFile.files).isEmpty(); + assertThat(tsConfigFile.getFiles()).isEmpty(); assertThat(logTester.logs(ERROR)).contains("Other error"); } diff --git a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/AnalysisWithWatchProgram.java b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/AnalysisWithWatchProgram.java index 76a53528411..097e1c40adb 100644 --- a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/AnalysisWithWatchProgram.java +++ b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/AnalysisWithWatchProgram.java @@ -53,7 +53,6 @@ public void analyzeFiles(List inputFiles, List tsConfigs) thr progressReport.start(inputFiles.size(), inputFiles.iterator().next().toString()); for (InputFile inputFile : inputFiles) { var tsConfigFile = tsConfigCache.getTsConfigForInputFile(inputFile); - // process analyzeFile(inputFile, tsConfigFile == null ? List.of() : List.of(tsConfigFile.getFilename()), null); } success = true; diff --git a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/TsConfigCache.java b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/TsConfigCache.java index 6efa9bc14cd..3509ecaaf45 100644 --- a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/TsConfigCache.java +++ b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/TsConfigCache.java @@ -1,3 +1,22 @@ +/* + * SonarQube JavaScript Plugin + * Copyright (C) 2011-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * 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 GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ package org.sonar.plugins.javascript.analysis; import java.util.List; diff --git a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/TsConfigCacheImpl.java b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/TsConfigCacheImpl.java index 87268730c9f..9484fbbf2ea 100644 --- a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/TsConfigCacheImpl.java +++ b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/TsConfigCacheImpl.java @@ -1,6 +1,24 @@ +/* + * SonarQube JavaScript Plugin + * Copyright (C) 2011-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * 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 GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ package org.sonar.plugins.javascript.analysis; - import java.nio.file.Path; import java.util.ArrayDeque; import java.util.ArrayList; diff --git a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/TsConfigOrigin.java b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/TsConfigOrigin.java index 83e930bbfeb..44860cb6a3f 100644 --- a/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/TsConfigOrigin.java +++ b/sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/TsConfigOrigin.java @@ -1,6 +1,24 @@ +/* + * SonarQube JavaScript Plugin + * Copyright (C) 2011-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * 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 GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ package org.sonar.plugins.javascript.analysis; - public enum TsConfigOrigin { PROPERTY, LOOKUP,