From: Matteo Mara Date: Mon, 14 Oct 2024 14:21:50 +0000 (+0200) Subject: NO-JIRA Fix the Quality Gate X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c6168aa2917eeef83c3383c7eddf35e84394b499;p=sonarqube.git NO-JIRA Fix the Quality Gate --- diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/security/GithubAppSecurityImplTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/security/GithubAppSecurityImplTest.java index 08ad4f1a87d..872dc19513d 100644 --- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/security/GithubAppSecurityImplTest.java +++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/security/GithubAppSecurityImplTest.java @@ -25,7 +25,6 @@ import java.security.spec.InvalidKeySpecException; import java.time.Clock; import java.time.Instant; import java.time.ZoneId; -import java.util.Random; import org.junit.Test; import org.junit.runner.RunWith; import org.sonar.auth.github.GithubAppConfiguration; @@ -144,7 +143,7 @@ public class GithubAppSecurityImplTest { } private GithubAppConfiguration createAppConfigurationForPrivateKey(String privateKey) { - long applicationId = new Random().nextInt(654); + long applicationId = 1L; return new GithubAppConfiguration(applicationId, privateKey, secure().nextAlphabetic(8)); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java index 65910eb79f0..0a3397eb155 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java @@ -20,7 +20,7 @@ package org.sonar.ce.task.projectanalysis.metric; import javax.annotation.CheckForNull; -import org.sonar.ce.task.projectanalysis.measure.Measure; +import org.sonar.ce.task.projectanalysis.measure.Measure.ValueType; public interface Metric { /** @@ -51,32 +51,32 @@ public interface Metric { /** * The decimal scale of float measures. Returned value is greater than or equal zero. - * @throws IllegalStateException if the value type is not decimal (see {@link org.sonar.ce.task.projectanalysis.measure.Measure.ValueType} + * @throws IllegalStateException if the value type is not decimal (see {@link ValueType} */ int getDecimalScale(); boolean isDeleteHistoricalData(); enum MetricType { - INT(Measure.ValueType.INT), - MILLISEC(Measure.ValueType.LONG), - RATING(Measure.ValueType.INT), - WORK_DUR(Measure.ValueType.LONG), - FLOAT(Measure.ValueType.DOUBLE), - PERCENT(Measure.ValueType.DOUBLE), - BOOL(Measure.ValueType.BOOLEAN), - STRING(Measure.ValueType.STRING), - DISTRIB(Measure.ValueType.STRING), - DATA(Measure.ValueType.STRING), - LEVEL(Measure.ValueType.LEVEL); + INT(ValueType.INT), + MILLISEC(ValueType.LONG), + RATING(ValueType.INT), + WORK_DUR(ValueType.LONG), + FLOAT(ValueType.DOUBLE), + PERCENT(ValueType.DOUBLE), + BOOL(ValueType.BOOLEAN), + STRING(ValueType.STRING), + DISTRIB(ValueType.STRING), + DATA(ValueType.STRING), + LEVEL(ValueType.LEVEL); - private final Measure.ValueType valueType; + private final ValueType valueType; - MetricType(Measure.ValueType valueType) { + MetricType(ValueType valueType) { this.valueType = valueType; } - public Measure.ValueType getValueType() { + public ValueType getValueType() { return valueType; } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SendAnalysisTelemetryStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SendAnalysisTelemetryStep.java index 62700fad800..112c846da43 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SendAnalysisTelemetryStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SendAnalysisTelemetryStep.java @@ -89,4 +89,4 @@ public class SendAnalysisTelemetryStep implements ComputationStep { public String getDescription() { return "This step pushes telemetry data from the Sonar analyzers to Telemetry V2 server in case telemetry is enabled."; } -} \ No newline at end of file +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java index 49f305100e7..74849bf4f04 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java @@ -23,7 +23,6 @@ import java.util.Collection; import java.util.List; import java.util.Optional; import java.util.Set; -import java.util.function.Function; import javax.annotation.Nullable; import org.sonar.api.utils.System2; import org.sonar.db.Dao; @@ -39,8 +38,6 @@ public class ProjectDao implements Dao { private final System2 system2; private final AuditPersister auditPersister; - private final Function> languageFilters = language -> Set.of(language + "=%", "%;" + language + "=%"); - public ProjectDao(System2 system2, AuditPersister auditPersister) { this.system2 = system2; this.auditPersister = auditPersister; diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java index efff8f1b796..750fdff9f10 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java @@ -53,7 +53,7 @@ import org.subethamail.wiser.WiserMessage; import static java.util.stream.Collectors.toMap; import static java.util.stream.Collectors.toSet; import static junit.framework.Assert.fail; -import static org.apache.commons.lang3.RandomStringUtils.random; +import static org.apache.commons.lang3.RandomStringUtils.secure; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -93,7 +93,7 @@ public class EmailNotificationChannelTest { @Test public void isActivated_returns_true_if_smpt_host_is_not_empty() { - when(configuration.getSmtpHost()).thenReturn(random(5)); + when(configuration.getSmtpHost()).thenReturn(secure().next(5)); assertThat(underTest.isActivated()).isTrue(); } diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/legacy/TelemetryDataLoaderImpl.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/legacy/TelemetryDataLoaderImpl.java index 9bfffe45fc0..c133c57afb0 100644 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/legacy/TelemetryDataLoaderImpl.java +++ b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/legacy/TelemetryDataLoaderImpl.java @@ -76,8 +76,6 @@ import static java.util.stream.Collectors.toMap; import static org.apache.commons.lang3.StringUtils.startsWithIgnoreCase; import static org.sonar.api.measures.CoreMetrics.BUGS_KEY; import static org.sonar.api.measures.CoreMetrics.DEVELOPMENT_COST_KEY; -import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY; -import static org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY; import static org.sonar.api.measures.CoreMetrics.SECURITY_HOTSPOTS_KEY; import static org.sonar.api.measures.CoreMetrics.TECHNICAL_DEBT_KEY; import static org.sonar.api.measures.CoreMetrics.VULNERABILITIES_KEY; @@ -394,12 +392,6 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader { return this.defaultQualityProfileByLanguage.get(language); } - private Map getNclocMetricUuidMap(DbSession dbSession) { - return dbClient.metricDao().selectByKeys(dbSession, asList(NCLOC_KEY, NCLOC_LANGUAGE_DISTRIBUTION_KEY)) - .stream() - .collect(toMap(MetricDto::getKey, MetricDto::getUuid)); - } - private void resolveQualityGates(TelemetryData.Builder data, DbSession dbSession) { List qualityGates = new ArrayList<>(); Collection qualityGateDtos = dbClient.qualityGateDao().selectAll(dbSession); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionTest.java index 283dd04fb5c..e750f8ea2d7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionTest.java @@ -45,7 +45,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.sonar.test.JsonAssert.assertJson; -public class SafeModeHealthActionTest { +class SafeModeHealthActionTest { private final HealthChecker healthChecker = mock(HealthChecker.class); private final SystemPasscode systemPasscode = mock(SystemPasscode.class); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java index 97d33f200fa..30472694f71 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java @@ -276,7 +276,7 @@ class PluginFilesTest { FileAndMd5() throws IOException { this.file = Files.createTempFile(tempDir, "jar", null); - Files.write(this.file, RandomStringUtils.random(3).getBytes()); + Files.write(this.file, RandomStringUtils.secure().next(3).getBytes()); try (InputStream fis = Files.newInputStream(this.file)) { this.md5 = DigestUtils.md5Hex(fis); } catch (IOException e) { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java index 3be0fda2132..40d785b4c51 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java @@ -38,7 +38,7 @@ import org.sonar.scanner.ProjectInfo; import org.sonar.scanner.bootstrap.GlobalConfiguration; import static java.lang.String.format; -import static org.apache.commons.lang3.RandomStringUtils.randomAscii; +import static org.apache.commons.lang3.RandomStringUtils.secure; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -181,7 +181,7 @@ class ProjectReactorValidatorTest { null, "1.0", "2017-10-16", - randomAscii(100) + secure().nextAscii(100) ); } @@ -199,7 +199,7 @@ class ProjectReactorValidatorTest { null, "1.0", "2017-10-16", - randomAscii(100) + secure().nextAscii(100) ); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedFileTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedFileTest.java index 20ee5a69035..d6e7fef0d5e 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedFileTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedFileTest.java @@ -26,7 +26,6 @@ import org.sonar.api.batch.fs.internal.DefaultIndexedFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.SensorStrategy; -import static org.apache.commons.lang3.RandomStringUtils.random; import static org.apache.commons.lang3.RandomStringUtils.secure; import static org.assertj.core.api.Assertions.assertThat; @@ -82,11 +81,11 @@ public class ChangedFileTest { private DefaultIndexedFile composeDefaultIndexFile(Path path, String oldRelativePath) { return new DefaultIndexedFile( path, - random(5), - random(5), - random(5), + secure().next(5), + secure().next(5), + secure().next(5), InputFile.Type.MAIN, - random(5), + secure().next(5), Integer.parseInt(secure().nextNumeric(5)), new SensorStrategy(), oldRelativePath);