aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>2021-11-04 10:20:46 +0100
committersonartech <sonartech@sonarsource.com>2021-11-04 20:03:25 +0000
commit873ce42305a4f53449065bb085732fbcb9b071ec (patch)
tree0c5cd6d0b2903af4512489f311aa78b91c741899 /server
parent81ce7e4b29a83c0562e8278b407d17c511078c49 (diff)
downloadsonarqube-873ce42305a4f53449065bb085732fbcb9b071ec.tar.gz
sonarqube-873ce42305a4f53449065bb085732fbcb9b071ec.zip
SONAR-15574 improving the code quality
Diffstat (limited to 'server')
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/DumpElement.java14
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/DumpWriterImpl.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStep.java3
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/MutableDumpReaderImpl.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/util/Protobuf2.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepTest.java5
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesChangelogStepTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/rule/RuleTest.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStepTest.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepTest.java2
10 files changed, 20 insertions, 26 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/DumpElement.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/DumpElement.java
index 708fc374688..8f6e6783215 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/DumpElement.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/DumpElement.java
@@ -28,7 +28,7 @@ import javax.annotation.concurrent.Immutable;
* File element in the dump report.
*/
@Immutable
-public class DumpElement<MSG extends Message> {
+public class DumpElement<M extends Message> {
public static final long NO_DATETIME = 0;
public static final DumpElement<ProjectDump.Metadata> METADATA = new DumpElement<>("metadata.pb", ProjectDump.Metadata.parser());
@@ -50,9 +50,9 @@ public class DumpElement<MSG extends Message> {
public static final DumpElement<ProjectDump.NewCodePeriod> NEW_CODE_PERIODS = new DumpElement<>("new_code_periods.pb", ProjectDump.NewCodePeriod.parser());
private final String filename;
- private final Parser<MSG> parser;
+ private final Parser<M> parser;
- private DumpElement(String filename, Parser<MSG> parser) {
+ private DumpElement(String filename, Parser<M> parser) {
this.filename = filename;
this.parser = parser;
}
@@ -61,14 +61,14 @@ public class DumpElement<MSG extends Message> {
return filename;
}
- public Parser<MSG> parser() {
+ public Parser<M> parser() {
return parser;
}
public static class IssueDumpElement extends DumpElement<ProjectDump.Issue> {
- public final int NO_LINE = 0;
- public final double NO_GAP = -1;
- public final long NO_EFFORT = -1;
+ public static final int NO_LINE = 0;
+ public static final double NO_GAP = -1;
+ public static final long NO_EFFORT = -1;
public IssueDumpElement() {
super("issues.pb", ProjectDump.Issue.parser());
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/DumpWriterImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/DumpWriterImpl.java
index 3905550a96d..bd24d132063 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/DumpWriterImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/DumpWriterImpl.java
@@ -69,7 +69,7 @@ public class DumpWriterImpl implements DumpWriter {
}
@Override
- public <MSG extends Message> StreamWriter<MSG> newStreamWriter(DumpElement<MSG> elt) {
+ public <M extends Message> StreamWriter<M> newStreamWriter(DumpElement<M> elt) {
checkNotPublished();
File file = new File(rootDir, elt.filename());
return StreamWriterImpl.create(file);
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStep.java
index 70b74b15f5e..7be3b98bb16 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStep.java
@@ -19,7 +19,6 @@
*/
package org.sonar.ce.task.projectexport.steps;
-import com.google.common.collect.ImmutableSet;
import com.sonarsource.governance.projectdump.protobuf.ProjectDump;
import java.util.List;
import java.util.Set;
@@ -41,7 +40,7 @@ public class ExportSettingsStep implements ComputationStep {
* These properties are not exported as values depend on environment data that are not
* exported within the dump (Quality Gate, users).
*/
- private static final Set<String> IGNORED_KEYS = ImmutableSet.of("sonar.issues.defaultAssigneeLogin");
+ private static final Set<String> IGNORED_KEYS = Set.of("sonar.issues.defaultAssigneeLogin");
private final DbClient dbClient;
private final ProjectHolder projectHolder;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/MutableDumpReaderImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/MutableDumpReaderImpl.java
index e6ef3605f42..b9dc5b9929c 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/MutableDumpReaderImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/MutableDumpReaderImpl.java
@@ -78,7 +78,7 @@ public class MutableDumpReaderImpl implements MutableDumpReader {
}
@Override
- public <MSG extends Message> MessageStream<MSG> stream(DumpElement<MSG> elt) {
+ public <M extends Message> MessageStream<M> stream(DumpElement<M> elt) {
File file = new File(tempRootDir(), elt.filename());
checkState(file.exists(), "Missing file: %s", file);
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/util/Protobuf2.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/util/Protobuf2.java
index ec1ef74aa24..86c8d76d39b 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/util/Protobuf2.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/util/Protobuf2.java
@@ -52,7 +52,7 @@ public class Protobuf2 {
return this;
}
- public <MSG extends Message> MSG parseFrom(Parser<MSG> parser, InputStream input) {
+ public <M extends Message> M parseFrom(Parser<M> parser, InputStream input) {
try {
return parser.parseFrom(input);
} catch (InvalidProtocolBufferException e) {
@@ -61,7 +61,7 @@ public class Protobuf2 {
}
@CheckForNull
- public <MSG extends Message> MSG parseDelimitedFrom(Parser<MSG> parser, InputStream input) {
+ public <M extends Message> M parseDelimitedFrom(Parser<M> parser, InputStream input) {
try {
return parser.parseDelimitedFrom(input);
} catch (InvalidProtocolBufferException e) {
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepTest.java
index 7a0bade945f..c24cd2c7a10 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepTest.java
@@ -168,9 +168,4 @@ public class ExportComponentsStepTest {
assertThat(underTest.getDescription()).isEqualTo("Export components");
}
- @Test
- public void name() {
- System.err.println(new Date(1313272860000L));
-
- }
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesChangelogStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesChangelogStepTest.java
index 4a1705280b6..2db984504da 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesChangelogStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesChangelogStepTest.java
@@ -197,7 +197,7 @@ public class ExportIssuesChangelogStepTest {
underTest.execute(new TestComputationStepContext());
ProjectDump.IssueChange issueChange = getSingleMessage();
- assertThat(issueChange.getCreatedAt()).isEqualTo(0L);
+ assertThat(issueChange.getCreatedAt()).isZero();
}
@Test
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/rule/RuleTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/rule/RuleTest.java
index f33cff5dcc6..28cab509a77 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/rule/RuleTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/rule/RuleTest.java
@@ -64,7 +64,7 @@ public class RuleTest {
@Test
public void hashcode_is_based_on_repository_and_key() {
- assertThat(underTest.hashCode()).isEqualTo(new Rule(SOME_DUMP_UUID, SOME_REPOSITORY, SOME_KEY).hashCode());
+ assertThat(underTest).hasSameHashCodeAs(new Rule(SOME_DUMP_UUID, SOME_REPOSITORY, SOME_KEY));
assertThat(underTest.hashCode()).isNotEqualTo(new Rule(SOME_DUMP_UUID, SOME_KEY, SOME_REPOSITORY).hashCode());
assertThat(underTest.hashCode()).isNotEqualTo(new Rule(SOME_DUMP_UUID, "other repository", SOME_KEY).hashCode());
assertThat(underTest.hashCode()).isNotEqualTo(new Rule(SOME_DUMP_UUID, SOME_REPOSITORY, "other key").hashCode());
@@ -72,12 +72,12 @@ public class RuleTest {
@Test
public void hashcode_ignores_dump_id() {
- assertThat(underTest.hashCode()).isEqualTo(new Rule("uuid-8888", SOME_REPOSITORY, SOME_KEY).hashCode());
+ assertThat(underTest).hasSameHashCodeAs(new Rule("uuid-8888", SOME_REPOSITORY, SOME_KEY));
}
@Test
public void toString_displays_all_fields() {
- assertThat(underTest.toString()).isEqualTo("Rule{ref='uuid-12334', repository='some repository', key='some key'}");
+ assertThat(underTest).hasToString("Rule{ref='uuid-12334', repository='some repository', key='some key'}");
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStepTest.java
index b46e772ee77..0ed2e499887 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportLiveMeasuresStepTest.java
@@ -89,7 +89,7 @@ public class ExportLiveMeasuresStepTest {
.extracting(ProjectDump.LiveMeasure::getMetricRef, m -> m.getDoubleValue().getValue(), ProjectDump.LiveMeasure::hasVariation)
.containsOnly(tuple(0, 4711.0d, false));
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("1 live measures exported");
- assertThat(metricRepository.getRefByUuid().keySet()).containsOnly(metric.getUuid());
+ assertThat(metricRepository.getRefByUuid()).containsOnlyKeys(metric.getUuid());
}
@Test
@@ -161,7 +161,7 @@ public class ExportLiveMeasuresStepTest {
"test",
7.0d));
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("1 live measures exported");
- assertThat(metricRepository.getRefByUuid().keySet()).containsOnly(metric.getUuid());
+ assertThat(metricRepository.getRefByUuid()).containsOnlyKeys(metric.getUuid());
}
@Test
@@ -191,7 +191,7 @@ public class ExportLiveMeasuresStepTest {
"",
false));
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("1 live measures exported");
- assertThat(metricRepository.getRefByUuid().keySet()).containsOnly(metric.getUuid());
+ assertThat(metricRepository.getRefByUuid()).containsOnlyKeys(metric.getUuid());
}
@Test
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepTest.java
index 698d1a5be02..251bbc97183 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepTest.java
@@ -142,7 +142,7 @@ public class ExportMeasuresStepTest {
assertThat(exportedMeasures).extracting(ProjectDump.Measure::getAnalysisUuid).containsOnly(firstAnalysis.getUuid(), secondAnalysis.getUuid());
assertThat(exportedMeasures).extracting(ProjectDump.Measure::getMetricRef).containsOnly(0);
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("2 measures exported");
- assertThat(metricRepository.getRefByUuid().keySet()).containsOnly(NCLOC.getUuid());
+ assertThat(metricRepository.getRefByUuid()).containsOnlyKeys(NCLOC.getUuid());
}
@Test