org.sonar.api.utils.Version Java Examples

The following examples show how to use org.sonar.api.utils.Version. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClojurePluginTest.java    From sonar-clojure with MIT License 5 votes vote down vote up
@Before
public void setUp() {
    SonarRuntime runtime = SonarRuntimeImpl
            .forSonarQube(Version.create(7, 9, 3), SonarQubeSide.SERVER, SonarEdition.COMMUNITY);
    context = new Plugin.Context(runtime);
    new ClojurePlugin().define(context);
}
 
Example #2
Source File: CloverPluginTest.java    From sonar-clover with Apache License 2.0 5 votes vote down vote up
@Test
public void test_define() {
  final Plugin.Context context = new Plugin.Context(SonarRuntimeImpl.forSonarQube(
          Version.parse("6.7.4"),
          SonarQubeSide.SCANNER));
  new CloverPlugin().define(context);
  assertThat(context.getExtensions()).hasSize(1);
}
 
Example #3
Source File: EsqlPluginTest.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
private List<PropertyDefinition> properties() {
  List<PropertyDefinition> propertiesList = new ArrayList<>();
  List extensions = setupContext(SonarRuntimeImpl.forSonarQube(Version.create(7, 9), SonarQubeSide.SERVER, SonarEdition.COMMUNITY)).getExtensions();

  for (Object extension : extensions) {
    if (extension instanceof PropertyDefinition) {
      propertiesList.add((PropertyDefinition) extension);
    }
  }

  return propertiesList;
}
 
Example #4
Source File: PluginTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void should_get_the_right_version() {
  Context context = new Context(Version.create(5, 6));
  new Plugin().define(context);
  assertThat(context.getSonarQubeVersion().major()).isEqualTo(5);
  assertThat(context.getSonarQubeVersion().minor()).isEqualTo(6);
}
 
Example #5
Source File: RubyPluginTest.java    From sonar-ruby-plugin with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testDefine() {
    RubyPlugin plugin = new RubyPlugin();

    Plugin.Context context = new Plugin.Context(Version.create(1, 0));

    plugin.define(context);

    assertThat(context.getExtensions().size()).isEqualTo(18);

    assertThat(context.getExtensions().stream().filter(ext -> ext instanceof PropertyDefinition).count()).isEqualTo(7);
    assertThat(context.getExtensions().stream().filter(ext -> ext instanceof Class).count()).isEqualTo(11);
}
 
Example #6
Source File: ColdfusionSensorTest.java    From sonar-coldfusion with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicCFMAnalysis() {
    DefaultFileSystem fileSystem = new DefaultFileSystem(tmpFolder.getRoot());
    fileSystem.setEncoding(Charsets.UTF_8);
    fileSystem.setWorkDir(tmpFolder.getRoot().toPath());

    context.setFileSystem(fileSystem);
    context.setRuntime(SonarRuntimeImpl.forSonarQube(Version.create(7, 6), SonarQubeSide.SCANNER));

    context.settings().appendProperty("sonar.projectBaseDir", baseDir.getPath());
    addFilesToFs();

    CommandExecutor commandExecutor = CommandExecutor.create();
    String javaHome = System.getProperty("java.home");
    Assert.assertTrue(javaHome!=null && !javaHome.equals(""));

    if(OSValidator.isWindows()) {
        context.settings().appendProperty(ColdFusionPlugin.CFLINT_JAVA, javaHome + "/bin/java.exe");
    } else {
        context.settings().appendProperty(ColdFusionPlugin.CFLINT_JAVA, javaHome + "/bin/java");
    }

    ColdFusionSensor sensor = new ColdFusionSensor(context.fileSystem(), rulesProfile);
    sensor.execute(context);

    Integer nloc = 0;
    Integer comments = 0;
    Integer complexity = 0;
    for (InputFile o : context.fileSystem().inputFiles()) {
        Measure<Integer> measureNloc = context.measure(o.key(),CoreMetrics.NCLOC.key());
        Measure<Integer> measureComment = context.measure(o.key(),CoreMetrics.COMMENT_LINES.key());
        Measure<Integer> measureComplexity = context.measure(o.key(),CoreMetrics.COMPLEXITY.key());
        nloc+=measureNloc.value();
        comments+=measureComment.value();
        complexity+=measureComplexity.value();
    }
    assertThat(nloc).isEqualTo(56);
    assertThat(comments).isEqualTo(9);
    assertThat(complexity).isEqualTo(10);
}
 
