aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java2
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/noDefinitionsToRegister-result.xml6
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/registerOnlyNewDefinitions-result.xml6
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/reset-result.xml12
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/shared.xml6
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/saveModelAndCharacteristics.xml2
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/testGraphOfCharacteristics.xml4
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/testTreeOfCharacteristics.xml2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java12
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Model.java42
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/characteristic.rb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/138_add_characteristic_description.rb1
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/139_add_characteristic_enabled.rb27
13 files changed, 97 insertions, 29 deletions
diff --git a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java
index f258d01481f..54cbf7f3464 100644
--- a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java
+++ b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java
@@ -30,7 +30,7 @@ import javax.persistence.*;
public class SchemaMigration {
public final static int VERSION_UNKNOWN = -1;
- public static final int LAST_VERSION = 138;
+ public static final int LAST_VERSION = 139;
public final static String TABLE_NAME = "schema_migrations";
diff --git a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/noDefinitionsToRegister-result.xml b/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/noDefinitionsToRegister-result.xml
index e1f6a9edc04..c26de5371bb 100644
--- a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/noDefinitionsToRegister-result.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/noDefinitionsToRegister-result.xml
@@ -2,9 +2,9 @@
<quality_models id="1" name="M1" />
<quality_models id="2" name="M2" />
- <characteristics id="1" kee="M1C1" name="M1C1" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" />
- <characteristics id="2" kee="M1C2" name="M1C2" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="2" description="[null]" />
- <characteristics id="3" kee="M2C1" name="M2C1" quality_model_id="2" rule_id="[null]" characteristic_order="1" depth="1" description="[null]"/>
+ <characteristics id="1" kee="M1C1" name="M1C1" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true" />
+ <characteristics id="2" kee="M1C2" name="M1C2" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="2" description="[null]" enabled="true" />
+ <characteristics id="3" kee="M2C1" name="M2C1" quality_model_id="2" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true"/>
<characteristic_edges child_id="2" parent_id="1"/>
</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/registerOnlyNewDefinitions-result.xml b/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/registerOnlyNewDefinitions-result.xml
index a33aec7b5e5..455cfb41cde 100644
--- a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/registerOnlyNewDefinitions-result.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/registerOnlyNewDefinitions-result.xml
@@ -5,9 +5,9 @@
<!-- NEW MODEL -->
<quality_models id="3" name="NEWMODEL" />
- <characteristics id="1" kee="M1C1" name="M1C1" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" />
- <characteristics id="2" kee="M1C2" name="M1C2" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="2" description="[null]" />
- <characteristics id="3" kee="M2C1" name="M2C1" quality_model_id="2" rule_id="[null]" characteristic_order="1" depth="1" description="[null]"/>
+ <characteristics id="1" kee="M1C1" name="M1C1" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true" />
+ <characteristics id="2" kee="M1C2" name="M1C2" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="2" description="[null]" enabled="true" />
+ <characteristics id="3" kee="M2C1" name="M2C1" quality_model_id="2" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true"/>
<characteristic_edges child_id="2" parent_id="1"/>
</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/reset-result.xml b/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/reset-result.xml
index 4eaeb3441d9..bbffd8e4a77 100644
--- a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/reset-result.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/reset-result.xml
@@ -3,12 +3,12 @@
<quality_models id="2" name="M2" />
<quality_models id="3" name="M1" />
- <!--<characteristics id="1" kee="M1C1" name="M1C1" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" />-->
- <!--<characteristics id="2" kee="M1C2" name="M1C2" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="2" description="[null]"/>-->
- <characteristics id="3" kee="M2C1" name="M2C1" quality_model_id="2" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" />
- <characteristics id="4" kee="NEWM1C1A" name="NEWM1C1A" quality_model_id="3" rule_id="[null]" characteristic_order="1" depth="2" description="[null]"/>
- <characteristics id="5" kee="NEWM1C1" name="NEWM1C1" quality_model_id="3" rule_id="[null]" characteristic_order="1" depth="1" description="[null]"/>
- <characteristics id="6" kee="NEWM1C2" name="NEWM1C2" quality_model_id="3" rule_id="[null]" characteristic_order="2" depth="1" description="[null]"/>
+ <!--<characteristics id="1" kee="M1C1" name="M1C1" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true" />-->
+ <!--<characteristics id="2" kee="M1C2" name="M1C2" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="2" description="[null]" enabled="true"/>-->
+ <characteristics id="3" kee="M2C1" name="M2C1" quality_model_id="2" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true" />
+ <characteristics id="4" kee="NEWM1C1A" name="NEWM1C1A" quality_model_id="3" rule_id="[null]" characteristic_order="1" depth="2" description="[null]" enabled="true"/>
+ <characteristics id="5" kee="NEWM1C1" name="NEWM1C1" quality_model_id="3" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true"/>
+ <characteristics id="6" kee="NEWM1C2" name="NEWM1C2" quality_model_id="3" rule_id="[null]" characteristic_order="2" depth="1" description="[null]" enabled="true"/>
<!--<characteristic_edges child_id="2" parent_id="1"/>-->
<characteristic_edges child_id="4" parent_id="5"/>
diff --git a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/shared.xml
index e1f6a9edc04..c26de5371bb 100644
--- a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/shared.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/qualitymodel/DefaultModelFinderTest/shared.xml
@@ -2,9 +2,9 @@
<quality_models id="1" name="M1" />
<quality_models id="2" name="M2" />
- <characteristics id="1" kee="M1C1" name="M1C1" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" />
- <characteristics id="2" kee="M1C2" name="M1C2" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="2" description="[null]" />
- <characteristics id="3" kee="M2C1" name="M2C1" quality_model_id="2" rule_id="[null]" characteristic_order="1" depth="1" description="[null]"/>
+ <characteristics id="1" kee="M1C1" name="M1C1" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true" />
+ <characteristics id="2" kee="M1C2" name="M1C2" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="2" description="[null]" enabled="true" />
+ <characteristics id="3" kee="M2C1" name="M2C1" quality_model_id="2" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true"/>
<characteristic_edges child_id="2" parent_id="1"/>
</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/saveModelAndCharacteristics.xml b/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/saveModelAndCharacteristics.xml
index 7c9b11d41a8..cd0705734b2 100644
--- a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/saveModelAndCharacteristics.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/saveModelAndCharacteristics.xml
@@ -1,4 +1,4 @@
<dataset>
<quality_models id="1" name="initial" />
- <characteristics id="1" kee="FAKE" name="fake" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" />
+ <characteristics id="1" kee="FAKE" name="fake" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true" />
</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/testGraphOfCharacteristics.xml b/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/testGraphOfCharacteristics.xml
index c0dc6f60071..ee6e959b85b 100644
--- a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/testGraphOfCharacteristics.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/testGraphOfCharacteristics.xml
@@ -1,8 +1,8 @@
<dataset>
<quality_models id="1" name="initial" />
- <characteristics id="1" kee="FAKE1" name="fake1" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="1" description="[null]"/>
- <characteristics id="2" kee="FAKE2" name="fake2" quality_model_id="1" rule_id="[null]" characteristic_order="2" depth="1" description="[null]" />
+ <characteristics id="1" kee="FAKE1" name="fake1" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true"/>
+ <characteristics id="2" kee="FAKE2" name="fake2" quality_model_id="1" rule_id="[null]" characteristic_order="2" depth="1" description="[null]" enabled="true" />
<characteristic_edges child_id="2" parent_id="1"/>
</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/testTreeOfCharacteristics.xml b/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/testTreeOfCharacteristics.xml
index 2b3b22aaf38..ef3d9a58680 100644
--- a/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/testTreeOfCharacteristics.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/qualitymodel/ModelTest/testTreeOfCharacteristics.xml
@@ -1,5 +1,5 @@
<dataset>
<quality_models id="1" name="initial" />
- <characteristics id="1" kee="FAKE" name="fake" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" />
+ <characteristics id="1" kee="FAKE" name="fake" quality_model_id="1" rule_id="[null]" characteristic_order="1" depth="1" description="[null]" enabled="true" />
<characteristic_edges child_id="1" parent_id="1"/>
</dataset> \ No newline at end of file
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java
index 3922ec8d3b2..1b2d30ea961 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java
@@ -68,6 +68,9 @@ public final class Characteristic implements Comparable<Characteristic> {
@Column(name = "description", nullable = true, length = 4000)
private String description;
+ @Column(name = "enabled", updatable = true, nullable = true)
+ private Boolean enabled = Boolean.TRUE;
+
@ManyToMany
@JoinTable(
name = "characteristic_edges",
@@ -134,6 +137,15 @@ public final class Characteristic implements Comparable<Characteristic> {
return this;
}
+ public Boolean getEnabled() {
+ return enabled;
+ }
+
+ public Characteristic setEnabled(Boolean b) {
+ this.enabled = b;
+ return this;
+ }
+
public Characteristic addChildren(Characteristic... list) {
if (list != null) {
for (Characteristic c : list) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Model.java b/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Model.java
index 5e698902084..20bb2a46a57 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Model.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Model.java
@@ -19,6 +19,7 @@
*/
package org.sonar.api.qualitymodel;
+import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
@@ -44,7 +45,7 @@ public final class Model implements Comparable<Model> {
private String name;
@OneToMany(mappedBy = "model", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
- private List<Characteristic> characteristics = new ArrayList<Characteristic>();
+ private List<Characteristic> characteristics = Lists.newArrayList();
/**
* Use the factory method <code>Model</code>
@@ -104,32 +105,57 @@ public final class Model implements Comparable<Model> {
return c;
}
+ /**
+ * @return enabled characteristics
+ */
public List<Characteristic> getCharacteristics() {
- return characteristics;
+ return getCharacteristics(true);
+ }
+
+ public List<Characteristic> getCharacteristics(boolean onlyEnabled) {
+ if (!onlyEnabled) {
+ return characteristics;
+ }
+ List<Characteristic> result = Lists.newArrayList();
+ for (Characteristic characteristic : characteristics) {
+ if (characteristic.getEnabled()) {
+ result.add(characteristic);
+ }
+ }
+ return result;
}
+ /**
+ * Search for an ENABLED characteristic by its key.
+ */
public Characteristic getCharacteristicByKey(String key) {
- for (Characteristic characteristic : getCharacteristics()) {
- if (StringUtils.equals(key, characteristic.getKey())) {
+ for (Characteristic characteristic : characteristics) {
+ if (characteristic.getEnabled() && StringUtils.equals(key, characteristic.getKey())) {
return characteristic;
}
}
return null;
}
+ /**
+ * Search for ENABLED characteristics by their depth.
+ */
public List<Characteristic> getCharacteristicsByDepth(int depth) {
- List<Characteristic> result = new ArrayList<Characteristic>();
+ List<Characteristic> result = Lists.newArrayList();
for (Characteristic c : characteristics) {
- if (c.getDepth()==depth) {
+ if (c.getEnabled() && c.getDepth()==depth) {
result.add(c);
}
}
return result;
}
+ /**
+ * Search for an ENABLED characteristic by its name.
+ */
public Characteristic getCharacteristicByName(String name) {
- for (Characteristic characteristic : getCharacteristics()) {
- if (StringUtils.equals(name, characteristic.getName())) {
+ for (Characteristic characteristic : characteristics) {
+ if (characteristic.getEnabled() && StringUtils.equals(name, characteristic.getName())) {
return characteristic;
}
}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/characteristic.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/characteristic.rb
index 2603b99ac29..ad372e6ae5d 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/characteristic.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/characteristic.rb
@@ -28,6 +28,10 @@ class Characteristic < ActiveRecord::Base
belongs_to :rule
belongs_to :quality_model
+
+ validates_uniqueness_of :name, :scope => :quality_model_id, :case_sensitive => false, :if => Proc.new { |c| c.rule_id.nil? }
+ validates_length_of :name, :in => 1..100, :allow_blank => false, :if => Proc.new { |c| c.rule_id.nil? }
+ validates_presence_of :quality_model
def root?
depth==1
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/138_add_characteristic_description.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/138_add_characteristic_description.rb
index 88f1f5147af..cef6e279898 100644
--- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/138_add_characteristic_description.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/138_add_characteristic_description.rb
@@ -21,7 +21,6 @@ class AddCharacteristicDescription < ActiveRecord::Migration
def self.up
add_column 'characteristics', 'description', :string, :null => true, :limit => 4000
- Characteristic.reset_column_information
end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/139_add_characteristic_enabled.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/139_add_characteristic_enabled.rb
new file mode 100644
index 00000000000..ec149acfb09
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/139_add_characteristic_enabled.rb
@@ -0,0 +1,27 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2009 SonarSource SA
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar 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.
+#
+# Sonar 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 Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+#
+class AddCharacteristicEnabled < ActiveRecord::Migration
+
+ def self.up
+ add_column 'characteristics', 'enabled', :boolean, :null => true
+ Characteristic.reset_column_information
+ end
+
+end