diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-01-19 11:00:29 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-01-24 18:36:49 +0100 |
commit | a44a90d1b181b92a8d7e85a7c945518ed2bca38b (patch) | |
tree | 30cd4165c211cd992a8b69c7f3a3087732cea8c3 /server | |
parent | cb1bf8f96e441de011ad58f6495049933a9dbace (diff) | |
download | sonarqube-a44a90d1b181b92a8d7e85a7c945518ed2bca38b.tar.gz sonarqube-a44a90d1b181b92a8d7e85a7c945518ed2bca38b.zip |
SONAR-8684 Remove Java classes related to rails
Diffstat (limited to 'server')
37 files changed, 21 insertions, 1588 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java b/server/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java index 75cb463c396..69c9b1425ad 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java @@ -21,8 +21,6 @@ package org.sonar.server.component; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import org.sonar.api.component.Component; -import org.sonar.api.component.RubyComponentService; import org.sonar.api.resources.Qualifiers; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -33,7 +31,10 @@ import org.sonar.server.permission.PermissionTemplateService; import static org.sonar.server.component.NewComponent.newComponentBuilder; -public class DefaultRubyComponentService implements RubyComponentService { +/** + * Used in GOV + */ +public class DefaultRubyComponentService { private final DbClient dbClient; private final ComponentService componentService; @@ -51,25 +52,11 @@ public class DefaultRubyComponentService implements RubyComponentService { this.defaultOrganizationProvider = defaultOrganizationProvider; } - @Override - @CheckForNull - public Component findByKey(String key) { - try (DbSession dbSession = dbClient.openSession(false)) { - return dbClient.componentDao().selectByKey(dbSession, key).orNull(); - } - } - // Used in GOV @CheckForNull public Long createComponent(String key, String name, String qualifier) { - return createComponent(key, null, name, qualifier); - } - - // Used in rails - @CheckForNull - public Long createComponent(String key, @Nullable String branch, String name, @Nullable String qualifier) { try (DbSession dbSession = dbClient.openSession(false)) { - return createComponent(dbSession, key, branch, name, qualifier); + return createComponent(dbSession, key, null, name, qualifier); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/CreateAction.java index 023ed3b06b0..1e9a45fc59c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/CreateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/CreateAction.java @@ -33,7 +33,6 @@ import org.sonar.db.MyBatis; import org.sonar.db.measure.custom.CustomMeasureDto; import org.sonar.db.metric.MetricDto; import org.sonar.server.exceptions.BadRequestException; -import org.sonar.server.ruby.RubyBridge; import org.sonar.server.user.UserSession; import static org.sonar.server.util.MetricKeyValidator.checkMetricKeyFormat; @@ -55,12 +54,10 @@ public class CreateAction implements MetricsWsAction { private final DbClient dbClient; private final UserSession userSession; - private final RubyBridge rubyBridge; - public CreateAction(DbClient dbClient, UserSession userSession, RubyBridge rubyBridge) { + public CreateAction(DbClient dbClient, UserSession userSession) { this.dbClient = dbClient; this.userSession = userSession; - this.rubyBridge = rubyBridge; } @Override @@ -116,7 +113,6 @@ public class CreateAction implements MetricsWsAction { JsonWriter json = response.newJsonWriter(); writeMetric(json, metricInDb); json.close(); - rubyBridge.metricCache().invalidate(); } finally { MyBatis.closeQuietly(dbSession); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/DeleteAction.java b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/DeleteAction.java index 8e66e5389d8..9973cc534d3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/DeleteAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/DeleteAction.java @@ -29,7 +29,6 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.MyBatis; import org.sonar.db.metric.MetricDto; -import org.sonar.server.ruby.RubyBridge; import org.sonar.server.user.UserSession; import static com.google.common.base.Preconditions.checkArgument; @@ -40,12 +39,10 @@ public class DeleteAction implements MetricsWsAction { private final DbClient dbClient; private final UserSession userSession; - private final RubyBridge rubyBridge; - public DeleteAction(DbClient dbClient, UserSession userSession, RubyBridge rubyBridge) { + public DeleteAction(DbClient dbClient, UserSession userSession) { this.dbClient = dbClient; this.userSession = userSession; - this.rubyBridge = rubyBridge; } @Override @@ -79,7 +76,6 @@ public class DeleteAction implements MetricsWsAction { } response.noContent(); - rubyBridge.metricCache().invalidate(); } private List<Integer> loadIds(DbSession dbSession, Request request) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/UpdateAction.java b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/UpdateAction.java index d9b5f493833..39d5eedb3fe 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/UpdateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/UpdateAction.java @@ -33,7 +33,6 @@ import org.sonar.db.MyBatis; import org.sonar.db.measure.custom.CustomMeasureDto; import org.sonar.db.metric.MetricDto; import org.sonar.server.exceptions.BadRequestException; -import org.sonar.server.ruby.RubyBridge; import org.sonar.server.user.UserSession; import org.sonar.server.util.MetricKeyValidator; @@ -56,12 +55,10 @@ public class UpdateAction implements MetricsWsAction { private final DbClient dbClient; private final UserSession userSession; - private final RubyBridge rubyBridge; - public UpdateAction(DbClient dbClient, UserSession userSession, RubyBridge rubyBridge) { + public UpdateAction(DbClient dbClient, UserSession userSession) { this.dbClient = dbClient; this.userSession = userSession; - this.rubyBridge = rubyBridge; } @Override @@ -113,7 +110,6 @@ public class UpdateAction implements MetricsWsAction { JsonWriter json = response.newJsonWriter(); writeMetric(json, metricInDb); json.close(); - rubyBridge.metricCache().invalidate(); } finally { MyBatis.closeQuietly(dbSession); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/db/migration/DatabaseMigrationImpl.java b/server/sonar-server/src/main/java/org/sonar/server/platform/db/migration/DatabaseMigrationImpl.java index db6f61bab79..a594b8ed7cc 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/db/migration/DatabaseMigrationImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/db/migration/DatabaseMigrationImpl.java @@ -28,7 +28,6 @@ import org.sonar.core.util.logs.Profiler; import org.sonar.server.platform.Platform; import org.sonar.server.platform.db.migration.engine.MigrationEngine; import org.sonar.server.platform.db.migration.step.MigrationStepExecutionException; -import org.sonar.server.ruby.RubyBridge; import static org.sonar.server.platform.db.migration.DatabaseMigrationState.Status; @@ -43,7 +42,6 @@ public class DatabaseMigrationImpl implements DatabaseMigration { * ExecutorService implements threads management. */ private final DatabaseMigrationExecutorService executorService; - private final RubyBridge rubyBridge; private final MigrationEngine migrationEngine; private final Platform platform; private final MutableDatabaseMigrationState migrationState; @@ -62,10 +60,9 @@ public class DatabaseMigrationImpl implements DatabaseMigration { private final AtomicBoolean running = new AtomicBoolean(false); public DatabaseMigrationImpl(DatabaseMigrationExecutorService executorService, MutableDatabaseMigrationState migrationState, - RubyBridge rubyBridge, MigrationEngine migrationEngine, Platform platform) { + MigrationEngine migrationEngine, Platform platform) { this.executorService = executorService; this.migrationState = migrationState; - this.rubyBridge = rubyBridge; this.migrationEngine = migrationEngine; this.platform = platform; } @@ -107,7 +104,6 @@ public class DatabaseMigrationImpl implements DatabaseMigration { profiler.startInfo("Starting DB Migration and container restart"); doUpgradeDb(); doRestartContainer(); - doRecreateWebRoutes(); migrationState.setStatus(Status.SUCCEEDED); profiler.stopInfo("DB Migration and container restart: success"); } catch (MigrationStepExecutionException e) { @@ -142,11 +138,4 @@ public class DatabaseMigrationImpl implements DatabaseMigration { profiler.stopTrace("Container restarted successfully"); } - private void doRecreateWebRoutes() { - Profiler profiler = Profiler.createIfTrace(LOGGER); - profiler.startTrace("Recreating web routes"); - rubyBridge.railsRoutes().recreate(); - profiler.startTrace("Routes recreated successfully"); - } - } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java index 583ce633d84..a62db05f2a9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java @@ -50,7 +50,6 @@ import org.sonar.server.platform.cluster.ClusterImpl; import org.sonar.server.platform.cluster.ClusterProperties; import org.sonar.server.platform.db.EmbeddedDatabaseFactory; import org.sonar.server.qualityprofile.index.ActiveRuleIndex; -import org.sonar.server.ruby.PlatformRackBridge; import org.sonar.server.rule.index.RuleIndex; import org.sonar.server.search.EsSearchModule; import org.sonar.server.setting.ThreadLocalSettings; @@ -99,9 +98,6 @@ public class PlatformLevel1 extends PlatformLevel { new TempFolderProvider(), System2.INSTANCE, - // rack bridges - PlatformRackBridge.class, - // user session ThreadLocalUserSession.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel2.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel2.java index 827c7c98f60..77b360f8b0e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel2.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel2.java @@ -35,13 +35,10 @@ import org.sonar.server.platform.db.migration.charset.DatabaseCharsetChecker; import org.sonar.server.platform.db.migration.history.MigrationHistoryTable; import org.sonar.server.platform.db.migration.history.MigrationHistoryTableImpl; import org.sonar.server.platform.db.migration.version.DatabaseVersion; -import org.sonar.server.platform.web.RailsAppsDeployer; import org.sonar.server.plugins.InstalledPluginReferentialFactory; import org.sonar.server.plugins.ServerPluginJarExploder; import org.sonar.server.plugins.ServerPluginRepository; import org.sonar.server.plugins.WebServerExtensionInstaller; -import org.sonar.server.ruby.PlatformRubyBridge; -import org.sonar.server.ui.JRubyI18n; public class PlatformLevel2 extends PlatformLevel { public PlatformLevel2(PlatformLevel parent) { @@ -58,10 +55,6 @@ public class PlatformLevel2 extends PlatformLevel { new StartupMetadataProvider(), DefaultServerUpgradeStatus.class, Durations.class, - JRubyI18n.class, - - // depends on Ruby - PlatformRubyBridge.class, // plugins ServerPluginRepository.class, @@ -72,7 +65,6 @@ public class PlatformLevel2 extends PlatformLevel { WebServerExtensionInstaller.class, // depends on plugins - RailsAppsDeployer.class, DefaultI18n.class, RuleI18nManager.class); diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index f2c05468e89..48008257cbb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -189,13 +189,12 @@ import org.sonar.server.test.index.TestIndexer; import org.sonar.server.test.ws.CoveredFilesAction; import org.sonar.server.test.ws.TestsWs; import org.sonar.server.text.MacroInterpreter; +import org.sonar.server.ui.DeprecatedViews; import org.sonar.server.ui.PageDecorations; import org.sonar.server.ui.PageRepository; -import org.sonar.server.ui.DeprecatedViews; import org.sonar.server.ui.ws.NavigationWsModule; import org.sonar.server.updatecenter.UpdateCenterModule; import org.sonar.server.user.DefaultUserFinder; -import org.sonar.server.user.DefaultUserService; import org.sonar.server.user.DeprecatedUserFinder; import org.sonar.server.user.NewUserNotifier; import org.sonar.server.user.SecurityRealmFactory; @@ -339,7 +338,6 @@ public class PlatformLevel4 extends PlatformLevel { DeprecatedUserFinder.class, NewUserNotifier.class, DefaultUserFinder.class, - DefaultUserService.class, UserIndexDefinition.class, UserIndexer.class, UserIndex.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/web/RailsAppsDeployer.java b/server/sonar-server/src/main/java/org/sonar/server/platform/web/RailsAppsDeployer.java deleted file mode 100644 index c280730d666..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/web/RailsAppsDeployer.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.platform.web; - -import com.google.common.annotations.VisibleForTesting; -import java.io.File; -import java.io.IOException; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringUtils; -import org.picocontainer.Startable; -import org.sonar.api.Plugin; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.core.platform.PluginInfo; -import org.sonar.core.platform.PluginRepository; -import org.sonar.server.platform.ServerFileSystem; -import org.sonar.server.util.ClassLoaderUtils; - -/** - * Ruby on Rails requires the files to be on filesystem but not in Java classpath (JAR). This component extracts - * all the needed files from plugins and copy them to $SONAR_HOME/temp - * - * @since 3.0 - */ -public class RailsAppsDeployer implements Startable { - - private static final Logger LOG = Loggers.get(RailsAppsDeployer.class); - private static final String ROR_PATH = "org/sonar/ror/"; - - private final ServerFileSystem fs; - private final PluginRepository pluginRepository; - - public RailsAppsDeployer(ServerFileSystem fs, PluginRepository pluginRepository) { - this.fs = fs; - this.pluginRepository = pluginRepository; - } - - @Override - public void start() { - LOG.info("Deploying Ruby on Rails applications"); - File appsDir = prepareRailsDirectory(); - - for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) { - String pluginKey = pluginInfo.getKey(); - Plugin plugin = pluginRepository.getPluginInstance(pluginKey); - try { - deployRailsApp(appsDir, pluginKey, plugin.getClass().getClassLoader()); - } catch (Exception e) { - throw new IllegalStateException(String.format("Fail to deploy Ruby on Rails application of plugin [%s]", pluginKey), e); - } - } - } - - @Override - public void stop() { - // do nothing - } - - @VisibleForTesting - File prepareRailsDirectory() { - File appsDir = new File(fs.getTempDir(), "ror"); - prepareDir(appsDir); - return appsDir; - } - - @VisibleForTesting - static void deployRailsApp(File appsDir, final String pluginKey, ClassLoader appClassLoader) { - if (hasRailsApp(pluginKey, appClassLoader)) { - LOG.info("Deploying app: " + pluginKey); - File appDir = new File(appsDir, pluginKey); - ClassLoaderUtils.copyResources(appClassLoader, pathToRubyInitFile(pluginKey), appDir, relativePath -> - // 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 - StringUtils.substringAfter(relativePath, pluginKey + "/") - ); - } - } - - private static String pathToRubyInitFile(String pluginKey) { - return ROR_PATH + pluginKey + "/init.rb"; - } - - @VisibleForTesting - static boolean hasRailsApp(String pluginKey, ClassLoader classLoader) { - return classLoader.getResource(pathToRubyInitFile(pluginKey)) != null; - } - - private void prepareDir(File appsDir) { - if (appsDir.exists() && appsDir.isDirectory()) { - try { - org.sonar.core.util.FileUtils.deleteDirectory(appsDir); - } catch (IOException e) { - throw new IllegalStateException("Fail to delete temp directory: " + appsDir, e); - } - } - try { - FileUtils.forceMkdir(appsDir); - } catch (IOException e) { - throw new IllegalStateException("Fail to create temp directory: " + appsDir, e); - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/web/RegisterServletFilters.java b/server/sonar-server/src/main/java/org/sonar/server/platform/web/RegisterServletFilters.java index 3b0dba41233..7a650dd2316 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/web/RegisterServletFilters.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/web/RegisterServletFilters.java @@ -46,4 +46,3 @@ public class RegisterServletFilters { } } } - diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/web/RubyRailsContextListener.java b/server/sonar-server/src/main/java/org/sonar/server/platform/web/RubyRailsContextListener.java deleted file mode 100644 index bdc957b4269..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/web/RubyRailsContextListener.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.platform.web; - -import com.google.common.base.Throwables; -import javax.servlet.ServletContextEvent; -import org.jruby.rack.RackApplicationFactory; -import org.jruby.rack.rails.RailsServletContextListener; -import org.jruby.rack.servlet.ServletRackContext; - -/** - * Overriding {@link RailsServletContextListener} allows to disable initialization of Ruby on Rails - * environment when Java components fail to start. - * See https://jira.sonarsource.com/browse/SONAR-6740 - */ -public class RubyRailsContextListener extends RailsServletContextListener { - - @Override - public void contextInitialized(ServletContextEvent event) { - if (event.getServletContext().getAttribute(PlatformServletContextListener.STARTED_ATTRIBUTE) != null) { - super.contextInitialized(event); - } - } - - // Always stop server when an error is raised during startup. - // By default Rack only logs an error (see org.jruby.rack.RackServletContextListener#handleInitializationException()). - // Rack propagates exceptions if the properties jruby.rack.exception or jruby.rack.error are set to true. - // Unfortunately we didn't succeed in defining these properties, so the method is overridden here. - // Initial need: SONAR-6171 - @Override - protected void handleInitializationException(Exception e, RackApplicationFactory factory, ServletRackContext rackContext) { - throw Throwables.propagate(e); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/ruby/CallInvalidateMetricCache.java b/server/sonar-server/src/main/java/org/sonar/server/ruby/CallInvalidateMetricCache.java deleted file mode 100644 index cad96716be6..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/ruby/CallInvalidateMetricCache.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.ruby; - -public interface CallInvalidateMetricCache { - void callInvalidate(); -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/ruby/CallLoadJavaWebServices.java b/server/sonar-server/src/main/java/org/sonar/server/ruby/CallLoadJavaWebServices.java deleted file mode 100644 index 9cd1097a39e..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/ruby/CallLoadJavaWebServices.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.ruby; - -/** - * Interface which must be a top-level public class to be used by the Ruby engine but that hides name of the Ruby - * method in the Ruby script from the rest of the platform (only {@link RubyRailsRoutes} is known to the platform). - */ -public interface CallLoadJavaWebServices { - /** - * Java method that calls the call_upgrade_and_start method defined in the {@code call_load_java_web_services.rb} script. - */ - void callLoadJavaWebServices(); -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/ruby/PlatformRackBridge.java b/server/sonar-server/src/main/java/org/sonar/server/ruby/PlatformRackBridge.java deleted file mode 100644 index f52eda34e1c..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/ruby/PlatformRackBridge.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.ruby; - -import org.jruby.Ruby; -import org.jruby.rack.RackApplicationFactory; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; - -/** - * Implementation of {@link RackBridge} which get access to the Rack object through the {@link ServletContext}. - */ -public class PlatformRackBridge implements RackBridge { - public static final String RACK_FACTORY_ATTR_KEY = "rack.factory"; - private final ServletContext servletContext; - - public PlatformRackBridge(ServletContext servletContext) { - this.servletContext = servletContext; - } - - /** - * From {@link org.jruby.rack.RackServletContextListener#contextInitialized(ServletContextEvent)} implementation, we - * know that the {@link RackApplicationFactory} is stored in the {@link ServletContext} under the attribute key - * {@link #RACK_FACTORY_ATTR_KEY}. - * - * @return a {@link Ruby} object representing the runtime environment of the RoR application of the platform. - * - * @throws RuntimeException if the {@link RackApplicationFactory} can not be retrieved - */ - @Override - public Ruby getRubyRuntime() { - Object attribute = servletContext.getAttribute(RACK_FACTORY_ATTR_KEY); - if (!(attribute instanceof RackApplicationFactory)) { - throw new RuntimeException("Can not retrieve the RackApplicationFactory from ServletContext. " + - "Ruby runtime can not be retrieved"); - } - - RackApplicationFactory rackApplicationFactory = (RackApplicationFactory) attribute; - return rackApplicationFactory.getApplication().getRuntime(); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/ruby/PlatformRubyBridge.java b/server/sonar-server/src/main/java/org/sonar/server/ruby/PlatformRubyBridge.java deleted file mode 100644 index cabdf149442..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/ruby/PlatformRubyBridge.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.ruby; - -import java.io.IOException; -import java.io.InputStream; -import javax.annotation.Nullable; -import org.jruby.Ruby; -import org.jruby.RubyNil; -import org.jruby.embed.InvokeFailedException; -import org.jruby.javasupport.JavaEmbedUtils; -import org.jruby.javasupport.JavaUtil; -import org.jruby.runtime.builtin.IRubyObject; - -public class PlatformRubyBridge implements RubyBridge { - private static final String CALL_LOAD_JAVA_WEB_SERVICES_RB_FILENAME = "call_load_java_web_services.rb"; - private static final String CALL_INVALIDATE_METRIC_CACHE_RB_FILENAME = "call_invalidate_metric_cache.rb"; - - private final RackBridge rackBridge; - - public PlatformRubyBridge(RackBridge rackBridge) { - this.rackBridge = rackBridge; - } - - @Override - public RubyRailsRoutes railsRoutes() { - CallLoadJavaWebServices callLoadJavaWebServices = parseMethodScriptToInterface( - CALL_LOAD_JAVA_WEB_SERVICES_RB_FILENAME, CallLoadJavaWebServices.class - ); - - return callLoadJavaWebServices::callLoadJavaWebServices; - } - - @Override - public RubyMetricCache metricCache() { - CallInvalidateMetricCache callInvalidateMetricCache = parseMethodScriptToInterface( - CALL_INVALIDATE_METRIC_CACHE_RB_FILENAME, CallInvalidateMetricCache.class - ); - - return callInvalidateMetricCache::callInvalidate; - } - - /** - * Parses a Ruby script that defines a single method and returns an instance of the specified interface type as a - * wrapper to this Ruby method. - */ - private <T> T parseMethodScriptToInterface(String fileName, Class<T> clazz) { - try (InputStream in = getClass().getResourceAsStream(fileName)) { - Ruby rubyRuntime = rackBridge.getRubyRuntime(); - JavaEmbedUtils.EvalUnit evalUnit = JavaEmbedUtils.newRuntimeAdapter().parse(rubyRuntime, in, fileName, 0); - IRubyObject rubyObject = evalUnit.run(); - Object receiver = JavaEmbedUtils.rubyToJava(rubyObject); - T wrapper = getInstance(rubyRuntime, receiver, clazz); - return wrapper; - } catch (IOException e) { - throw new RuntimeException("Failed to load script " + fileName, e); - } - } - - /** - * Fork of method {@link org.jruby.embed.internal.EmbedRubyInterfaceAdapterImpl#getInstance(Object, Class)} - */ - @SuppressWarnings("unchecked") - public <T> T getInstance(Ruby runtime, @Nullable Object receiver, @Nullable Class<T> clazz) { - if (clazz == null || !clazz.isInterface()) { - return null; - } - Object o; - if (receiver == null || receiver instanceof RubyNil) { - o = JavaEmbedUtils.rubyToJava(runtime, runtime.getTopSelf(), clazz); - } else if (receiver instanceof IRubyObject) { - o = JavaEmbedUtils.rubyToJava(runtime, (IRubyObject) receiver, clazz); - } else { - IRubyObject rubyReceiver = JavaUtil.convertJavaToRuby(runtime, receiver); - o = JavaEmbedUtils.rubyToJava(runtime, rubyReceiver, clazz); - } - String name = clazz.getName(); - try { - Class<T> c = (Class<T>) Class.forName(name, true, o.getClass().getClassLoader()); - return c.cast(o); - } catch (ClassNotFoundException e) { - throw new InvokeFailedException(e); - } - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/ruby/RackBridge.java b/server/sonar-server/src/main/java/org/sonar/server/ruby/RackBridge.java deleted file mode 100644 index 9b03cfdbd88..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/ruby/RackBridge.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.ruby; - -import org.jruby.Ruby; - -/** - * Acts as a bridge between the Java application of the platform and the Rack application. - */ -public interface RackBridge { - /** - * Provides access to {@link Ruby} runtime instance created by the Rack application. - * @return - */ - Ruby getRubyRuntime(); -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/ruby/RubyBridge.java b/server/sonar-server/src/main/java/org/sonar/server/ruby/RubyBridge.java deleted file mode 100644 index 47cc44b0833..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/ruby/RubyBridge.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.ruby; - -/** - * This component acts as a bridge between a Ruby runtime and Java. Each method it defines creates a wrapping - * Java object which an underlying Ruby implementation. - */ -public interface RubyBridge { - - /** - * Returns a class that allows calling the (re)creation of web routes in Rails. - * - * @return a {@link RubyRailsRoutes} - */ - RubyRailsRoutes railsRoutes(); - - RubyMetricCache metricCache(); -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/ruby/RubyMetricCache.java b/server/sonar-server/src/main/java/org/sonar/server/ruby/RubyMetricCache.java deleted file mode 100644 index 06b3f7d51f0..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/ruby/RubyMetricCache.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.ruby; - -@FunctionalInterface -public interface RubyMetricCache { - void invalidate(); -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/ruby/RubyRailsRoutes.java b/server/sonar-server/src/main/java/org/sonar/server/ruby/RubyRailsRoutes.java deleted file mode 100644 index 3eb7ad03222..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/ruby/RubyRailsRoutes.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.ruby; - -@FunctionalInterface -public interface RubyRailsRoutes { - /** - * Triggers the (re)creation of web route in Ruby On Rails. - * <strong>This is not thread safe!</strong> - */ - void recreate(); -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/ruby/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/ruby/package-info.java deleted file mode 100644 index b232c0e777b..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/ruby/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.server.ruby; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/server/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java deleted file mode 100644 index 2bf2e38e9af..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.ui; - -import java.sql.Connection; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Optional; -import javax.annotation.Nullable; -import org.sonar.api.Plugin; -import org.sonar.api.config.PropertyDefinitions; -import org.sonar.api.config.Settings; -import org.sonar.api.resources.Language; -import org.sonar.api.resources.ResourceType; -import org.sonar.api.resources.ResourceTypes; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.web.RubyRailsWebservice; -import org.sonar.core.platform.ComponentContainer; -import org.sonar.core.platform.PluginInfo; -import org.sonar.core.platform.PluginRepository; -import org.sonar.core.timemachine.Periods; -import org.sonar.db.Database; -import org.sonar.db.DbClient; -import org.sonar.db.DbSession; -import org.sonar.db.property.PropertiesDao; -import org.sonar.db.property.PropertyDto; -import org.sonar.process.ProcessProperties; -import org.sonar.server.component.ComponentCleanerService; -import org.sonar.server.platform.PersistentSettings; -import org.sonar.server.platform.Platform; -import org.sonar.server.platform.db.migration.DatabaseMigrationState; -import org.sonar.server.platform.db.migration.version.DatabaseVersion; -import org.sonar.server.platform.ws.UpgradesAction; - -import static com.google.common.collect.Lists.newArrayList; -import static org.sonar.server.platform.db.migration.DatabaseMigrationState.Status; - -public final class JRubyFacade { - - private static final JRubyFacade SINGLETON = new JRubyFacade(); - - public static JRubyFacade getInstance() { - return SINGLETON; - } - - <T> T get(Class<T> componentType) { - return getContainer().getComponentByType(componentType); - } - - public Collection<ResourceType> getResourceTypes() { - return get(ResourceTypes.class).getAllOrdered(); - } - - public ResourceType getResourceType(String qualifier) { - return get(ResourceTypes.class).get(qualifier); - } - - public List<String> getQualifiersWithProperty(final String propertyKey) { - List<String> qualifiers = newArrayList(); - for (ResourceType type : getResourceTypes()) { - if (type.getBooleanProperty(propertyKey) == Boolean.TRUE) { - qualifiers.add(type.getQualifier()); - } - } - return qualifiers; - } - - public Collection<String> getResourceLeavesQualifiers(String qualifier) { - return get(ResourceTypes.class).getLeavesQualifiers(qualifier); - } - - public Collection<String> getResourceChildrenQualifiers(String qualifier) { - return get(ResourceTypes.class).getChildrenQualifiers(qualifier); - } - - // PLUGINS ------------------------------------------------------------------ - public PropertyDefinitions getPropertyDefinitions() { - return get(PropertyDefinitions.class); - } - - /** - * Used for WS api/updatecenter/installed_plugins, to be replaced by api/plugins/installed. - */ - public Collection<PluginInfo> getPluginInfos() { - return get(PluginRepository.class).getPluginInfos(); - } - - public Collection<RubyRailsWebservice> getRubyRailsWebservices() { - return getContainer().getComponentsByType(RubyRailsWebservice.class); - } - - public Collection<Language> getLanguages() { - return getContainer().getComponentsByType(Language.class); - } - - public Database getDatabase() { - return get(Database.class); - } - - public boolean isDbUptodate() { - return getContainer().getComponentByType(DatabaseVersion.class).getStatus() == DatabaseVersion.Status.UP_TO_DATE; - } - - /* PROFILES CONSOLE : RULES AND METRIC THRESHOLDS */ - - public void saveProperty(String key, @Nullable Long componentId, @Nullable Long userId, @Nullable String value) { - if (componentId == null && userId == null) { - get(PersistentSettings.class).saveProperty(key, value); - } else { - DbClient dbClient = get(DbClient.class); - PropertiesDao propertiesDao = dbClient.propertiesDao(); - - try (DbSession dbSession = dbClient.openSession(false)) { - if (value == null) { - propertiesDao.delete(dbSession, new PropertyDto().setKey(key).setResourceId(componentId).setUserId(userId)); - } else { - propertiesDao.saveProperty(dbSession, new PropertyDto().setKey(key).setResourceId(componentId).setUserId(userId).setValue(value)); - } - dbSession.commit(); - } - } - } - - public String getConfigurationValue(String key) { - return get(Settings.class).getString(key); - } - - public Connection getConnection() { - try { - return get(Database.class).getDataSource().getConnection(); - } catch (Exception e) { - /* activerecord does not correctly manage exceptions when connection can not be opened. */ - return null; - } - } - - public Object getComponentByClassname(String pluginKey, String className) { - Plugin plugin = get(PluginRepository.class).getPluginInstance(pluginKey); - try { - Class componentClass = plugin.getClass().getClassLoader().loadClass(className); - return get(componentClass); - } catch (ClassNotFoundException e) { - throw new IllegalStateException(String.format("Class [%s] not found in plugin [%s]", className, pluginKey), e); - } - } - - private JRubyI18n getJRubyI18n() { - return get(JRubyI18n.class); - } - - public String getMessage(String rubyLocale, String key, String defaultValue, Object... parameters) { - return getJRubyI18n().message(rubyLocale, key, defaultValue, parameters); - } - - /* - * /!\ Used by Views - */ - public void deleteResourceTree(String projectKey) { - try { - get(ComponentCleanerService.class).delete(projectKey); - } catch (RuntimeException e) { - Loggers.get(JRubyFacade.class).error("Fail to delete resource with key: " + projectKey, e); - throw e; - } - } - - public void logError(String message) { - Loggers.get(getClass()).error(message); - } - - public String getServerHome() { - return get(Settings.class).getString(ProcessProperties.PATH_HOME); - } - - public ComponentContainer getContainer() { - return Platform.getInstance().getContainer(); - } - - public String getPeriodLabel(int periodIndex) { - return get(Periods.class).label(periodIndex); - } - - public String getPeriodLabel(String mode, String param, Date date) { - return get(Periods.class).label(mode, param, date); - } - - public String getPeriodLabel(String mode, String param, String date) { - return get(Periods.class).label(mode, param, date); - } - - public String getPeriodAbbreviation(int periodIndex) { - return get(Periods.class).abbreviation(periodIndex); - } - - /** - * Checks whether the SQ instance is up and running (ie. not in safemode and with an up-to-date database). - * <p> - * This method duplicates most of the logic code written in {@link UpgradesAction} - * class. There is no need to refactor code to avoid this duplication since this method is only used by RoR code - * which will soon be replaced by pure JS code based on the {@link UpgradesAction} - * WebService. - * </p> - */ - public boolean isSonarAccessAllowed() { - ComponentContainer container = Platform.getInstance().getContainer(); - DatabaseMigrationState databaseMigrationState = container.getComponentByType(DatabaseMigrationState.class); - Status migrationStatus = databaseMigrationState.getStatus(); - if (migrationStatus == Status.RUNNING || migrationStatus == Status.FAILED) { - return false; - } - if (migrationStatus == Status.SUCCEEDED) { - return true; - } - - DatabaseVersion databaseVersion = container.getComponentByType(DatabaseVersion.class); - Optional<Long> currentVersion = databaseVersion.getVersion(); - if (!currentVersion.isPresent()) { - throw new IllegalStateException("Version can not be retrieved from Database. Database is either blank or corrupted"); - } - DatabaseVersion.Status status = databaseVersion.getStatus(); - if (status == DatabaseVersion.Status.UP_TO_DATE || status == DatabaseVersion.Status.REQUIRES_DOWNGRADE) { - return true; - } - - Database database = container.getComponentByType(Database.class); - return !database.getDialect().supportsMigration(); - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/JRubyI18n.java b/server/sonar-server/src/main/java/org/sonar/server/ui/JRubyI18n.java deleted file mode 100644 index e8605295b48..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/ui/JRubyI18n.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.ui; - -import com.google.common.collect.Maps; -import java.util.Date; -import java.util.Locale; -import java.util.Map; -import javax.annotation.Nullable; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.server.ServerSide; -import org.sonar.api.i18n.I18n; -import org.sonar.api.utils.Duration; -import org.sonar.api.utils.Durations; -import org.sonar.server.user.UserSession; - -/** - * Used through ruby code <pre>Internal.i18n</pre> - * - * Bridge between JRuby webapp and Java I18n component - */ -@ServerSide -public class JRubyI18n { - - private final I18n i18n; - private final Durations durations; - private final UserSession userSession; - private Map<String, Locale> localesByRubyKey = Maps.newHashMap(); - - public JRubyI18n(I18n i18n, Durations durations, UserSession userSession) { - this.i18n = i18n; - this.durations = durations; - this.userSession = userSession; - } - - Locale getLocale(String rubyKey) { - Locale locale = localesByRubyKey.get(rubyKey); - if (locale == null) { - locale = toLocale(rubyKey); - localesByRubyKey.put(rubyKey, locale); - } - return locale; - } - - Map<String, Locale> getLocalesByRubyKey() { - return localesByRubyKey; - } - - public static Locale toLocale(@Nullable String rubyKey) { - Locale locale; - if (rubyKey == null) { - locale = Locale.ENGLISH; - } else { - String[] fields = StringUtils.split(rubyKey, "-"); - if (fields.length == 1) { - locale = new Locale(fields[0]); - } else { - locale = new Locale(fields[0], fields[1]); - } - } - return locale; - } - - public String message(String rubyLocale, String key, String defaultValue, Object... parameters) { - return StringUtils.defaultString(i18n.message(getLocale(rubyLocale), key, defaultValue, parameters), key); - } - - public String ageFromNow(Date date) { - return i18n.ageFromNow(userSession.locale(), date); - } - - public String formatDuration(Duration duration, String format) { - return durations.format(userSession.locale(), duration, Durations.DurationFormat.valueOf(format)); - } - - public String formatLongDuration(long duration, String format) { - return formatDuration(Duration.create(duration), format); - } - - public String formatDateTime(Date date) { - return i18n.formatDateTime(userSession.locale(), date); - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/DefaultUserService.java b/server/sonar-server/src/main/java/org/sonar/server/user/DefaultUserService.java deleted file mode 100644 index 6100a1e1cd6..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/user/DefaultUserService.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.user; - -import java.util.List; -import java.util.Map; -import javax.annotation.CheckForNull; -import org.sonar.api.user.RubyUserService; -import org.sonar.api.user.User; -import org.sonar.api.user.UserFinder; -import org.sonar.api.user.UserQuery; -import org.sonar.server.util.RubyUtils; - -public class DefaultUserService implements RubyUserService { - - private final UserFinder finder; - - public DefaultUserService(UserFinder finder) { - this.finder = finder; - } - - @Override - @CheckForNull - public User findByLogin(String login) { - return finder.findByLogin(login); - } - - @Override - public List<User> find(Map<String, Object> params) { - UserQuery query = parseQuery(params); - return finder.find(query); - } - - private static UserQuery parseQuery(Map<String, Object> params) { - UserQuery.Builder builder = UserQuery.builder(); - if (RubyUtils.toBoolean(params.get("includeDeactivated")) == Boolean.TRUE) { - builder.includeDeactivated(); - } - builder.logins(RubyUtils.toStrings(params.get("logins"))); - builder.searchText((String) params.get("s")); - return builder.build(); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java index c685157aac0..f7638ab2897 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java @@ -34,20 +34,16 @@ import org.sonar.db.metric.MetricDto; import org.sonar.db.metric.MetricTesting; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.ServerException; -import org.sonar.server.ruby.RubyBridge; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsTester; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; -import static org.mockito.Mockito.mock; import static org.sonar.server.metric.ws.CreateAction.PARAM_DESCRIPTION; import static org.sonar.server.metric.ws.CreateAction.PARAM_DOMAIN; import static org.sonar.server.metric.ws.CreateAction.PARAM_KEY; import static org.sonar.server.metric.ws.CreateAction.PARAM_NAME; import static org.sonar.server.metric.ws.CreateAction.PARAM_TYPE; - public class CreateActionTest { private static final String DEFAULT_KEY = "custom-metric-key"; @@ -69,7 +65,7 @@ public class CreateActionTest { @Before public void setUp() { - ws = new WsTester(new MetricsWs(new CreateAction(dbClient, userSessionRule, mock(RubyBridge.class, RETURNS_DEEP_STUBS)))); + ws = new WsTester(new MetricsWs(new CreateAction(dbClient, userSessionRule))); userSessionRule.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java index 60f1609b644..90932fc086b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java @@ -35,16 +35,12 @@ import org.sonar.db.measure.custom.CustomMeasureTesting; import org.sonar.db.metric.MetricDao; import org.sonar.db.metric.MetricDto; import org.sonar.server.exceptions.ForbiddenException; -import org.sonar.server.ruby.RubyBridge; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsTester; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; -import static org.mockito.Mockito.mock; import static org.sonar.db.metric.MetricTesting.newMetricDto; - public class DeleteActionTest { @Rule @@ -62,7 +58,7 @@ public class DeleteActionTest { @Before public void setUp() { userSessionRule.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); - ws = new WsTester(new MetricsWs(new DeleteAction(dbClient, userSessionRule, mock(RubyBridge.class, RETURNS_DEEP_STUBS)))); + ws = new WsTester(new MetricsWs(new DeleteAction(dbClient, userSessionRule))); metricDao = dbClient.metricDao(); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/MetricsWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/MetricsWsTest.java index df49c94ffc9..ef32b2cebeb 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/MetricsWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/MetricsWsTest.java @@ -23,7 +23,6 @@ import org.junit.Before; import org.junit.Test; import org.sonar.api.server.ws.WebService; import org.sonar.db.DbClient; -import org.sonar.server.ruby.RubyBridge; import org.sonar.server.user.UserSession; import org.sonar.server.ws.WsTester; @@ -38,16 +37,13 @@ public class MetricsWsTest { public void setUp() { DbClient dbClient = mock(DbClient.class); UserSession userSession = mock(UserSession.class); - RubyBridge rubyBridge = mock(RubyBridge.class); ws = new WsTester(new MetricsWs( new SearchAction(dbClient), - new CreateAction(dbClient, userSession, rubyBridge), - new UpdateAction(dbClient, userSession, rubyBridge), - new DeleteAction(dbClient, userSession, rubyBridge), + new CreateAction(dbClient, userSession), + new UpdateAction(dbClient, userSession), + new DeleteAction(dbClient, userSession), new TypesAction(), - new DomainsAction(dbClient) - )); - + new DomainsAction(dbClient))); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java index f2e38b7f456..9fb2fb00fce 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java @@ -32,13 +32,10 @@ import org.sonar.db.DbTester; import org.sonar.db.metric.MetricDto; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.ServerException; -import org.sonar.server.ruby.RubyBridge; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsTester; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; -import static org.mockito.Mockito.mock; import static org.sonar.db.measure.custom.CustomMeasureTesting.newCustomMeasureDto; import static org.sonar.server.metric.ws.UpdateAction.PARAM_DESCRIPTION; import static org.sonar.server.metric.ws.UpdateAction.PARAM_DOMAIN; @@ -47,7 +44,6 @@ import static org.sonar.server.metric.ws.UpdateAction.PARAM_KEY; import static org.sonar.server.metric.ws.UpdateAction.PARAM_NAME; import static org.sonar.server.metric.ws.UpdateAction.PARAM_TYPE; - public class UpdateActionTest { private static final String DEFAULT_KEY = "custom-metric-key"; @@ -69,7 +65,7 @@ public class UpdateActionTest { @Before public void setUp() { - ws = new WsTester(new MetricsWs(new UpdateAction(dbClient, userSessionRule, mock(RubyBridge.class, RETURNS_DEEP_STUBS)))); + ws = new WsTester(new MetricsWs(new UpdateAction(dbClient, userSessionRule))); userSessionRule.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplAsynchronousTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplAsynchronousTest.java index eea53055a8a..0cf1f895cce 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplAsynchronousTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplAsynchronousTest.java @@ -22,7 +22,6 @@ package org.sonar.server.platform.db.migration; import org.junit.Test; import org.sonar.server.platform.Platform; import org.sonar.server.platform.db.migration.engine.MigrationEngine; -import org.sonar.server.ruby.RubyBridge; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -41,10 +40,9 @@ public class DatabaseMigrationImplAsynchronousTest { } }; private MutableDatabaseMigrationState migrationState = mock(MutableDatabaseMigrationState.class); - private RubyBridge rubyBridge = mock(RubyBridge.class); private Platform platform = mock(Platform.class); private MigrationEngine migrationEngine = mock(MigrationEngine.class); - private DatabaseMigrationImpl underTest = new DatabaseMigrationImpl(executorService, migrationState, rubyBridge, migrationEngine, platform); + private DatabaseMigrationImpl underTest = new DatabaseMigrationImpl(executorService, migrationState, migrationEngine, platform); @Test public void testName() throws Exception { diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java index 2f7965a7334..e65e58838b5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java @@ -29,12 +29,9 @@ import org.junit.After; import org.junit.Test; import org.sonar.server.platform.Platform; import org.sonar.server.platform.db.migration.engine.MigrationEngine; -import org.sonar.server.ruby.RubyBridge; -import org.sonar.server.ruby.RubyRailsRoutes; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class DatabaseMigrationImplConcurrentAccessTest { @@ -68,10 +65,8 @@ public class DatabaseMigrationImplConcurrentAccessTest { } }; private MutableDatabaseMigrationState migrationState = mock(MutableDatabaseMigrationState.class); - private RubyBridge rubyBridge = mock(RubyBridge.class); private Platform platform = mock(Platform.class); - private RubyRailsRoutes railsRoutes = mock(RubyRailsRoutes.class); - private DatabaseMigrationImpl underTest = new DatabaseMigrationImpl(executorService, migrationState, rubyBridge, incrementingMigrationEngine, platform); + private DatabaseMigrationImpl underTest = new DatabaseMigrationImpl(executorService, migrationState, incrementingMigrationEngine, platform); @After public void tearDown() { @@ -80,8 +75,6 @@ public class DatabaseMigrationImplConcurrentAccessTest { @Test public void two_concurrent_calls_to_startit_call_migration_engine_only_once() throws Exception { - when(rubyBridge.railsRoutes()).thenReturn(railsRoutes); - pool.submit(new CallStartit()); pool.submit(new CallStartit()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplTest.java index c5d12e79f3e..c0c14c15acd 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplTest.java @@ -24,15 +24,12 @@ import org.junit.Test; import org.mockito.InOrder; import org.sonar.server.platform.Platform; import org.sonar.server.platform.db.migration.engine.MigrationEngine; -import org.sonar.server.ruby.RubyBridge; -import org.sonar.server.ruby.RubyRailsRoutes; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * Unit test for DatabaseMigrationImpl which does not test any of its concurrency management and asynchronous execution code. @@ -50,31 +47,23 @@ public class DatabaseMigrationImplTest { } }; private MutableDatabaseMigrationState migrationState = new DatabaseMigrationStateImpl(); - private RubyBridge rubyBridge = mock(RubyBridge.class); - private RubyRailsRoutes rubyRailsRoutes = mock(RubyRailsRoutes.class); private Platform platform = mock(Platform.class); private MigrationEngine migrationEngine = mock(MigrationEngine.class); - private InOrder inOrder = inOrder(rubyBridge, rubyRailsRoutes, platform, migrationEngine); + private InOrder inOrder = inOrder(platform, migrationEngine); - private DatabaseMigrationImpl underTest = new DatabaseMigrationImpl(executorService, migrationState, rubyBridge, migrationEngine, platform); + private DatabaseMigrationImpl underTest = new DatabaseMigrationImpl(executorService, migrationState, migrationEngine, platform); @Test public void startit_calls_MigrationEngine_execute() { - when(rubyBridge.railsRoutes()).thenReturn(rubyRailsRoutes); - underTest.startIt(); inOrder.verify(migrationEngine).execute(); inOrder.verify(platform).doStart(); - inOrder.verify(rubyBridge).railsRoutes(); - inOrder.verify(rubyRailsRoutes).recreate(); inOrder.verifyNoMoreInteractions(); } @Test public void status_is_SUCCEEDED_and_failure_is_null_when_trigger_runs_without_an_exception() { - when(rubyBridge.railsRoutes()).thenReturn(rubyRailsRoutes); - underTest.startIt(); assertThat(migrationState.getStatus()).isEqualTo(DatabaseMigrationState.Status.SUCCEEDED); @@ -115,11 +104,9 @@ public class DatabaseMigrationImplTest { private void mockMigrationThrowsError() { doThrow(AN_ERROR).when(migrationEngine).execute(); - when(rubyBridge.railsRoutes()).thenReturn(rubyRailsRoutes); } private void mockMigrationDoesNothing() { doNothing().when(migrationEngine).execute(); - when(rubyBridge.railsRoutes()).thenReturn(rubyRailsRoutes); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/web/RailsAppsDeployerTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/web/RailsAppsDeployerTest.java deleted file mode 100644 index 937d5e8c29a..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/web/RailsAppsDeployerTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.platform.web; - -import java.io.File; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Collections; -import org.apache.commons.io.FileUtils; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.sonar.core.platform.PluginRepository; -import org.sonar.server.platform.ServerFileSystem; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class RailsAppsDeployerTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Test - public void hasRubyRailsApp() throws Exception { - ClassLoader classLoader = new URLClassLoader(new URL[]{ - getClass().getResource("/org/sonar/server/platform/web/RailsAppsDeployerTest/FakeRubyRailsApp.jar").toURI().toURL()}, null); - - assertTrue(RailsAppsDeployer.hasRailsApp("fake", classLoader)); - assertFalse(RailsAppsDeployer.hasRailsApp("other", classLoader)); - } - - @Test - public void deployRubyRailsApp() throws Exception { - File tempDir = this.temp.getRoot(); - ClassLoader classLoader = new URLClassLoader(new URL[]{ - getClass().getResource("/org/sonar/server/platform/web/RailsAppsDeployerTest/FakeRubyRailsApp.jar").toURI().toURL()}, null); - - RailsAppsDeployer.deployRailsApp(tempDir, "fake", classLoader); - - File appDir = new File(tempDir, "fake"); - assertThat(appDir.isDirectory(), is(true)); - assertThat(appDir.exists(), is(true)); - assertThat(FileUtils.listFiles(appDir, null, true).size(), is(3)); - assertThat(new File(appDir, "init.rb").exists(), is(true)); - assertThat(new File(appDir, "app/controllers/fake_controller.rb").exists(), is(true)); - assertThat(new File(appDir, "app/views/fake/index.html.erb").exists(), is(true)); - } - - @Test - public void deployRubyRailsApps_no_apps() { - ServerFileSystem fileSystem = mock(ServerFileSystem.class); - File tempDir = this.temp.getRoot(); - when(fileSystem.getTempDir()).thenReturn(tempDir); - - PluginRepository pluginRepository = mock(PluginRepository.class); - when(pluginRepository.getPluginInfos()).thenReturn(Collections.emptyList()); - new RailsAppsDeployer(fileSystem, pluginRepository).start(); - - File appDir = new File(tempDir, "ror"); - assertThat(appDir.isDirectory(), is(true)); - assertThat(appDir.exists(), is(true)); - assertThat(FileUtils.listFiles(appDir, null, true).size(), is(0)); - } - - @Test - public void prepareRubyRailsRootDirectory() throws Exception { - ServerFileSystem fileSystem = mock(ServerFileSystem.class); - File tempDir = this.temp.getRoot(); - when(fileSystem.getTempDir()).thenReturn(tempDir); - - File dir = new RailsAppsDeployer(fileSystem, mock(PluginRepository.class)).prepareRailsDirectory(); - - assertThat(dir.isDirectory(), is(true)); - assertThat(dir.exists(), is(true)); - assertThat(dir.getCanonicalPath(), is(new File(tempDir, "ror").getCanonicalPath())); - } - - @Test - public void prepareRubyRailsRootDirectory_delete_existing_dir() throws Exception { - ServerFileSystem fileSystem = mock(ServerFileSystem.class); - File tempDir = this.temp.getRoot(); - when(fileSystem.getTempDir()).thenReturn(tempDir); - - File file = new File(tempDir, "ror/foo/bar.txt"); - FileUtils.writeStringToFile(file, "foooo"); - - File dir = new RailsAppsDeployer(fileSystem, mock(PluginRepository.class)).prepareRailsDirectory(); - - assertThat(dir.isDirectory(), is(true)); - assertThat(dir.exists(), is(true)); - assertThat(dir.getCanonicalPath(), is(new File(tempDir, "ror").getCanonicalPath())); - assertThat(FileUtils.listFiles(new File(tempDir, "ror"), null, true).size(), is(0)); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/web/RubyRailsContextListenerTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/web/RubyRailsContextListenerTest.java deleted file mode 100644 index 8a20e31e607..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/platform/web/RubyRailsContextListenerTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.platform.web; - -import java.io.IOException; -import javax.servlet.ServletContextEvent; -import org.jruby.rack.RackApplicationFactory; -import org.jruby.rack.servlet.ServletRackContext; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mockito; -import org.sonar.server.platform.web.PlatformServletContextListener; -import org.sonar.server.platform.web.RubyRailsContextListener; - -import static java.lang.Boolean.TRUE; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class RubyRailsContextListenerTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - ServletContextEvent event = mock(ServletContextEvent.class, Mockito.RETURNS_DEEP_STUBS); - RubyRailsContextListener underTest = new RubyRailsContextListener(); - - @Test - public void do_not_initialize_rails_if_error_during_startup() { - when(event.getServletContext().getAttribute(PlatformServletContextListener.STARTED_ATTRIBUTE)).thenReturn(null); - - underTest.contextInitialized(event); - - verify(event.getServletContext(), never()).setAttribute(anyString(), anyObject()); - } - - @Test - public void initialize_rails_if_no_errors_during_startup() { - when(event.getServletContext().getAttribute(PlatformServletContextListener.STARTED_ATTRIBUTE)).thenReturn(TRUE); - underTest.contextInitialized(event); - // Ruby environment is started - // See RailsServletContextListener -> RackServletContextListener - verify(event.getServletContext()).setAttribute(eq("rack.factory"), anyObject()); - } - - @Test - public void always_propagates_initialization_errors() { - expectedException.expect(RuntimeException.class); - - underTest.handleInitializationException(new IOException(), mock(RackApplicationFactory.class), mock(ServletRackContext.class)); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/ruby/PlatformRackBridgeTest.java b/server/sonar-server/src/test/java/org/sonar/server/ruby/PlatformRackBridgeTest.java deleted file mode 100644 index d3d8359cedc..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/ruby/PlatformRackBridgeTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.ruby; - -import org.jruby.rack.RackApplication; -import org.jruby.rack.RackApplicationFactory; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import javax.servlet.ServletContext; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class PlatformRackBridgeTest { - @Mock - private ServletContext servletContext; - @Mock - private RackApplicationFactory rackApplicationFactory; - @Mock - private RackApplication rackApplication; - - @InjectMocks - PlatformRackBridge underTest; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - } - - @Test(expected = RuntimeException.class) - public void getRubyRuntime_throws_RE_when_RackApplicationFactory_is_not_in_ServletContext() { - underTest.getRubyRuntime(); - } - - @Test - public void getRubyRuntime_returns_Ruby_instance_from_rack_application() { - when(servletContext.getAttribute("rack.factory")).thenReturn(rackApplicationFactory); - when(rackApplicationFactory.getApplication()).thenReturn(rackApplication); - - // since Ruby object can not be mocked and creating a Ruby instance is costly, we only make sure rackApplication#getRuntime method is - // called and that we get null (as rackApplication#getRuntime() returns null) - assertThat(underTest.getRubyRuntime()).isNull(); - verify(rackApplication).getRuntime(); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/ruby/PlatformRubyBridgeTest.java b/server/sonar-server/src/test/java/org/sonar/server/ruby/PlatformRubyBridgeTest.java deleted file mode 100644 index 1c51261f12e..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/ruby/PlatformRubyBridgeTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.ruby; - -import com.google.common.collect.ImmutableList; -import java.io.File; -import java.net.URISyntaxException; -import java.net.URL; -import org.jruby.embed.LocalContextScope; -import org.jruby.embed.ScriptingContainer; -import org.jruby.exceptions.RaiseException; -import org.junit.Before; -import org.junit.Test; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class PlatformRubyBridgeTest { - private static ScriptingContainer container = setupScriptingContainer(); - - private RackBridge rackBridge = mock(RackBridge.class); - private PlatformRubyBridge underTest; - - @Before - public void setUp() { - when(rackBridge.getRubyRuntime()).thenReturn(container.getProvider().getRuntime()); - underTest = new PlatformRubyBridge(rackBridge); - } - - /** - * Creates a Ruby runtime which loading path includes the test resource directory where our Ruby test DatabaseVersion - * is defined. - */ - private static ScriptingContainer setupScriptingContainer() { - try { - ScriptingContainer container = new ScriptingContainer(LocalContextScope.THREADSAFE); - URL resource = PlatformRubyBridge.class.getResource("database_version.rb"); - String dirPath = new File(resource.toURI()).getParentFile().getPath(); - container.setLoadPaths(ImmutableList.of(dirPath)); - - return container; - } catch (URISyntaxException e) { - throw new RuntimeException(e); - } - } - - /** - * unit test only makes sure the wrapping and method forwarding provided by JRuby works so building the - * RubyRailsRoutes object and calling its trigger method is enough as it would otherwise raise an exception - */ - @Test - public void testRailsRoutes() { - try { - underTest.railsRoutes().recreate(); - } catch (RaiseException e) { - e.printStackTrace(); - throw new RuntimeException("Loading error with container loadPath " + container.getLoadPaths(), e); - } - } - - /** - * unit test only makes sure the wrapping and method forwarding provided by JRuby works so building the - * RubyRailsRoutes object and calling its trigger method is enough as it would otherwise raise an exception - */ - @Test - public void testInvalidateCache() { - try { - underTest.metricCache().invalidate(); - } catch (RaiseException e) { - e.printStackTrace(); - throw new RuntimeException("Loading error with container loadPath " + container.getLoadPaths(), e); - } - } - -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/JRubyI18nTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/JRubyI18nTest.java deleted file mode 100644 index b5bbdf888b6..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/ui/JRubyI18nTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.ui; - -import java.util.Date; -import java.util.Locale; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.sonar.api.i18n.I18n; -import org.sonar.api.utils.Duration; -import org.sonar.api.utils.Durations; -import org.sonar.server.tester.UserSessionRule; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.verify; - -@RunWith(MockitoJUnitRunner.class) -public class JRubyI18nTest { - @Rule - public UserSessionRule userSessionRule = UserSessionRule.standalone(); - - @Mock - I18n i18n; - - @Mock - Durations durations; - - JRubyI18n jRubyI18n; - - - @Before - public void setUp() { - jRubyI18n = new JRubyI18n(i18n, durations, userSessionRule); - } - - @Test - public void convert_locales() { - assertThat(JRubyI18n.toLocale("fr")).isEqualTo(Locale.FRENCH); - assertThat(JRubyI18n.toLocale("fr-CH")).isEqualTo(new Locale("fr", "CH")); - } - - @Test - public void cache_locales() { - assertThat(jRubyI18n.getLocalesByRubyKey()).isEmpty(); - - jRubyI18n.getLocale("fr"); - - assertThat(jRubyI18n.getLocalesByRubyKey()).hasSize(1); - assertThat(jRubyI18n.getLocalesByRubyKey().get("fr")).isNotNull(); - } - - @Test - public void default_locale_should_be_english() { - assertThat(JRubyI18n.toLocale(null)).isEqualTo(Locale.ENGLISH); - } - - @Test - public void message() { - jRubyI18n.message("en", "my.key", "default"); - verify(i18n).message(any(Locale.class), eq("my.key"), eq("default")); - } - - @Test - public void age_from_now() { - Date date = new Date(); - jRubyI18n.ageFromNow(date); - verify(i18n).ageFromNow(any(Locale.class), eq(date)); - } - - @Test - public void format_work_duration() { - jRubyI18n.formatDuration(Duration.create(10L), "SHORT"); - verify(durations).format(any(Locale.class), eq(Duration.create(10L)), eq(Durations.DurationFormat.SHORT)); - } - - @Test - public void format_long_work_duration() { - jRubyI18n.formatLongDuration(10L, "SHORT"); - verify(durations).format(any(Locale.class), eq(Duration.create(10L)), eq(Durations.DurationFormat.SHORT)); - } - - @Test - public void format_date_time() { - Date date = new Date(); - jRubyI18n.formatDateTime(date); - verify(i18n).formatDateTime(any(Locale.class), eq(date)); - } - -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/DefaultUserServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/DefaultUserServiceTest.java deleted file mode 100644 index 4464a8ef1b6..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/user/DefaultUserServiceTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.user; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.ArgumentMatcher; -import org.sonar.api.user.UserFinder; -import org.sonar.api.user.UserQuery; - -import static org.mockito.Matchers.argThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -public class DefaultUserServiceTest { - - private UserFinder finder = mock(UserFinder.class); - private DefaultUserService service = new DefaultUserService(finder); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void parse_query() { - service.find(ImmutableMap.of( - "logins", "simon,loic", - "includeDeactivated", "true", - "s", "sim")); - - verify(finder, times(1)).find(argThat(new ArgumentMatcher<UserQuery>() { - @Override - public boolean matches(Object o) { - UserQuery query = (UserQuery) o; - return query.includeDeactivated() && - query.logins().contains("simon") && query.logins().contains("loic") && query.logins().size() == 2 && - query.searchText().equals("sim"); - } - })); - } - - @Test - public void test_empty_query() throws Exception { - service.find(Maps.newHashMap()); - - verify(finder, times(1)).find(argThat(new ArgumentMatcher<UserQuery>() { - @Override - public boolean matches(Object o) { - UserQuery query = (UserQuery) o; - return !query.includeDeactivated() && query.logins() == null && query.searchText() == null; - } - })); - } -} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/platform/web/RailsAppsDeployerTest/FakeRubyRailsApp.jar b/server/sonar-server/src/test/resources/org/sonar/server/platform/web/RailsAppsDeployerTest/FakeRubyRailsApp.jar Binary files differdeleted file mode 100644 index 9ed866620ec..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/platform/web/RailsAppsDeployerTest/FakeRubyRailsApp.jar +++ /dev/null |