org.sonar.api.Plugin Java Examples

The following examples show how to use org.sonar.api.Plugin. 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: CommunityBranchPluginBootstrap.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void define(Context context) {
    if (SonarQubeSide.SCANNER != context.getRuntime().getSonarQubeSide()) {
        return;
    }
    try {
        ClassLoader classLoader =
                elevatedClassLoaderFactoryProvider.createFactory(context).createClassLoader(getClass());
        Class<?> targetClass = classLoader.loadClass(getClass().getName().replace("Bootstrap", ""));
        Object instance = targetClass.getDeclaredConstructor().newInstance();
        if (!(instance instanceof Plugin)) {
            throw new IllegalStateException(
                    String.format("Expected loaded class to be instance of '%s' but was '%s'",
                                  Plugin.class.getName(), instance.getClass().getName()));
        }
        ((Plugin) instance).define(context);
    } catch (ReflectiveOperationException ex) {
        throw new IllegalStateException("Could not create CommunityBranchPlugin instance", ex);
    }
}
 
Example #2
Source File: ClassReferenceElevatedClassLoaderFactoryTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testLoadClass() throws ClassNotFoundException, MalformedURLException {
    ClassloaderBuilder builder = new ClassloaderBuilder();
    builder.newClassloader("_api_", getClass().getClassLoader());
    builder.setMask("_api_", new Mask().addInclusion("java/").addInclusion("org/sonar/api/"));

    builder.newClassloader("_customPlugin");
    builder.setParent("_customPlugin", "_api_", new Mask());
    builder.setLoadingOrder("_customPlugin", ClassloaderBuilder.LoadingOrder.SELF_FIRST);

    for (URL pluginUrl : findSonarqubePluginJars()) {
        builder.addURL("_customPlugin", pluginUrl);
    }

    Map<String, ClassLoader> loaders = builder.build();
    ClassLoader classLoader = loaders.get("_customPlugin");

    Class<? extends Plugin> loadedClass = (Class<? extends Plugin>) classLoader.loadClass(SVN_PLUGIN_CLASS);

    ClassReferenceElevatedClassLoaderFactory testCase =
            new ClassReferenceElevatedClassLoaderFactory(ActiveRule.class.getName());
    ClassLoader elevatedLoader = testCase.createClassLoader(loadedClass);
    Class<?> elevatedClass = elevatedLoader.loadClass(loadedClass.getName());
    // Getting closer than this is going to be difficult since the URLClassLoader that actually loads is an inner class of evelvatedClassLoader
    assertNotSame(elevatedLoader, elevatedClass.getClassLoader());
}
 
Example #3
Source File: ReflectiveElevatedClassLoaderFactory.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ClassLoader createClassLoader(Class<? extends Plugin> pluginClass) {
    ClassLoader pluginClassLoader =
            AccessController.doPrivileged((PrivilegedAction<ClassLoader>) pluginClass::getClassLoader);

    if (!CLASS_REALM_NAME.equals(pluginClassLoader.getClass().getName())) {
        throw new IllegalStateException(
                String.format("Expected classloader of type '%s' but got '%s'", CLASS_REALM_NAME,
                              pluginClassLoader.getClass().getName()));
    }


    try {
        return createFromPluginClassLoader(pluginClassLoader);
    } catch (ReflectiveOperationException e) {
        throw new IllegalStateException("Could not access ClassLoader chain using reflection", e);
    }
}
 
Example #4
Source File: CommunityBranchPluginBootstrapTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDefineInvokedOnSuccessLoad() throws ClassNotFoundException {
    Plugin.Context context = spy(mock(Plugin.Context.class));
    Configuration configuration = mock(Configuration.class);
    when(context.getBootConfiguration()).thenReturn(configuration);
    when(configuration.get(any())).thenReturn(Optional.empty());
    SonarRuntime sonarRuntime = mock(SonarRuntime.class);
    when(context.getRuntime()).thenReturn(sonarRuntime);
    when(sonarRuntime.getSonarQubeSide()).thenReturn(SonarQubeSide.SCANNER);

    ClassLoader classLoader = mock(ClassLoader.class);
    when(classLoader.loadClass(any())).thenReturn((Class) MockPlugin.class);

    ElevatedClassLoaderFactory elevatedClassLoaderFactory = mock(ElevatedClassLoaderFactory.class);
    when(elevatedClassLoaderFactory.createClassLoader(any())).thenReturn(classLoader);

    ElevatedClassLoaderFactoryProvider elevatedClassLoaderFactoryProvider =
            mock(ElevatedClassLoaderFactoryProvider.class);
    when(elevatedClassLoaderFactoryProvider.createFactory(any())).thenReturn(elevatedClassLoaderFactory);

    CommunityBranchPluginBootstrap testCase =
            new CommunityBranchPluginBootstrap(elevatedClassLoaderFactoryProvider);
    testCase.define(context);

    assertEquals(context, MockPlugin.invokedContext);
}
 
