Browse Source

Update to new update center API

tags/3.5
Julien Lancelot 11 years ago
parent
commit
aa5c27a9b1

+ 5
- 37
sonar-server/src/main/java/org/sonar/server/platform/Platform.java View File

@@ -46,14 +46,7 @@ import org.sonar.core.measure.MeasureFilterExecutor;
import org.sonar.core.measure.MeasureFilterFactory;
import org.sonar.core.metric.DefaultMetricFinder;
import org.sonar.core.notification.DefaultNotificationManager;
import org.sonar.core.persistence.DaoUtils;
import org.sonar.core.persistence.DatabaseMigrator;
import org.sonar.core.persistence.DatabaseVersion;
import org.sonar.core.persistence.DefaultDatabase;
import org.sonar.core.persistence.DryRunDatabaseFactory;
import org.sonar.core.persistence.MyBatis;
import org.sonar.core.persistence.SemaphoreUpdater;
import org.sonar.core.persistence.SemaphoresImpl;
import org.sonar.core.persistence.*;
import org.sonar.core.qualitymodel.DefaultModelFinder;
import org.sonar.core.resource.DefaultResourcePermissions;
import org.sonar.core.rule.DefaultRuleFinder;
@@ -77,37 +70,12 @@ import org.sonar.server.database.EmbeddedDatabaseFactory;
import org.sonar.server.notifications.NotificationCenter;
import org.sonar.server.notifications.NotificationService;
import org.sonar.server.notifications.reviews.ReviewsNotificationManager;
import org.sonar.server.plugins.ApplicationDeployer;
import org.sonar.server.plugins.DefaultServerPluginRepository;
import org.sonar.server.plugins.InstalledPluginCenterFactory;
import org.sonar.server.plugins.PluginDeployer;
import org.sonar.server.plugins.PluginDownloader;
import org.sonar.server.plugins.PluginReferentialMetadataConverter;
import org.sonar.server.plugins.ServerExtensionInstaller;
import org.sonar.server.plugins.UpdateCenterClient;
import org.sonar.server.plugins.UpdateCenterMatrixFactory;
import org.sonar.server.plugins.*;
import org.sonar.server.qualitymodel.DefaultModelManager;
import org.sonar.server.rules.ProfilesConsole;
import org.sonar.server.rules.RulesConsole;
import org.sonar.server.startup.DeleteDeprecatedMeasures;
import org.sonar.server.startup.GenerateBootstrapIndex;
import org.sonar.server.startup.GeneratePluginIndex;
import org.sonar.server.startup.GwtPublisher;
import org.sonar.server.startup.JdbcDriverDeployer;
import org.sonar.server.startup.LogServerId;
import org.sonar.server.startup.RegisterMetrics;
import org.sonar.server.startup.RegisterNewDashboards;
import org.sonar.server.startup.RegisterNewMeasureFilters;
import org.sonar.server.startup.RegisterNewProfiles;
import org.sonar.server.startup.RegisterQualityModels;
import org.sonar.server.startup.RegisterRules;
import org.sonar.server.startup.RenameDeprecatedPropertyKeys;
import org.sonar.server.startup.ServerMetadataPersister;
import org.sonar.server.ui.CodeColorizers;
import org.sonar.server.ui.JRubyI18n;
import org.sonar.server.ui.PageDecorations;
import org.sonar.server.ui.SecurityRealmFactory;
import org.sonar.server.ui.Views;
import org.sonar.server.startup.*;
import org.sonar.server.ui.*;

import javax.servlet.ServletContext;

@@ -184,7 +152,7 @@ public final class Platform {
}
rootContainer.addSingleton(PluginDeployer.class);
rootContainer.addSingleton(PluginReferentialMetadataConverter.class);
rootContainer.addSingleton(InstalledPluginCenterFactory.class);
rootContainer.addSingleton(InstalledPluginReferentialFactory.class);
rootContainer.addSingleton(DefaultServerPluginRepository.class);

rootContainer.addSingleton(DefaultServerFileSystem.class);

sonar-server/src/main/java/org/sonar/server/plugins/InstalledPluginCenterFactory.java → sonar-server/src/main/java/org/sonar/server/plugins/InstalledPluginReferentialFactory.java View File

@@ -21,43 +21,24 @@ package org.sonar.server.plugins;

import org.sonar.api.ServerComponent;
import org.sonar.api.platform.PluginRepository;
import org.sonar.api.platform.Server;
import org.sonar.updatecenter.common.PluginCenter;
import org.sonar.updatecenter.common.PluginReferential;
import org.sonar.updatecenter.common.Version;

