org.sonar.api.utils.Version.parse()方法的使用及代码示例

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

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

Version.parse介绍

[英]Convert a String to a Version. Supported formats:

  • 1
  • 1.2
  • 1.2.3
  • 1-beta-1
  • 1.2-beta-1
  • 1.2.3-beta-1
  • 1.2.3.4567
  • 1.2.3.4567-beta-1
    Note that the optional qualifier is the part after the first "-".
    [中]将字符串转换为版本。支持的格式:
  • 1
  • 1.2
  • 1.2.3
    *1-β-1
    *1.2-β-1
    *1.2.3-beta-1
  • 1.2.3.4567
    *1.2.3.4567-beta-1
    请注意,可选限定符是第一个“-”之后的部分。

代码示例

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

@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

@Test
public void test_equals() {
 Version one = parse("1");
 assertThat(one).isEqualTo(one);
 assertThat(one).isEqualTo(parse("1"));
 assertThat(one).isEqualTo(parse("1.0"));
 assertThat(one).isEqualTo(parse("1.0.0"));
 assertThat(one).isNotEqualTo(parse("1.2.3"));
 assertThat(one).isNotEqualTo("1");
 assertThat(parse("1.2.3")).isEqualTo(parse("1.2.3"));
 assertThat(parse("1.2.3")).isNotEqualTo(parse("1.2.4"));
 assertThat(parse("1.2.3")).isEqualTo(parse("1.2.3-b1"));
 assertThat(parse("1.2.3-b1")).isEqualTo(parse("1.2.3-b2"));
}

代码示例来源: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 compareTo_handles_build_number() {
 assertThat(parse("1.2").compareTo(parse("1.2.0.0"))).isEqualTo(0);
 assertThat(parse("1.2.3.1234").compareTo(parse("1.2.3.4567"))).isLessThan(0);
 assertThat(parse("1.2.3.1234").compareTo(parse("1.2.3"))).isGreaterThan(0);
 assertThat(parse("1.2.3.1234").compareTo(parse("1.2.4"))).isLessThan(0);
 assertThat(parse("1.2.3.9999").compareTo(parse("1.2.4.1111"))).isLessThan(0);
}

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

@Test
public void test_parse() {
 assertVersion(parse(""), 0, 0, 0, 0, "");
 assertVersion(parse("1"), 1, 0, 0, 0, "");
 assertVersion(parse("1.2"), 1, 2, 0, 0,"");
 assertVersion(parse("1.2.3"), 1, 2, 3, 0,"");
 assertVersion(parse("1.2-beta-1"), 1, 2, 0, 0,"beta-1");
 assertVersion(parse("1.2.3-beta1"), 1, 2, 3, 0,"beta1");
 assertVersion(parse("1.2.3-beta-1"), 1, 2, 3, 0,"beta-1");
 assertVersion(parse("1.2.3.4567"), 1, 2, 3, 4567,"");
 assertVersion(parse("1.2.3.4567-alpha"), 1, 2, 3, 4567,"alpha");
}

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

@Test
public void isGte() {
 Version version = Version.parse("1.2.3");
 SonarQubeVersion qubeVersion = new SonarQubeVersion(version);
 assertThat(qubeVersion.get()).isEqualTo(version);
 assertThat(qubeVersion.isGreaterThanOrEqual(version)).isTrue();
 assertThat(qubeVersion.isGreaterThanOrEqual(Version.parse("1.1"))).isTrue();
 assertThat(qubeVersion.isGreaterThanOrEqual(Version.parse("1.3"))).isFalse();
}

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

@Test
public void shouldProvideComponents() {
 assertThat(adaptor.activeRules()).isEqualTo(activeRules);
 assertThat(adaptor.fileSystem()).isEqualTo(fs);
 assertThat(adaptor.settings()).isEqualTo(settings);
 assertThat(adaptor.getSonarQubeVersion()).isEqualTo(Version.parse("5.5"));
 assertThat(adaptor.runtime()).isEqualTo(runtime);
 assertThat(adaptor.newIssue()).isNotNull();
 assertThat(adaptor.newExternalIssue()).isNotNull();
 assertThat(adaptor.newAdHocRule()).isNotNull();
 assertThat(adaptor.newMeasure()).isNotNull();
 assertThat(adaptor.newAnalysisError()).isEqualTo(ModuleSensorContext.NO_OP_NEW_ANALYSIS_ERROR);
 assertThat(adaptor.isCancelled()).isFalse();
 assertThat(adaptor.newSignificantCode()).isNotNull();
}

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

