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 issues related to Java v17 bump #4589

Merged
merged 3 commits into from
Mar 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions sonar-plugin/css/src/main/java/org/sonar/css/CssRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.sonar.api.batch.rule.CheckFactory;
import org.sonar.api.batch.rule.Checks;
Expand Down Expand Up @@ -115,6 +114,6 @@ public RuleKey getActiveSonarKey(String stylelintKey) {
public List<StylelintRule> getStylelintRules() {
return this.rules.stream()
.map(rule -> new StylelintRule(rule.stylelintKey(), rule.stylelintOptions()))
.collect(Collectors.toList());
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.sonar.sslr.api.Token;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Tokenizer {

Expand All @@ -33,6 +32,6 @@ public List<CssToken> tokenize(String css) {
List<Token> cloneTokenList = new ArrayList<>(tokenList);
cloneTokenList.remove(cloneTokenList.size() - 1);

return cloneTokenList.stream().map(CssToken::new).collect(Collectors.toList());
return cloneTokenList.stream().map(CssToken::new).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class RuleUtils {

Expand All @@ -33,6 +32,6 @@ public static List<String> splitAndTrim(String parameterValue) {
return Collections.emptyList();
}
String[] split = parameterValue.split(",");
return Arrays.stream(split).map(String::trim).collect(Collectors.toList());
return Arrays.stream(split).map(String::trim).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ public class SelectorTypeNoUnknown implements CssRule {

@RuleProperty(
key = "ignore",
description = "Comma-separated list of ignored elements. The possible values are:\n" +
"\"custom-elements\": Allow custom elements (e.g \"x-foo\").\n" +
"\"default-namespace\": Allow unknown type selectors if they belong to the default namespace.",
description = """
Comma-separated list of ignored elements. The possible values are:
"custom-elements": Allow custom elements (e.g "x-foo").
"default-namespace": Allow unknown type selectors if they belong to the default namespace.
""",
defaultValue = "" + DEFAULT_IGNORE
)
String ignore = DEFAULT_IGNORE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
import org.sonar.plugins.javascript.api.EslintBasedCheck;
Expand All @@ -44,9 +43,7 @@ public class NoUnknownPropertyCheck implements EslintBasedCheck {
@Override
public List<Object> configurations() {
return Collections.singletonList(
new Config(
Arrays.asList(whitelist.split(",")).stream().map(String::trim).collect(Collectors.toList())
)
new Config(Arrays.asList(whitelist.split(",")).stream().map(String::trim).toList())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.sonar.api.SonarProduct;
Expand Down Expand Up @@ -254,7 +253,7 @@ private NodeCommand initNodeCommand(SensorContext context, File scriptFile, Stri
return nodeCommandBuilder.build();
}

private Map<String, String> getEnv() {
private static Map<String, String> getEnv() {
Map<String, String> env = new HashMap<>();
if (LOG.isDebugEnabled()) {
env.put("TIMING", "all");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.zip.GZIPInputStream;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveInputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.utils.IOUtils;

Expand All @@ -42,7 +43,7 @@ static void extractFromClasspath(InputStream resource, Path targetPath) throws I
Objects.requireNonNull(resource);
try (
InputStream stream = new GZIPInputStream(new BufferedInputStream(resource));
ArchiveInputStream archive = new TarArchiveInputStream(stream)
ArchiveInputStream<TarArchiveEntry> archive = new TarArchiveInputStream(stream)
) {
ArchiveEntry entry;
while ((entry = archive.getNextEntry()) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.sonar.api.SonarProduct;
import org.sonar.api.SonarRuntime;
Expand Down Expand Up @@ -231,7 +230,7 @@ protected List<InputFile> getInputFiles() {
.spliterator(),
false
)
.collect(Collectors.toList());
.toList();
}

public static boolean hasCssFiles(SensorContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.plugins.javascript.JavaScriptLanguage;
import org.sonar.plugins.javascript.TypeScriptLanguage;
Expand All @@ -43,8 +42,7 @@ class EslintRule {
String language
) {
this.key = key;
this.fileTypeTarget =
fileTypeTarget.stream().map(InputFile.Type::name).collect(Collectors.toList());
this.fileTypeTarget = fileTypeTarget.stream().map(InputFile.Type::name).toList();
this.configurations = configurations;
// unfortunately we can't check this using types, so it's enforced at runtime
if (!JavaScriptLanguage.KEY.equals(language) && !TypeScriptLanguage.KEY.equals(language)) {
Expand All @@ -71,10 +69,7 @@ static EslintRule findFirstRuleWithKey(List<EslintRule> rules, String eslintKey)
}

static List<EslintRule> findAllBut(List<EslintRule> rules, Set<String> blackListRuleKeys) {
return rules
.stream()
.filter(rule -> !blackListRuleKeys.contains(rule.key))
.collect(Collectors.toList());
return rules.stream().filter(rule -> !blackListRuleKeys.contains(rule.key)).toList();
}

private static Predicate<EslintRule> ruleMatcher(String eslintKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.FilePredicates;
Expand Down Expand Up @@ -116,7 +115,7 @@ protected List<InputFile> getInputFiles() {
)
);
var inputFiles = context.fileSystem().inputFiles(filePredicate);
return StreamSupport.stream(inputFiles.spliterator(), false).collect(Collectors.toList());
return StreamSupport.stream(inputFiles.spliterator(), false).toList();
}

private void analyze(InputFile file, CacheStrategy cacheStrategy) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.sonar.api.batch.rule.CheckFactory;
Expand Down Expand Up @@ -169,7 +168,7 @@ List<EslintRule> eslintRules() {
)
)
)
.collect(Collectors.toList());
.toList();
}

static class LanguageAndRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import javax.annotation.Nullable;
import org.sonar.api.batch.fs.FilePredicate;
Expand Down Expand Up @@ -95,7 +94,7 @@ protected List<InputFile> getInputFiles() {
FilePredicate allFilesPredicate = JavaScriptFilePredicate.getJsTsPredicate(fileSystem);
return StreamSupport
.stream(fileSystem.inputFiles(allFilesPredicate).spliterator(), false)
.collect(Collectors.toList());
.toList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.sonar.api.scanner.ScannerSide;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
Expand Down Expand Up @@ -70,7 +69,7 @@ public RulesBundles(RulesBundle[] rulesBundles) {
}
return resource;
})
.collect(Collectors.toList());
.toList();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;

import com.google.gson.Gson;
import java.io.File;
Expand Down Expand Up @@ -141,7 +140,7 @@ public List<String> tsconfigs(SensorContext context) {
FileProvider fileProvider = new FileProvider(baseDir, pattern);
List<File> matchingTsconfigs = fileProvider.getMatchingFiles();
if (!matchingTsconfigs.isEmpty()) {
tsconfigs.addAll(matchingTsconfigs.stream().map(File::getAbsolutePath).collect(toList()));
tsconfigs.addAll(matchingTsconfigs.stream().map(File::getAbsolutePath).toList());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.sonar.api.batch.fs.FilePredicates;
import org.sonar.api.batch.fs.InputFile;
Expand Down Expand Up @@ -111,7 +110,7 @@ protected List<InputFile> getInputFiles() {
input -> isSamTemplate(input, LOG)
);
var inputFiles = context.fileSystem().inputFiles(filePredicate);
return StreamSupport.stream(inputFiles.spliterator(), false).collect(Collectors.toList());
return StreamSupport.stream(inputFiles.spliterator(), false).toList();
}

// Inspired from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.sonar.plugins.javascript.bridge.cache;

import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toList;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -38,7 +37,7 @@ class CacheKey {
private final String pluginVersion;

private CacheKey(List<String> prefixes, @Nullable String pluginVersion, String file) {
this.prefixes = prefixes.stream().filter(Objects::nonNull).collect(toList());
this.prefixes = prefixes.stream().filter(Objects::nonNull).toList();
this.pluginVersion = pluginVersion;
this.file = file;
}
Expand Down Expand Up @@ -68,7 +67,7 @@ CacheKey forFileMetadata() {

CacheKey withPrefix(String... prefixes) {
return new CacheKey(
Stream.concat(this.prefixes.stream(), Arrays.stream(prefixes)).collect(toList()),
Stream.concat(this.prefixes.stream(), Arrays.stream(prefixes)).toList(),
pluginVersion,
file
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static java.util.Collections.emptyList;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

import java.io.BufferedOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -110,7 +109,7 @@ private static FilesManifest createManifest(Path directory, FileIterator enumera
FilesManifest writeToCache(@Nullable List<String> generatedFiles) throws IOException {
List<Path> paths = generatedFiles == null
? emptyList()
: generatedFiles.stream().map(Path::of).collect(toList());
: generatedFiles.stream().map(Path::of).toList();
var iterator = new FileIterator(paths);

try (var sequence = new SequenceInputStream(new IteratorEnumeration<>(iterator))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.stream.Collectors;
import org.sonar.api.batch.fs.InputFile;

/**
Expand Down Expand Up @@ -114,7 +113,7 @@ private static List<String> readLines(InputFile file) {
new InputStreamReader(file.inputStream(), file.charset())
)
) {
return reader.lines().collect(Collectors.toList());
return reader.lines().toList();
} catch (IOException e) {
throw new IllegalStateException("Unable to read file " + file.uri(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.sonar.plugins.javascript.filter;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFileFilter;
Expand All @@ -44,14 +43,14 @@ public JavaScriptExclusionsFileFilter(Configuration configuration) {
new BundleAssessor()
)
.filter(assessor -> shouldBeEnabled(assessor, configuration))
.collect(Collectors.toUnmodifiableList());
.toList();

// We ignore the size limit for CSS files, because analyzing large CSS files takes a reasonable amount of time
cssAssessors =
Stream
.of(new PathAssessor(configuration), new MinificationAssessor(), new BundleAssessor())
.filter(assessor -> shouldBeEnabled(assessor, configuration))
.collect(Collectors.toUnmodifiableList());
.toList();
}

private static boolean shouldBeEnabled(Assessor assessor, Configuration configuration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.CheckForNull;
import org.sonar.api.batch.fs.InputFile;
Expand Down Expand Up @@ -66,7 +65,7 @@ static LCOVParser create(SensorContext context, List<File> files, FileLocator fi
final List<String> lines = new LinkedList<>();
for (File file : files) {
try (Stream<String> fileLines = Files.lines(file.toPath())) {
lines.addAll(fileLines.collect(Collectors.toList()));
lines.addAll(fileLines.toList());
} catch (IOException e) {
throw new IllegalArgumentException("Could not read content from file: " + file, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,10 @@ static Rule fromSqRule(String repository, RulesDefinition.Rule sqRule, @Nullable
rule.params = sqRule.params();
rule.scope = sqRule.scope();
rule.activatedByDefault = sqRule.activatedByDefault();
if (check instanceof EslintBasedCheck) {
var eslintBasedCheck = (EslintBasedCheck) check;
if (check instanceof EslintBasedCheck eslintBasedCheck) {
rule.eslintKey = eslintBasedCheck.eslintKey();
rule.defaultParams = eslintBasedCheck.configurations();
} else if (check instanceof CssRule) {
var cssRule = (CssRule) check;
} else if (check instanceof CssRule cssRule) {
rule.stylelintKey = cssRule.stylelintKey();
rule.defaultParams = cssRule.stylelintOptions();
}
Expand Down
Loading
Loading