use of org.sonar.updatecenter.common.UpdateCenter in project sonarqube by SonarSource.
the class AvailableAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkIsSystemAdministrator();
JsonWriter jsonWriter = response.newJsonWriter();
jsonWriter.beginObject();
Optional<UpdateCenter> updateCenter = updateCenterFactory.getUpdateCenter(DO_NOT_FORCE_REFRESH);
writePlugins(jsonWriter, updateCenter);
pluginWSCommons.writeUpdateCenterProperties(jsonWriter, updateCenter);
jsonWriter.endObject();
jsonWriter.close();
}
use of org.sonar.updatecenter.common.UpdateCenter in project sonarqube by SonarSource.
the class InstallAction method findAvailablePluginByKey.
private PluginUpdate findAvailablePluginByKey(String key) {
PluginUpdate pluginUpdate = MISSING_PLUGIN;
Optional<UpdateCenter> updateCenter = updateCenterFactory.getUpdateCenter(false);
if (updateCenter.isPresent()) {
pluginUpdate = Iterables.find(updateCenter.get().findAvailablePlugins(), hasKey(key), MISSING_PLUGIN);
}
if (pluginUpdate == MISSING_PLUGIN) {
throw new IllegalArgumentException(format("No plugin with key '%s' or plugin '%s' is already installed in latest version", key, key));
}
return pluginUpdate;
}
use of org.sonar.updatecenter.common.UpdateCenter in project sonarqube by SonarSource.
the class PluginDownloaderTest method before.
@Before
public void before() throws Exception {
updateCenterMatrixFactory = mock(UpdateCenterMatrixFactory.class);
updateCenter = mock(UpdateCenter.class);
when(updateCenterMatrixFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.of(updateCenter));
httpDownloader = mock(HttpDownloader.class);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock inv) throws Throwable {
File toFile = (File) inv.getArguments()[1];
touch(toFile);
return null;
}
}).when(httpDownloader).download(any(URI.class), any(File.class));
ServerFileSystem fs = mock(ServerFileSystem.class);
downloadDir = testFolder.newFolder("downloads");
when(fs.getDownloadedPluginsDir()).thenReturn(downloadDir);
pluginDownloader = new PluginDownloader(updateCenterMatrixFactory, httpDownloader, fs);
}
use of org.sonar.updatecenter.common.UpdateCenter in project sonarqube by SonarSource.
the class InstalledActionTest method category_is_returned_when_in_additional_fields.
@Test
public void category_is_returned_when_in_additional_fields() throws Exception {
logInAsSystemAdministrator();
String jarFilename = getClass().getSimpleName() + "/" + "some.jar";
when(pluginRepository.getPluginInfos()).thenReturn(of(new PluginInfo("plugKey").setName("plugName").setDescription("desc_it").setVersion(Version.create("1.0")).setLicense("license_hey").setOrganizationName("org_name").setOrganizationUrl("org_url").setHomepageUrl("homepage_url").setIssueTrackerUrl("issueTracker_url").setImplementationBuild("sou_rev_sha1").setJarFile(new File(getClass().getResource(jarFilename).toURI()))));
UpdateCenter updateCenter = mock(UpdateCenter.class);
when(updateCenterMatrixFactory.getUpdateCenter(false)).thenReturn(Optional.of(updateCenter));
when(updateCenter.findAllCompatiblePlugins()).thenReturn(Arrays.asList(Plugin.factory("plugKey").setCategory("cat_1")));
when(request.paramAsStrings(Param.FIELDS)).thenReturn(singletonList("category"));
underTest.handle(request, response);
assertJson(response.outputAsString()).isSimilarTo("{" + " \"plugins\":" + " [" + " {" + " \"key\": \"plugKey\"," + " \"name\": \"plugName\"," + " \"description\": \"desc_it\"," + " \"version\": \"1.0\"," + " \"category\":\"cat_1\"," + " \"license\": \"license_hey\"," + " \"organizationName\": \"org_name\"," + " \"organizationUrl\": \"org_url\"," + " \"homepageUrl\": \"homepage_url\"," + " \"issueTrackerUrl\": \"issueTracker_url\"," + " \"implementationBuild\": \"sou_rev_sha1\"" + " }" + " ]" + "}");
}
use of org.sonar.updatecenter.common.UpdateCenter in project sonarqube by SonarSource.
the class PendingActionTest method newUpdateCenter.
private UpdateCenter newUpdateCenter(String... pluginKeys) {
UpdateCenter updateCenter = mock(UpdateCenter.class);
when(updateCenterMatrixFactory.getUpdateCenter(false)).thenReturn(Optional.of(updateCenter));
List<Plugin> plugins = new ArrayList<>();
for (String pluginKey : pluginKeys) {
plugins.add(Plugin.factory(pluginKey).setCategory("cat_1"));
}
when(updateCenter.findAllCompatiblePlugins()).thenReturn(plugins);
return updateCenter;
}
Aggregations