aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-10 12:27:33 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-10 12:27:33 +0000
commit5cd839bbecd061d9463694d025788754bfca0f08 (patch)
tree6140b78f770fd0ab9654784e2068e80dadfb6345 /sonar-server/src
parent5c90df84c8d4c69c38868736bd28cb61f89d4b31 (diff)
downloadsonarqube-5cd839bbecd061d9463694d025788754bfca0f08.tar.gz
sonarqube-5cd839bbecd061d9463694d025788754bfca0f08.zip
simplify ValidationMessages and ProfileDefinition
Diffstat (limited to 'sonar-server/src')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java3
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java37
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb4
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java4
5 files changed, 30 insertions, 22 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 bb3db460eff..17b42d3df23 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
@@ -132,8 +132,7 @@ public final class DeprecatedProfiles {
private ProfilePrototype prototype;
DefaultProfileDefinition(String name, String language) {
- super(name, language);
- this.prototype = ProfilePrototype.create();
+ this.prototype = ProfilePrototype.create(name, language);
}
public static DefaultProfileDefinition create(String name, String language) {
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 ed5c23fe520..9e66f2ca222 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
@@ -92,13 +92,13 @@ public final class ProfilesConsole implements ServerComponent {
for (ProfilePrototype.RulePrototype rulePrototype : prototype.getRules()) {
Rule rule = findRule(rulePrototype);
if (rule == null) {
- messages.addWarning("profiles.missingRule", "The following rule has been ignored: " + rulePrototype);
+ 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.addWarning("profiles.missingRuleParameter", "The rule " + rulePrototype + " has no parameter named '" + entry.getKey() + "'.");
+ messages.addWarningText("The rule " + rulePrototype + " has no parameter named '" + entry.getKey() + "'.");
} else {
activeRule.setParameter(entry.getKey(), entry.getValue());
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 a270e602beb..999d065f605 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
@@ -69,19 +69,29 @@ public final class RegisterProvidedProfiles {
public void start() {
TimeProfiler profiler = new TimeProfiler().start("Load provided profiles");
+
+ List<ProfilePrototype> prototypes = createPrototypes();
DatabaseSession session = sessionFactory.getSession();
- deleteDeprecatedProfiles(session);
- saveProvidedProfiles(session);
+ deleteDeprecatedProfiles(prototypes, session);
+ saveProvidedProfiles(prototypes, session);
profiler.stop();
}
- void deleteDeprecatedProfiles(DatabaseSession session) {
+ List<ProfilePrototype> createPrototypes() {
+ List<ProfilePrototype> result = new ArrayList<ProfilePrototype>();
+ for (ProfileDefinition definition : definitions) {
+ result.add(definition.createPrototype());
+ }
+ return result;
+ }
+
+ void deleteDeprecatedProfiles(List<ProfilePrototype> prototypes, DatabaseSession session) {
TimeProfiler profiler = new TimeProfiler().start("Delete deprecated profiles");
List<RulesProfile> existingProfiles = session.getResults(RulesProfile.class, "provided", true);
for (RulesProfile existingProfile : existingProfiles) {
boolean isDeprecated = true;
- for (ProfileDefinition definition : definitions) {
- if (StringUtils.equals(existingProfile.getName(), definition.getName()) && StringUtils.equals(existingProfile.getLanguage(), definition.getLanguage())) {
+ for (ProfilePrototype profile: prototypes) {
+ if (StringUtils.equals(existingProfile.getName(), profile.getName()) && StringUtils.equals(existingProfile.getLanguage(), profile.getLanguage())) {
isDeprecated = false;
break;
}
@@ -101,16 +111,15 @@ public final class RegisterProvidedProfiles {
}
- void saveProvidedProfiles(DatabaseSession session) {
- for (ProfileDefinition definition : definitions) {
- TimeProfiler profiler = new TimeProfiler().start("Save profile " + definition);
- ProfilePrototype prototype = definition.createPrototype();
- RulesProfile profile = findOrCreate(definition, session);
+ 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 " + definition + " defines an unknown rule: " + rulePrototype);
+ LOGGER.warn("The profile " + prototype + " defines an unknown rule: " + rulePrototype);
} else {
ActiveRule activeRule = profile.activateRule(rule, rulePrototype.getPriority());
@@ -135,10 +144,10 @@ public final class RegisterProvidedProfiles {
return null;
}
- private RulesProfile findOrCreate(ProfileDefinition definition, DatabaseSession session) {
- RulesProfile profile = session.getSingleResult(RulesProfile.class, "name", definition.getName(), "language", definition.getLanguage());
+ private RulesProfile findOrCreate(ProfilePrototype prototype, DatabaseSession session) {
+ RulesProfile profile = session.getSingleResult(RulesProfile.class, "name", prototype.getName(), "language", prototype.getLanguage());
if (profile == null) {
- profile = RulesProfile.create(definition.getName(), definition.getLanguage());
+ profile = RulesProfile.create(prototype.getName(), prototype.getLanguage());
profile.setProvided(true);
profile.setDefaultProfile(false);
}
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 f0b76336a06..f6f81574756 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
@@ -118,7 +118,7 @@
</td>
<td align="right">
- <% if !profile.provided? %>
+ <% if !(profile.provided?) %>
<% form_tag(:action => 'rename', :id => profile.id) do -%>
<%= hidden_field_tag 'rename_' + profile.id.to_s %>
<input type="button" name="button_rename" id="rename_<%= u profile.key %>" value="Rename" onClick='var name=prompt("New name"); if (name!=null) {$("rename_<%= profile.id %>").value=name; submit();} else {return false;}'>
@@ -130,7 +130,7 @@
<% form_tag(:action => 'copy', :id => profile.id) do -%>
<%= hidden_field_tag 'copy_' + profile.id.to_s %>
<input type="button" name="button_copy" id="copy_<%= u profile.key %>" value="Copy" onClick='var name=prompt("Name for the new profile"); if (name!=null) {$("copy_<%= profile.id %>").value=name; submit();} else {return false;}'>
- <% end
+ <% end %>
</td>
<td>
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 1d94991ce8e..373f7369654 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
@@ -31,8 +31,8 @@ public class DeprecatedProfilesTest {
@Test
public void testCreate() {
DeprecatedProfiles.DefaultProfileDefinition def = DeprecatedProfiles.DefaultProfileDefinition.create("sonar way", "java");
- assertThat(def.getName(), is("sonar way"));
- assertThat(def.getLanguage(), is("java"));
+ assertThat(def.createPrototype().getName(), is("sonar way"));
+ assertThat(def.createPrototype().getLanguage(), is("java"));
}
@Test