import java.util.Date;
public class InstalledPluginReferentialFactory implements ServerComponent {

public class InstalledPluginCenterFactory implements ServerComponent {

private final PluginDeployer pluginDeployer;
private final PluginReferentialMetadataConverter pluginReferentialMetadataConverter;
private PluginRepository pluginRepository;
private Version sonarVersion;
private PluginCenter installedPluginCenter;
private final PluginRepository pluginRepository;
private PluginReferential installedPluginReferential;

public InstalledPluginCenterFactory(PluginRepository pluginRepository, Server server, PluginDeployer pluginDeployer,
PluginReferentialMetadataConverter pluginReferentialMetadataConverter) {
public InstalledPluginReferentialFactory(PluginRepository pluginRepository, PluginReferentialMetadataConverter pluginReferentialMetadataConverter) {
this.pluginRepository = pluginRepository;
this.pluginDeployer = pluginDeployer;
this.pluginReferentialMetadataConverter = pluginReferentialMetadataConverter;
this.sonarVersion = Version.create(server.getVersion());
}

public PluginCenter getPluginCenter() {
if (installedPluginCenter == null) {
init();
}
return installedPluginCenter;
}

public PluginReferential getInstalledPluginReferential() {
return pluginReferentialMetadataConverter.getInstalledPluginReferential(pluginRepository.getMetadata());
}

private void init() {
PluginReferential installedPluginReferential = getInstalledPluginReferential();
installedPluginCenter = PluginCenter.createForInstalledPlugins(installedPluginReferential, sonarVersion).setDate(new Date());
if (installedPluginReferential == null) {
installedPluginReferential = pluginReferentialMetadataConverter.getInstalledPluginReferential(pluginRepository.getMetadata());
}
return installedPluginReferential;
}

}

+ 1
- 1
sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java View File

@@ -90,7 +90,7 @@ public class PluginDownloader implements ServerComponent {
}

public void download(String pluginKey, Version version) {
for (Release release : updateCenterMatrixFactory.getPluginCenter(false).findInstallablePlugins(pluginKey, version)) {
for (Release release : updateCenterMatrixFactory.getUpdateCenter(false).findInstallablePlugins(pluginKey, version)) {
try {
downloadRelease(release);


+ 6
- 6
sonar-server/src/main/java/org/sonar/server/plugins/PluginReferentialMetadataConverter.java View File

@@ -40,16 +40,16 @@ public class PluginReferentialMetadataConverter implements ServerComponent {
this.sonarVersion = Version.create(server.getVersion());
}

public PluginReferential getInstalledPluginReferential(Collection<PluginMetadata> pluginMetadatas) {
List<PluginManifest> pluginManifestList = getPluginManifestList(pluginMetadatas);
public PluginReferential getInstalledPluginReferential(Collection<PluginMetadata> metadata) {
List<PluginManifest> pluginManifestList = getPluginManifestList(metadata);
return PluginReferentialManifestConverter.fromPluginManifests(pluginManifestList, sonarVersion);
}

private List<PluginManifest> getPluginManifestList(Collection<PluginMetadata> pluginMetadatas) {
private List<PluginManifest> getPluginManifestList(Collection<PluginMetadata> metadata) {
List<PluginManifest> pluginManifestList = newArrayList();
for (PluginMetadata metadata : pluginMetadatas) {
if (!metadata.isCore()) {
pluginManifestList.add(toPluginManifest(metadata));
for (PluginMetadata plugin : metadata) {
if (!plugin.isCore()) {
pluginManifestList.add(toPluginManifest(plugin));
}
}
return pluginManifestList;

+ 11
- 11
sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java View File

@@ -28,8 +28,8 @@ import org.sonar.api.PropertyType;
import org.sonar.api.ServerComponent;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.UriReader;
import org.sonar.updatecenter.common.PluginReferential;
import org.sonar.updatecenter.common.PluginReferentialDeserializer;
import org.sonar.updatecenter.common.UpdateCenter;
import org.sonar.updatecenter.common.UpdateCenterDeserializer;

import java.io.InputStream;
import java.net.URI;
@@ -64,7 +64,7 @@ public class UpdateCenterClient implements ServerComponent {
public static final String URL_PROPERTY = "sonar.updatecenter.url";
public static final int PERIOD_IN_MILLISECONDS = 60 * 60 * 1000;
private URI uri;
private PluginReferential pluginReferential = null;
private UpdateCenter pluginCenter = null;
private long lastRefreshDate = 0;
private UriReader uriReader;

@@ -74,16 +74,16 @@ public class UpdateCenterClient implements ServerComponent {
LoggerFactory.getLogger(getClass()).info("Update center: " + uriReader.description(uri));
}

public PluginReferential getPluginReferential() {
return getPlugins(false);
public UpdateCenter getUpdateCenter() {
return getUpdateCenter(false);
}

public PluginReferential getPlugins(boolean forceRefresh) {
if (pluginReferential == null || forceRefresh || needsRefresh()) {
pluginReferential = init();
public UpdateCenter getUpdateCenter(boolean forceRefresh) {
if (pluginCenter == null || forceRefresh || needsRefresh()) {
pluginCenter = init();
lastRefreshDate = System.currentTimeMillis();
}
return pluginReferential;
return pluginCenter;
}

public Date getLastRefreshDate() {
@@ -94,14 +94,14 @@ public class UpdateCenterClient implements ServerComponent {
return lastRefreshDate + PERIOD_IN_MILLISECONDS < System.currentTimeMillis();
}

private PluginReferential init() {
private UpdateCenter init() {
InputStream input = null;
try {
String content = uriReader.readString(uri, Charsets.UTF_8);
java.util.Properties properties = new java.util.Properties();
input = IOUtils.toInputStream(content, Charsets.UTF_8.name());
properties.load(input);
return PluginReferentialDeserializer.fromProperties(properties);
return UpdateCenterDeserializer.fromProperties(properties);

} catch (Exception e) {
LoggerFactory.getLogger(getClass()).error("Fail to connect to update center", e);

+ 9
- 11
sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterMatrixFactory.java View File

@@ -21,8 +21,7 @@ package org.sonar.server.plugins;

import org.sonar.api.ServerComponent;
import org.sonar.api.platform.Server;
import org.sonar.updatecenter.common.PluginCenter;
import org.sonar.updatecenter.common.PluginReferential;
import org.sonar.updatecenter.common.UpdateCenter;
import org.sonar.updatecenter.common.Version;

/**
@@ -32,20 +31,19 @@ public final class UpdateCenterMatrixFactory implements ServerComponent {

private UpdateCenterClient centerClient;
private Version sonarVersion;
private InstalledPluginCenterFactory installedPluginCenterFactory;
private InstalledPluginReferentialFactory installedPluginReferentialFactory;

public UpdateCenterMatrixFactory(UpdateCenterClient centerClient, InstalledPluginCenterFactory installedPluginCenterFactory, Server server) {
public UpdateCenterMatrixFactory(UpdateCenterClient centerClient, InstalledPluginReferentialFactory installedPluginReferentialFactory, Server server) {
this.centerClient = centerClient;
this.installedPluginCenterFactory = installedPluginCenterFactory;
this.installedPluginReferentialFactory = installedPluginReferentialFactory;
this.sonarVersion = Version.create(server.getVersion());
}

public PluginCenter getPluginCenter(boolean refreshUpdateCenter) {
PluginReferential updateCenterPluginReferential = centerClient.getPlugins(refreshUpdateCenter);
if (updateCenterPluginReferential != null) {
return PluginCenter.create(updateCenterPluginReferential,
installedPluginCenterFactory.getInstalledPluginReferential(),
sonarVersion)
public UpdateCenter getUpdateCenter(boolean refreshUpdateCenter) {
UpdateCenter updatePluginCenter = centerClient.getUpdateCenter(refreshUpdateCenter);
if (updatePluginCenter != null) {
return updatePluginCenter.setInstalledSonarVersion(sonarVersion).registerInstalledPlugins(
installedPluginReferentialFactory.getInstalledPluginReferential())
.setDate(centerClient.getLastRefreshDate());
} else {
return null;

+ 10
- 26
sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java View File

@@ -41,11 +41,7 @@ import org.sonar.api.test.MutableTestable;
import org.sonar.api.test.TestPlan;
import org.sonar.api.test.Testable;
import org.sonar.api.utils.ValidationMessages;
import org.sonar.api.web.Footer;
import org.sonar.api.web.NavigationSection;
import org.sonar.api.web.Page;
import org.sonar.api.web.RubyRailsWebservice;
import org.sonar.api.web.Widget;
import org.sonar.api.web.*;
import org.sonar.api.workflow.Review;
import org.sonar.api.workflow.internal.DefaultReview;
import org.sonar.api.workflow.internal.DefaultWorkflowContext;
@@ -66,30 +62,18 @@ import org.sonar.markdown.Markdown;
import org.sonar.server.configuration.Backup;
import org.sonar.server.configuration.ProfilesManager;
import org.sonar.server.notifications.reviews.ReviewsNotificationManager;
import org.sonar.server.platform.NewUserNotifier;
import org.sonar.server.platform.Platform;
import org.sonar.server.platform.ServerIdGenerator;
import org.sonar.server.platform.ServerSettings;
import org.sonar.server.platform.SettingsChangeNotifier;
import org.sonar.server.plugins.DefaultServerPluginRepository;
import org.sonar.server.plugins.InstalledPluginCenterFactory;
import org.sonar.server.plugins.PluginDeployer;
import org.sonar.server.plugins.PluginDownloader;
import org.sonar.server.plugins.UpdateCenterMatrixFactory;
import org.sonar.server.platform.*;
import org.sonar.server.plugins.*;
import org.sonar.server.rules.ProfilesConsole;
import org.sonar.server.rules.RulesConsole;
import org.sonar.updatecenter.common.PluginCenter;
import org.sonar.updatecenter.common.PluginReferential;
import org.sonar.updatecenter.common.UpdateCenter;
import org.sonar.updatecenter.common.Version;

import javax.annotation.Nullable;

import java.net.InetAddress;
import java.sql.Connection;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

import static com.google.common.collect.Lists.newArrayList;

@@ -189,12 +173,12 @@ public final class JRubyFacade {
return get(PluginDeployer.class).getUninstalls();
}

public PluginCenter getUpdatePluginCenter(boolean forceReload) {
return get(UpdateCenterMatrixFactory.class).getPluginCenter(forceReload);
public UpdateCenter getUpdatePluginCenter(boolean forceReload) {
return get(UpdateCenterMatrixFactory.class).getUpdateCenter(forceReload);
}

public PluginCenter getInstalledPluginCenter() {
return get(InstalledPluginCenterFactory.class).getPluginCenter();
public PluginReferential getInstalledPluginReferential() {
return get(InstalledPluginReferentialFactory.class).getInstalledPluginReferential();
}

// PLUGINS ------------------------------------------------------------------

+ 1
- 3
sonar-server/src/main/webapp/WEB-INF/app/controllers/updatecenter_controller.rb View File

@@ -137,9 +137,7 @@ class UpdatecenterController < ApplicationController
def load_plugin_center
@update_plugin_center = java_facade.getUpdatePluginCenter(params[:reload]=='true')
@update_center_referential = @update_plugin_center.updateCenterPluginReferential

@installed_plugin_center = java_facade.getInstalledPluginCenter()
@installed_plugin_referential = @installed_plugin_center.installedPluginReferential
@installed_plugin_referential = java_facade.installedPluginReferential
end

def updatecenter_activated

+ 8
- 13
sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterClientTest.java View File

@@ -25,19 +25,14 @@ import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.UriReader;
import org.sonar.updatecenter.common.PluginReferential;
import org.sonar.updatecenter.common.UpdateCenter;
import org.sonar.updatecenter.common.Version;

import java.net.URI;
import java.net.URISyntaxException;

import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

public class UpdateCenterClientTest {

@@ -55,7 +50,7 @@ public class UpdateCenterClientTest {
@Test
public void downloadUpdateCenter() throws URISyntaxException {
when(reader.readString(new URI(BASE_URL), Charsets.UTF_8)).thenReturn("sonar.versions=2.2,2.3");
PluginReferential plugins = client.getPluginReferential();
UpdateCenter plugins = client.getUpdateCenter();
verify(reader, times(1)).readString(new URI(BASE_URL), Charsets.UTF_8);
assertThat(plugins.getSonar().getVersions()).containsOnly(Version.create("2.2"), Version.create("2.3"));
assertThat(client.getLastRefreshDate()).isNotNull();
@@ -69,15 +64,15 @@ public class UpdateCenterClientTest {
@Test
public void ignore_connection_errors() {
when(reader.readString(any(URI.class), eq(Charsets.UTF_8))).thenThrow(new SonarException());
assertThat(client.getPluginReferential()).isNull();
assertThat(client.getUpdateCenter()).isNull();
}

@Test
public void cache_data() throws Exception {
when(reader.readString(new URI(BASE_URL), Charsets.UTF_8)).thenReturn("sonar.versions=2.2,2.3");

client.getPluginReferential();
client.getPluginReferential();
client.getUpdateCenter();
client.getUpdateCenter();

verify(reader, times(1)).readString(new URI(BASE_URL), Charsets.UTF_8);
}
@@ -86,8 +81,8 @@ public class UpdateCenterClientTest {
public void forceRefresh() throws Exception {
when(reader.readString(new URI(BASE_URL), Charsets.UTF_8)).thenReturn("sonar.versions=2.2,2.3");

client.getPluginReferential();
client.getPlugins(true);
client.getUpdateCenter();
client.getUpdateCenter(true);

verify(reader, times(2)).readString(new URI(BASE_URL), Charsets.UTF_8);
}

Loading…
Cancel
Save