@Before
public void setUp() throws IOException {
 when(fs.getDeployedPluginsDir()).thenReturn(temp.newFolder());
 when(fs.getDownloadedPluginsDir()).thenReturn(temp.newFolder());
 when(fs.getHomeDir()).thenReturn(temp.newFolder());
 when(fs.getInstalledPluginsDir()).thenReturn(temp.newFolder());
 when(fs.getTempDir()).thenReturn(temp.newFolder());
 when(runtime.getApiVersion()).thenReturn(org.sonar.api.utils.Version.parse("5.2"));
}

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

@Test
public void fail_if_plugin_does_not_support_sq_version() throws Exception {
 when(runtime.getApiVersion()).thenReturn(org.sonar.api.utils.Version.parse("1.0"));
 copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir());
 try {
  underTest.start();
  fail();
 } catch (MessageException e) {
  assertThat(e).hasMessage("Plugin Base Plugin [testbase] requires at least SonarQube 4.5.4");
 }
}

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

@Test
public void parse_throws_IAE_if_more_than_4_fields() {
 expectedException.expect(IllegalArgumentException.class);
 expectedException.expectMessage("Maximum 4 fields are accepted: 1.2.3.456.7");
 parse("1.2.3.456.7");
}

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

@Test
public void provide_extensions_for_7_2() {
 SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("7.2"), SonarQubeSide.SCANNER);
 Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
 new XooPlugin().define(context);
 assertThat(getExtensions(context))
  .hasSize(55)
  .contains(OneExternalIssuePerLineSensor.class);
}

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

@Test
public void provide_extensions_for_5_6() {
 SonarRuntime runtime = SonarRuntimeImpl.forSonarLint(Version.parse("5.4"));
 Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
 new XooPlugin().define(context);
 assertThat(getExtensions(context))
  .hasSize(48)
  .doesNotContain(XooBuiltInQualityProfilesDefinition.class);
}

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

@Test
public void provide_extensions_for_6_6() {
 SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("6.6"), SonarQubeSide.SCANNER);
 Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
 new XooPlugin().define(context);
 assertThat(getExtensions(context))
  .hasSize(51)
  .contains(XooBuiltInQualityProfilesDefinition.class);
}

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

@Test
public void provide_extensions_for_7_3() {
 SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("7.3"), SonarQubeSide.SCANNER);
 Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
 new XooPlugin().define(context);
 assertThat(getExtensions(context))
  .hasSize(56)
  .contains(OneExternalIssuePerLineSensor.class);
}

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

@Test
public void provide_extensions_for_7_6() {
 SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("7.6"), SonarQubeSide.SCANNER);
 Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
 new XooPlugin().define(context);
 assertThat(getExtensions(context))
  .hasSize(58)
  .contains(GlobalProjectSensor.class)
  .contains(XooIgnoreCommand.class);
}

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

private WebhookCaller newSender() {
  SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("6.2"), SonarQubeSide.SERVER);
  return new WebhookCallerImpl(system, new OkHttpClientProvider().provide(new MapSettings().asConfig(), runtime));
 }
}

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

@Test
public void testProvideGap_before_5_5() throws IOException {
 DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.xoo")
  .setLanguage(Xoo.KEY)
  .initMetadata("a\nb\nc\nd\ne\nf\ng\nh\ni\n")
  .build();
 SensorContextTester context = SensorContextTester.create(temp.newFolder());
 context.fileSystem().add(inputFile);
 context.settings().setProperty(OneIssuePerLineSensor.EFFORT_TO_FIX_PROPERTY, "1.2");
 context.setRuntime(SonarRuntimeImpl.forSonarQube(Version.parse("5.4"), SonarQubeSide.SCANNER));
 sensor.execute(context);
 assertThat(context.allIssues()).hasSize(10); // One issue per line
 for (Issue issue : context.allIssues()) {
  assertThat(issue.gap()).isEqualTo(1.2d);
 }
}

相关文章