Skip to content

Commit f5bd16f

Browse files
Fix quality gate issues
1 parent 7c23f14 commit f5bd16f

File tree

2 files changed

+13
-34
lines changed

2 files changed

+13
-34
lines changed

its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.sonar.orchestrator.locator.MavenLocation;
3030
import java.io.File;
3131
import java.io.IOException;
32-
import java.nio.charset.StandardCharsets;
3332
import java.nio.file.Files;
3433
import java.nio.file.Path;
3534
import java.nio.file.Paths;
@@ -92,7 +91,8 @@ public static void afterAllAnalysis() throws IOException {
9291
public static void prepare() throws Exception {
9392
Set<String> result = new HashSet<>();
9493
List<String> extraNonDefaultRules = List.of("S3546", "S6374");
95-
ProfileGenerator.generate(ORCHESTRATOR, "Sonar Way", ImmutableMap.of(), new HashSet<>(), SUBSET_OF_ENABLED_RULES, result, extraNonDefaultRules);
94+
ProfileGenerator.generate(ORCHESTRATOR, "Sonar Way", ImmutableMap.of(), new HashSet<>(), SUBSET_OF_ENABLED_RULES, result,
95+
extraNonDefaultRules);
9696
assertThat(result).hasSize(23); // ALL symbolic-execution rules
9797

9898
Path allRulesFolder = Paths.get("src/test/resources");
@@ -123,7 +123,7 @@ private static void copyFile(Path source, Path targetDir) {
123123
try {
124124
Files.copy(source, targetDir.resolve(source.getFileName()), StandardCopyOption.REPLACE_EXISTING);
125125
} catch (IOException e) {
126-
throw new IllegalStateException("Unable to copy file: " + source.toString());
126+
throw new IllegalStateException("Unable to copy file: " + source);
127127
}
128128
}
129129

@@ -143,16 +143,15 @@ public void guava() throws Exception {
143143

144144
@Test
145145
public void eclipse_jetty() throws Exception {
146-
List<String> dirs = Arrays.asList("jetty-http/", "jetty-io/", "jetty-jmx/", "jetty-server/", "jetty-slf4j-impl/", "jetty-util/", "jetty-util-ajax/", "jetty-xml/", "tests" +
146+
List<String> dirs = Arrays.asList("jetty-http/", "jetty-io/", "jetty-jmx/", "jetty-server/", "jetty-slf4j-impl/", "jetty-util/",
147+
"jetty-util-ajax/", "jetty-xml/", "tests" +
147148
"/jetty-http-tools/");
148149

149150
String mainBranchSourceCode = "eclipse-jetty";
150151
String mainBinaries = dirs.stream().map(dir -> FileLocation.of("../sources/" + mainBranchSourceCode + "/" + dir + "target/classes"))
151152
.map(JavaRulingTest::getFileLocationAbsolutePath)
152153
.collect(Collectors.joining(","));
153154

154-
final var mainBranch = "eclipse-jetty-main";
155-
156155
MavenBuild branchBuild = test_project("org.eclipse.jetty:jetty-project", mainBranchSourceCode)
157156
// re-define binaries from initial maven build
158157
.setProperty("sonar.java.binaries", mainBinaries)
@@ -234,15 +233,6 @@ private static MavenBuild test_project(String projectKey, @Nullable String path,
234233
return mavenBuild;
235234
}
236235

237-
private static MavenBuild test_existing_project(String projectKey, String projectName) throws IOException {
238-
String pomLocation = "../sources/" + projectName + "/pom.xml";
239-
File pomFile = FileLocation.of(pomLocation).getFile().getCanonicalFile();
240-
//prepareProject(projectKey, projectName);
241-
MavenBuild mavenBuild = MavenBuild.create().setPom(pomFile).setCleanPackageSonarGoals().addArgument("-DskipTests");
242-
mavenBuild.setProperty("sonar.projectKey", projectKey);
243-
return mavenBuild;
244-
}
245-
246236
private static void prepareProject(String projectKey, String projectName) {
247237
ORCHESTRATOR.getServer().provisionProject(projectKey, projectName);
248238
ORCHESTRATOR.getServer().associateProjectToQualityProfile(projectKey, "java", "rules");
@@ -299,9 +289,9 @@ private static void dumpServerLogLastLines(File logFile) throws IOException {
299289
if (nbLines > LOGS_NUMBER_LINES) {
300290
logs = logs.subList(nbLines - LOGS_NUMBER_LINES, nbLines);
301291
}
302-
LOG.error("=================================== START " + logFile.getName() + " ===================================");
303-
LOG.error(System.lineSeparator() + logs.stream().collect(Collectors.joining(System.lineSeparator())));
304-
LOG.error("===================================== END " + logFile.getName() + " ===================================");
292+
LOG.error("=================================== START {} ===================================", logFile.getName());
293+
LOG.error("{}{}", System.lineSeparator(), logs.stream().collect(Collectors.joining(System.lineSeparator())));
294+
LOG.error("===================================== END {} ===================================", logFile.getName());
305295
}
306296

307297
private static String litsDifferencesPath(String projectName) {
@@ -310,7 +300,7 @@ private static String litsDifferencesPath(String projectName) {
310300

311301
private static void assertNoDifferences(String projectName) throws IOException {
312302

313-
String differences = new String(Files.readAllBytes(Paths.get(litsDifferencesPath(projectName))), StandardCharsets.UTF_8);
303+
String differences = Files.readString(Paths.get(litsDifferencesPath(projectName)));
314304
assertThat(differences).isEmpty();
315305
}
316306

its/ruling/src/test/java/org/sonar/java/it/ProfileGenerator.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,8 @@ public class ProfileGenerator {
4545

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

48-
static void generate(OrchestratorRule orchestrator, ImmutableMap<String, ImmutableMap<String, String>> rulesParameters,
49-
Set<String> excluded, Set<String> subsetOfEnabledRules, Set<String> activatedRuleKeys) {
50-
generate(orchestrator, null, rulesParameters, excluded, subsetOfEnabledRules, activatedRuleKeys);
51-
}
52-
53-
/**
54-
* @return the list of enabled rule keys for the given profile
55-
*/
56-
static void generate(OrchestratorRule orchestrator, @Nullable String qualityProfile, ImmutableMap<String, ImmutableMap<String, String>> rulesParameters,
57-
Set<String> excluded, Set<String> subsetOfEnabledRules, Set<String> activatedRuleKeys) {
58-
generate(orchestrator, null, rulesParameters, excluded, subsetOfEnabledRules, activatedRuleKeys, List.of());
59-
}
60-
61-
static void generate(OrchestratorRule orchestrator, @Nullable String qualityProfile, ImmutableMap<String, ImmutableMap<String, String>> rulesParameters,
48+
static void generate(OrchestratorRule orchestrator, @Nullable String qualityProfile,
49+
ImmutableMap<String, ImmutableMap<String, String>> rulesParameters,
6250
Set<String> excluded, Set<String> subsetOfEnabledRules, Set<String> activatedRuleKeys, List<String> extraNonDefaultRules) {
6351
try {
6452
LOG.info("Generating profile containing all the rules");
@@ -143,7 +131,8 @@ private static Optional<String> getQualityProfileName(OrchestratorRule orchestra
143131
if (qualityProfile == null || qualityProfile.isEmpty()) {
144132
return Optional.empty();
145133
}
146-
org.sonarqube.ws.client.qualityprofiles.SearchRequest request = new org.sonarqube.ws.client.qualityprofiles.SearchRequest().setLanguage(LANGUAGE);
134+
org.sonarqube.ws.client.qualityprofiles.SearchRequest request =
135+
new org.sonarqube.ws.client.qualityprofiles.SearchRequest().setLanguage(LANGUAGE);
147136

148137
return newAdminWsClient(orchestrator).qualityprofiles().search(request).getProfilesList().stream()
149138
.filter(p -> qualityProfile.equalsIgnoreCase(p.getName()))

0 commit comments

Comments
 (0)