Example #5
Source File: CommunityBranchPluginTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testScannerSideDefine() {
    final CommunityBranchPlugin testCase = new CommunityBranchPlugin();

    final Plugin.Context context = spy(mock(Plugin.Context.class, Mockito.RETURNS_DEEP_STUBS));
    when(context.getRuntime().getSonarQubeSide()).thenReturn(SonarQubeSide.SCANNER);

    testCase.define(context);

    final ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
    verify(context, times(1))
            .addExtensions(argumentCaptor.capture(), argumentCaptor.capture(), argumentCaptor.capture());


    assertEquals(Arrays.asList(CommunityProjectBranchesLoader.class, CommunityProjectPullRequestsLoader.class,
                               CommunityBranchConfigurationLoader.class, CommunityBranchParamsValidator.class),
                 argumentCaptor.getAllValues().subList(0, 4));
}
 
Example #6
Source File: ReflectiveElevatedClassLoaderFactoryTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testLoadClassInvalidClassloader() throws ClassNotFoundException, MalformedURLException {

    File[] sonarQubeDistributions = new File("sonarqube-lib/").listFiles();
    File[] plugins = new File(sonarQubeDistributions[0], "extensions/plugins/").listFiles();

    URL[] urls = new URL[plugins.length];
    int i = 0;
    for (File pluginJar : plugins) {
        urls[i++] = pluginJar.toURI().toURL();
    }

    ClassLoader classLoader = new URLClassLoader(urls);

    Class<? extends Plugins> loadedClass =
            (Class<? extends Plugins>) classLoader.loadClass("org.sonar.plugins.scm.svn.SvnPlugin");

    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage(IsEqual.equalTo(
            "Expected classloader of type 'org.sonar.classloader.ClassRealm' but got 'java.net.URLClassLoader'"));

    ReflectiveElevatedClassLoaderFactory testCase = new ReflectiveElevatedClassLoaderFactory();
    testCase.createClassLoader((Class<? extends Plugin>) loadedClass);

}
 
Example #7
Source File: CommunityBranchPluginBootstrapTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDefineNotInvokedForNonScanner() throws ClassNotFoundException {
    Plugin.Context context = spy(mock(Plugin.Context.class));
    Configuration configuration = mock(Configuration.class);
    when(context.getBootConfiguration()).thenReturn(configuration);
    when(configuration.get(any())).thenReturn(Optional.empty());
    SonarRuntime sonarRuntime = mock(SonarRuntime.class);
    when(context.getRuntime()).thenReturn(sonarRuntime);
    when(sonarRuntime.getSonarQubeSide()).thenReturn(SonarQubeSide.SERVER);

    ClassLoader classLoader = mock(ClassLoader.class);
    when(classLoader.loadClass(any())).thenReturn((Class) MockPlugin.class);

    ElevatedClassLoaderFactory elevatedClassLoaderFactory = mock(ElevatedClassLoaderFactory.class);
    when(elevatedClassLoaderFactory.createClassLoader(any())).thenReturn(classLoader);

    ElevatedClassLoaderFactoryProvider elevatedClassLoaderFactoryProvider =
            mock(ElevatedClassLoaderFactoryProvider.class);
    when(elevatedClassLoaderFactoryProvider.createFactory(any())).thenReturn(elevatedClassLoaderFactory);

    CommunityBranchPluginBootstrap testCase =
            new CommunityBranchPluginBootstrap(elevatedClassLoaderFactoryProvider);
    testCase.define(context);

    assertNull(MockPlugin.invokedContext);
}
 
