aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-13 17:54:36 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-13 17:54:36 +0000
commitb384d1804d4d4759be92094ceb417276ed1dfecf (patch)
treec7f170689f9e15b44929c82b7661c2a1a8274940
parentcdd05f32ec75a1594f8f86e1fdb0bd4101598654 (diff)
downloadsonarqube-b384d1804d4d4759be92094ceb417276ed1dfecf.tar.gz
sonarqube-b384d1804d4d4759be92094ceb417276ed1dfecf.zip
SONAR-1776 - Add a page Permalinks to the profile console
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java62
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java43
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java88
-rw-r--r--sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/plugins/resource_controller.rb1
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb5
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb2
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java13
8 files changed, 88 insertions, 130 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java
index 90a87b695bc..fde68c21443 100644
--- a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java
+++ b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java
@@ -25,12 +25,8 @@ import org.sonar.api.checks.profiles.Check;
import org.sonar.api.checks.profiles.CheckProfile;
import org.sonar.api.checks.profiles.CheckProfileProvider;
import org.sonar.api.profiles.ProfileDefinition;
-import org.sonar.api.profiles.ProfilePrototype;
import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.ActiveRuleParam;
-import org.sonar.api.rules.RulePriority;
-import org.sonar.api.rules.RulesRepository;
+import org.sonar.api.rules.*;
import org.sonar.api.utils.ValidationMessages;
import java.util.ArrayList;
@@ -41,33 +37,38 @@ public final class DeprecatedProfiles {
private RulesRepository[] deprecatedRepositories;
private Plugins plugins;
+ private RuleFinder ruleFinder;
private CheckProfile[] deprecatedCheckProfiles;
private CheckProfileProvider[] deprecatedCheckProfileProviders;
- public DeprecatedProfiles(Plugins plugins, RulesRepository[] r, CheckProfile[] deprecatedCheckProfiles, CheckProfileProvider[] deprecatedCheckProfileProviders) {
+ public DeprecatedProfiles(Plugins plugins, RuleFinder ruleFinder, RulesRepository[] r, CheckProfile[] deprecatedCheckProfiles, CheckProfileProvider[] deprecatedCheckProfileProviders) {
this.deprecatedRepositories = r;
this.plugins = plugins;
+ this.ruleFinder = ruleFinder;
this.deprecatedCheckProfiles = deprecatedCheckProfiles;
this.deprecatedCheckProfileProviders = deprecatedCheckProfileProviders;
}
- public DeprecatedProfiles(Plugins plugins, RulesRepository[] r, CheckProfile[] deprecatedCheckProfiles) {
+ public DeprecatedProfiles(Plugins plugins, RuleFinder ruleFinder, RulesRepository[] r, CheckProfile[] deprecatedCheckProfiles) {
this.deprecatedRepositories = r;
this.plugins = plugins;
+ this.ruleFinder = ruleFinder;
this.deprecatedCheckProfiles = deprecatedCheckProfiles;
this.deprecatedCheckProfileProviders = new CheckProfileProvider[0];
}
- public DeprecatedProfiles(Plugins plugins, RulesRepository[] r, CheckProfileProvider[] deprecatedCheckProfileProviders) {
+ public DeprecatedProfiles(Plugins plugins, RuleFinder ruleFinder, RulesRepository[] r, CheckProfileProvider[] deprecatedCheckProfileProviders) {
this.deprecatedRepositories = r;
this.plugins = plugins;
+ this.ruleFinder = ruleFinder;
this.deprecatedCheckProfiles = new CheckProfile[0];
this.deprecatedCheckProfileProviders = deprecatedCheckProfileProviders;
}
- public DeprecatedProfiles(Plugins plugins, RulesRepository[] r) {
+ public DeprecatedProfiles(Plugins plugins, RuleFinder ruleFinder, RulesRepository[] r) {
this.deprecatedRepositories = r;
this.plugins = plugins;
+ this.ruleFinder = ruleFinder;
this.deprecatedCheckProfiles = new CheckProfile[0];
this.deprecatedCheckProfileProviders = new CheckProfileProvider[0];
}
@@ -94,14 +95,17 @@ public final class DeprecatedProfiles {
for (int index = 0; index < repository.getProvidedProfiles().size(); index++) {
RulesProfile deprecated = (RulesProfile) repository.getProvidedProfiles().get(index);
DefaultProfileDefinition providedProfile = DefaultProfileDefinition.create(deprecated.getName(), repository.getLanguage().getKey());
- for (ActiveRule activeRule : deprecated.getActiveRules()) {
- String repositoryKey = activeRule.getRepositoryKey();
+ for (ActiveRule deprecatedActiveRule : deprecated.getActiveRules()) {
+ String repositoryKey = deprecatedActiveRule.getRepositoryKey();
if (StringUtils.isBlank(repositoryKey)) {
repositoryKey = getPluginKey(repository);
}
- ProfilePrototype.RulePrototype rule = providedProfile.activateRule(repositoryKey, activeRule.getRuleKey(), activeRule.getPriority());
- for (ActiveRuleParam arp : activeRule.getActiveRuleParams()) {
- rule.setParameter(arp.getKey(), arp.getValue());
+ Rule rule = ruleFinder.findByKey(repositoryKey, deprecatedActiveRule.getRuleKey());
+ if (rule != null) {
+ ActiveRule activeRule = providedProfile.activateRule(rule, deprecatedActiveRule.getPriority());
+ for (ActiveRuleParam arp : deprecatedActiveRule.getActiveRuleParams()) {
+ activeRule.setParameter(arp.getKey(), arp.getValue());
+ }
}
}
result.add(providedProfile);
@@ -116,9 +120,12 @@ public final class DeprecatedProfiles {
if (check.getPriority() != null) {
priority = RulePriority.fromCheckPriority(check.getPriority());
}
- ProfilePrototype.RulePrototype rule = definition.activateRule(check.getRepositoryKey(), check.getTemplateKey(), priority);
- for (Map.Entry<String, String> entry : rule.getParameters().entrySet()) {
- rule.setParameter(entry.getKey(), entry.getValue());
+ Rule rule = ruleFinder.findByKey(check.getRepositoryKey(), check.getTemplateKey());
+ if (rule != null) {
+ ActiveRule activeRule = definition.activateRule(rule, priority);
+ for (Map.Entry<String, String> entry : check.getProperties().entrySet()) {
+ activeRule.setParameter(entry.getKey(), entry.getValue());
+ }
}
}
return definition;
@@ -130,10 +137,10 @@ public final class DeprecatedProfiles {
public static class DefaultProfileDefinition extends ProfileDefinition {
- private ProfilePrototype prototype;
+ private RulesProfile profile;
DefaultProfileDefinition(String name, String language) {
- this.prototype = ProfilePrototype.create(name, language);
+ this.profile = RulesProfile.create(name, language);
}
public static DefaultProfileDefinition create(String name, String language) {
@@ -141,20 +148,21 @@ public final class DeprecatedProfiles {
}
@Override
- public ProfilePrototype createPrototype(ValidationMessages validation) {
- return prototype;
+ public RulesProfile createProfile(ValidationMessages validation) {
+ return profile;
}
- public List<ProfilePrototype.RulePrototype> getRules() {
- return prototype.getRules();
+ public List<ActiveRule> getRules() {
+ return profile.getActiveRules();
}
- public List<ProfilePrototype.RulePrototype> getRulesByRepositoryKey(String repositoryKey) {
- return prototype.getRulesByRepositoryKey(repositoryKey);
+
+ public List<ActiveRule> getRulesByRepositoryKey(String repositoryKey) {
+ return profile.getActiveRulesByRepository(repositoryKey);
}
- public ProfilePrototype.RulePrototype activateRule(String repositoryKey, String key, RulePriority nullablePriority) {
- return prototype.activateRule(repositoryKey, key, nullablePriority);
+ public ActiveRule activateRule(Rule rule, RulePriority nullablePriority) {
+ return profile.activateRule(rule, nullablePriority);
}
}
diff --git a/sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java b/sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java
index 3f9451f903b..0a67c2a7fed 100644
--- a/sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java
+++ b/sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java
@@ -79,45 +79,13 @@ public final class ProfilesConsole implements ServerComponent {
if (profile != null) {
session.remove(session);
}
- profile = RulesProfile.create(profileName, language);
ValidationMessages messages = ValidationMessages.create();
- ProfilePrototype prototype = XMLProfileImporter.create().importProfile(new StringReader(xmlBackup), messages);
- completeProfileWithPrototype(profile, prototype, messages);
+ profile = XMLProfileImporter.create(ruleFinder).importProfile(new StringReader(xmlBackup), messages);
session.saveWithoutFlush(profile);
session.commit();
return messages;
}
- private void completeProfileWithPrototype(RulesProfile profile, ProfilePrototype prototype, ValidationMessages messages) {
- for (ProfilePrototype.RulePrototype rulePrototype : prototype.getRules()) {
- Rule rule = findRule(rulePrototype);
- if (rule == null) {
- messages.addWarningText("The following rule has been ignored: " + rulePrototype);
-
- } else {
- ActiveRule activeRule = profile.activateRule(rule, rulePrototype.getPriority());
- for (Map.Entry<String, String> entry : rulePrototype.getParameters().entrySet()) {
- if (rule.getParam(entry.getKey())==null) {
- messages.addWarningText("The rule " + rulePrototype + " has no parameter named '" + entry.getKey() + "'.");
-
- } else {
- activeRule.setParameter(entry.getKey(), entry.getValue());
- }
- }
- }
- }
- }
-
- private Rule findRule(ProfilePrototype.RulePrototype rulePrototype) {
- if (StringUtils.isNotBlank(rulePrototype.getKey())) {
- return ruleFinder.findByKey(rulePrototype.getRepositoryKey(), rulePrototype.getKey());
- }
- if (StringUtils.isNotBlank(rulePrototype.getConfigKey())) {
- return ruleFinder.find(RuleQuery.create().withRepositoryKey(rulePrototype.getRepositoryKey()).withConfigKey(rulePrototype.getConfigKey()));
- }
- return null;
- }
-
private RulesProfile loadProfile(DatabaseSession session, int profileId) {
return session.getSingleResult(RulesProfile.class, "id", profileId);
}
@@ -154,14 +122,15 @@ public final class ProfilesConsole implements ServerComponent {
return null;
}
- public ValidationMessages importProfile(int profileId, String importerKey, String profileDefinition) {
+ /**
+ * Important : the ruby controller has already removed existing profile with same name/language.
+ */
+ public ValidationMessages importProfile(String profileName, String language, String importerKey, String profileDefinition) {
ValidationMessages messages = ValidationMessages.create();
ProfileImporter importer = getProfileImporter(importerKey);
- ProfilePrototype prototype = importer.importProfile(new StringReader(profileDefinition), messages);
+ RulesProfile profile = importer.importProfile(new StringReader(profileDefinition), messages);
if (!messages.hasErrors()) {
DatabaseSession session = sessionFactory.getSession();
- RulesProfile profile = loadProfile(session, profileId); // the profile has been create in the ruby controller
- completeProfileWithPrototype(profile, prototype, messages);
session.saveWithoutFlush(profile);
session.commit();
}
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java
index 06fb6390035..0e07aa95b0a 100644
--- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java
+++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java
@@ -24,12 +24,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.profiles.ProfileDefinition;
-import org.sonar.api.profiles.ProfilePrototype;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.rules.RuleQuery;
+import org.sonar.api.rules.ActiveRuleParam;
import org.sonar.api.utils.TimeProfiler;
import org.sonar.api.utils.ValidationMessages;
import org.sonar.jpa.session.DatabaseSessionFactory;
@@ -38,65 +35,62 @@ import org.sonar.server.rules.DeprecatedProfiles;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.Map;
public final class RegisterProvidedProfiles {
private static final Logger LOGGER = LoggerFactory.getLogger(RegisterProvidedProfiles.class);
- private RuleFinder ruleFinder;
private DatabaseSessionFactory sessionFactory;
private List<ProfileDefinition> definitions = new ArrayList<ProfileDefinition>();
+ private DeprecatedProfiles deprecatedProfiles = null;
- public RegisterProvidedProfiles(RuleFinder ruleFinder, DatabaseSessionFactory sessionFactory,
+ public RegisterProvidedProfiles(DatabaseSessionFactory sessionFactory,
DeprecatedProfiles deprecatedBridge, RegisterRules registerRulesBefore,
ProfileDefinition[] definitions) {
- this.ruleFinder = ruleFinder;
this.sessionFactory = sessionFactory;
this.definitions.addAll(Arrays.asList(definitions));
- if (deprecatedBridge != null) {
- this.definitions.addAll(deprecatedBridge.getProfiles());
- }
+ this.deprecatedProfiles = deprecatedBridge;
}
- public RegisterProvidedProfiles(RuleFinder ruleFinder, DatabaseSessionFactory sessionFactory,
+ public RegisterProvidedProfiles(DatabaseSessionFactory sessionFactory,
DeprecatedProfiles deprecatedBridge, RegisterRules registerRulesBefore) {
- this.ruleFinder = ruleFinder;
this.sessionFactory = sessionFactory;
- if (deprecatedBridge != null) {
- this.definitions.addAll(deprecatedBridge.getProfiles());
- }
+ this.deprecatedProfiles = deprecatedBridge;
}
public void start() {
TimeProfiler profiler = new TimeProfiler().start("Load provided profiles");
- List<ProfilePrototype> prototypes = createPrototypes();
+ List<RulesProfile> profiles = createProfiles();
DatabaseSession session = sessionFactory.getSession();
- deleteDeprecatedProfiles(prototypes, session);
- saveProvidedProfiles(prototypes, session);
+ cleanProvidedProfiles(profiles, session);
+ saveProvidedProfiles(profiles, session);
profiler.stop();
}
- List<ProfilePrototype> createPrototypes() {
- List<ProfilePrototype> result = new ArrayList<ProfilePrototype>();
+ List<RulesProfile> createProfiles() {
+ List<RulesProfile> result = new ArrayList<RulesProfile>();
+
+ // this must not be moved in the constructor, because rules are still not saved
+ definitions.addAll(deprecatedProfiles.getProfiles());
+
for (ProfileDefinition definition : definitions) {
ValidationMessages validation = ValidationMessages.create();
- ProfilePrototype prototype = definition.createPrototype(validation);
+ RulesProfile profile = definition.createProfile(validation);
validation.log(LOGGER);
- if (prototype != null && !validation.hasErrors()) {
- result.add(prototype);
+ if (profile != null && !validation.hasErrors()) {
+ result.add(profile);
}
}
return result;
}
- void deleteDeprecatedProfiles(List<ProfilePrototype> prototypes, DatabaseSession session) {
- TimeProfiler profiler = new TimeProfiler().start("Delete deprecated profiles");
+ void cleanProvidedProfiles(List<RulesProfile> profiles, DatabaseSession session) {
+ TimeProfiler profiler = new TimeProfiler().start("Clean provided profiles");
List<RulesProfile> existingProfiles = session.getResults(RulesProfile.class, "provided", true);
for (RulesProfile existingProfile : existingProfiles) {
boolean isDeprecated = true;
- for (ProfilePrototype profile: prototypes) {
+ for (RulesProfile profile : profiles) {
if (StringUtils.equals(existingProfile.getName(), profile.getName()) && StringUtils.equals(existingProfile.getLanguage(), profile.getLanguage())) {
isDeprecated = false;
break;
@@ -117,43 +111,29 @@ public final class RegisterProvidedProfiles {
}
- void saveProvidedProfiles(List<ProfilePrototype> prototypes, DatabaseSession session) {
- for (ProfilePrototype prototype : prototypes) {
- TimeProfiler profiler = new TimeProfiler().start("Save profile " + prototype);
- RulesProfile profile = findOrCreate(prototype, session);
-
- for (ProfilePrototype.RulePrototype rulePrototype : prototype.getRules()) {
- Rule rule = findRule(rulePrototype);
- if (rule == null) {
- LOGGER.warn("The profile " + prototype + " defines an unknown rule: " + rulePrototype);
+ void saveProvidedProfiles(List<RulesProfile> profiles, DatabaseSession session) {
+ for (RulesProfile profile : profiles) {
+ TimeProfiler profiler = new TimeProfiler().start("Save profile " + profile);
+ RulesProfile persistedProfile = findOrCreate(profile.getName(), profile.getLanguage(), session);
- } else {
- ActiveRule activeRule = profile.activateRule(rule, rulePrototype.getPriority());
- for (Map.Entry<String, String> entry : rulePrototype.getParameters().entrySet()) {
- activeRule.setParameter(entry.getKey(), entry.getValue());
- }
+ for (ActiveRule activeRule : profile.getActiveRules()) {
+ ActiveRule persistedRule = persistedProfile.activateRule(activeRule.getRule(), activeRule.getPriority());
+ for (ActiveRuleParam param : activeRule.getActiveRuleParams()) {
+ persistedRule.setParameter(param.getKey(), param.getValue());
}
}
- session.saveWithoutFlush(profile);
+
+ session.saveWithoutFlush(persistedProfile);
session.commit();
profiler.stop();
}
- }
- private Rule findRule(ProfilePrototype.RulePrototype rulePrototype) {
- if (StringUtils.isNotBlank(rulePrototype.getKey())) {
- return ruleFinder.findByKey(rulePrototype.getRepositoryKey(), rulePrototype.getKey());
- }
- if (StringUtils.isNotBlank(rulePrototype.getConfigKey())) {
- return ruleFinder.find(RuleQuery.create().withRepositoryKey(rulePrototype.getRepositoryKey()).withConfigKey(rulePrototype.getConfigKey()));
- }
- return null;
}
- private RulesProfile findOrCreate(ProfilePrototype prototype, DatabaseSession session) {
- RulesProfile profile = session.getSingleResult(RulesProfile.class, "name", prototype.getName(), "language", prototype.getLanguage());
+ private RulesProfile findOrCreate(String name, String language, DatabaseSession session) {
+ RulesProfile profile = session.getSingleResult(RulesProfile.class, "name", name, "language", language);
if (profile == null) {
- profile = RulesProfile.create(prototype.getName(), prototype.getLanguage());
+ profile = RulesProfile.create(name, language);
profile.setProvided(true);
profile.setDefaultProfile(false);
}
diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
index 404e2dac725..2c2cd383a4d 100644
--- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
+++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
@@ -152,8 +152,8 @@ public class JRubyFacade {
return getContainer().getComponent(ProfilesConsole.class).exportProfile(profileId, exporterKey);
}
- public ValidationMessages importProfile(int profileId, String importerKey, String fileContent) {
- return getContainer().getComponent(ProfilesConsole.class).importProfile(profileId, importerKey, fileContent);
+ public ValidationMessages importProfile(String profileName, String language, String importerKey, String fileContent) {
+ return getContainer().getComponent(ProfilesConsole.class).importProfile(profileName, language, importerKey, fileContent);
}
public String getProfileExporterMimeType(String exporterKey) {
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/plugins/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/plugins/resource_controller.rb
index 7d7d596a5a0..05aae87c7bf 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/plugins/resource_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/plugins/resource_controller.rb
@@ -20,6 +20,7 @@
class Plugins::ResourceController < ApplicationController
SECTION=Navigation::SECTION_RESOURCE
+ helper :project
def index
@project = ::Project.by_key(params[:id])
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb
index e5487a11ad7..93dd9d3e065 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb
@@ -176,12 +176,11 @@ class ProfilesController < ApplicationController
#
#
def export
- name = CGI::unescape(params[:name])
language = params[:language]
- if (name.blank?)
+ if (params[:name].blank?)
profile = Profile.find_active_profile_by_language(language)
else
- profile = Profile.find_by_name_and_language(name, language)
+ profile = Profile.find_by_name_and_language(CGI::unescape(params[:name]), language)
end
exporter_key = params[:format]
result = java_facade.exportProfile(profile.id, exporter_key)
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 2207696bb3f..0fb92332142 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
@@ -80,7 +80,7 @@
<tbody>
<% @profiles.select{|p| p.language==language.getKey()}.each do |profile| %>
<tr class="<%= cycle 'even', 'odd', :name => language.getKey() -%>" id="<%= u profile.key %>">
- <td><a href="<%= url_for :controller => 'rules_configuration', :action => 'index', :id => profile.id -%>"><%= h profile.name %></a></td>
+ <td><a href="<%= url_for :controller => 'rules_configuration', :action => 'index', :id => profile.id -%>" id="rules-<%= language.getKey() -%>-<%= u(profile.name) -%>"><%= h profile.name %></a></td>
<td align="right">
<span id="activated_rules_<%= u profile.key -%>"><%= profile.active_rules.count -%></span>
diff --git a/sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java b/sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java
index 90ef31a03e3..cd5b40f38ab 100644
--- a/sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java
@@ -20,6 +20,7 @@
package org.sonar.server.rules;
import org.junit.Test;
+import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.utils.ValidationMessages;
import org.sonar.server.rules.DeprecatedProfiles;
@@ -32,15 +33,15 @@ public class DeprecatedProfilesTest {
@Test
public void testCreate() {
DeprecatedProfiles.DefaultProfileDefinition def = DeprecatedProfiles.DefaultProfileDefinition.create("sonar way", "java");
- assertThat(def.createPrototype(ValidationMessages.create()).getName(), is("sonar way"));
- assertThat(def.createPrototype(ValidationMessages.create()).getLanguage(), is("java"));
+ assertThat(def.createProfile(ValidationMessages.create()).getName(), is("sonar way"));
+ assertThat(def.createProfile(ValidationMessages.create()).getLanguage(), is("java"));
}
@Test
public void testActivateRule() {
DeprecatedProfiles.DefaultProfileDefinition def = DeprecatedProfiles.DefaultProfileDefinition.create("sonar way", "java");
- def.activateRule("checkstyle", "IllegalRegexp", RulePriority.BLOCKER);
- def.activateRule("pmd", "NullPointer", RulePriority.INFO);
+ def.activateRule(Rule.create("checkstyle", "IllegalRegexp", "Illegal Regexp"), RulePriority.BLOCKER);
+ def.activateRule(Rule.create("pmd", "NullPointer", "Null Pointer"), RulePriority.INFO);
assertThat(def.getRules().size(), is(2));
assertThat(def.getRulesByRepositoryKey("checkstyle").size(), is(1));
@@ -50,7 +51,7 @@ public class DeprecatedProfilesTest {
@Test
public void priorityIsOptional() {
DeprecatedProfiles.DefaultProfileDefinition def = DeprecatedProfiles.DefaultProfileDefinition.create("sonar way", "java");
- def.activateRule("checkstyle", "IllegalRegexp", null);
- assertThat(def.getRules().get(0).getPriority(), nullValue());
+ def.activateRule(Rule.create("checkstyle", "IllegalRegexp", "Illegal regexp").setPriority(RulePriority.BLOCKER), null);
+ assertThat(def.getRules().get(0).getPriority(), is(RulePriority.BLOCKER));
}
}