From 8eae78c9476d0d5dab0c6f51b2e72267916b2574 Mon Sep 17 00:00:00 2001 From: Bruno Andrade Date: Wed, 14 Jul 2021 07:10:09 -0300 Subject: [PATCH] Code smell fix: Replacing ImmutableList from List --- .../duplication/DuplicationMeasures.java | 6 +++--- .../step/CommentMeasuresStep.java | 9 +++++---- .../step/ComplexityMeasuresStep.java | 8 ++++---- .../step/CoverageMeasuresStep.java | 7 ++++--- .../step/LanguageDistributionMeasuresStep.java | 5 ++--- .../step/NewCoverageMeasuresStep.java | 7 +++---- .../step/NewSizeMeasuresStep.java | 5 ++--- .../step/UnitTestMeasuresStep.java | 5 ++--- .../main/java/org/sonar/db/dialect/Oracle.java | 5 +---- .../java/org/sonar/db/dialect/PostgreSql.java | 4 +--- .../core/permission/GlobalPermissions.java | 12 +++++++----- .../org/sonar/db/component/ProjectLinkDto.java | 10 +++++++--- .../permission/PermissionServiceImpl.java | 18 +++++++++++------- .../component/ws/SearchProjectsAction.java | 4 +--- .../sonar/server/hotspot/ws/SearchAction.java | 3 +-- .../server/issue/IssueChangeWSSupport.java | 13 ++++++------- .../sonar/server/issue/ws/SearchAction.java | 11 +++++------ .../server/issue/ws/SearchResponseData.java | 4 +--- .../server/permission/ws/AddGroupAction.java | 6 ++---- .../sonar/server/rule/ws/RuleQueryFactory.java | 5 ++--- .../sonar/server/setting/ws/ResetAction.java | 4 +--- .../org/sonar/server/setting/ws/SetAction.java | 3 +-- .../sonar/server/text/MacroInterpreter.java | 7 ++----- .../server/platform/web/RedirectFilter.java | 7 +++---- 24 files changed, 77 insertions(+), 91 deletions(-) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasures.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasures.java index f156f8be540..fcf48afb20b 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasures.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasures.java @@ -19,9 +19,9 @@ */ package org.sonar.ce.task.projectanalysis.duplication; -import com.google.common.collect.ImmutableList; import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Optional; import java.util.Set; import javax.annotation.CheckForNull; @@ -47,7 +47,7 @@ import static org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_KEY; import static org.sonar.api.measures.CoreMetrics.LINES_KEY; public class DuplicationMeasures { - protected final ImmutableList formulas; + protected final List formulas; protected final TreeRootHolder treeRootHolder; protected final MetricRepository metricRepository; protected final MeasureRepository measureRepository; @@ -60,7 +60,7 @@ public class DuplicationMeasures { this.measureRepository = measureRepository; // will be null for views this.duplicationRepository = duplicationRepository; - this.formulas = ImmutableList.of(new DuplicationFormula()); + this.formulas = List.of(new DuplicationFormula()); } /** diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CommentMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CommentMeasuresStep.java index 290dab0f085..505e53851b3 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CommentMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CommentMeasuresStep.java @@ -19,7 +19,7 @@ */ package org.sonar.ce.task.projectanalysis.step; -import com.google.common.collect.ImmutableList; +import java.util.List; import java.util.Optional; import org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit; import org.sonar.ce.task.projectanalysis.component.PathAwareCrawler; @@ -52,15 +52,16 @@ public class CommentMeasuresStep implements ComputationStep { private final TreeRootHolder treeRootHolder; private final MetricRepository metricRepository; private final MeasureRepository measureRepository; - private final ImmutableList formulas; + private final List formulas; public CommentMeasuresStep(TreeRootHolder treeRootHolder, MetricRepository metricRepository, MeasureRepository measureRepository) { this.treeRootHolder = treeRootHolder; this.metricRepository = metricRepository; this.measureRepository = measureRepository; - this.formulas = ImmutableList.of( + this.formulas = List.of( new DocumentationFormula(), - new CommentDensityFormula()); + new CommentDensityFormula() + ); } @Override diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComplexityMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComplexityMeasuresStep.java index 45ea3787f8e..52e5fe82577 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComplexityMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ComplexityMeasuresStep.java @@ -19,7 +19,7 @@ */ package org.sonar.ce.task.projectanalysis.step; -import com.google.common.collect.ImmutableList; +import java.util.List; import org.sonar.ce.task.projectanalysis.component.PathAwareCrawler; import org.sonar.ce.task.projectanalysis.component.TreeRootHolder; import org.sonar.ce.task.projectanalysis.formula.AverageFormula; @@ -48,8 +48,7 @@ import static org.sonar.ce.task.projectanalysis.formula.SumFormula.createIntSumF * Computes complexity measures on files and then aggregates them on higher components. */ public class ComplexityMeasuresStep implements ComputationStep { - - private static final ImmutableList FORMULAS = ImmutableList.of( + private static final List FORMULAS = List.of( createIntSumFormula(COMPLEXITY_KEY), createIntSumFormula(COMPLEXITY_IN_CLASSES_KEY), createIntSumFormula(COMPLEXITY_IN_FUNCTIONS_KEY), @@ -67,7 +66,8 @@ public class ComplexityMeasuresStep implements ComputationStep { AverageFormula.Builder.newBuilder().setOutputMetricKey(FUNCTION_COMPLEXITY_KEY) .setMainMetricKey(COMPLEXITY_IN_FUNCTIONS_KEY) .setByMetricKey(FUNCTIONS_KEY) - .build()); + .build() + ); private final TreeRootHolder treeRootHolder; private final MetricRepository metricRepository; diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CoverageMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CoverageMeasuresStep.java index bc5acfc0c44..ecaad9b10bd 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CoverageMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CoverageMeasuresStep.java @@ -19,7 +19,7 @@ */ package org.sonar.ce.task.projectanalysis.step; -import com.google.common.collect.ImmutableList; +import java.util.List; import org.sonar.ce.task.projectanalysis.batch.BatchReportReader; import org.sonar.ce.task.projectanalysis.component.Component; import org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit; @@ -55,14 +55,15 @@ import static org.sonar.ce.task.projectanalysis.formula.SumFormula.createIntSumF * Computes coverage measures on files and then aggregates them on higher components. */ public class CoverageMeasuresStep implements ComputationStep { - private static final ImmutableList COVERAGE_FORMULAS = ImmutableList.of( + private static final List COVERAGE_FORMULAS = List.of( createIntSumFormula(LINES_TO_COVER_KEY), createIntSumFormula(UNCOVERED_LINES_KEY), createIntSumFormula(CONDITIONS_TO_COVER_KEY), createIntSumFormula(UNCOVERED_CONDITIONS_KEY), new CodeCoverageFormula(), new BranchCoverageFormula(), - new LineCoverageFormula()); + new LineCoverageFormula() + ); private final TreeRootHolder treeRootHolder; private final MetricRepository metricRepository; diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LanguageDistributionMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LanguageDistributionMeasuresStep.java index 129e7fdc7cb..5d858fac4ac 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LanguageDistributionMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LanguageDistributionMeasuresStep.java @@ -20,9 +20,9 @@ package org.sonar.ce.task.projectanalysis.step; import com.google.common.base.Function; -import com.google.common.collect.ImmutableList; import com.google.common.collect.Multiset; import com.google.common.collect.TreeMultiset; +import java.util.List; import java.util.Map; import java.util.Optional; import javax.annotation.Nonnull; @@ -50,10 +50,9 @@ import static org.sonar.api.utils.KeyValueFormat.newStringConverter; import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder; public class LanguageDistributionMeasuresStep implements ComputationStep { - private static final String UNKNOWN_LANGUAGE_KEY = ""; - private static final ImmutableList FORMULAS = ImmutableList.of(new LanguageDistributionFormula()); + private static final List FORMULAS = List.of(new LanguageDistributionFormula()); private static final String[] LANGUAGE_DISTRIBUTION_FORMULA_METRICS = new String[] {NCLOC_LANGUAGE_DISTRIBUTION_KEY}; diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java index 639d078ff08..bbb6777d20a 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java @@ -19,7 +19,6 @@ */ package org.sonar.ce.task.projectanalysis.step; -import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import java.util.Collections; import java.util.List; @@ -60,12 +59,12 @@ import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilde * Computes measures related to the New Coverage. These measures do not have values, only variations. */ public class NewCoverageMeasuresStep implements ComputationStep { - - private static final List FORMULAS = ImmutableList.of( + private static final List FORMULAS = List.of( // UT coverage new NewCoverageFormula(), new NewBranchCoverageFormula(), - new NewLineCoverageFormula()); + new NewLineCoverageFormula() + ); private final TreeRootHolder treeRootHolder; private final MetricRepository metricRepository; diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStep.java index 24402acdc84..6a33321b52b 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewSizeMeasuresStep.java @@ -19,9 +19,9 @@ */ package org.sonar.ce.task.projectanalysis.step; -import com.google.common.collect.ImmutableList; import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Optional; import java.util.Set; import java.util.stream.IntStream; @@ -53,7 +53,6 @@ import static org.sonar.api.measures.CoreMetrics.NEW_LINES_KEY; * Computes measures on new code related to the size */ public class NewSizeMeasuresStep implements ComputationStep { - private final TreeRootHolder treeRootHolder; private final MetricRepository metricRepository; private final MeasureRepository measureRepository; @@ -76,7 +75,7 @@ public class NewSizeMeasuresStep implements ComputationStep { public void execute(ComputationStep.Context context) { new PathAwareCrawler<>( FormulaExecutorComponentVisitor.newBuilder(metricRepository, measureRepository) - .buildFor(ImmutableList.of(duplicationFormula))) + .buildFor(List.of(duplicationFormula))) .visit(treeRootHolder.getRoot()); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UnitTestMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UnitTestMeasuresStep.java index 3eab05cf3f3..eb1d1bae893 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UnitTestMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UnitTestMeasuresStep.java @@ -19,7 +19,7 @@ */ package org.sonar.ce.task.projectanalysis.step; -import com.google.common.collect.ImmutableList; +import java.util.List; import java.util.Optional; import org.sonar.ce.task.projectanalysis.component.Component; import org.sonar.ce.task.projectanalysis.component.PathAwareCrawler; @@ -47,10 +47,9 @@ import static org.sonar.api.measures.CoreMetrics.TEST_SUCCESS_DENSITY_KEY; * Computes unit test measures on files and then aggregates them on higher components. */ public class UnitTestMeasuresStep implements ComputationStep { - private static final String[] METRICS = new String[] {TESTS_KEY, TEST_ERRORS_KEY, TEST_FAILURES_KEY, SKIPPED_TESTS_KEY, TEST_SUCCESS_DENSITY_KEY, TEST_EXECUTION_TIME_KEY}; - private static final ImmutableList FORMULAS = ImmutableList.of(new UnitTestsFormula()); + private static final List FORMULAS = List.of(new UnitTestsFormula()); private final TreeRootHolder treeRootHolder; private final MetricRepository metricRepository; diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/Oracle.java b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/Oracle.java index 36731c12f77..e374d7934b1 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/Oracle.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/Oracle.java @@ -19,7 +19,6 @@ */ package org.sonar.db.dialect; -import com.google.common.collect.ImmutableList; import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.util.List; @@ -28,12 +27,10 @@ import org.sonar.api.utils.MessageException; import org.sonar.api.utils.Version; public class Oracle extends AbstractDialect { - public static final String ID = "oracle"; - private static final List INIT_STATEMENTS = ImmutableList.of("ALTER SESSION SET NLS_SORT='BINARY'"); + private static final List INIT_STATEMENTS = List.of("ALTER SESSION SET NLS_SORT='BINARY'"); private static final Version MIN_SUPPORTED_VERSION = Version.create(11, 0, 0); - public Oracle() { super(ID, "oracle.jdbc.OracleDriver", "1", "0", "SELECT 1 FROM DUAL"); } diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/PostgreSql.java b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/PostgreSql.java index ce441f099d6..de38c155669 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/PostgreSql.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/PostgreSql.java @@ -19,7 +19,6 @@ */ package org.sonar.db.dialect; -import com.google.common.collect.ImmutableList; import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.util.List; @@ -30,9 +29,8 @@ import org.sonar.api.utils.log.Loggers; import static com.google.common.base.Preconditions.checkState; public class PostgreSql extends AbstractDialect { - public static final String ID = "postgresql"; - static final List INIT_STATEMENTS = ImmutableList.of("SET standard_conforming_strings=on", "SET backslash_quote=off"); + static final List INIT_STATEMENTS = List.of("SET standard_conforming_strings=on", "SET backslash_quote=off"); private static final Version MIN_SUPPORTED_VERSION = Version.create(9, 3, 0); private static final Version MIN_UPSERT_VERSION = Version.create(9, 5, 0); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/core/permission/GlobalPermissions.java b/server/sonar-db-dao/src/main/java/org/sonar/core/permission/GlobalPermissions.java index 9462a758c4a..38eba07a727 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/core/permission/GlobalPermissions.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/core/permission/GlobalPermissions.java @@ -20,7 +20,6 @@ package org.sonar.core.permission; import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; import java.util.List; import org.sonar.db.permission.GlobalPermission; @@ -31,7 +30,6 @@ import org.sonar.db.permission.GlobalPermission; */ @Deprecated public final class GlobalPermissions { - public static final String SYSTEM_ADMIN = "admin"; public static final String QUALITY_PROFILE_ADMIN = "profileadmin"; public static final String QUALITY_GATE_ADMIN = "gateadmin"; @@ -41,12 +39,16 @@ public final class GlobalPermissions { /** * All the global permissions values, ordered from {@link #SYSTEM_ADMIN} to {@link #PROVISIONING}. */ - public static final List ALL = ImmutableList.of( - SYSTEM_ADMIN, QUALITY_PROFILE_ADMIN, QUALITY_GATE_ADMIN, SCAN_EXECUTION, PROVISIONING); + public static final List ALL = List.of( + SYSTEM_ADMIN, + QUALITY_PROFILE_ADMIN, + QUALITY_GATE_ADMIN, + SCAN_EXECUTION, + PROVISIONING + ); public static final String ALL_ON_ONE_LINE = Joiner.on(", ").join(GlobalPermissions.ALL); private GlobalPermissions() { // only static methods } - } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ProjectLinkDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ProjectLinkDto.java index eb8f0994f57..bf6bfba6580 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ProjectLinkDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ProjectLinkDto.java @@ -19,13 +19,11 @@ */ package org.sonar.db.component; -import com.google.common.collect.ImmutableList; import java.util.List; import javax.annotation.CheckForNull; import javax.annotation.Nullable; public class ProjectLinkDto { - public static final String TYPE_HOME_PAGE = "homepage"; public static final String TYPE_CI = "ci"; public static final String TYPE_ISSUE_TRACKER = "issue"; @@ -33,7 +31,13 @@ public class ProjectLinkDto { public static final String TYPE_SOURCES_DEV = "scm_dev"; - public static final List PROVIDED_TYPES = ImmutableList.of(TYPE_HOME_PAGE, TYPE_CI, TYPE_ISSUE_TRACKER, TYPE_SOURCES, TYPE_SOURCES_DEV); + public static final List PROVIDED_TYPES = List.of( + TYPE_HOME_PAGE, + TYPE_CI, + TYPE_ISSUE_TRACKER, + TYPE_SOURCES, + TYPE_SOURCES_DEV + ); private String uuid; private String projectUuid; diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/PermissionServiceImpl.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/PermissionServiceImpl.java index e1aaaed9aad..1ac31cbf7ba 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/PermissionServiceImpl.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/permission/PermissionServiceImpl.java @@ -19,7 +19,6 @@ */ package org.sonar.server.permission; -import com.google.common.collect.ImmutableList; import java.util.List; import javax.annotation.concurrent.Immutable; import org.sonar.api.resources.Qualifiers; @@ -31,21 +30,26 @@ import static java.util.stream.Collectors.toList; @Immutable public class PermissionServiceImpl implements PermissionService { + private static final List ALL_PROJECT_PERMISSIONS = List.of( + UserRole.ADMIN, + UserRole.CODEVIEWER, + UserRole.ISSUE_ADMIN, + UserRole.SECURITYHOTSPOT_ADMIN, + UserRole.SCAN, + UserRole.USER + ); - private static final List ALL_PROJECT_PERMISSIONS = ImmutableList.of( - UserRole.ADMIN, UserRole.CODEVIEWER, UserRole.ISSUE_ADMIN, UserRole.SECURITYHOTSPOT_ADMIN, UserRole.SCAN, UserRole.USER); - - private static final List ALL_GLOBAL_PERMISSIONS = ImmutableList.copyOf(GlobalPermission.values()); + private static final List ALL_GLOBAL_PERMISSIONS = List.of(GlobalPermission.values()); private final List globalPermissions; private final List projectPermissions; public PermissionServiceImpl(ResourceTypes resourceTypes) { - globalPermissions = ImmutableList.copyOf(ALL_GLOBAL_PERMISSIONS.stream() + globalPermissions = List.copyOf(ALL_GLOBAL_PERMISSIONS.stream() .filter(s -> !s.equals(GlobalPermission.APPLICATION_CREATOR) || resourceTypes.isQualifierPresent(Qualifiers.APP)) .filter(s -> !s.equals(GlobalPermission.PORTFOLIO_CREATOR) || resourceTypes.isQualifierPresent(Qualifiers.VIEW)) .collect(toList())); - projectPermissions = ImmutableList.copyOf(ALL_PROJECT_PERMISSIONS.stream() + projectPermissions = List.copyOf(ALL_PROJECT_PERMISSIONS.stream() .filter(s -> !s.equals(GlobalPermission.APPLICATION_CREATOR.getKey()) || resourceTypes.isQualifierPresent(Qualifiers.APP)) .filter(s -> !s.equals(GlobalPermission.PORTFOLIO_CREATOR.getKey()) || resourceTypes.isQualifierPresent(Qualifiers.VIEW)) .collect(toList())); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java index 855d248205b..d5c8e3aaa90 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java @@ -72,7 +72,6 @@ import org.sonarqube.ws.Components.SearchProjectsWsResponse; import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.collect.ImmutableList.of; import static com.google.common.collect.Sets.newHashSet; import static java.util.Collections.emptyMap; import static java.util.Objects.requireNonNull; @@ -95,7 +94,6 @@ import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUA import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS; public class SearchProjectsAction implements ComponentsWsAction { - public static final int MAX_PAGE_SIZE = 500; public static final int DEFAULT_PAGE_SIZE = 100; private static final String ALL = "_all"; @@ -368,7 +366,7 @@ public class SearchProjectsAction implements ComponentsWsAction { if (httpRequest.hasParam(FIELDS)) { List paramsAsString = httpRequest.mandatoryParamAsStrings(FIELDS); if (paramsAsString.contains(ALL)) { - request.setAdditionalFields(of(ANALYSIS_DATE, LEAK_PERIOD_DATE)); + request.setAdditionalFields(List.of(ANALYSIS_DATE, LEAK_PERIOD_DATE)); } else { request.setAdditionalFields(paramsAsString); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java index 0fb20222fe8..63fcd54367c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java @@ -19,7 +19,6 @@ */ package org.sonar.server.hotspot.ws; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import java.util.Arrays; import java.util.Collection; @@ -109,7 +108,7 @@ public class SearchAction implements HotspotsWsAction { private static final String PARAM_CWE = "cwe"; private static final String PARAM_FILES = "files"; - private static final List STATUSES = ImmutableList.of(STATUS_TO_REVIEW, STATUS_REVIEWED); + private static final List STATUSES = List.of(STATUS_TO_REVIEW, STATUS_REVIEWED); private final DbClient dbClient; private final UserSession userSession; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java index a46a82e7920..c2a6b868d37 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java @@ -20,7 +20,6 @@ package org.sonar.server.issue; import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; import com.google.common.collect.Ordering; @@ -105,8 +104,8 @@ public class IssueChangeWSSupport { Set preloadedUsers, Set preloadedComponents) { Set issueKeys = dtos.stream().map(IssueDto::getKey).collect(toSet()); - List changes = ImmutableList.of(); - List comments = ImmutableList.of(); + List changes = List.of(); + List comments = List.of(); switch (load) { case CHANGE_LOG: changes = dbClient.issueChangeDao().selectByTypeAndIssueKeys(dbSession, issueKeys, TYPE_FIELD_CHANGE); @@ -316,18 +315,18 @@ public class IssueChangeWSSupport { public List getChanges(IssueDto dto) { List fieldDiffs = changesByIssueKey.get(dto.getKey()); if (fieldDiffs == null) { - return ImmutableList.of(); + return List.of(); } - return ImmutableList.copyOf(fieldDiffs); + return List.copyOf(fieldDiffs); } @Override public List getComments(IssueDto dto) { List comments = commentsByIssueKey.get(dto.getKey()); if (comments == null) { - return ImmutableList.of(); + return List.of(); } - return ImmutableList.copyOf(comments); + return List.copyOf(comments); } @Override diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java index a41aa0c7943..26b5bbc97a2 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java @@ -19,7 +19,6 @@ */ package org.sonar.server.issue.ws; -import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import java.util.ArrayList; import java.util.Arrays; @@ -131,12 +130,11 @@ import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_TIMEZONE; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_TYPES; public class SearchAction implements IssuesWsAction { - private static final String LOGIN_MYSELF = "__me__"; private static final Set ISSUE_SCOPES = Arrays.stream(IssueScope.values()).map(Enum::name).collect(Collectors.toSet()); private static final EnumSet ALL_RULE_TYPES_EXCEPT_SECURITY_HOTSPOTS = EnumSet.complementOf(EnumSet.of(RuleType.SECURITY_HOTSPOT)); - static final List SUPPORTED_FACETS = ImmutableList.of( + static final List SUPPORTED_FACETS = List.of( FACET_PROJECTS, PARAM_MODULE_UUIDS, PARAM_FILES, @@ -157,7 +155,8 @@ public class SearchAction implements IssuesWsAction { PARAM_SANS_TOP_25, PARAM_CWE, PARAM_CREATED_AT, - PARAM_SONARSOURCE_SECURITY); + PARAM_SONARSOURCE_SECURITY + ); private static final String INTERNAL_PARAMETER_DISCLAIMER = "This parameter is mostly used by the Issues page, please prefer usage of the componentKeys parameter. "; private static final Set FACETS_REQUIRING_PROJECT = newHashSet(PARAM_MODULE_UUIDS, PARAM_FILES, PARAM_DIRECTORIES); @@ -422,7 +421,7 @@ public class SearchAction implements IssuesWsAction { collectFacets(collector, facets); } SearchResponseData preloadedData = new SearchResponseData(emptyList()); - preloadedData.addRules(ImmutableList.copyOf(query.rules())); + preloadedData.addRules(List.copyOf(query.rules())); SearchResponseData data = searchResponseLoader.load(preloadedData, collector, additionalFields, facets); // FIXME allow long in Paging @@ -588,7 +587,7 @@ public class SearchAction implements IssuesWsAction { List assigneeUuid = userDtos.stream().map(UserDto::getUuid).collect(toList()); if ((assigneeLogins != null) && firstNonNull(assigneeUuid, emptyList()).isEmpty()) { - assigneeUuid = ImmutableList.of("non-existent-uuid"); + assigneeUuid = List.of("non-existent-uuid"); } return assigneeUuid; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java index 8c1d215855c..b7954a53ea1 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java @@ -20,7 +20,6 @@ package org.sonar.server.issue.ws; import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ListMultimap; import java.util.ArrayList; import java.util.Collection; @@ -44,7 +43,6 @@ import static com.google.common.base.Preconditions.checkNotNull; * All the data required to write response of api/issues/search */ public class SearchResponseData { - private final List issues; private Long effortTotal = null; @@ -58,7 +56,7 @@ public class SearchResponseData { public SearchResponseData(IssueDto issue) { checkNotNull(issue); - this.issues = ImmutableList.of(issue); + this.issues = List.of(issue); } public SearchResponseData(List issues) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java index f90ebb93d18..6cac5bdbcea 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java @@ -19,7 +19,7 @@ */ package org.sonar.server.permission.ws; -import com.google.common.collect.ImmutableList; +import java.util.List; import java.util.Optional; import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.Request; @@ -41,7 +41,6 @@ import static org.sonar.server.permission.ws.WsParameters.createProjectParameter import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION; public class AddGroupAction implements PermissionsWsAction { - public static final String ACTION = "add_group"; private final DbClient dbClient; @@ -95,9 +94,8 @@ public class AddGroupAction implements PermissionsWsAction { request.mandatoryParam(PARAM_PERMISSION), project.orElse(null), group, permissionService); - permissionUpdater.apply(dbSession, ImmutableList.of(change)); + permissionUpdater.apply(dbSession, List.of(change)); } response.noContent(); } - } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java index cd5888e2e7e..e8b9af6f62b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java @@ -19,8 +19,8 @@ */ package org.sonar.server.rule.ws; -import com.google.common.collect.ImmutableList; import java.util.Date; +import java.util.List; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rules.RuleType; import org.sonar.api.server.ServerSide; @@ -56,7 +56,6 @@ import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_TYPES; @ServerSide public class RuleQueryFactory { - private final DbClient dbClient; public RuleQueryFactory(DbClient dbClient) { @@ -90,7 +89,7 @@ public class RuleQueryFactory { setProfile(dbSession, query, request); setCompareToProfile(dbSession, query, request); QProfileDto profile = query.getQProfile(); - query.setLanguages(profile == null ? request.paramAsStrings(PARAM_LANGUAGES) : ImmutableList.of(profile.getLanguage())); + query.setLanguages(profile == null ? request.paramAsStrings(PARAM_LANGUAGES) : List.of(profile.getLanguage())); query.setActivation(request.paramAsBoolean(PARAM_ACTIVATION)); query.setTags(request.paramAsStrings(PARAM_TAGS)); query.setInheritance(request.paramAsStrings(PARAM_INHERITANCE)); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ResetAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ResetAction.java index e09641b88d2..3ba655bb2ff 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ResetAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ResetAction.java @@ -19,7 +19,6 @@ */ package org.sonar.server.setting.ws; -import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -50,7 +49,6 @@ import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001; public class ResetAction implements SettingsWsAction { - private final DbClient dbClient; private final ComponentFinder componentFinder; private final SettingsUpdater settingsUpdater; @@ -114,7 +112,7 @@ public class ResetAction implements SettingsWsAction { resetRequest.getKeys().forEach(key -> { SettingsWsSupport.validateKey(key); SettingData data = new SettingData(key, emptyList(), component.orElse(null)); - ImmutableList.of(validations.scope(), validations.qualifier()) + List.of(validations.scope(), validations.qualifier()) .forEach(validation -> validation.accept(data)); }); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java index a0a346b911c..bfa2f5d524c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java @@ -20,7 +20,6 @@ package org.sonar.server.setting.ws; import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ListMultimap; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; @@ -205,7 +204,7 @@ public class SetAction implements SettingsWsAction { checkValueIsSet(request); String settingKey = request.getKey(); SettingData settingData = new SettingData(settingKey, valuesFromRequest(request), component.orElse(null)); - ImmutableList.of(validations.scope(), validations.qualifier(), validations.valueType()) + List.of(validations.scope(), validations.qualifier(), validations.valueType()) .forEach(validation -> validation.accept(settingData)); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/text/MacroInterpreter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/text/MacroInterpreter.java index 1cad70a35b4..e55ee0da620 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/text/MacroInterpreter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/text/MacroInterpreter.java @@ -19,7 +19,6 @@ */ package org.sonar.server.text; -import com.google.common.collect.ImmutableList; import org.sonar.api.server.ServerSide; import org.sonar.api.platform.Server; @@ -27,13 +26,12 @@ import java.util.List; @ServerSide public class MacroInterpreter { - private final List macros; public MacroInterpreter(Server server) { - this.macros = ImmutableList.of( + this.macros = List.of( new RuleMacro(server.getContextPath()) - ); + ); } public String interpret(String text) { @@ -43,5 +41,4 @@ public class MacroInterpreter { } return textReplaced; } - } diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/web/RedirectFilter.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/web/RedirectFilter.java index 6af2e0672cd..c676ca0b779 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/web/RedirectFilter.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/web/RedirectFilter.java @@ -19,7 +19,6 @@ */ package org.sonar.server.platform.web; -import com.google.common.collect.ImmutableList; import java.io.IOException; import java.util.List; import java.util.function.Function; @@ -37,11 +36,11 @@ import org.sonar.core.util.stream.MoreCollectors; import static java.lang.String.format; public class RedirectFilter implements Filter { - private static final String EMPTY = ""; - private static final List REDIRECTS = ImmutableList.of( - newSimpleRedirect("/api", "/api/webservices/list")); + private static final List REDIRECTS = List.of( + newSimpleRedirect("/api", "/api/webservices/list") + ); @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { -- 2.39.5