Example #8
Source File: ReflectiveElevatedClassLoaderFactoryTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testLoadClassNoParentRef()
        throws ClassNotFoundException, IllegalAccessException, InstantiationException, MalformedURLException {
    ClassloaderBuilder builder = new ClassloaderBuilder();
    builder.newClassloader("_xxx_", getClass().getClassLoader());
    builder.setMask("_xxx_", new Mask());

    File[] sonarQubeDistributions = new File("sonarqube-lib/").listFiles();

    for (File pluginJar : new File(sonarQubeDistributions[0], "extensions/plugins/").listFiles()) {
        builder.addURL("_xxx_", pluginJar.toURI().toURL());
    }

    Map<String, ClassLoader> loaders = builder.build();
    ClassLoader classLoader = loaders.get("_xxx_");

    Class<? extends Plugin> loadedClass =
            (Class<? extends Plugin>) classLoader.loadClass("org.sonar.plugins.scm.svn.SvnPlugin");

    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage(IsEqual.equalTo("Could not access ClassLoader chain using reflection"));

    ReflectiveElevatedClassLoaderFactory testCase = new ReflectiveElevatedClassLoaderFactory();
    testCase.createClassLoader(loadedClass);

}
 
Example #9
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 #10
Source File: ProviderTypeTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testClassReferenceTypeMatched() {
    Plugin.Context context = mock(Plugin.Context.class);
    Configuration configuration = mock(Configuration.class);
    when(context.getBootConfiguration()).thenReturn(configuration);

    assertTrue(ProviderType.fromName("CLASS_REFERENCE")
                       .createFactory(context) instanceof ClassReferenceElevatedClassLoaderFactory);
}
 
Example #11
Source File: DefaultElevatedClassLoaderFactoryProviderTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void validFactoryReturnedOnNoPropertiesSet() {
    Plugin.Context context = mock(Plugin.Context.class);
    Configuration configuration = mock(Configuration.class);
    when(context.getBootConfiguration()).thenReturn(configuration);
    when(configuration.get(any())).thenReturn(Optional.empty());

    assertTrue(DefaultElevatedClassLoaderFactoryProvider.getInstance()
                       .createFactory(context) instanceof ClassReferenceElevatedClassLoaderFactory);
}
 
Example #12
Source File: CommunityBranchPluginBootstrapTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testFailureOnIncorrectClassTypeReturned() throws ReflectiveOperationException {
    ClassLoader classLoader = mock(ClassLoader.class);
    doReturn(this.getClass()).when(classLoader).loadClass(any());

    ElevatedClassLoaderFactory classLoaderFactory = mock(ElevatedClassLoaderFactory.class);
    when(classLoaderFactory.createClassLoader(any())).thenReturn(classLoader);

    Plugin.Context context = mock(Plugin.Context.class, Mockito.RETURNS_DEEP_STUBS);
    SonarRuntime sonarRuntime = mock(SonarRuntime.class);
    when(context.getRuntime()).thenReturn(sonarRuntime);
    when(sonarRuntime.getSonarQubeSide()).thenReturn(SonarQubeSide.SCANNER);

    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage(IsEqual.equalTo(
            "Expected loaded class to be instance of 'org.sonar.api.Plugin' but was '" + getClass().getName() +
            "'"));

    ElevatedClassLoaderFactory elevatedClassLoaderFactory = mock(ElevatedClassLoaderFactory.class);
    when(elevatedClassLoaderFactory.createClassLoader(any())).thenReturn(classLoader);

    ElevatedClassLoaderFactoryProvider elevatedClassLoaderFactoryProvider =
            mock(ElevatedClassLoaderFactoryProvider.class);
    when(elevatedClassLoaderFactoryProvider.createFactory(any())).thenReturn(elevatedClassLoaderFactory);


    CommunityBranchPluginBootstrap testCase =
            new CommunityBranchPluginBootstrap(elevatedClassLoaderFactoryProvider);
    testCase.define(context);
}
 
Example #13
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 #14
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 #15
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 #16
Source File: ColdfusionPluginTest.java    From sonar-coldfusion with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtensions() {
    ColdFusionPlugin plugin = new ColdFusionPlugin();
    SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(VERSION_7_6, SonarQubeSide.SERVER);
    Plugin.Context context = new Plugin.Context(runtime);
    plugin.define(context);

    Assert.assertEquals(5, context.getExtensions().size());
}
 
Example #17
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 #18
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 #19
Source File: ProviderTypeTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testReflectiveTypeMatched() {
    Plugin.Context context = mock(Plugin.Context.class);
    Configuration configuration = mock(Configuration.class);
    when(context.getBootConfiguration()).thenReturn(configuration);

    assertTrue(ProviderType.fromName("REFLECTIVE")
                       .createFactory(context) instanceof ReflectiveElevatedClassLoaderFactory);
}
 
