本文整理了Java中org.sonar.api.utils.Version.create()
方法的一些代码示例,展示了Version.create()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Version.create()
方法的具体详情如下:
包路径:org.sonar.api.utils.Version
类名称:Version
方法名:create
暂无
代码示例来源:origin: SonarSource/sonarqube
Version checkDbVersion(DatabaseMetaData metaData, Version minSupported) throws SQLException {
int major = metaData.getDatabaseMajorVersion();
int minor = metaData.getDatabaseMinorVersion();
Version version = Version.create(major, minor, 0);
if (version.compareTo(minSupported) < 0) {
throw MessageException.of(String.format(
"Unsupported %s version: %s. Minimal supported version is %s.", getId(), version, minSupported));
}
return version;
}
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void test_create() {
assertVersion(Version.create(1, 2), 1, 2, 0, 0, "");
assertVersion(Version.create(1, 2, 3), 1, 2, 3, 0, "");
assertVersion(Version.create(1, 2, 0, ""), 1, 2, 0, 0, "");
assertVersion(Version.create(1, 2, 3, "build1"), 1, 2, 3, 0, "build1");
assertThat(Version.create(1, 2, 3, "build1").toString()).isEqualTo("1.2.3-build1");
}
代码示例来源:origin: SonarSource/sonarqube
public Optional<UpdateCenter> getUpdateCenter(boolean refreshUpdateCenter) {
Optional<UpdateCenter> updateCenter = centerClient.getUpdateCenter(refreshUpdateCenter);
if (updateCenter.isPresent()) {
org.sonar.api.utils.Version fullVersion = sonarRuntime.getApiVersion();
org.sonar.api.utils.Version semanticVersion = org.sonar.api.utils.Version.create(fullVersion.major(), fullVersion.minor(), fullVersion.patch());
return Optional.of(updateCenter.get().setInstalledSonarVersion(Version.create(semanticVersion.toString())).registerInstalledPlugins(
installedPluginReferentialFactory.getInstalledPluginReferential())
.setDate(centerClient.getLastRefreshDate()));
}
return Optional.absent();
}
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void test_getVersion() {
Version version = Version.create(6, 1);
when(runtime.getApiVersion()).thenReturn(version);
assertThat(underTest.getVersion()).isEqualTo(version.toString());
}
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void load_from_database_if_server_is_startup_follower() {
SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.SERVER);
when(webServer.isStartupLeader()).thenReturn(false);
testLoadingFromDatabase(runtime, false);
}
代码示例来源:origin: SonarSource/sonarqube
private void test(SonarQubeSide side) {
underTest = new ServerIdManager(serverIdChecksum, serverIdFactory, dbClient, SonarRuntimeImpl.forSonarQube(Version.create(6, 7), side), webServer);
underTest.start();
}
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void load_from_database_if_compute_engine_of_startup_leader_server() {
SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.COMPUTE_ENGINE);
testLoadingFromDatabase(runtime, true);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void load_from_database_if_compute_engine_of_startup_follower_server() {
SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.COMPUTE_ENGINE);
testLoadingFromDatabase(runtime, false);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void generate_SERVER_STARTIME_but_do_not_persist_it_if_server_is_startup_leader() {
when(system.now()).thenReturn(A_DATE);
SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.SERVER);
when(webServer.isStartupLeader()).thenReturn(true);
StartupMetadata metadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient());
assertThat(metadata.getStartedAt()).isEqualTo(A_DATE);
assertNotPersistedProperty(CoreProperties.SERVER_STARTTIME);
// keep a cache
StartupMetadata secondMetadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient());
assertThat(secondMetadata).isSameAs(metadata);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void fail_to_load_from_database_if_properties_are_not_persisted() {
SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.COMPUTE_ENGINE);
when(webServer.isStartupLeader()).thenReturn(false);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Property sonar.core.startTime is missing in database");
underTest.provide(system, runtime, webServer, dbTester.getDbClient());
}
代码示例来源:origin: SonarSource/sonarqube
@Before
public void setUp() {
XooRulesDefinition def = new XooRulesDefinition(SonarRuntimeImpl.forSonarQube(Version.create(7, 3), SonarQubeSide.SCANNER));
context = new RulesDefinition.Context();
def.define(context);
}
代码示例来源:origin: SonarSource/sonarqube
if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(6, 6))) {
context.addExtension(XooBuiltInQualityProfilesDefinition.class);
if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(6, 4))) {
context.addExtension(DeprecatedGlobalSensor.class);
if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(7, 6))) {
context.addExtensions(
GlobalProjectSensor.class,
XooIgnoreCommand.class);
if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(7, 2))) {
context.addExtensions(
OneExternalIssuePerLineSensor.class,
SignificantCodeSensor.class);
if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(7, 3))) {
context.addExtension(HotspotSensor.class);
代码示例来源:origin: SonarSource/sonarqube
private void createIssues(InputFile file, SensorContext context, String repo) {
RuleKey ruleKey = RuleKey.of(repo, RULE_KEY);
String severity = context.settings().getString(FORCE_SEVERITY_PROPERTY);
for (int line = 1; line <= file.lines(); line++) {
NewIssue newIssue = context.newIssue();
newIssue
.forRule(ruleKey)
.at(newIssue.newLocation()
.on(file)
.at(file.selectLine(line))
.message("This issue is generated on each line"))
.overrideSeverity(severity != null ? Severity.valueOf(severity) : null);
if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(5, 5))) {
newIssue.gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY));
} else {
newIssue.gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY));
}
newIssue.save();
}
}
代码示例来源:origin: SonarSource/sonarqube
.setDebtRemediationFunction(hotspot.debtRemediationFunctions().constantPerIssue("2min"));
if (version != null && version.isGreaterThanOrEqual(Version.create(7, 3))) {
hotspot
.addOwaspTop10(OwaspTop10.A1, OwaspTop10.A3)
代码示例来源:origin: org.sonarsource.sonarqube/sonar-db-core
Version checkDbVersion(DatabaseMetaData metaData, Version minSupported) throws SQLException {
int major = metaData.getDatabaseMajorVersion();
int minor = metaData.getDatabaseMinorVersion();
Version version = Version.create(major, minor, 0);
if (version.compareTo(minSupported) < 0) {
throw MessageException.of(String.format(
"Unsupported %s version: %s. Minimal supported version is %s.", getId(), version, minSupported));
}
return version;
}
}
代码示例来源:origin: org.sonarsource.python/sonar-python-plugin
private static void importReport(File reportPath, SensorContext context, Set<String> unresolvedInputFiles) {
try (InputStream in = new FileInputStream(reportPath)) {
LOG.info("Importing {}", reportPath);
boolean engineIdIsSupported = context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(7, 4));
BanditJsonReportReader.read(in, issue -> saveIssue(context, issue, unresolvedInputFiles, engineIdIsSupported));
} catch (IOException | ParseException | RuntimeException e) {
LOG.error("No issues information will be saved as the report file '{}' can't be read. " +
e.getClass().getSimpleName() + ": " + e.getMessage(), reportPath, e);
}
}
代码示例来源:origin: SonarSource/sonar-python
private static void importReport(File reportPath, SensorContext context, Set<String> unresolvedInputFiles) {
try (InputStream in = new FileInputStream(reportPath)) {
LOG.info("Importing {}", reportPath);
boolean engineIdIsSupported = context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(7, 4));
BanditJsonReportReader.read(in, issue -> saveIssue(context, issue, unresolvedInputFiles, engineIdIsSupported));
} catch (IOException | ParseException | RuntimeException e) {
LOG.error("No issues information will be saved as the report file '{}' can't be read. " +
e.getClass().getSimpleName() + ": " + e.getMessage(), reportPath, e);
}
}
代码示例来源:origin: org.sonarsource.sonarqube/sonar-server
public Optional<UpdateCenter> getUpdateCenter(boolean refreshUpdateCenter) {
Optional<UpdateCenter> updateCenter = centerClient.getUpdateCenter(refreshUpdateCenter);
if (updateCenter.isPresent()) {
org.sonar.api.utils.Version fullVersion = sonarRuntime.getApiVersion();
org.sonar.api.utils.Version semanticVersion = org.sonar.api.utils.Version.create(fullVersion.major(), fullVersion.minor(), fullVersion.patch());
return Optional.of(updateCenter.get().setInstalledSonarVersion(Version.create(semanticVersion.toString())).registerInstalledPlugins(
installedPluginReferentialFactory.getInstalledPluginReferential())
.setDate(centerClient.getLastRefreshDate()));
}
return Optional.absent();
}
}
代码示例来源:origin: sonar-perl/sonar-perl
@SuppressWarnings("unchecked")
@Test
public void test() {
Version v60 = Version.create(6, 0);
assertThat(extensions(SonarRuntimeImpl.forSonarQube(v60, SonarQubeSide.SERVER))).hasSize(7);
}
代码示例来源:origin: SonarSource/sonar-java
static SonarComponents sonarComponents(File file) {
SensorContextTester context = SensorContextTester.create(new File("")).setRuntime(SonarRuntimeImpl.forSonarLint(Version.create(6, 7)));
context.setSettings(new MapSettings().setProperty("sonar.java.failOnException", true));
SonarComponents sonarComponents = new SonarComponents(null, context.fileSystem(), null, null, null) {
@Override
public boolean reportAnalysisError(RecognitionException re, File file) {
return false;
}
};
sonarComponents.setSensorContext(context);
context.fileSystem().add(new TestInputFileBuilder("", file.getPath()).setCharset(StandardCharsets.UTF_8).build());
return sonarComponents;
}
内容来源于网络,如有侵权,请联系作者删除!