aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-07 23:53:42 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-07 23:53:42 +0000
commit7a07af0d844c1bb30b2c7df4aeafa0642fc7ce2f (patch)
tree339f625242b165d546562bbaa8c30f43e3f4db98 /sonar-server
parent3cc63963cfd20176c605c27f023fb6e70db69b80 (diff)
downloadsonarqube-7a07af0d844c1bb30b2c7df4aeafa0642fc7ce2f.tar.gz
sonarqube-7a07af0d844c1bb30b2c7df4aeafa0642fc7ce2f.zip
SONAR-1654 Export rules in rules engine exports everything (Java, PHP, VB...) when you select any in plugins
+ sort quality profiles by language
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfileExporters.java11
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb9
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb27
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/index.html.erb2
5 files changed, 40 insertions, 11 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfileExporters.java b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfileExporters.java
index e5fc8865416..623f6c0abf6 100644
--- a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfileExporters.java
+++ b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfileExporters.java
@@ -52,7 +52,7 @@ public final class DeprecatedProfileExporters implements ServerComponent {
List<ProfileExporter> result = new ArrayList<ProfileExporter>();
for (RulesRepository repo : deprecatedRepositories) {
if (repo instanceof ConfigurationExportable) {
- result.add(new DeprecatedProfileExporter(getPlugin(repo), (ConfigurationExportable)repo));
+ result.add(new DeprecatedProfileExporter(getPlugin(repo), repo));
}
}
return result;
@@ -64,18 +64,19 @@ public final class DeprecatedProfileExporters implements ServerComponent {
}
class DeprecatedProfileExporter extends ProfileExporter {
- private ConfigurationExportable repository;
+ private RulesRepository exportableRepository;
- protected DeprecatedProfileExporter(Plugin plugin, ConfigurationExportable repository) {
+ protected DeprecatedProfileExporter(Plugin plugin, RulesRepository exportableRepository) {
super(plugin.getKey(), plugin.getName());
- this.repository = repository;
+ this.exportableRepository = exportableRepository;
+ setSupportedLanguages(exportableRepository.getLanguage().getKey());
setMimeType("application/xml");
}
@Override
public void exportProfile(RulesProfile profile, Writer writer) {
- String xml = repository.exportConfiguration(profile);
+ String xml = ((ConfigurationExportable)exportableRepository).exportConfiguration(profile);
if (xml != null) {
try {
writer.append(xml);
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb
index 8c850104edd..42c08aa35e0 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb
@@ -26,10 +26,11 @@ class Api::RulesController < Api::RestController
set_backward_compatibility_params
language = params[:language] || ''
options= {}
- if params[:plugins]
- options[:plugins] = params[:plugins].split(',')
- else
+ if params[:plugins].blank?
options[:plugins] = java_facade.getRuleRepositoriesByLanguage(language).collect { |repo| repo.getKey() }
+
+ else
+ options[:plugins] = params[:plugins].split(',')
end
options[:categories]=params[:categories].split(',') if params[:categories]
options[:priorities]=params[:priorities].split(',') if params[:priorities]
@@ -39,7 +40,7 @@ class Api::RulesController < Api::RestController
if params[:profile]
- profile = RulesProfile.find_by_name_and_language(params[:profile], language)
+ profile = Profile.find_by_name_and_language(params[:profile], language)
if profile.nil?
rest_render([])
else
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb
index bf615b3fc64..064174f54ba 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb
@@ -23,6 +23,8 @@ class Profile < ActiveRecord::Base
has_many :alerts, :dependent => :delete_all
has_many :active_rules, :class_name => 'ActiveRule', :foreign_key => 'profile_id', :dependent => :destroy, :include => ['rule']
has_many :projects, :order => 'name asc'
+ has_many :active_rules_with_params, :class_name => 'ActiveRule', :foreign_key => 'profile_id',
+ :include => ['active_rule_parameters']
validates_uniqueness_of :name, :scope => :language, :case_sensitive => false
validates_presence_of :name
@@ -73,4 +75,29 @@ class Profile < ActiveRecord::Base
end
self
end
+
+ def active_by_rule_id(rule_id)
+ active_hash_by_rule_id[rule_id]
+ end
+
+ def self.options_for_select
+ array=[]
+ RulesProfile.find(:all, :order => 'name').each do |profile|
+ label = profile.name
+ label = label + ' (active)' if profile.default_profile?
+ array<<[label, profile.id]
+ end
+ array
+ end
+
+ @active_hash_by_rule_id=nil
+ def active_hash_by_rule_id
+ if @active_hash_by_rule_id.nil?
+ @active_hash_by_rule_id={}
+ active_rules_with_params.each do |active_rule|
+ @active_hash_by_rule_id[active_rule.rule_id]=active_rule
+ end
+ end
+ @active_hash_by_rule_id
+ end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb
index 4beb03a9591..373495c35d6 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb
@@ -1,5 +1,5 @@
<%
- languages.each do |language|
+ languages.sort{|x,y| x.getName() <=> y.getName()}.each do |language|
exporters=controller.java_facade.getProfileExportersForLanguage(language.getKey())
importers=controller.java_facade.getProfileImportersForLanguage(language.getKey())
%>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/index.html.erb
index 59fd4e04eb8..fea009d1b28 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/index.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/index.html.erb
@@ -75,7 +75,7 @@
<ul style="float: right" class="horizontal">
<li class="marginleft10">
<div class="csv">
- <a href="<%= url_for(:controller => 'api/rules', :action => 'index', :language => @profile.language, :profile => @profile.name, :plugins => @plugins.join(','), :rule_status => @status, :searchtext => @searchtext, :priorities => @priorities.join(','), :categories => @categories.join(','), :format => 'csv') -%>" onClick="return downloadCsv()" id="download-link" class="">Download</a>
+ <a href="<%= url_for(:controller => 'api/rules', :action => 'index', :language => @profile.language, :profile => @profile.name, :plugins => @plugins.join(','), :status => @status, :searchtext => @searchtext, :priorities => @priorities.join(','), :categories => @categories.join(','), :format => 'csv') -%>" onClick="return downloadCsv()" id="download-link" class="">Download</a>
</div>
</li>
<% if enable_modification %>