Skip to content

Commit

Permalink
JS-389 Add missing license and clean up (#4890)
Browse files Browse the repository at this point in the history
  • Loading branch information
yassin-kammoun-sonarsource authored Nov 4, 2024
1 parent 12baa4d commit 5a93a39
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,23 @@
*/
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<String> files;
final List<String> projectReferences;
private final String filename;
private final Set<String> files;
private final List<String> projectReferences;

public TsConfigFile(String filename, List<String> files, List<String> projectReferences) {
this.filename = filename;
this.files = files.stream().map(TsConfigFile::normalizePath).collect(Collectors.toSet());
this.projectReferences = projectReferences;
}

public static String normalizePath(String path) {
return Path
.of(path)
.toString()
.replaceAll("[\\\\/]", "/");
}

public List<String> getProjectReferences() {
return projectReferences;
}
Expand All @@ -65,4 +52,11 @@ public Set<String> getFiles() {
public String toString() {
return filename;
}

private static String normalizePath(String path) {
return Path
.of(path)
.toString()
.replaceAll("[\\\\/]", "/");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public void analyzeFiles(List<InputFile> inputFiles, List<String> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 5a93a39

Please sign in to comment.