diff options
10 files changed, 52 insertions, 19 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/VisitorsCrawler.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/VisitorsCrawler.java index 6fa5db3068d..0dcb3d70618 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/VisitorsCrawler.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/VisitorsCrawler.java @@ -151,7 +151,7 @@ public class VisitorsCrawler implements ComponentCrawler { public VisitorWrapper apply(@Nonnull ComponentVisitor componentVisitor) { if (componentVisitor instanceof TypeAwareVisitor typeAwareVisitor) { return new TypeAwareVisitorWrapper(typeAwareVisitor); - } else if (componentVisitor instanceof PathAwareVisitor pathAwareVisitor) { + } else if (componentVisitor instanceof PathAwareVisitor<?> pathAwareVisitor) { return new PathAwareVisitorWrapper(pathAwareVisitor); } else { throw new IllegalArgumentException("Only TypeAwareVisitor and PathAwareVisitor can be used"); diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java index 03785dec338..344f7c1ad99 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java @@ -419,7 +419,7 @@ public class DatabaseUtilsTest { List<String> outputs = DatabaseUtils.executeLargeInputs(inputs, input -> { // Check that each partition is only done on 1000 elements max - assertThat(input.size()).isLessThanOrEqualTo(1000); + assertThat(input).hasSizeLessThanOrEqualTo(1000); return input.stream().map(String::valueOf).collect(MoreCollectors.toList()); }); @@ -463,7 +463,7 @@ public class DatabaseUtilsTest { List<Integer> processed = newArrayList(); DatabaseUtils.executeLargeUpdates(inputs, input -> { - assertThat(input.size()).isLessThanOrEqualTo(1000); + assertThat(input).hasSizeLessThanOrEqualTo(1000); processed.addAll(input); }); assertThat(processed).containsExactlyElementsOf(inputs); @@ -537,7 +537,8 @@ public class DatabaseUtilsTest { @Test public void checkThatNotTooManyConditions_throws_IAE_if_strictly_more_than_1000_conditions() { - assertThatThrownBy(() -> DatabaseUtils.checkThatNotTooManyConditions(Collections.nCopies(1_001, "foo"), "the message")) + List<String> list = Collections.nCopies(1_001, "foo"); + assertThatThrownBy(() -> DatabaseUtils.checkThatNotTooManyConditions(list, "the message")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("the message"); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/pushevent/PushEventDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/pushevent/PushEventDto.java index 924d25e7500..03b40ad061b 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/pushevent/PushEventDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/pushevent/PushEventDto.java @@ -20,6 +20,7 @@ package org.sonar.db.pushevent; import javax.annotation.CheckForNull; +import javax.annotation.Nullable; public class PushEventDto { private String uuid; @@ -65,7 +66,7 @@ public class PushEventDto { return language; } - public PushEventDto setLanguage(String language) { + public PushEventDto setLanguage(@Nullable String language) { this.language = language; return this; } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/RenameColumnsBuilder.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/RenameColumnsBuilder.java index 67632b7ab79..2478e79eb56 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/RenameColumnsBuilder.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/RenameColumnsBuilder.java @@ -68,12 +68,17 @@ public class RenameColumnsBuilder { private List<String> createSqlStatement() { return renamings.stream().map( - r -> switch (dialect.getId()) { - case H2.ID -> "ALTER TABLE " + tableName + " ALTER COLUMN " + r.getOldColumnName() + " RENAME TO " + r.getNewColumnName(); - case Oracle.ID, PostgreSql.ID -> - "ALTER TABLE " + tableName + " RENAME COLUMN " + r.getOldColumnName() + " TO " + r.getNewColumnName(); - case MsSql.ID -> "EXEC sp_rename '" + tableName + "." + r.getOldColumnName() + "', '" + r.getNewColumnName() + "', 'COLUMN'"; - default -> throw new IllegalArgumentException("Unsupported dialect id " + dialect.getId()); + r -> { + switch (dialect.getId()) { + case H2.ID: + return "ALTER TABLE " + tableName + " ALTER COLUMN " + r.getOldColumnName() + " RENAME TO " + r.getNewColumnName(); + case Oracle.ID, PostgreSql.ID: + return "ALTER TABLE " + tableName + " RENAME COLUMN " + r.getOldColumnName() + " TO " + r.getNewColumnName(); + case MsSql.ID: + return "EXEC sp_rename '" + tableName + "." + r.getOldColumnName() + "', '" + r.getNewColumnName() + "', 'COLUMN'"; + default: + throw new IllegalArgumentException("Unsupported dialect id " + dialect.getId()); + } }).toList(); } diff --git a/server/sonar-main/src/main/java/org/sonar/application/command/JvmOptions.java b/server/sonar-main/src/main/java/org/sonar/application/command/JvmOptions.java index f5637492a2c..b4a118c8e92 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/command/JvmOptions.java +++ b/server/sonar-main/src/main/java/org/sonar/application/command/JvmOptions.java @@ -67,7 +67,8 @@ public class JvmOptions<T extends JvmOptions> { public T addFromMandatoryProperty(Props props, String propertyName) { String value = props.nonNullValue(propertyName); if (!value.isEmpty()) { - List<String> jvmOptions = Arrays.stream(value.split(" (?=-)")).map(String::trim).toList(); + String splitRegex = " (?=-)"; + List<String> jvmOptions = Arrays.stream(value.split(splitRegex)).map(String::trim).toList(); checkOptionFormat(propertyName, jvmOptions); checkMandatoryOptionOverwrite(propertyName, jvmOptions); options.addAll(jvmOptions); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java index b2d4f83f761..40f88950a0a 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java @@ -19,7 +19,6 @@ */ package org.sonar.server.es; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSortedMap; import java.util.Arrays; import java.util.Map; @@ -44,7 +43,7 @@ class IndexDefinitionHash { IndexType.IndexMainType mainType = index.getMainType(); return of( index.getSettings().toString(), - ImmutableMap.of(mainType.getIndex(), mainType), + Map.of(mainType.getIndex(), mainType), index.getRelationTypes().stream().collect(uniqueIndex(IndexType.IndexRelationType::getName, t -> t)), index.getAttributes()); } @@ -69,7 +68,7 @@ class IndexDefinitionHash { private static void appendObject(StringBuilder sb, Object value) { if (value instanceof Object[] arrayValue) { sb.append(Arrays.toString(arrayValue)); - } else if (value instanceof Map map) { + } else if (value instanceof Map<?, ?> map) { appendMap(sb, map); } else if (value instanceof IndexType indexType) { sb.append(indexType.format()); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionEvaluatorTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionEvaluatorTest.java index a719dcc8146..c0d7c6c5d08 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionEvaluatorTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionEvaluatorTest.java @@ -75,6 +75,28 @@ public class ConditionEvaluatorTest { } @Test + public void GREATER_THAN_long() { + test(new FakeMeasure(10L), Condition.Operator.GREATER_THAN, "9", EvaluatedCondition.EvaluationStatus.ERROR, "10"); + test(new FakeMeasure(10L), Condition.Operator.GREATER_THAN, "10", EvaluatedCondition.EvaluationStatus.OK, "10"); + test(new FakeMeasure(10L), Condition.Operator.GREATER_THAN, "11", EvaluatedCondition.EvaluationStatus.OK, "10"); + + test(new FakeMeasure(10L), Condition.Operator.GREATER_THAN, "9", EvaluatedCondition.EvaluationStatus.ERROR, "10"); + test(new FakeMeasure(10L), Condition.Operator.GREATER_THAN, "10", EvaluatedCondition.EvaluationStatus.OK, "10"); + test(new FakeMeasure(10L), Condition.Operator.GREATER_THAN, "11", EvaluatedCondition.EvaluationStatus.OK, "10"); + } + + @Test + public void LESS_THAN_long() { + test(new FakeMeasure(10L), Condition.Operator.LESS_THAN, "9", EvaluatedCondition.EvaluationStatus.OK, "10"); + test(new FakeMeasure(10L), Condition.Operator.LESS_THAN, "10", EvaluatedCondition.EvaluationStatus.OK, "10"); + test(new FakeMeasure(10L), Condition.Operator.LESS_THAN, "11", EvaluatedCondition.EvaluationStatus.ERROR, "10"); + + test(new FakeMeasure(10L), Condition.Operator.LESS_THAN, "9", EvaluatedCondition.EvaluationStatus.OK, "10"); + test(new FakeMeasure(10L), Condition.Operator.LESS_THAN, "10", EvaluatedCondition.EvaluationStatus.OK, "10"); + test(new FakeMeasure(10L), Condition.Operator.LESS_THAN, "11", EvaluatedCondition.EvaluationStatus.ERROR, "10"); + } + + @Test public void evaluate_throws_IAE_if_fail_to_parse_threshold() { assertThatThrownBy(() -> test(new FakeMeasure(10), Condition.Operator.LESS_THAN, "9bar", EvaluatedCondition.EvaluationStatus.ERROR, "10da")) .isInstanceOf(IllegalArgumentException.class) diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/FakeMeasure.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/FakeMeasure.java index f8391d4afbf..0f8623bcd65 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/FakeMeasure.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/FakeMeasure.java @@ -46,6 +46,11 @@ public class FakeMeasure implements QualityGateEvaluator.Measure { this.valueType = Metric.ValueType.INT; } + public FakeMeasure(@Nullable Long value) { + this.value = value == null ? null : value.doubleValue(); + this.valueType = Metric.ValueType.MILLISEC; + } + @Override public Metric.ValueType getType() { return valueType; diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java index 4a03dd19e76..224fb50edc5 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java @@ -61,7 +61,7 @@ public class ServerPluginRepository implements PluginRepository { @Override public Collection<PluginInfo> getPluginInfos() { - return pluginByKey.values().stream().map(ServerPlugin::getPluginInfo).collect(Collectors.toUnmodifiableList()); + return pluginByKey.values().stream().map(ServerPlugin::getPluginInfo).toList(); } @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 0fadbc7a96c..94514468038 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 @@ -65,7 +65,6 @@ import static java.lang.String.format; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static java.util.Optional.ofNullable; -import static java.util.stream.Collectors.toList; import static org.sonar.api.issue.Issue.RESOLUTIONS; import static org.sonar.api.issue.Issue.RESOLUTION_FIXED; import static org.sonar.api.issue.Issue.RESOLUTION_REMOVED; @@ -109,9 +108,9 @@ import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_FILES; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_IN_NEW_CODE_PERIOD; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ISSUES; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_LANGUAGES; -import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_OWASP_ASVS_LEVEL; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ON_COMPONENT_ONLY; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_OWASP_ASVS_40; +import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_OWASP_ASVS_LEVEL; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_OWASP_TOP_10; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_OWASP_TOP_10_2021; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PCI_DSS_32; @@ -596,7 +595,7 @@ public class SearchAction implements IssuesWsAction { private static List<String> allRuleTypesExceptHotspotsIfEmpty(@Nullable List<String> types) { if (types == null || types.isEmpty()) { - return ALL_RULE_TYPES_EXCEPT_SECURITY_HOTSPOTS.stream().map(Enum::name).collect(toList()); + return ALL_RULE_TYPES_EXCEPT_SECURITY_HOTSPOTS.stream().map(Enum::name).toList(); } return types; } |