Search in sources :

Example 1 with PluginRepository

use of org.sonar.core.platform.PluginRepository in project sonarqube by SonarSource.

the class StaticResourcesServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String pluginKey = getPluginKey(request);
    String resource = getResourcePath(request);
    InputStream in = null;
    OutputStream out = null;
    try {
        PluginRepository pluginRepository = Platform.getInstance().getContainer().getComponentByType(PluginRepository.class);
        if (!pluginRepository.hasPlugin(pluginKey)) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        in = pluginRepository.getPluginInstance(pluginKey).getClass().getClassLoader().getResourceAsStream(resource);
        if (in != null) {
            // mime type must be set before writing response body
            completeContentType(response, resource);
            out = response.getOutputStream();
            IOUtils.copy(in, out);
        } else {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    } catch (Exception e) {
        LOG.error(String.format("Unable to load resource [%s] from plugin [%s]", resource, pluginKey), e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(out);
    }
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) PluginRepository(org.sonar.core.platform.PluginRepository) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 2 with PluginRepository

use of org.sonar.core.platform.PluginRepository in project sonarqube by SonarSource.

the class DebtModelPluginRepositoryTest method test_component_initialization.

@Test
public void test_component_initialization() throws Exception {
    // we do have the "csharp-model.xml" file in src/test/resources
    PluginInfo csharpPluginMetadata = new PluginInfo("csharp");
    // but we don' have the "php-model.xml" one
    PluginInfo phpPluginMetadata = new PluginInfo("php");
    PluginRepository repository = mock(PluginRepository.class);
    when(repository.getPluginInfos()).thenReturn(Lists.newArrayList(csharpPluginMetadata, phpPluginMetadata));
    FakePlugin fakePlugin = new FakePlugin();
    when(repository.getPluginInstance(anyString())).thenReturn(fakePlugin);
    underTest = new DebtModelPluginRepository(repository, TEST_XML_PREFIX_PATH);
    // when
    underTest.start();
    // assert
    Collection<String> contributingPluginList = underTest.getContributingPluginList();
    assertThat(contributingPluginList.size()).isEqualTo(2);
    assertThat(contributingPluginList).containsOnly("technical-debt", "csharp");
}
Also used : PluginRepository(org.sonar.core.platform.PluginRepository) PluginInfo(org.sonar.core.platform.PluginInfo) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 3 with PluginRepository

use of org.sonar.core.platform.PluginRepository in project sonarqube by SonarSource.

the class InstalledPluginReferentialFactoryTest method should_encapsulate_exception.

@Test(expected = RuntimeException.class)
public void should_encapsulate_exception() {
    PluginRepository pluginRepository = mock(PluginRepository.class);
    when(pluginRepository.getPluginInfos()).thenThrow(new IllegalArgumentException());
    InstalledPluginReferentialFactory factory = new InstalledPluginReferentialFactory(pluginRepository);
    factory.start();
}
Also used : PluginRepository(org.sonar.core.platform.PluginRepository) Test(org.junit.Test)

Example 4 with PluginRepository

use of org.sonar.core.platform.PluginRepository in project sonarqube by SonarSource.

the class GeneratePluginIndexTest method shouldWriteIndex.

@Test
public void shouldWriteIndex() throws IOException {
    PluginRepository repository = mock(PluginRepository.class);
    PluginInfo sqale = newInfo("sqale");
    PluginInfo checkstyle = newInfo("checkstyle");
    when(repository.getPluginInfos()).thenReturn(Arrays.asList(sqale, checkstyle));
    new GeneratePluginIndex(fileSystem, repository).start();
    List<String> lines = FileUtils.readLines(index);
    assertThat(lines.size(), Is.is(2));
    assertThat(lines.get(0), containsString("sqale"));
    assertThat(lines.get(1), containsString("checkstyle"));
}
Also used : PluginRepository(org.sonar.core.platform.PluginRepository) PluginInfo(org.sonar.core.platform.PluginInfo) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Test(org.junit.Test)

Example 5 with PluginRepository

use of org.sonar.core.platform.PluginRepository in project sonarqube by SonarSource.

the class GlobalActionTest method init.

private void init(org.sonar.api.web.page.Page[] pages, ResourceTypeTree[] resourceTypeTrees) {
    when(dbClient.getDatabase().getDialect()).thenReturn(new H2());
    when(server.getVersion()).thenReturn("6.42");
    PluginRepository pluginRepository = mock(PluginRepository.class);
    when(pluginRepository.hasPlugin(anyString())).thenReturn(true);
    PageRepository pageRepository = new PageRepository(pluginRepository, new PageDefinition[] { context -> {
        for (Page page : pages) {
            context.addPage(page);
        }
    } });
    pageRepository.start();
    ws = new WsActionTester(new GlobalAction(pageRepository, settings, new ResourceTypes(resourceTypeTrees), server, dbClient, organizationFlags));
}
Also used : ResourceTypes(org.sonar.api.resources.ResourceTypes) PluginRepository(org.sonar.core.platform.PluginRepository) PageRepository(org.sonar.server.ui.PageRepository) H2(org.sonar.db.dialect.H2) Page(org.sonar.api.web.page.Page) WsActionTester(org.sonar.server.ws.WsActionTester)

Aggregations

PluginRepository (org.sonar.core.platform.PluginRepository)15 Test (org.junit.Test)9 Page (org.sonar.api.web.page.Page)8 Before (org.junit.Before)6 Matchers.anyString (org.mockito.Matchers.anyString)6 List (java.util.List)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Assertions.tuple (org.assertj.core.api.Assertions.tuple)5 Rule (org.junit.Rule)5 ExpectedException (org.junit.rules.ExpectedException)5 Mockito.mock (org.mockito.Mockito.mock)5 Mockito.when (org.mockito.Mockito.when)5 Qualifiers (org.sonar.api.resources.Qualifiers)5 LogTester (org.sonar.api.utils.log.LogTester)5 Qualifier (org.sonar.api.web.page.Page.Qualifier)5 COMPONENT (org.sonar.api.web.page.Page.Scope.COMPONENT)5 GLOBAL (org.sonar.api.web.page.Page.Scope.GLOBAL)5 PageDefinition (org.sonar.api.web.page.PageDefinition)5 PluginInfo (org.sonar.core.platform.PluginInfo)5 PageRepository (org.sonar.server.ui.PageRepository)3