Example #20
Source File: ClassReferenceElevatedClassLoaderFactoryTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testClassloaderReturnedOnHappyPath() throws ReflectiveOperationException, MalformedURLException {
    URLClassLoader mockClassLoader = new URLClassLoader(findSonarqubePluginJars());
    ElevatedClassLoaderFactory testCase = spy(new ClassReferenceElevatedClassLoaderFactory(getClass().getName()));
    testCase.createClassLoader((Class<? extends Plugin>) mockClassLoader.loadClass(SVN_PLUGIN_CLASS));

    ArgumentCaptor<ClassLoader> argumentCaptor = ArgumentCaptor.forClass(ClassLoader.class);
    verify(testCase).createClassLoader(argumentCaptor.capture(), argumentCaptor.capture());

    assertEquals(Arrays.asList(mockClassLoader, getClass().getClassLoader()), argumentCaptor.getAllValues());
}
 
Example #21
Source File: ClassReferenceElevatedClassLoaderFactoryTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testExceptionOnNoSuchClass() {
    ClassReferenceElevatedClassLoaderFactory testCase = new ClassReferenceElevatedClassLoaderFactory("1");

    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage(IsEqual.equalTo("Could not load class '1' from Plugin Classloader"));

    testCase.createClassLoader(((Plugin) context -> {
    }).getClass());
}
 
Example #22
Source File: ReflectiveElevatedClassLoaderFactoryTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testLoadClassInvalidApiClassloader()
        throws ClassNotFoundException, IllegalAccessException, InstantiationException, MalformedURLException {
    ClassloaderBuilder builder = new ClassloaderBuilder();
    builder.newClassloader("_customPlugin");
    builder.setParent("_customPlugin", new URLClassLoader(new URL[0]), new Mask());
    builder.setLoadingOrder("_customPlugin", ClassloaderBuilder.LoadingOrder.SELF_FIRST);

    File[] sonarQubeDistributions = new File("sonarqube-lib/").listFiles();

    for (File pluginJar : new File(sonarQubeDistributions[0], "extensions/plugins/").listFiles()) {
        builder.addURL("_customPlugin", pluginJar.toURI().toURL());
    }

    Map<String, ClassLoader> loaders = builder.build();
    ClassLoader classLoader = loaders.get("_customPlugin");

    Class<? extends Plugins> loadedClass =
            (Class<? extends Plugins>) classLoader.loadClass("org.sonar.plugins.scm.svn.SvnPlugin");

    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage(IsEqual.equalTo(
            "Expected classloader of type 'org.sonar.classloader.ClassRealm' but got 'java.net.URLClassLoader'"));

    ReflectiveElevatedClassLoaderFactory testCase = new ReflectiveElevatedClassLoaderFactory();
    testCase.createClassLoader((Class<? extends Plugin>) loadedClass);

}
 
Example #23
Source File: ReflectiveElevatedClassLoaderFactoryTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testLoadClassInvalidClassRealmKey()
        throws ClassNotFoundException, IllegalAccessException, InstantiationException, MalformedURLException {
    ClassloaderBuilder builder = new ClassloaderBuilder();
    builder.newClassloader("_xxx_", getClass().getClassLoader());
    builder.setMask("_xxx_", new Mask().addInclusion("java/").addInclusion("org/sonar/api/"));

    builder.newClassloader("_customPlugin");
    builder.setParent("_customPlugin", "_xxx_", new Mask());
    builder.setLoadingOrder("_customPlugin", ClassloaderBuilder.LoadingOrder.SELF_FIRST);

    File[] sonarQubeDistributions = new File("sonarqube-lib/").listFiles();

    for (File pluginJar : new File(sonarQubeDistributions[0], "extensions/plugins/").listFiles()) {
        builder.addURL("_customPlugin", pluginJar.toURI().toURL());
    }

    Map<String, ClassLoader> loaders = builder.build();
    ClassLoader classLoader = loaders.get("_customPlugin");

    Class<? extends Plugin> loadedClass =
            (Class<? extends Plugin>) classLoader.loadClass("org.sonar.plugins.scm.svn.SvnPlugin");

    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage(IsEqual.equalTo("Expected classloader with key '_api_' but found key '_xxx_'"));

    ReflectiveElevatedClassLoaderFactory testCase = new ReflectiveElevatedClassLoaderFactory();
    testCase.createClassLoader(loadedClass);

}
 
