aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common/src
diff options
context:
space:
mode:
authorMatteo Mara <matteo.mara@sonarsource.com>2023-01-06 12:59:21 +0100
committersonartech <sonartech@sonarsource.com>2023-01-10 20:03:01 +0000
commit18f91c25d369917f3a99841f6bb31b94a02467fc (patch)
tree9939b8dfb10c74b95a5addbcadb8fb91ba296f31 /server/sonar-server-common/src
parent215dd7343dc55f91613b820d43c208c19a50d176 (diff)
downloadsonarqube-18f91c25d369917f3a99841f6bb31b94a02467fc.tar.gz
sonarqube-18f91c25d369917f3a99841f6bb31b94a02467fc.zip
[NO-JIRA] Remove reported code smells about switch statements
Diffstat (limited to 'server/sonar-server-common/src')
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java10
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexer.java10
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndexer.java10
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/ConditionEvaluator.java19
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/webhook/WebhookCallerImpl.java14
5 files changed, 19 insertions, 44 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java b/server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java
index a08b332e000..202f45328a5 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java
@@ -90,20 +90,14 @@ public class ComponentIndexer implements ProjectIndexer, NeedAuthorizationIndexe
@Override
public Collection<EsQueueDto> prepareForRecovery(DbSession dbSession, Collection<String> projectUuids, Cause cause) {
switch (cause) {
- case MEASURE_CHANGE:
- case PROJECT_TAGS_UPDATE:
- case PERMISSION_CHANGE:
+ case MEASURE_CHANGE, PROJECT_TAGS_UPDATE, PERMISSION_CHANGE:
// measures, tags and permissions are not part of type components/component
return emptyList();
-
- case PROJECT_CREATION:
- case PROJECT_DELETION:
- case PROJECT_KEY_UPDATE:
+ case PROJECT_CREATION, PROJECT_DELETION, PROJECT_KEY_UPDATE:
List<EsQueueDto> items = projectUuids.stream()
.map(branchUuid -> EsQueueDto.create(TYPE_COMPONENT.format(), branchUuid, null, branchUuid))
.collect(MoreCollectors.toArrayList(projectUuids.size()));
return dbClient.esQueueDao().insert(dbSession, items);
-
default:
// defensive case
throw new IllegalStateException("Unsupported cause: " + cause);
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexer.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexer.java
index 34701bef9ab..975f73ccc01 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexer.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexer.java
@@ -123,13 +123,9 @@ public class IssueIndexer implements ProjectIndexer, NeedAuthorizationIndexer {
@Override
public Collection<EsQueueDto> prepareForRecovery(DbSession dbSession, Collection<String> projectUuids, ProjectIndexer.Cause cause) {
switch (cause) {
- case PROJECT_CREATION:
- // nothing to do, issues do not exist at project creation
- case MEASURE_CHANGE:
- case PROJECT_KEY_UPDATE:
- case PROJECT_TAGS_UPDATE:
- case PERMISSION_CHANGE:
- // nothing to do. Measures, permissions, project key and tags are not used in type issues/issue
+ case PROJECT_CREATION, MEASURE_CHANGE, PROJECT_KEY_UPDATE, PROJECT_TAGS_UPDATE, PERMISSION_CHANGE:
+ // Nothing to do, issues do not exist at project creation
+ // Measures, permissions, project key and tags are not used in type issues/issue
return emptyList();
case PROJECT_DELETION:
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndexer.java b/server/sonar-server-common/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndexer.java
index 3819871ae55..86dbfc1eec6 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndexer.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndexer.java
@@ -93,13 +93,9 @@ public class ProjectMeasuresIndexer implements ProjectIndexer, NeedAuthorization
case PERMISSION_CHANGE:
// nothing to do, permissions are not used in type projectmeasures/projectmeasure
return Collections.emptyList();
- case MEASURE_CHANGE:
- case PROJECT_KEY_UPDATE:
- // project must be re-indexed because key is used in this index
- case PROJECT_CREATION:
- // provisioned projects are supported by WS api/components/search_projects
- case PROJECT_TAGS_UPDATE:
- case PROJECT_DELETION:
+ case MEASURE_CHANGE, PROJECT_KEY_UPDATE, PROJECT_CREATION, PROJECT_TAGS_UPDATE, PROJECT_DELETION:
+ // when MEASURE_CHANGE or PROJECT_KEY_UPDATE project must be re-indexed because key is used in this index
+ // when PROJECT_CREATION provisioned projects are supported by WS api/components/search_projects
List<EsQueueDto> items = projectUuids.stream()
.map(projectUuid -> EsQueueDto.create(TYPE_PROJECT_MEASURES.format(), projectUuid, null, projectUuid))
.collect(MoreCollectors.toArrayList(projectUuids.size()));
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/ConditionEvaluator.java b/server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/ConditionEvaluator.java
index 7ca1c0768a7..6c2c7b7a62d 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/ConditionEvaluator.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/ConditionEvaluator.java
@@ -128,19 +128,12 @@ class ConditionEvaluator {
}
private static Comparable getNumericValue(ValueType type, double value) {
- switch (type) {
- case INT:
- case RATING:
- return (int) value;
- case FLOAT:
- case PERCENT:
- return value;
- case MILLISEC:
- case WORK_DUR:
- return (long) value;
- default:
- throw new IllegalArgumentException("Condition on numeric value is not allowed for type " + type);
- }
+ return switch (type) {
+ case INT, RATING -> (int) value;
+ case FLOAT, PERCENT -> value;
+ case MILLISEC, WORK_DUR -> (long) value;
+ default -> throw new IllegalArgumentException("Condition on numeric value is not allowed for type " + type);
+ };
}
private static int parseInteger(String value) {
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/webhook/WebhookCallerImpl.java b/server/sonar-server-common/src/main/java/org/sonar/server/webhook/WebhookCallerImpl.java
index 65cba7e23bb..97bcefd7bbd 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/webhook/WebhookCallerImpl.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/webhook/WebhookCallerImpl.java
@@ -101,21 +101,17 @@ public class WebhookCallerImpl implements WebhookCaller {
private Response execute(Request request) throws IOException {
Response response = okHttpClient.newCall(request).execute();
- switch (response.code()) {
- case HTTP_MOVED_PERM:
- case HTTP_MOVED_TEMP:
- case HTTP_TEMP_REDIRECT:
- case HTTP_PERM_REDIRECT:
+ return switch (response.code()) {
+ case HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_TEMP_REDIRECT, HTTP_PERM_REDIRECT ->
// OkHttpClient does not follow the redirect with the same HTTP method. A POST is
// redirected to a GET. Because of that the redirect must be manually
// implemented.
// See:
// https://github.com/square/okhttp/blob/07309c1c7d9e296014268ebd155ebf7ef8679f6c/okhttp/src/main/java/okhttp3/internal/http/RetryAndFollowUpInterceptor.java#L316
// https://github.com/square/okhttp/issues/936#issuecomment-266430151
- return followPostRedirect(response);
- default:
- return response;
- }
+ followPostRedirect(response);
+ default -> response;
+ };
}
/**