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);
}
}
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");
}
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();
}
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"));
}
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));
}
Aggregations