Example #24
Source File: ReflectiveElevatedClassLoaderFactoryTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testLoadClass() throws ClassNotFoundException, MalformedURLException {
    ClassloaderBuilder builder = new ClassloaderBuilder();
    builder.newClassloader("_api_", getClass().getClassLoader());
    builder.setMask("_api_", new Mask().addInclusion("java/").addInclusion("org/sonar/api/"));

    builder.newClassloader("_customPlugin");
    builder.setParent("_customPlugin", "_api_", new Mask());
    builder.setLoadingOrder("_customPlugin", ClassloaderBuilder.LoadingOrder.SELF_FIRST);

    File[] sonarQubeDistributions = new File("sonarqube-lib/").listFiles();

    for (File pluginJar : new File(sonarQubeDistributions[0], "extensions/plugins/").listFiles()) {
        builder.addURL("_customPlugin", pluginJar.toURI().toURL());
    }

    Map<String, ClassLoader> loaders = builder.build();
    ClassLoader classLoader = loaders.get("_customPlugin");

    Class<? extends Plugin> loadedClass =
            (Class<? extends Plugin>) classLoader.loadClass("org.sonar.plugins.scm.svn.SvnPlugin");

    ReflectiveElevatedClassLoaderFactory testCase = new ReflectiveElevatedClassLoaderFactory();
    ClassLoader elevatedLoader = testCase.createClassLoader(loadedClass);
    Class<?> elevatedClass = elevatedLoader.loadClass(loadedClass.getName());
    // Getting closer than this is going to be difficult since the URLClassLoader that actually loads is an inner class of evelvatedClassLoader
    assertNotSame(elevatedLoader, elevatedClass.getClassLoader());
}
 
Example #25
Source File: CommunityBranchPluginTest.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testNonScannerSideDefine() {
    final CommunityBranchPlugin testCase = new CommunityBranchPlugin();

    final Plugin.Context context = spy(mock(Plugin.Context.class, Mockito.RETURNS_DEEP_STUBS));
    when(context.getRuntime().getSonarQubeSide()).thenReturn(SonarQubeSide.SERVER);

    testCase.define(context);

    verify(context, never()).addExtensions(any());
}
 
Example #26
Source File: TypeScriptPluginTest.java    From SonarTsPlugin with MIT License 5 votes vote down vote up
@Test
public void advertisesAppropriateExtensions() {
    Plugin.Context context = new Plugin.Context(SonarQubeVersion.V5_6);

    this.plugin.define(context);

    List extensions = context.getExtensions();

    assertTrue(extensions.contains(TypeScriptRuleProfile.class));
    assertTrue(extensions.contains(TypeScriptLanguage.class));
    assertTrue(extensions.contains(TsLintSensor.class));
    assertTrue(extensions.contains(CombinedCoverageSensor.class));
    assertTrue(extensions.contains(TsRulesDefinition.class));
}
 
Example #27
Source File: ClassReferenceElevatedClassLoaderFactory.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ClassLoader createClassLoader(Class<? extends Plugin> pluginClass) {
    Class<?> coreClass;
    try {
        coreClass = Class.forName(className);
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException(
                String.format("Could not load class '%s' from Plugin Classloader", className), e);
    }
    return createClassLoader(pluginClass.getClassLoader(), coreClass.getClassLoader());
}
 
Example #28
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 #29
Source File: CommunityBranchPlugin.java    From sonarqube-community-branch-plugin with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void define(Plugin.Context context) {
    if (SonarQubeSide.SCANNER == context.getRuntime().getSonarQubeSide()) {
        context.addExtensions(CommunityProjectBranchesLoader.class, CommunityProjectPullRequestsLoader.class,
                              CommunityBranchConfigurationLoader.class, CommunityBranchParamsValidator.class,
                              ScannerPullRequestPropertySensor.class);
    }
}
 
Example #30
Source File: EsqlPluginTest.java    From sonar-esql-plugin with Apache License 2.0 4 votes vote down vote up
private Plugin.Context setupContext(SonarRuntime runtime) {
  Plugin.Context context = new Plugin.Context(runtime);
  new EsqlPlugin().define(context);
  return context;
}