diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-03-22 19:30:15 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-03-22 19:31:59 +0100 |
commit | 46464911a15220d9ca866488922d1645fa9f5e65 (patch) | |
tree | 1f4f9af72f5dfc6fc5d4350baeefed918f4fc734 /sonar-server/src/main/java | |
parent | c152a8c09c6dc62a7cc102721c1a848a493fb68d (diff) | |
download | sonarqube-46464911a15220d9ca866488922d1645fa9f5e65.tar.gz sonarqube-46464911a15220d9ca866488922d1645fa9f5e65.zip |
SONAR-3224 remove the need for server restart
Diffstat (limited to 'sonar-server/src/main/java')
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java | 16 | ||||
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/platform/Platform.java | 9 | ||||
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/plugins/ApplicationDeployer.java (renamed from sonar-server/src/main/java/org/sonar/server/startup/ApplicationDeployer.java) | 49 | ||||
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/plugins/ClassLoaderUtils.java (renamed from sonar-server/src/main/java/org/sonar/server/startup/ClassLoaderUtils.java) | 2 | ||||
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java | 10 |
5 files changed, 46 insertions, 40 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java b/sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java index 17f66d2abbb..0560513eff2 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java @@ -27,7 +27,7 @@ import org.slf4j.LoggerFactory; import org.sonar.api.CoreProperties; import org.sonar.api.config.Settings; import org.sonar.api.platform.ServerFileSystem; -import org.sonar.jpa.session.DatabaseConnector; +import org.sonar.core.persistence.Database; import java.io.File; import java.io.FileFilter; @@ -45,12 +45,12 @@ public class DefaultServerFileSystem implements ServerFileSystem { private static final Logger LOGGER = LoggerFactory.getLogger(DefaultServerFileSystem.class); - private DatabaseConnector databaseConnector; + private Database database; private File deployDir; private File homeDir; - public DefaultServerFileSystem(DatabaseConnector databaseConnector, Settings settings) { - this.databaseConnector = databaseConnector; + public DefaultServerFileSystem(Database database, Settings settings) { + this.database = database; this.homeDir = new File(settings.getString(CoreProperties.SONAR_HOME)); String deployPath = settings.getString(ServerSettings.DEPLOY_DIR); @@ -62,8 +62,8 @@ public class DefaultServerFileSystem implements ServerFileSystem { /** * for unit tests */ - public DefaultServerFileSystem(DatabaseConnector databaseConnector, File homeDir, File deployDir) { - this.databaseConnector = databaseConnector; + public DefaultServerFileSystem(Database database, File homeDir, File deployDir) { + this.database = database; this.deployDir = deployDir; this.homeDir = homeDir; } @@ -102,7 +102,7 @@ public class DefaultServerFileSystem implements ServerFileSystem { public File getHomeDir() { return homeDir; } - + public File getTempDir() { return new File(homeDir, "temp"); } @@ -128,7 +128,7 @@ public class DefaultServerFileSystem implements ServerFileSystem { } public File getJdbcDriver() { - String dialect = databaseConnector.getDialect().getId(); + String dialect = database.getDialect().getId(); File dir = new File(getHomeDir(), "/extensions/jdbc-driver/" + dialect + "/"); List<File> jars = getFiles(dir, "jar"); if (jars.isEmpty()) { diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java index f479bab8123..682cd208416 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java @@ -141,6 +141,10 @@ public final class Platform { for (Class daoClass : DaoUtils.getDaoClasses()) { rootContainer.addSingleton(daoClass); } + rootContainer.addSingleton(PluginDeployer.class); + rootContainer.addSingleton(DefaultServerPluginRepository.class); + rootContainer.addSingleton(DefaultServerFileSystem.class); + rootContainer.addSingleton(ApplicationDeployer.class); rootContainer.startComponents(); } @@ -153,10 +157,8 @@ public final class Platform { coreContainer = rootContainer.createChild(); coreContainer.addSingleton(ServerDatabaseSettingsLoader.class); coreContainer.addSingleton(DefaultDatabaseConnector.class); - coreContainer.addSingleton(PluginDeployer.class); - coreContainer.addSingleton(DefaultServerPluginRepository.class); + coreContainer.addSingleton(ServerExtensionInstaller.class); - coreContainer.addSingleton(DefaultServerFileSystem.class); coreContainer.addSingleton(ThreadLocalDatabaseSessionFactory.class); coreContainer.addPicoAdapter(new DatabaseSessionProvider()); coreContainer.startComponents(); @@ -220,7 +222,6 @@ public final class Platform { private void executeStartupTasks() { ComponentContainer startupContainer = servicesContainer.createChild(); startupContainer.addSingleton(GwtPublisher.class); - startupContainer.addSingleton(ApplicationDeployer.class); startupContainer.addSingleton(RegisterMetrics.class); startupContainer.addSingleton(RegisterRules.class); startupContainer.addSingleton(RegisterProvidedProfiles.class); diff --git a/sonar-server/src/main/java/org/sonar/server/startup/ApplicationDeployer.java b/sonar-server/src/main/java/org/sonar/server/plugins/ApplicationDeployer.java index 5d3165abbbf..ea22a3dae35 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/ApplicationDeployer.java +++ b/sonar-server/src/main/java/org/sonar/server/plugins/ApplicationDeployer.java @@ -17,7 +17,7 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.server.startup; +package org.sonar.server.plugins; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; @@ -25,8 +25,10 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.sonar.api.platform.PluginMetadata; +import org.sonar.api.platform.PluginRepository; import org.sonar.api.platform.ServerFileSystem; -import org.sonar.api.web.RubyRailsApp; +import org.sonar.server.plugins.ClassLoaderUtils; import javax.annotation.Nullable; import java.io.File; @@ -40,17 +42,14 @@ import java.io.IOException; */ public class ApplicationDeployer { private static final Logger LOG = LoggerFactory.getLogger(ApplicationDeployer.class); + private static final String ROR_PATH = "org/sonar/ror/"; private ServerFileSystem fileSystem; - private RubyRailsApp[] apps; + private PluginRepository pluginRepository; - public ApplicationDeployer(ServerFileSystem fileSystem, RubyRailsApp[] apps) { + public ApplicationDeployer(ServerFileSystem fileSystem, PluginRepository pluginRepository) { this.fileSystem = fileSystem; - this.apps = apps; - } - - public ApplicationDeployer(ServerFileSystem fileSystem) { - this(fileSystem, new RubyRailsApp[0]); + this.pluginRepository = pluginRepository; } public void start() throws IOException { @@ -61,11 +60,12 @@ public class ApplicationDeployer { LOG.info("Deploy Ruby on Rails applications"); File appsDir = prepareRubyRailsRootDirectory(); - for (final RubyRailsApp app : apps) { + for (PluginMetadata pluginMetadata : pluginRepository.getMetadata()) { + String pluginKey = pluginMetadata.getKey(); try { - deployRubyRailsApp(appsDir, app, app.getClass().getClassLoader()); + deployRubyRailsApp(appsDir, pluginKey, pluginRepository.getPlugin(pluginKey).getClass().getClassLoader()); } catch (Exception e) { - throw new IllegalStateException("Fail to deploy Ruby on Rails application: " + app.getKey(), e); + throw new IllegalStateException("Fail to deploy Ruby on Rails application: " + pluginKey, e); } } } @@ -78,24 +78,29 @@ public class ApplicationDeployer { } @VisibleForTesting - static void deployRubyRailsApp(File appsDir, final RubyRailsApp app, ClassLoader appClassLoader) { - LOG.debug("Deploy: " + app.getKey()); - File appDir = new File(appsDir, app.getKey()); - if (appDir.exists()) { - LOG.error("Ruby on Rails application already exists: " + app.getKey()); - } else { - ClassLoaderUtils.copyResources(appClassLoader, app.getPath(), appDir, new Function<String, String>() { + static void deployRubyRailsApp(File appsDir, final String pluginKey, ClassLoader appClassLoader) { + if (hasRubyRailsApp(pluginKey, appClassLoader)) { + LOG.info("Deploy app: " + pluginKey); + File appDir = new File(appsDir, pluginKey); + ClassLoaderUtils.copyResources(appClassLoader, ROR_PATH + pluginKey, appDir, new Function<String, String>() { @Override public String apply(@Nullable String relativePath) { - // relativePath format is: org/sonar/sqale/app/controllers/foo_controller.rb - // app path is: /org/sonar/sqale + // Relocate the deployed files : + // relativePath format is: org/sonar/ror/sqale/app/controllers/foo_controller.rb + // app path is: org/sonar/ror/sqale // -> deployed file is app/controllers/foo_controller.rb - return StringUtils.substringAfter(relativePath, StringUtils.removeStart(app.getPath(), "/") + "/"); + return StringUtils.substringAfter(relativePath, pluginKey + "/"); } }); } } + @VisibleForTesting + static boolean hasRubyRailsApp(String pluginKey, ClassLoader classLoader) { + return classLoader.getResource(ROR_PATH + pluginKey) != null; + + } + private void prepareDir(File appsDir) { if (appsDir.exists() && appsDir.isDirectory()) { try { diff --git a/sonar-server/src/main/java/org/sonar/server/startup/ClassLoaderUtils.java b/sonar-server/src/main/java/org/sonar/server/plugins/ClassLoaderUtils.java index 95e95b26cff..66bfed510cb 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/ClassLoaderUtils.java +++ b/sonar-server/src/main/java/org/sonar/server/plugins/ClassLoaderUtils.java @@ -17,7 +17,7 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.server.startup; +package org.sonar.server.plugins; import com.google.common.base.*; import com.google.common.collect.Lists; diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java b/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java index d098265f977..df05348967d 100644 --- a/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java +++ b/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java @@ -47,15 +47,15 @@ public class PluginDeployer implements ServerComponent { private DefaultServerFileSystem fileSystem; private Map<String, PluginMetadata> pluginByKeys = Maps.newHashMap(); - private PluginInstaller extractor; + private PluginInstaller installer; public PluginDeployer(DefaultServerFileSystem fileSystem) { this(fileSystem, new PluginInstaller()); } - PluginDeployer(DefaultServerFileSystem fileSystem, PluginInstaller extractor) { + PluginDeployer(DefaultServerFileSystem fileSystem, PluginInstaller installer) { this.fileSystem = fileSystem; - this.extractor = extractor; + this.installer = installer; } public void start() throws IOException { @@ -90,7 +90,7 @@ public class PluginDeployer implements ServerComponent { } private void registerPlugin(File file, boolean isCore, boolean canDelete) throws IOException { - DefaultPluginMetadata metadata = extractor.extractMetadata(file, isCore); + DefaultPluginMetadata metadata = installer.extractMetadata(file, isCore); if (StringUtils.isNotBlank(metadata.getKey())) { PluginMetadata existing = pluginByKeys.get(metadata.getKey()); if (existing != null) { @@ -198,7 +198,7 @@ public class PluginDeployer implements ServerComponent { plugin.addDeprecatedExtension(deprecatedExtension); } - extractor.install(plugin, pluginDeployDir); + installer.install(plugin, pluginDeployDir); } catch (IOException e) { throw new RuntimeException("Fail to deploy the plugin " + plugin, e); |