aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorBruno Andrade <bruno@artsman.dev>2021-07-13 08:38:59 -0300
committersonartech <sonartech@sonarsource.com>2021-07-29 20:04:50 +0000
commit9bdb3491660e86d805c88a7df0a10a05d4885b3b (patch)
tree3d94ababacb64b8f393876cf09399fe8a5c7a717 /server
parent8eae78c9476d0d5dab0c6f51b2e72267916b2574 (diff)
downloadsonarqube-9bdb3491660e86d805c88a7df0a10a05d4885b3b.tar.gz
sonarqube-9bdb3491660e86d805c88a7df0a10a05d4885b3b.zip
Code smell fix: Remove unnecessary parameters
Diffstat (limited to 'server')
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasure.java20
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java6
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/platform/ServerImpl.java6
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndexer.java9
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/platform/ServerImplTest.java17
6 files changed, 16 insertions, 48 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasure.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasure.java
index 93fa85f200c..3912d1a8026 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasure.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasure.java
@@ -52,7 +52,7 @@ public class BatchMeasureToMeasure {
case LEVEL:
return toLevelMeasure(builder, batchMeasure);
case NO_VALUE:
- return toNoValueMeasure(builder, batchMeasure);
+ return toNoValueMeasure(builder);
default:
throw new IllegalArgumentException("Unsupported Measure.ValueType " + metric.getType().getValueType());
}
@@ -60,21 +60,21 @@ public class BatchMeasureToMeasure {
private static Optional<Measure> toIntegerMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
- return toNoValueMeasure(builder, batchMeasure);
+ return toNoValueMeasure(builder);
}
return of(builder.create(batchMeasure.getIntValue().getValue(), trimToNull(batchMeasure.getIntValue().getData())));
}
private static Optional<Measure> toLongMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
- return toNoValueMeasure(builder, batchMeasure);
+ return toNoValueMeasure(builder);
}
return of(builder.create(batchMeasure.getLongValue().getValue(), trimToNull(batchMeasure.getLongValue().getData())));
}
private static Optional<Measure> toDoubleMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
- return toNoValueMeasure(builder, batchMeasure);
+ return toNoValueMeasure(builder);
}
return of(builder.create(batchMeasure.getDoubleValue().getValue(),
// Decimals are not truncated in scanner report, so an arbitrary decimal scale is applied when reading values from report
@@ -83,30 +83,30 @@ public class BatchMeasureToMeasure {
private static Optional<Measure> toBooleanMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
- return toNoValueMeasure(builder, batchMeasure);
+ return toNoValueMeasure(builder);
}
return of(builder.create(batchMeasure.getBooleanValue().getValue(), trimToNull(batchMeasure.getBooleanValue().getData())));
}
private static Optional<Measure> toStringMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
- return toNoValueMeasure(builder, batchMeasure);
+ return toNoValueMeasure(builder);
}
return of(builder.create(batchMeasure.getStringValue().getValue()));
}
private static Optional<Measure> toLevelMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
- return toNoValueMeasure(builder, batchMeasure);
+ return toNoValueMeasure(builder);
}
Optional<Measure.Level> level = Measure.Level.toLevel(batchMeasure.getStringValue().getValue());
- if (!level.isPresent()) {
- return toNoValueMeasure(builder, batchMeasure);
+ if (level.isEmpty()) {
+ return toNoValueMeasure(builder);
}
return of(builder.create(level.get()));
}
- private static Optional<Measure> toNoValueMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
+ private static Optional<Measure> toNoValueMeasure(Measure.NewMeasureBuilder builder) {
return of(builder.createNoValue());
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java
index 1189d83c164..0f0323031b5 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java
@@ -27,8 +27,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.sonar.api.utils.MessageException;
-import org.sonar.api.utils.System2;
-import org.sonar.ce.task.log.CeTaskMessages;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.ComponentVisitor;
@@ -51,14 +49,13 @@ import static org.sonar.core.component.ComponentKeys.ALLOWED_CHARACTERS_MESSAGE;
import static org.sonar.core.component.ComponentKeys.isValidProjectKey;
public class ValidateProjectStep implements ComputationStep {
-
private static final Joiner MESSAGES_JOINER = Joiner.on("\n o ");
private final DbClient dbClient;
private final TreeRootHolder treeRootHolder;
private final AnalysisMetadataHolder analysisMetadataHolder;
- public ValidateProjectStep(DbClient dbClient, TreeRootHolder treeRootHolder, AnalysisMetadataHolder analysisMetadataHolder, CeTaskMessages taskMessages, System2 system2) {
+ public ValidateProjectStep(DbClient dbClient, TreeRootHolder treeRootHolder, AnalysisMetadataHolder analysisMetadataHolder) {
this.dbClient = dbClient;
this.treeRootHolder = treeRootHolder;
this.analysisMetadataHolder = analysisMetadataHolder;
@@ -151,5 +148,4 @@ public class ValidateProjectStep implements ComputationStep {
return Optional.of(baseComponent);
}
}
-
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java
index ed9087b10ea..781e3fed82b 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java
@@ -23,7 +23,6 @@ import java.util.Date;
import javax.annotation.Nullable;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.System2;
@@ -48,10 +47,8 @@ import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
public class ValidateProjectStepTest {
-
static long PAST_ANALYSIS_TIME = 1_420_088_400_000L; // 2015-01-01
static long DEFAULT_ANALYSIS_TIME = 1_433_131_200_000L; // 2015-06-01
- static long NOW = 1_500_000_000_000L;
static final String PROJECT_KEY = "PROJECT_KEY";
static final Branch DEFAULT_BRANCH = new DefaultBranchImpl();
@@ -64,12 +61,11 @@ public class ValidateProjectStepTest {
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule()
.setAnalysisDate(new Date(DEFAULT_ANALYSIS_TIME))
.setBranch(DEFAULT_BRANCH);
- private final System2 system2 = new TestSystem2().setNow(NOW);
private final CeTaskMessages taskMessages = mock(CeTaskMessages.class);
private final DbClient dbClient = db.getDbClient();
- private final ValidateProjectStep underTest = new ValidateProjectStep(dbClient, treeRootHolder, analysisMetadataHolder, taskMessages, system2);
+ private final ValidateProjectStep underTest = new ValidateProjectStep(dbClient, treeRootHolder, analysisMetadataHolder);
@Test
public void dont_fail_for_long_forked_from_master_with_modules() {
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/platform/ServerImpl.java b/server/sonar-server-common/src/main/java/org/sonar/server/platform/ServerImpl.java
index a65daae278a..f229dca1bee 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/platform/ServerImpl.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/platform/ServerImpl.java
@@ -31,17 +31,14 @@ import org.sonar.api.server.ServerSide;
@ComputeEngineSide
@ServerSide
public class ServerImpl extends Server {
-
private final Configuration config;
private final StartupMetadata state;
- private final ServerFileSystem fs;
private final UrlSettings urlSettings;
private final SonarRuntime runtime;
- public ServerImpl(Configuration config, StartupMetadata state, ServerFileSystem fs, UrlSettings urlSettings, SonarRuntime runtime) {
+ public ServerImpl(Configuration config, StartupMetadata state, UrlSettings urlSettings, SonarRuntime runtime) {
this.config = config;
this.state = state;
- this.fs = fs;
this.urlSettings = urlSettings;
this.runtime = runtime;
}
@@ -84,5 +81,4 @@ public class ServerImpl extends Server {
public boolean isSecured() {
return urlSettings.isSecured();
}
-
}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndexer.java b/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndexer.java
index 81763f18947..73c1f1875f6 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndexer.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndexer.java
@@ -45,7 +45,6 @@ import static org.sonar.core.util.stream.MoreCollectors.toList;
import static org.sonar.server.user.index.UserIndexDefinition.TYPE_USER;
public class UserIndexer implements ResilientIndexer {
-
private final DbClient dbClient;
private final EsClient esClient;
@@ -93,14 +92,10 @@ public class UserIndexer implements ResilientIndexer {
dbClient.esQueueDao().insert(dbSession, items);
dbSession.commit();
- postCommit(dbSession, users.stream().map(UserDto::getLogin).collect(toList()), items);
+ postCommit(dbSession, items);
}
- /**
- * Entry point for Byteman tests. See directory tests/resilience.
- * The parameter "logins" is used only by the Byteman script.
- */
- private void postCommit(DbSession dbSession, Collection<String> logins, Collection<EsQueueDto> items) {
+ private void postCommit(DbSession dbSession, Collection<EsQueueDto> items) {
index(dbSession, items);
}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/platform/ServerImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/platform/ServerImplTest.java
index 79657e160ea..800424d0ea6 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/platform/ServerImplTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/platform/ServerImplTest.java
@@ -19,11 +19,7 @@
*/
package org.sonar.server.platform;
-import java.io.File;
-import java.io.IOException;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
import org.sonar.api.SonarRuntime;
import org.sonar.api.config.internal.MapSettings;
@@ -34,16 +30,11 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class ServerImplTest {
-
private MapSettings settings = new MapSettings();
private StartupMetadata state = mock(StartupMetadata.class);
- private ServerFileSystem fs = mock(ServerFileSystem.class);
private UrlSettings urlSettings = mock(UrlSettings.class);
private SonarRuntime runtime = mock(SonarRuntime.class);
- private ServerImpl underTest = new ServerImpl(settings.asConfig(), state, fs, urlSettings, runtime);
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
+ private ServerImpl underTest = new ServerImpl(settings.asConfig(), state, urlSettings, runtime);
@Test
public void test_url_information() {
@@ -57,12 +48,6 @@ public class ServerImplTest {
}
@Test
- public void test_file_system_information() throws IOException {
- File home = temp.newFolder();
- when(fs.getHomeDir()).thenReturn(home);
- }
-
- @Test
public void test_startup_information() {
long time = 123_456_789L;
when(state.getStartedAt()).thenReturn(time);