Search in sources :

Example 1 with UpdateCenter

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();
}
Also used : UpdateCenter(org.sonar.updatecenter.common.UpdateCenter) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 2 with UpdateCenter

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;
}
Also used : UpdateCenter(org.sonar.updatecenter.common.UpdateCenter) PluginUpdate(org.sonar.updatecenter.common.PluginUpdate)

Example 3 with UpdateCenter

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);
}
Also used : ServerFileSystem(org.sonar.server.platform.ServerFileSystem) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) UpdateCenter(org.sonar.updatecenter.common.UpdateCenter) HttpDownloader(org.sonar.api.utils.HttpDownloader) InvocationOnMock(org.mockito.invocation.InvocationOnMock) File(java.io.File) URI(java.net.URI) Before(org.junit.Before)

Example 4 with UpdateCenter

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\"" + "    }" + "  ]" + "}");
}
Also used : UpdateCenter(org.sonar.updatecenter.common.UpdateCenter) PluginInfo(org.sonar.core.platform.PluginInfo) File(java.io.File) Test(org.junit.Test)

Example 5 with UpdateCenter

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;
}
Also used : UpdateCenter(org.sonar.updatecenter.common.UpdateCenter) ArrayList(java.util.ArrayList) Plugin(org.sonar.updatecenter.common.Plugin)

Aggregations

UpdateCenter (org.sonar.updatecenter.common.UpdateCenter)9 File (java.io.File)2 URI (java.net.URI)2 Test (org.junit.Test)2 JsonWriter (org.sonar.api.utils.text.JsonWriter)2 PluginUpdate (org.sonar.updatecenter.common.PluginUpdate)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 Before (org.junit.Before)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 HttpDownloader (org.sonar.api.utils.HttpDownloader)1 SonarException (org.sonar.api.utils.SonarException)1 PluginInfo (org.sonar.core.platform.PluginInfo)1 ServerFileSystem (org.sonar.server.platform.ServerFileSystem)1 Plugin (org.sonar.updatecenter.common.Plugin)1 Release (org.sonar.updatecenter.common.Release)1