Skip to content
Draft
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
5 changes: 0 additions & 5 deletions its/autoscan/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
<artifactId>gson</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -228,7 +227,7 @@ private static String absolutePathFor(String path) {

private static List<String> generateSonarWay(OrchestratorRule orchestrator) {
Set<String> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,15 +45,15 @@ public class ProfileGenerator {

private static final Logger LOG = LoggerFactory.getLogger(ProfileGenerator.class);

static void generate(OrchestratorRule orchestrator, ImmutableMap<String, ImmutableMap<String, String>> rulesParameters,
static void generate(OrchestratorRule orchestrator, Map<String, Map<String, String>> rulesParameters,
Set<String> excluded, Set<String> subsetOfEnabledRules, Set<String> activatedRuleKeys) {
generate(orchestrator, null, rulesParameters, excluded, subsetOfEnabledRules, activatedRuleKeys);
}

/**
* @return the list of enabled rule keys for the given profile
*/
static void generate(OrchestratorRule orchestrator, @Nullable String qualityProfile, ImmutableMap<String, ImmutableMap<String, String>> rulesParameters,
static void generate(OrchestratorRule orchestrator, @Nullable String qualityProfile, Map<String, Map<String, String>> rulesParameters,
Set<String> excluded, Set<String> subsetOfEnabledRules, Set<String> activatedRuleKeys) {
try {
LOG.info("Generating profile containing all the rules");
Expand Down Expand Up @@ -91,7 +89,7 @@ static void generate(OrchestratorRule orchestrator, @Nullable String qualityProf
.append("</profile>");

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();
Expand Down
5 changes: 0 additions & 5 deletions its/ruling/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
Expand Down
33 changes: 14 additions & 19 deletions its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -79,11 +77,11 @@ public class JavaRulingTest {
* mvn test -DsonarRules=S100,S101
* }</pre>
*/
private static final ImmutableSet<String> SUBSET_OF_ENABLED_RULES = ImmutableSet.copyOf(
Splitter.on(',').trimResults().omitEmptyStrings().splitToList(
System.getProperty("sonarRules", "")
)
);
private static final Set<String> 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();
Expand Down Expand Up @@ -114,23 +112,20 @@ private static OrchestratorRule createOrchestrator() {

@BeforeClass
public static void prepare_quality_profiles() throws Exception {
ImmutableMap<String, ImmutableMap<String, String>> rulesParameters = ImmutableMap.<String, ImmutableMap<String, String>>builder()
.put(
"S1120",
ImmutableMap.of("indentationLevel", "4"))
.put(
Map<String, Map<String, String>> 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<String> disabledRules = ImmutableSet.of(
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms."""),
"S5961", Map.of("MaximumAssertionNumber", "50"),
"S6539", Map.of("couplingThreshold", "20")
);
Set<String> disabledRules = Set.of(
"S1874",
"CycleBetweenPackages",
// disable because it generates too many issues, performance reasons
Expand Down
10 changes: 4 additions & 6 deletions its/ruling/src/test/java/org/sonar/java/it/ProfileGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,15 +43,15 @@ public class ProfileGenerator {

private static final Logger LOG = LoggerFactory.getLogger(ProfileGenerator.class);

static void generate(OrchestratorRule orchestrator, ImmutableMap<String, ImmutableMap<String, String>> rulesParameters,
static void generate(OrchestratorRule orchestrator, Map<String, Map<String, String>> rulesParameters,
Set<String> excluded, Set<String> subsetOfEnabledRules, Set<String> activatedRuleKeys) {
generate(orchestrator, null, rulesParameters, excluded, subsetOfEnabledRules, activatedRuleKeys);
}

/**
* @return the list of enabled rule keys for the given profile
*/
static void generate(OrchestratorRule orchestrator, @Nullable String qualityProfile, ImmutableMap<String, ImmutableMap<String, String>> rulesParameters,
static void generate(OrchestratorRule orchestrator, @Nullable String qualityProfile, Map<String, Map<String, String>> rulesParameters,
Set<String> excluded, Set<String> subsetOfEnabledRules, Set<String> activatedRuleKeys) {
try {
LOG.info("Generating profile containing all the rules");
Expand Down Expand Up @@ -89,7 +87,7 @@ static void generate(OrchestratorRule orchestrator, @Nullable String qualityProf
.append("</profile>");

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();
Expand Down
Loading