diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2013-11-29 11:02:48 +0100 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2013-12-02 15:54:24 +0100 |
commit | 612e1c3be1432d9370eb9dc37a2279aaeb0cf80c (patch) | |
tree | 16c4ca8d5104cdb3a2230a6229656939264470f4 | |
parent | 0e5517fe801cce6e26db2c0b2f269cd9d9649b74 (diff) | |
download | sonarqube-612e1c3be1432d9370eb9dc37a2279aaeb0cf80c.tar.gz sonarqube-612e1c3be1432d9370eb9dc37a2279aaeb0cf80c.zip |
SONAR-4756 Define a JRuby facade for profiling, use it in rules search
5 files changed, 116 insertions, 6 deletions
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 e6272ea17c9..138aab83d0e 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 @@ -19,8 +19,6 @@ */ package org.sonar.server.platform; -import org.sonar.core.profiling.Profiling; - import org.apache.commons.configuration.BaseConfiguration; import org.slf4j.LoggerFactory; import org.sonar.api.config.EmailSettings; @@ -56,6 +54,7 @@ import org.sonar.core.notification.DefaultNotificationManager; import org.sonar.core.permission.PermissionFacade; import org.sonar.core.persistence.*; import org.sonar.core.preview.PreviewCache; +import org.sonar.core.profiling.Profiling; import org.sonar.core.purge.PurgeProfiler; import org.sonar.core.resource.DefaultResourcePermissions; import org.sonar.core.rule.DefaultRuleFinder; @@ -167,6 +166,7 @@ public final class Platform { rootContainer.addSingleton(ServerImpl.class); rootContainer.addSingleton(Logback.class); rootContainer.addSingleton(Profiling.class); + rootContainer.addSingleton(JRubyProfiling.class); rootContainer.addSingleton(EmbeddedDatabaseFactory.class); rootContainer.addSingleton(DefaultDatabase.class); rootContainer.addSingleton(MyBatis.class); diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyProfiling.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyProfiling.java new file mode 100644 index 00000000000..1edf63cdafa --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyProfiling.java @@ -0,0 +1,51 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sonar.core.profiling.Profiling; +import org.sonar.core.profiling.Profiling.Level; +import org.sonar.core.profiling.StopWatch; + +/** + * @since 4.1 + */ +public class JRubyProfiling { + + private static final Logger LOG = LoggerFactory.getLogger(JRubyProfiling.class); + + private Profiling profiling; + + public JRubyProfiling(Profiling profiling) { + this.profiling = profiling; + } + + public StopWatch start(String domain, String level) { + Level profilingLevel = Level.NONE; + try { + profilingLevel = Level.valueOf(level); + } catch (IllegalArgumentException iae) { + LOG.warn("Unknown profiling level, defaulting to NONE: " + level, iae); + } + return profiling.start(domain, profilingLevel); + } +} diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb index caa8d6ceb31..65dd608b03b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb @@ -49,22 +49,27 @@ class RulesConfigurationController < ApplicationController @select_sort_by = [[message('rules_configuration.rule_name'), Rule::SORT_BY_RULE_NAME], [message('rules_configuration.creation_date'), Rule::SORT_BY_CREATION_DATE]] begin - @rules = Rule.search(java_facade, { - :profile => @profile, :activation => @activation, :priorities => @priorities, :inheritance => @inheritance, :status => @status, - :repositories => @repositories, :searchtext => @searchtext, :include_parameters_and_notes => true, :language => @profile.language, :sort_by => @sort_by}) + stop_watch = Internal.profiling.start("rules", "BASIC") + + criteria = { + :profile => @profile, :activation => @activation, :priorities => @priorities, :inheritance => @inheritance, :status => @status, + :repositories => @repositories, :searchtext => @searchtext, :include_parameters_and_notes => true, :language => @profile.language, :sort_by => @sort_by} + @rules = Rule.search(java_facade, criteria) unless @searchtext.blank? if @activation==STATUS_ACTIVE @hidden_inactives = Rule.search(java_facade, { :profile => @profile, :activation => STATUS_INACTIVE, :priorities => @priorities, :status => @status, :repositories => @repositories, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size - + elsif @activation==STATUS_INACTIVE @hidden_actives = Rule.search(java_facade, { :profile => @profile, :activation => STATUS_ACTIVE, :priorities => @priorities, :status => @status, :repositories => @repositories, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size end end + + stop_watch.stop("found #{@rules.size} rules with criteria #{criteria.to_json}") rescue @rules = [] end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/internal.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/internal.rb index c43de64b4d7..f47539460e3 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/internal.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/internal.rb @@ -58,6 +58,10 @@ class Internal component(Java::OrgSonarServerTechnicaldebt::InternalRubyTechnicalDebtService.java_class) end + def self.profiling + component(Java::OrgSonarServerUi::JRubyProfiling.java_class) + end + private def self.component(component_java_class) diff --git a/sonar-server/src/test/java/org/sonar/server/ui/JRubyProfilingTest.java b/sonar-server/src/test/java/org/sonar/server/ui/JRubyProfilingTest.java new file mode 100644 index 00000000000..f5cb118226e --- /dev/null +++ b/sonar-server/src/test/java/org/sonar/server/ui/JRubyProfilingTest.java @@ -0,0 +1,50 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 org.junit.Before; +import org.junit.Test; +import org.sonar.api.config.Settings; +import org.sonar.core.profiling.Profiling; + +import static org.fest.assertions.Assertions.assertThat; + +public class JRubyProfilingTest { + + private JRubyProfiling profilingFacade; + + @Before + public void initialize() { + profilingFacade = new JRubyProfiling(new Profiling(new Settings())); + } + + @Test + public void should_provide_stop_watch() { + String domain = "domain"; + assertThat(profilingFacade.start(domain, "FULL")).isNotNull(); + } + + @Test + public void should_safely_ignore_bad_level_parameter() { + String domain = "domain"; + assertThat(profilingFacade.start(domain, "POLOP")).isNotNull(); + } +} |