org.sonar.api.utils.Version类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(175)

本文整理了Java中org.sonar.api.utils.Version类的一些代码示例,展示了Version类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Version类的具体详情如下:
包路径:org.sonar.api.utils.Version
类名称:Version

Version介绍

[英]Version composed of maximum four fields (major, minor, patch and build ID numbers) and optionally a qualifier.

Examples: 1.0, 1.0.0, 1.2.3, 1.2-beta1, 1.2.1-beta-1, 1.2.3.4567

IMPORTANT NOTE

Qualifier is ignored when comparing objects (methods #equals(Object), #hashCode()and #compareTo(Version)).

assertThat(Version.parse("1.2")).isEqualTo(Version.parse("1.2-beta1")); 
assertThat(Version.parse("1.2").compareTo(Version.parse("1.2-beta1"))).isZero();

[中]由最多四个字段(主要、次要、修补程序和内部版本ID号)和可选的限定符组成的版本。
示例:1.0、1.0.0、1.2.3、1.2-beta1、1.2.1-beta-1、1.2.3.4567
####重要提示
比较对象(方法#equals(对象)、#hashCode()和#compareTo(版本))时忽略限定符。

assertThat(Version.parse("1.2")).isEqualTo(Version.parse("1.2-beta1")); 
assertThat(Version.parse("1.2").compareTo(Version.parse("1.2-beta1"))).isZero();

代码示例

代码示例来源: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

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

public static Version load(System2 system) {
  try {
   URL url = system.getResource(FILE_PATH);
   String versionInFile = Resources.toString(url, StandardCharsets.UTF_8);
   return Version.parse(versionInFile);
  } catch (IOException e) {
   throw new IllegalStateException("Can not load " + FILE_PATH + " from classpath", e);
  }
 }
}

代码示例来源: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_hashCode() {
 assertThat(parse("1").hashCode()).isEqualTo(parse("1").hashCode());
 assertThat(parse("1").hashCode()).isEqualTo(parse("1.0.0").hashCode());
 assertThat(parse("1.2.3-beta1").hashCode()).isEqualTo(parse("1.2.3").hashCode());
}

代码示例来源: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

@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 boolean isGreaterThanOrEqual(Version than) {
  return this.version.isGreaterThanOrEqual(than);
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public String getVersion() {
 return runtime.getApiVersion().toString();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void test_compareTo() {
 assertThat(parse("1.2").compareTo(parse("1.2.0"))).isEqualTo(0);
 assertThat(parse("1.2.3").compareTo(parse("1.2.3"))).isEqualTo(0);
 assertThat(parse("1.2.3").compareTo(parse("1.2.4"))).isLessThan(0);
 assertThat(parse("1.2.3").compareTo(parse("1.3"))).isLessThan(0);
 assertThat(parse("1.2.3").compareTo(parse("2.1"))).isLessThan(0);
 assertThat(parse("1.2.3").compareTo(parse("2.0.0"))).isLessThan(0);
 assertThat(parse("2.0").compareTo(parse("1.2"))).isGreaterThan(0);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void test_toString() {
 assertThat(parse("1").toString()).isEqualTo("1.0");
 assertThat(parse("1.2").toString()).isEqualTo("1.2");
 assertThat(parse("1.2.3").toString()).isEqualTo("1.2.3");
 assertThat(parse("1.2-b1").toString()).isEqualTo("1.2-b1");
 assertThat(parse("1.2.3-b1").toString()).isEqualTo("1.2.3-b1");
 assertThat(parse("1.2.3.4567").toString()).isEqualTo("1.2.3.4567");
 assertThat(parse("1.2.3.4567-beta1").toString()).isEqualTo("1.2.3.4567-beta1");
 // do not display zero numbers when possible
 assertThat(parse("1.2.0.0").toString()).isEqualTo("1.2");
 assertThat(parse("1.2.0.1").toString()).isEqualTo("1.2.0.1");
 assertThat(parse("1.2.1.0").toString()).isEqualTo("1.2.1");
 assertThat(parse("1.2.1.0-beta").toString()).isEqualTo("1.2.1-beta");
}

代码示例来源:origin: Riverside-Software/sonar-openedge

/**
 * @return ServerID based on the SonarQube version
 */
public static String getServerId(SensorContext context) {
 String str = context.config().get(context.getSonarQubeVersion().isGreaterThanOrEqual(Version.parse("6.7"))
     ? CoreProperties.SERVER_ID : CoreProperties.PERMANENT_SERVER_ID).orElse("");
 int dashIndex = str.indexOf('-');
 return (dashIndex == 8) && (str.length() >= 20) ? str.substring(dashIndex + 1) : str;
}

代码示例来源:origin: SonarSource/sonarqube

public boolean isGreaterThanOrEqual(Version than) {
 return this.compareTo(than) >= 0;
}

代码示例来源: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: 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: 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: org.sonarsource.sonarqube/sonar-plugin-api

public boolean isGreaterThanOrEqual(Version than) {
  return this.version.isGreaterThanOrEqual(than);
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public String getVersion() {
 return runtime.getApiVersion().toString();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void qualifier_is_ignored_from_comparison() {
 assertThat(parse("1.2.3")).isEqualTo(parse("1.2.3-build1"));
 assertThat(parse("1.2.3")).isEqualTo(parse("1.2.3-build1"));
 assertThat(parse("1.2.3").compareTo(parse("1.2.3-build1"))).isEqualTo(0);
}

代码示例来源:origin: SonarSource/sonarqube

@Override
 public void init(DatabaseMetaData metaData) throws SQLException {
  checkState(!initialized, "onInit() must be called once");

  Version version = checkDbVersion(metaData, MIN_SUPPORTED_VERSION);

  supportsUpsert = version.compareTo(MIN_UPSERT_VERSION) >= 0;
  if (!supportsUpsert) {
   Loggers.get(getClass()).warn("Upgrading PostgreSQL to {} or greater is recommended for better performances", MIN_UPSERT_VERSION);
  }

  initialized = true;
 }
}

相关文章