Example #7
Source File: FlowPluginTest.java    From sonar-flow-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void debug() {
  SonarRuntime runtime = 
      SonarRuntimeImpl.forSonarQube(Version.create(5, 6), SonarQubeSide.SCANNER);
  Plugin.Context context = new Plugin.Context(runtime);
  new FlowPlugin().define(context);
  logger.debug("Nr of extentions: " + context.getExtensions().size());
  assertTrue(context.getExtensions().size() == 13);
}
 
Example #8
Source File: MyGherkinCustomRulesPluginTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void should_get_the_right_version() {
  Plugin.Context context = new Plugin.Context(Version.create(5, 6));
  new MyGherkinCustomRulesPlugin().define(context);
  assertThat(context.getSonarQubeVersion().major()).isEqualTo(5);
  assertThat(context.getSonarQubeVersion().minor()).isEqualTo(6);
}
 
Example #9
Source File: AemRulesSonarPluginTest.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
@Test
public void webPluginTester() {
    Plugin.Context context = new Plugin.Context(SonarRuntimeImpl.forSonarQube(Version.create(6, 7), SonarQubeSide.SERVER, SonarEdition.COMMUNITY));

    new AemRulesSonarPlugin().define(context);
    assertThat(context.getExtensions()).hasSize(7);
}
 
Example #10
Source File: GherkinPluginTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void should_get_the_right_version() {
  Plugin.Context context = new Plugin.Context(Version.create(5, 6));
  new GherkinPlugin().define(context);
  assertThat(context.getSonarQubeVersion().major()).isEqualTo(5);
  assertThat(context.getSonarQubeVersion().minor()).isEqualTo(6);
}
 
Example #11
Source File: LuaPluginTest.java    From sonar-lua with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public void testGetExtensions() throws Exception {
  Plugin.Context context = new Plugin.Context(Version.create(5, 6));
  new LuaPlugin().define(context);
  assertThat(context.getExtensions()).isNotEmpty();
}
 
Example #12
Source File: EsqlPluginTest.java    From sonar-esql-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void count_extensions() throws Exception {
  Plugin.Context context = setupContext(SonarRuntimeImpl.forSonarQube(Version.create(7, 9), SonarQubeSide.SERVER, SonarEdition.COMMUNITY));

  assertThat(context.getExtensions()).hasSize(10);
}
 
Example #13
Source File: GherkinPluginTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public void should_get_the_right_number_of_extensions() {
  Plugin.Context context = new Plugin.Context(Version.create(5, 6));
  new GherkinPlugin().define(context);
  assertThat(context.getExtensions()).hasSize(4);
}
 
Example #14
Source File: MyGherkinCustomRulesPluginTest.java    From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public void should_get_the_right_number_of_extensions() {
  Plugin.Context context = new Plugin.Context(Version.create(5, 6));
  new MyGherkinCustomRulesPlugin().define(context);
  assertThat(context.getExtensions()).hasSize(1);
}
 
Example #15
Source File: PluginTest.java    From sonar-css-plugin with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public void should_get_the_right_number_of_extensions() {
  Context context = new Context(Version.create(5, 6));
  new Plugin().define(context);
  assertThat(context.getExtensions()).hasSize(13);
}
 
Example #16
Source File: AuthOidcPluginTest.java    From sonar-auth-oidc with Apache License 2.0 4 votes vote down vote up
MockContext() {
  super(SonarRuntimeImpl.forSonarQube(Version.create(7, 6), SonarQubeSide.SERVER));
}
 
Example #17
Source File: AnsiblePluginTest.java    From sonar-ansible with Apache License 2.0 4 votes vote down vote up
public void testExtensionCounts() {
    Plugin.Context context = new Plugin.Context(SonarRuntimeImpl.forSonarQube(Version.create(6, 2), SonarQubeSide.SERVER));
    new AnsiblePlugin().define(context);
    assertEquals(4, context.getExtensions().size());
}
 
Example #18
Source File: AbstractAnsibleExtrasPluginTest.java    From sonar-ansible with Apache License 2.0 4 votes vote down vote up
public void testExtensionCounts() {
    Plugin.Context context = new Plugin.Context(SonarRuntimeImpl.forSonarQube(Version.create(6, 2), SonarQubeSide.SERVER));
    new MyExtrasPlugin().define(context);
    assertEquals(2, context.getExtensions().size());
}