diff --git a/its/autoscan/pom.xml b/its/autoscan/pom.xml index b6d2c95979..3f32fe6d7d 100644 --- a/its/autoscan/pom.xml +++ b/its/autoscan/pom.xml @@ -31,11 +31,6 @@ gson test - - com.google.guava - guava - test - junit junit diff --git a/its/autoscan/src/test/java/org/sonar/java/it/AutoScanTest.java b/its/autoscan/src/test/java/org/sonar/java/it/AutoScanTest.java index 307045af9c..17dff2ef63 100644 --- a/its/autoscan/src/test/java/org/sonar/java/it/AutoScanTest.java +++ b/its/autoscan/src/test/java/org/sonar/java/it/AutoScanTest.java @@ -16,7 +16,6 @@ */ package org.sonar.java.it; -import com.google.common.collect.ImmutableMap; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -228,7 +227,7 @@ private static String absolutePathFor(String path) { private static List generateSonarWay(OrchestratorRule orchestrator) { Set results = new TreeSet<>(RULE_KEY_COMPARATOR); - ProfileGenerator.generate(orchestrator, "Sonar Way", ImmutableMap.of(), Collections.emptySet(), Collections.emptySet(), results); + ProfileGenerator.generate(orchestrator, "Sonar Way", Map.of(), Collections.emptySet(), Collections.emptySet(), results); return new ArrayList<>(results); } diff --git a/its/autoscan/src/test/java/org/sonar/java/it/ProfileGenerator.java b/its/autoscan/src/test/java/org/sonar/java/it/ProfileGenerator.java index daa0c3799c..6caf11b0d7 100644 --- a/its/autoscan/src/test/java/org/sonar/java/it/ProfileGenerator.java +++ b/its/autoscan/src/test/java/org/sonar/java/it/ProfileGenerator.java @@ -16,14 +16,12 @@ */ package org.sonar.java.it; -import com.google.common.collect.ImmutableMap; -import com.google.common.io.Files; import com.sonar.orchestrator.container.Server; import com.sonar.orchestrator.junit4.OrchestratorRule; import com.sonar.orchestrator.locator.FileLocation; import java.io.File; import java.io.IOException; -import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -47,7 +45,7 @@ public class ProfileGenerator { private static final Logger LOG = LoggerFactory.getLogger(ProfileGenerator.class); - static void generate(OrchestratorRule orchestrator, ImmutableMap> rulesParameters, + static void generate(OrchestratorRule orchestrator, Map> rulesParameters, Set excluded, Set subsetOfEnabledRules, Set activatedRuleKeys) { generate(orchestrator, null, rulesParameters, excluded, subsetOfEnabledRules, activatedRuleKeys); } @@ -55,7 +53,7 @@ static void generate(OrchestratorRule orchestrator, ImmutableMap> rulesParameters, + static void generate(OrchestratorRule orchestrator, @Nullable String qualityProfile, Map> rulesParameters, Set excluded, Set subsetOfEnabledRules, Set activatedRuleKeys) { try { LOG.info("Generating profile containing all the rules"); @@ -91,7 +89,7 @@ static void generate(OrchestratorRule orchestrator, @Nullable String qualityProf .append(""); File file = File.createTempFile("profile", ".xml"); - Files.asCharSink(file, StandardCharsets.UTF_8).write(sb); + Files.writeString(file.toPath(), sb); LOG.info("Restoring profile to SonarQube"); orchestrator.getServer().restoreProfile(FileLocation.of(file)); file.delete(); diff --git a/its/ruling/pom.xml b/its/ruling/pom.xml index 8a273286a3..174595f390 100644 --- a/its/ruling/pom.xml +++ b/its/ruling/pom.xml @@ -63,11 +63,6 @@ assertj-core test - - com.google.guava - guava - test - com.google.code.findbugs jsr305 diff --git a/its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java b/its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java index 6cb69a1657..5d9f867e03 100644 --- a/its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java +++ b/its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java @@ -16,9 +16,6 @@ */ package org.sonar.java.it; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import com.sonar.orchestrator.build.Build; import com.sonar.orchestrator.build.BuildResult; import com.sonar.orchestrator.build.MavenBuild; @@ -40,6 +37,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import javax.annotation.Nullable; @@ -79,11 +77,11 @@ public class JavaRulingTest { * mvn test -DsonarRules=S100,S101 * } */ - private static final ImmutableSet SUBSET_OF_ENABLED_RULES = ImmutableSet.copyOf( - Splitter.on(',').trimResults().omitEmptyStrings().splitToList( - System.getProperty("sonarRules", "") - ) - ); + private static final Set SUBSET_OF_ENABLED_RULES = + Arrays.stream(System.getProperty("sonarRules", "").split(",")) + .map(String::trim) + .filter(s -> !s.isEmpty()) + .collect(Collectors.toSet()); @ClassRule public static TemporaryFolder tmpDumpOldFolder = new TemporaryFolder(); @@ -114,23 +112,20 @@ private static OrchestratorRule createOrchestrator() { @BeforeClass public static void prepare_quality_profiles() throws Exception { - ImmutableMap> rulesParameters = ImmutableMap.>builder() - .put( - "S1120", - ImmutableMap.of("indentationLevel", "4")) - .put( + Map> rulesParameters = Map.of( + "S1120", Map.of("indentationLevel", "4"), "S1451", - ImmutableMap.of( + Map.of( "headerFormat", """ /* * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. - * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.""")) - .put("S5961", ImmutableMap.of("MaximumAssertionNumber", "50")) - .put("S6539", ImmutableMap.of("couplingThreshold", "20")) - .build(); - ImmutableSet disabledRules = ImmutableSet.of( + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms."""), + "S5961", Map.of("MaximumAssertionNumber", "50"), + "S6539", Map.of("couplingThreshold", "20") + ); + Set disabledRules = Set.of( "S1874", "CycleBetweenPackages", // disable because it generates too many issues, performance reasons diff --git a/its/ruling/src/test/java/org/sonar/java/it/ProfileGenerator.java b/its/ruling/src/test/java/org/sonar/java/it/ProfileGenerator.java index 5e3b064b90..2596ea4bd3 100644 --- a/its/ruling/src/test/java/org/sonar/java/it/ProfileGenerator.java +++ b/its/ruling/src/test/java/org/sonar/java/it/ProfileGenerator.java @@ -16,13 +16,11 @@ */ package org.sonar.java.it; -import com.google.common.collect.ImmutableMap; -import com.google.common.io.Files; import com.sonar.orchestrator.junit4.OrchestratorRule; import com.sonar.orchestrator.locator.FileLocation; import java.io.File; import java.io.IOException; -import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -45,7 +43,7 @@ public class ProfileGenerator { private static final Logger LOG = LoggerFactory.getLogger(ProfileGenerator.class); - static void generate(OrchestratorRule orchestrator, ImmutableMap> rulesParameters, + static void generate(OrchestratorRule orchestrator, Map> rulesParameters, Set excluded, Set subsetOfEnabledRules, Set activatedRuleKeys) { generate(orchestrator, null, rulesParameters, excluded, subsetOfEnabledRules, activatedRuleKeys); } @@ -53,7 +51,7 @@ static void generate(OrchestratorRule orchestrator, ImmutableMap> rulesParameters, + static void generate(OrchestratorRule orchestrator, @Nullable String qualityProfile, Map> rulesParameters, Set excluded, Set subsetOfEnabledRules, Set activatedRuleKeys) { try { LOG.info("Generating profile containing all the rules"); @@ -89,7 +87,7 @@ static void generate(OrchestratorRule orchestrator, @Nullable String qualityProf .append(""); File file = File.createTempFile("profile", ".xml"); - Files.asCharSink(file, StandardCharsets.UTF_8).write(sb); + Files.writeString(file.toPath(), sb); LOG.info("Restoring profile to SonarQube"); orchestrator.getServer().restoreProfile(FileLocation.of(file)); file.delete();