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;
}
private GithubAppConfiguration createAppConfigurationForPrivateKey(String privateKey) {
- long applicationId = new Random().nextInt(654);
+ long applicationId = 1L;
return new GithubAppConfiguration(applicationId, privateKey, secure().nextAlphabetic(8));
}
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 {
/**
/**
* 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;
}
}
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
+}
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;
private final System2 system2;
private final AuditPersister auditPersister;
- private final Function<String, Set<String>> languageFilters = language -> Set.of(language + "=%", "%;" + language + "=%");
-
public ProjectDao(System2 system2, AuditPersister auditPersister) {
this.system2 = system2;
this.auditPersister = auditPersister;
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;
@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();
}
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;
return this.defaultQualityProfileByLanguage.get(language);
}
- private Map<String, String> 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<TelemetryData.QualityGate> qualityGates = new ArrayList<>();
Collection<QualityGateDto> qualityGateDtos = dbClient.qualityGateDao().selectAll(dbSession);
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);
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) {
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;
null,
"1.0",
"2017-10-16",
- randomAscii(100)
+ secure().nextAscii(100)
);
}
null,
"1.0",
"2017-10-16",
- randomAscii(100)
+ secure().nextAscii(100)
);
}
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;
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);