aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2014-03-20 13:30:21 +0600
committerStas Vilchik <vilchiks@gmail.com>2014-03-20 13:30:21 +0600
commitea2f43be47be01cb790348d90b7cc12db5d27f48 (patch)
treed548181596fba60ca3fab48c67bdae18a178d1c6
parent27447442880586ef8636448b07857eee75d270c1 (diff)
parent02b1910cacbc3c5e563d55779ea13bb0c6dca528 (diff)
downloadsonarqube-ea2f43be47be01cb790348d90b7cc12db5d27f48.tar.gz
sonarqube-ea2f43be47be01cb790348d90b7cc12db5d27f48.zip
Merge branch 'master' into grunt
Conflicts: sonar-server/src/main/webapp/WEB-INF/app/views/quality_gates/templates/_quality_gate_detail_conditions_template.hbs.erb sonar-server/src/main/webapp/javascripts/quality-gate/views/quality-gate-detail-condition-view.js sonar-server/src/main/webapp/javascripts/quality-gate/views/quality-gate-detail-header-view.js
-rw-r--r--.gitignore1
-rw-r--r--plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties94
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/qualitygate/ConditionUtils.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/qualitygate/ConditionUtilsTest.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/BatchSession.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java13
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java15
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtModelSynchronizer.java7
-rw-r--r--sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtRuleCache.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtXMLImporter.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDao.java27
-rw-r--r--sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDto.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicMapper.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/template/LoadedTemplateDto.java1
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl2
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml18
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/technicaldebt/db/CharacteristicMapper.xml18
-rw-r--r--sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java43
-rw-r--r--sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDaoTest.java18
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/insert-result.xml2
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/insert_all-result.xml4
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/selectAll.xml2
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_by_characteristic_or_sub_characteristic_id.xml61
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_enables_and_non_manual.xml26
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/update-result.xml2
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable-result.xml6
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable.xml6
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/select_sub_characteristics_by_parent_id.xml31
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_characteristic-result.xml2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java21
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/debt/DebtCharacteristicsXMLImporter.java82
-rw-r--r--sonar-server/src/main/java/org/sonar/server/debt/DebtModelService.java58
-rw-r--r--sonar-server/src/main/java/org/sonar/server/debt/DebtModelSynchronizer.java19
-rw-r--r--sonar-server/src/main/java/org/sonar/server/debt/DebtRulesXMLImporter.java9
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java6
-rw-r--r--sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginJarsInstaller.java2
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualitygate/RegisterBuiltinQualityGate.java67
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java3
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java10
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/RuleRepositories.java15
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRules.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/RegisterDebtModel.java3
-rw-r--r--sonar-server/src/main/java/org/sonar/server/user/DoPrivileged.java45
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb100
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/520_add_debt_columns_to_rules.rb2
-rw-r--r--sonar-server/src/main/webapp/coffee/quality-gate/views/quality-gate-detail-condition-view.coffee3
-rw-r--r--sonar-server/src/main/webapp/coffee/quality-gate/views/quality-gate-detail-header-view.coffee3
-rw-r--r--sonar-server/src/main/webapp/js/templates/quality-gates.js16
-rw-r--r--sonar-server/src/main/webapp/less/style.less7
-rw-r--r--sonar-server/src/main/webapp/templates/quality-gates/quality-gate-detail-conditions.hbs43
-rw-r--r--sonar-server/src/test/java/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest.java33
-rw-r--r--sonar-server/src/test/java/org/sonar/server/debt/DebtModelServiceTest.java119
-rw-r--r--sonar-server/src/test/java/org/sonar/server/debt/DebtModelSynchronizerTest.java12
-rw-r--r--sonar-server/src/test/java/org/sonar/server/debt/DebtRulesXMLImporterTest.java12
-rw-r--r--sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarsInstallerTest.java2
-rw-r--r--sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterBuiltinQualityGateTest.java85
-rw-r--r--sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java11
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/RuleRegistrationTest.java4
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rule/RuleRepositoriesTest.java25
-rw-r--r--sonar-server/src/test/java/org/sonar/server/startup/RegisterDebtModelTest.java4
-rw-r--r--sonar-server/src/test/java/org/sonar/server/user/DoPrivilegedTest.java40
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest/fail_on_bad_xml.xml1
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/debt/DebtRulesXMLImporterTest/fail_on_bad_xml.xml1
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/plugins/ServerPluginJarsInstallerTest/fail_if_require_greater_SQ_version/extensions/plugins/sonar-switch-off-violations-plugin-1.1.jar (renamed from sonar-server/src/test/resources/org/sonar/server/plugins/ServerPluginJarsInstallerTest/should_fail_on_plugin_depending_on_more_recent_sonar/extensions/plugins/sonar-switch-off-violations-plugin-1.1.jar)bin12689 -> 12689 bytes
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/ignore_rule_debt_definitions_if_rule_is_linked_on_root_characteristic.xml2
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/insert_new_rules-result.xml6
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/not_disable_already_disabled_rules-result.xml8
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/not_disable_already_disabled_rules.xml4
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_characteristic_not_found-result.xml4
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_characteristic_not_found.xml2
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_default_characteristic_not_found_and_overriding_characteristic_disabled-result.xml4
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_default_characteristic_not_found_and_overriding_characteristic_disabled.xml4
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_default_characteristic_when_default_characteristic_not_found_but_characteristic_has_been_overridden-result.xml4
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_default_characteristic_when_default_characteristic_not_found_but_characteristic_has_been_overridden.xml4
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_rule_fields-result.xml4
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_rule_fields.xml2
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language-result.xml8
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language.xml8
80 files changed, 993 insertions, 365 deletions
diff --git a/.gitignore b/.gitignore
index feb8c276e46..f2948f10e37 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,6 +24,7 @@ target/
.classpath
.project
.settings
+.externalToolBuilders
# ---- Mac OS X
.DS_Store
diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
index 05087f7e7dd..3aab929203e 100644
--- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
+++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
@@ -852,96 +852,6 @@ property.sonar.global.test.exclusions.name=Global Test File Exclusions
property.sonar.global.test.exclusions.description=Patterns used to exclude some test files from analysis. They apply to every project and cannot be overridden.
property.category.exclusions.files=Files
property.category.exclusions.files.description=Configure which source code and tests you want to be omitted from analysis. Most of these parameters can also be configured at individual project level in each application's project settings.
-category.exclusions.help=<h2>Wildcards</h2>\
- <p>Following rules are applied:</p>\
- <table class="data">\
- <thead><tr><th colspan="2"></th></tr></thead>\
- <tr class="odd">\
- <td>*</td>\
- <td>Match zero or more characters</td>\
- </tr>\
- <tr class="even">\
- <td>**</td>\
- <td>Match zero or more directories</td>\
- </tr>\
- <tr class="odd">\
- <td>?</td>\
- <td>Match a single character</td>\
- </tr>\
- <tr class="even">\
- <td>file:</td>\
- <td>Prefix to define a pattern based on absolute path</td>\
- </tr>\
- </table>\
- <p>Examples:</p>\
- <table class="data">\
- <thead><tr><th>Filter</th><th>Description</th><th>Matches</th></tr></thead>\
- <tbody>\
- <tr class="odd">\
- <td>org/mycompany/*.java</td>\
- <td>matches all <code>.java</code> files in the <code>org/mycompany</code> directory</td>\
- <td>\
- <ul>\
- <li>org/mycompany/Foo.java</li>\
- <li>org/mycompany/Bar.java</li>\
- </ul>\
- </td>\
- </tr>\
- <tr class="even">\
- <td>org/*Model*.java</td>\
- <td>matches all <code>.java</code> files with <code>Model</code> in filename and in the <code>org</code> directory</td>\
- <td>\
- <ul>\
- <li>org/Model.java</li>\
- <li>org/FirstModel.java</li>\
- <li>org/ModelTest.java</li>\
- </ul>\
- </td>\
- </tr>\
- <tr class="odd">\
- <td>org/**</td>\
- <td>matches all files underneath the <code>org</code> directory</td>\
- <td>\
- <ul>\
- <li>org/Foo.java</li>\
- <li>org/foo/bar.jsp</li>\
- </ul>\
- </td>\
- </tr>\
- <tr class="even">\
- <td>org/**/Dummy.java</td>\
- <td>matches all <code>Dummy.java</code> files underneath the <code>org</code> directory</td>\
- <td>\
- <ul>\
- <li>org/Dummy.java</li>\
- <li>org/foo/Dummy.java</li>\
- <li>org/foo/bar/Dummy.java</li>\
- </ul>\
- </td>\
- </tr>\
- <tr class="odd">\
- <td>org/**/*.java</td>\
- <td>matches all <code>.java</code> files underneath the <code>org</code> directory</td>\
- <td>\
- <ul>\
- <li>org/Foo.java</li>\
- <li>org/foo/Bar.java</li>\
- <li>org/foo/bar/Baz.java</li>\
- </ul>\
- </td>\
- </tr>\
- <tr class="even">\
- <td>file:**/generated/**</td>\
- <td>matches all files whose one parent directory is 'generated'.</td>\
- <td>\
- <ul>\
- <li>/path/to/project/tmp/generated/org/castor/Model.java</li>\
- </ul>\
- </td>\
- </tr>\
- </tbody>\
- </table>
-
property.sonar.skippedModules.name=Module Exclusions
property.sonar.skippedModules.description=Comma-separated list of the modules to exclude from analysis.<br>\
If a module's artifactId differs from its module name (the directory name): it is the artifactId that should be use instead of the module name.
@@ -1670,6 +1580,10 @@ quality_gates.operator.LT=is less than
quality_gates.operator.GT=is greater than
quality_gates.operator.EQ=equals
quality_gates.operator.NE=is not
+quality_gates.delete.confirm.message=Are you sure that you want to delete the quality gate "{0}"?
+quality_gates.delete.confirm.default=Are you sure that you want to delete the quality gate "{0}", which is the default quality gate?
+quality_gates.delete_condition.confirm.message=Are you sure that you want to delete this condition?
+
#------------------------------------------------------------------------------
#
diff --git a/sonar-batch/src/main/java/org/sonar/batch/qualitygate/ConditionUtils.java b/sonar-batch/src/main/java/org/sonar/batch/qualitygate/ConditionUtils.java
index 18494255960..95c10767ae5 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/qualitygate/ConditionUtils.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/qualitygate/ConditionUtils.java
@@ -108,7 +108,7 @@ class ConditionUtils {
throw new NotImplementedException(metric.getType().toString());
}
} catch (NumberFormatException badValueFormat) {
- throw new IllegalArgumentException(String.format("Unable to parse value '%s' to compare against %s", value, metric.getName()));
+ throw new IllegalArgumentException(String.format("Quality Gate: Unable to parse value '%s' to compare against %s", value, metric.getName()));
}
return valueToCompare;
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/ConditionUtilsTest.java b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/ConditionUtilsTest.java
index 6ea5bee366f..91f7a4fc72a 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/ConditionUtilsTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/ConditionUtilsTest.java
@@ -237,7 +237,7 @@ public class ConditionUtilsTest {
ConditionUtils.getLevel(condition, measure);
fail();
} catch(Exception expected) {
- assertThat(expected).isInstanceOf(IllegalArgumentException.class).hasMessage("Unable to parse value 'polop' to compare against name");
+ assertThat(expected).isInstanceOf(IllegalArgumentException.class).hasMessage("Quality Gate: Unable to parse value 'polop' to compare against name");
}
}
@@ -256,7 +256,7 @@ public class ConditionUtilsTest {
ConditionUtils.getLevel(condition, measure);
fail();
} catch(Exception expected) {
- assertThat(expected).isInstanceOf(IllegalArgumentException.class).hasMessage("Unable to parse value 'polop' to compare against name");
+ assertThat(expected).isInstanceOf(IllegalArgumentException.class).hasMessage("Quality Gate: Unable to parse value 'polop' to compare against name");
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/BatchSession.java b/sonar-core/src/main/java/org/sonar/core/persistence/BatchSession.java
index 8f832b19046..2579314b8bb 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/BatchSession.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/BatchSession.java
@@ -32,7 +32,7 @@ import java.sql.Connection;
import java.util.List;
import java.util.Map;
-public final class BatchSession implements SqlSession {
+public class BatchSession implements SqlSession {
public static final int MAX_BATCH_SIZE = 250;
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
index 1557307c0f5..9afcd8014ee 100644
--- a/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
@@ -63,6 +63,19 @@ public class RuleDao implements BatchComponent, ServerComponent {
return getMapper(session).selectNonManual();
}
+ public List<RuleDto> selectByCharacteristicOrSubCharacteristicId(Integer characteristicOrSubCharacteristicId) {
+ SqlSession session = mybatis.openSession();
+ try {
+ return selectByCharacteristicOrSubCharacteristicId(characteristicOrSubCharacteristicId, session);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public List<RuleDto> selectByCharacteristicOrSubCharacteristicId(Integer characteristicOrSubCharacteristicId, SqlSession session) {
+ return getMapper(session).selectByCharacteristicOrSubCharacteristicId(characteristicOrSubCharacteristicId);
+ }
+
@CheckForNull
public RuleDto selectById(Integer id, SqlSession session) {
return getMapper(session).selectById(id);
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java
index 52f79d26ce8..86ab08a3dcd 100644
--- a/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java
@@ -24,7 +24,6 @@ import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.check.Cardinality;
-import org.sonar.core.technicaldebt.db.CharacteristicDto;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
@@ -33,6 +32,8 @@ import java.util.Date;
public final class RuleDto {
+ public static final Integer DISABLED_CHARACTERISTIC_ID = -1;
+
private Integer id;
private String repositoryKey;
private String ruleKey;
@@ -56,7 +57,7 @@ public final class RuleDto {
private String defaultRemediationFactor;
private String remediationOffset;
private String defaultRemediationOffset;
- private String effortToFixL10nKey;
+ private String effortToFixDescription;
private Date createdAt;
private Date updatedAt;
@@ -286,12 +287,12 @@ public final class RuleDto {
}
@CheckForNull
- public String getEffortToFixL10nKey() {
- return effortToFixL10nKey;
+ public String getEffortToFixDescription() {
+ return effortToFixDescription;
}
- public RuleDto setEffortToFixL10nKey(@Nullable String effortToFixL10nKey) {
- this.effortToFixL10nKey = effortToFixL10nKey;
+ public RuleDto setEffortToFixDescription(@Nullable String effortToFixDescription) {
+ this.effortToFixDescription = effortToFixDescription;
return this;
}
@@ -314,7 +315,7 @@ public final class RuleDto {
}
public boolean hasCharacteristic(){
- return (characteristicId != null && !CharacteristicDto.DISABLED_CHARACTERISTIC_ID.equals(characteristicId)) || defaultCharacteristicId != null;
+ return (characteristicId != null && !RuleDto.DISABLED_CHARACTERISTIC_ID.equals(characteristicId)) || defaultCharacteristicId != null;
}
@Override
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java
index dafe359d281..8733b199d02 100644
--- a/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java
@@ -30,6 +30,8 @@ public interface RuleMapper {
List<RuleDto> selectNonManual();
+ List<RuleDto> selectByCharacteristicOrSubCharacteristicId(int id);
+
RuleDto selectById(Integer id);
RuleDto selectByName(String name);
diff --git a/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtModelSynchronizer.java b/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtModelSynchronizer.java
index 6a04457a6f6..f4a76c5eb13 100644
--- a/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtModelSynchronizer.java
+++ b/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtModelSynchronizer.java
@@ -36,6 +36,10 @@ import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
+/**
+ * @deprecated since 4.3
+ */
+@Deprecated
public class TechnicalDebtModelSynchronizer implements ServerExtension {
private static final Logger LOG = LoggerFactory.getLogger(TechnicalDebtModelSynchronizer.class);
@@ -45,8 +49,7 @@ public class TechnicalDebtModelSynchronizer implements ServerExtension {
private final TechnicalDebtModelRepository languageModelFinder;
private final TechnicalDebtXMLImporter importer;
- public TechnicalDebtModelSynchronizer(MyBatis mybatis, CharacteristicDao dao,
- TechnicalDebtModelRepository modelRepository, TechnicalDebtXMLImporter importer) {
+ public TechnicalDebtModelSynchronizer(MyBatis mybatis, CharacteristicDao dao, TechnicalDebtModelRepository modelRepository, TechnicalDebtXMLImporter importer) {
this.mybatis = mybatis;
this.dao = dao;
this.languageModelFinder = modelRepository;
diff --git a/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtRuleCache.java b/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtRuleCache.java
index 8cba38a7b6d..6e06fcba40b 100644
--- a/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtRuleCache.java
+++ b/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtRuleCache.java
@@ -31,6 +31,10 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+/**
+ * @deprecated since 4.3
+ */
+@Deprecated
public class TechnicalDebtRuleCache {
private final RuleFinder ruleFinder;
diff --git a/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtXMLImporter.java b/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtXMLImporter.java
index a6164c1c3e5..b0a66036121 100644
--- a/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtXMLImporter.java
+++ b/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtXMLImporter.java
@@ -49,6 +49,10 @@ import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
+/**
+ * @deprecated since 4.3
+ */
+@Deprecated
public class TechnicalDebtXMLImporter implements ServerExtension {
private static final Logger LOG = LoggerFactory.getLogger(TechnicalDebtXMLImporter.class);
diff --git a/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDao.java b/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDao.java
index 05555a28486..355442d90ac 100644
--- a/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDao.java
@@ -88,6 +88,19 @@ public class CharacteristicDao implements BatchComponent, ServerComponent {
return session.getMapper(CharacteristicMapper.class).selectEnabledRootCharacteristics();
}
+ public List<CharacteristicDto> selectCharacteristicsByParentId(int parentId) {
+ SqlSession session = mybatis.openSession();
+ try {
+ return selectCharacteristicsByParentId(parentId, session);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public List<CharacteristicDto> selectCharacteristicsByParentId(int parentId, SqlSession session) {
+ return session.getMapper(CharacteristicMapper.class).selectCharacteristicsByParentId(parentId);
+ }
+
@CheckForNull
public CharacteristicDto selectByKey(String key) {
SqlSession session = mybatis.openSession();
@@ -207,18 +220,4 @@ public class CharacteristicDao implements BatchComponent, ServerComponent {
}
}
- public void disable(Integer id, SqlSession session) {
- session.getMapper(CharacteristicMapper.class).disable(id);
- }
-
- public void disable(Integer id) {
- SqlSession session = mybatis.openSession();
- try {
- disable(id, session);
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
}
diff --git a/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDto.java b/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDto.java
index 4f0b85be817..88889d8af79 100644
--- a/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDto.java
@@ -30,8 +30,6 @@ import java.util.Date;
public class CharacteristicDto implements Serializable {
- public static final Integer DISABLED_CHARACTERISTIC_ID = -1;
-
private Integer id;
private String kee;
private String name;
diff --git a/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicMapper.java b/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicMapper.java
index fe995a8c078..2767ef3eb77 100644
--- a/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicMapper.java
@@ -30,6 +30,8 @@ public interface CharacteristicMapper {
List<CharacteristicDto> selectEnabledRootCharacteristics();
+ List<CharacteristicDto> selectCharacteristicsByParentId(int parentId);
+
CharacteristicDto selectByKey(String key);
CharacteristicDto selectById(int id);
@@ -46,6 +48,4 @@ public interface CharacteristicMapper {
int update(CharacteristicDto characteristic);
- int disable(Integer id);
-
}
diff --git a/sonar-core/src/main/java/org/sonar/core/template/LoadedTemplateDto.java b/sonar-core/src/main/java/org/sonar/core/template/LoadedTemplateDto.java
index 263be701299..99cb9ba5447 100644
--- a/sonar-core/src/main/java/org/sonar/core/template/LoadedTemplateDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/template/LoadedTemplateDto.java
@@ -27,6 +27,7 @@ public final class LoadedTemplateDto {
public static final String FILTER_TYPE = "FILTER";
public static final String QUALITY_PROFILE_TYPE = "QUALITY_PROFILE";
public static final String PERMISSION_TEMPLATE_TYPE = "PERM_TEMPLATE";
+ public static final String QUALITY_GATE_TYPE = "QUALITY_GATE";
private Long id;
private String key;
diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
index 1af58ad3af3..71540499f8e 100644
--- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
+++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
@@ -163,7 +163,7 @@ CREATE TABLE "RULES" (
"DEFAULT_REMEDIATION_FACTOR" VARCHAR(20),
"REMEDIATION_OFFSET" VARCHAR(20),
"DEFAULT_REMEDIATION_OFFSET" VARCHAR(20),
- "EFFORT_TO_FIX_L10N_KEY" VARCHAR(100),
+ "EFFORT_TO_FIX_DESCRIPTION" VARCHAR(4000),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP
);
diff --git a/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml b/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml
index 8bbf979396c..17ddab71423 100644
--- a/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml
@@ -27,7 +27,7 @@
default_remediation_factor as "defaultRemediationFactor",
remediation_offset as "remediationOffset",
default_remediation_offset as "defaultRemediationOffset",
- effort_to_fix_l10n_key as "effortToFixL10nKey",
+ effort_to_fix_description as "effortToFixDescription",
created_at as "createdAt",
updated_at as "updatedAt"
</sql>
@@ -57,6 +57,14 @@
where plugin_name != 'manual'
</select>
+ <select id="selectByCharacteristicOrSubCharacteristicId" resultType="Rule">
+ select <include refid="selectColumns"/> from rules
+ <where>
+ and characteristic_id in (select c.id from characteristics c where (c.id=#{id} or c.parent_id=#{id}) and c.enabled=${_true})
+ and status!='REMOVED'
+ </where>
+ </select>
+
<update id="update" parameterType="Rule">
UPDATE rules SET
plugin_rule_key=#{ruleKey},
@@ -81,7 +89,7 @@
default_remediation_factor=#{defaultRemediationFactor},
remediation_offset=#{remediationOffset},
default_remediation_offset=#{defaultRemediationOffset},
- effort_to_fix_l10n_key=#{effortToFixL10nKey},
+ effort_to_fix_description=#{effortToFixDescription},
updated_at=#{updatedAt}
WHERE id=#{id}
</update>
@@ -90,7 +98,7 @@
(plugin_rule_key, plugin_name, description, status, name, plugin_config_key, priority, cardinality, language, parent_id,
characteristic_id, default_characteristic_id, remediation_function, default_remediation_function,
remediation_factor, default_remediation_factor, remediation_offset, default_remediation_offset,
- effort_to_fix_l10n_key,
+ effort_to_fix_description,
created_at, updated_at)
</sql>
@@ -100,7 +108,7 @@
#{severity}, #{cardinality}, #{language}, #{parentId},
#{characteristicId}, #{defaultCharacteristicId}, #{remediationFunction}, #{defaultRemediationFunction},
#{remediationFactor}, #{defaultRemediationFactor}, #{remediationOffset}, #{defaultRemediationOffset},
- #{effortToFixL10nKey},
+ #{effortToFixDescription},
#{createdAt}, #{updatedAt})
</insert>
@@ -110,7 +118,7 @@
#{severity}, #{cardinality}, #{language}, #{parentId},
#{characteristicId}, #{defaultCharacteristicId}, #{remediationFunction}, #{defaultRemediationFunction},
#{remediationFactor}, #{defaultRemediationFactor}, #{remediationOffset}, #{defaultRemediationOffset},
- #{effortToFixL10nKey},
+ #{effortToFixDescription},
#{createdAt}, #{updatedAt})
</insert>
diff --git a/sonar-core/src/main/resources/org/sonar/core/technicaldebt/db/CharacteristicMapper.xml b/sonar-core/src/main/resources/org/sonar/core/technicaldebt/db/CharacteristicMapper.xml
index e4cde1a0ac8..495ef37d1b1 100644
--- a/sonar-core/src/main/resources/org/sonar/core/technicaldebt/db/CharacteristicMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/technicaldebt/db/CharacteristicMapper.xml
@@ -38,6 +38,15 @@
order by characteristic_order asc
</select>
+ <select id="selectCharacteristicsByParentId" parameterType="map" resultType="Characteristic">
+ select <include refid="characteristicColumns"/>
+ from characteristics c
+ <where>
+ and c.parent_id=#{parent_id}
+ and c.enabled=${_true}
+ </where>
+ </select>
+
<select id="selectByKey" parameterType="String" resultType="Characteristic">
select <include refid="characteristicColumns"/>
from characteristics c
@@ -107,14 +116,7 @@
parent_id=#{parentId},
characteristic_order=#{characteristicOrder},
enabled=#{enabled},
- updated_at=current_timestamp
- where id=#{id}
- </update>
-
- <update id="disable" parameterType="Integer">
- update characteristics set
- enabled=${_false},
- updated_at=current_timestamp
+ updated_at=#{updatedAt}
where id=#{id}
</update>
diff --git a/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java b/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java
index c394e728e52..7e90f6aeb9c 100644
--- a/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java
@@ -19,7 +19,9 @@
*/
package org.sonar.core.rule;
+import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
import org.apache.ibatis.session.SqlSession;
import org.junit.Before;
import org.junit.Test;
@@ -31,6 +33,7 @@ import org.sonar.core.persistence.AbstractDaoTestCase;
import java.util.List;
+import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;
public class RuleDaoTest extends AbstractDaoTestCase {
@@ -63,7 +66,7 @@ public class RuleDaoTest extends AbstractDaoTestCase {
assertThat(ruleDto.getDefaultRemediationFactor()).isEqualTo("5d");
assertThat(ruleDto.getRemediationOffset()).isEqualTo("5min");
assertThat(ruleDto.getDefaultRemediationOffset()).isEqualTo("10h");
- assertThat(ruleDto.getEffortToFixL10nKey()).isEqualTo("squid.S115.effortToFix");
+ assertThat(ruleDto.getEffortToFixDescription()).isEqualTo("squid.S115.effortToFix");
}
@Test
@@ -87,7 +90,7 @@ public class RuleDaoTest extends AbstractDaoTestCase {
assertThat(ruleDto.getDefaultRemediationFactor()).isEqualTo("5d");
assertThat(ruleDto.getRemediationOffset()).isEqualTo("5min");
assertThat(ruleDto.getDefaultRemediationOffset()).isEqualTo("10h");
- assertThat(ruleDto.getEffortToFixL10nKey()).isEqualTo("squid.S115.effortToFix");
+ assertThat(ruleDto.getEffortToFixDescription()).isEqualTo("squid.S115.effortToFix");
}
@Test
@@ -132,6 +135,25 @@ public class RuleDaoTest extends AbstractDaoTestCase {
}
@Test
+ public void select_by_characteristic_or_sub_characteristic_id(){
+ setupData("select_by_characteristic_or_sub_characteristic_id");
+
+ // Rules from sub characteristic
+ List<RuleDto> ruleDtos = dao.selectByCharacteristicOrSubCharacteristicId(2);
+ assertThat(ruleDtos).hasSize(1);
+ assertThat(ruleDtos.get(0).getId()).isEqualTo(1);
+
+ // Rules from characteristic
+ ruleDtos = dao.selectByCharacteristicOrSubCharacteristicId(1);
+ assertThat(ruleDtos).hasSize(2);
+ assertThat(idsFromRuleDtos(ruleDtos)).containsExactly(1, 2);
+
+ // Rules from disabled characteristic
+ ruleDtos = dao.selectByCharacteristicOrSubCharacteristicId(11);
+ assertThat(ruleDtos).isEmpty();
+ }
+
+ @Test
public void update() {
setupData("update");
@@ -159,7 +181,7 @@ public class RuleDaoTest extends AbstractDaoTestCase {
.setDefaultRemediationFactor("5d")
.setRemediationOffset("5min")
.setDefaultRemediationOffset("10h")
- .setEffortToFixL10nKey("squid.S115.effortToFix")
+ .setEffortToFixDescription("squid.S115.effortToFix")
.setUpdatedAt(DateUtils.parseDate("2013-12-17"));
dao.update(ruleToUpdate);
@@ -191,7 +213,7 @@ public class RuleDaoTest extends AbstractDaoTestCase {
.setDefaultRemediationFactor("5d")
.setRemediationOffset("5min")
.setDefaultRemediationOffset("10h")
- .setEffortToFixL10nKey("squid.S115.effortToFix")
+ .setEffortToFixDescription("squid.S115.effortToFix")
.setCreatedAt(DateUtils.parseDate("2013-12-16"))
.setUpdatedAt(DateUtils.parseDate("2013-12-17"));
@@ -224,7 +246,7 @@ public class RuleDaoTest extends AbstractDaoTestCase {
.setDefaultRemediationFactor("5d")
.setRemediationOffset("5min")
.setDefaultRemediationOffset("10h")
- .setEffortToFixL10nKey("squid.S115.effortToFix")
+ .setEffortToFixDescription("squid.S115.effortToFix")
.setCreatedAt(DateUtils.parseDate("2013-12-16"))
.setUpdatedAt(DateUtils.parseDate("2013-12-17"));
@@ -248,7 +270,7 @@ public class RuleDaoTest extends AbstractDaoTestCase {
.setDefaultRemediationFactor("1h")
.setRemediationOffset("10h")
.setDefaultRemediationOffset("5min")
- .setEffortToFixL10nKey("squid.S115.effortToFix2")
+ .setEffortToFixDescription("squid.S115.effortToFix2")
.setCreatedAt(DateUtils.parseDate("2013-12-14"))
.setUpdatedAt(DateUtils.parseDate("2013-12-15"));
@@ -317,4 +339,13 @@ public class RuleDaoTest extends AbstractDaoTestCase {
checkTables("update_parameter", "rules_parameters");
}
+
+ private List<Integer> idsFromRuleDtos(List<RuleDto> ruleDtos){
+ return newArrayList(Iterables.transform(ruleDtos, new Function<RuleDto, Integer>() {
+ @Override
+ public Integer apply(RuleDto input) {
+ return input.getId();
+ }
+ }));
+ }
}
diff --git a/sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDaoTest.java b/sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDaoTest.java
index d89af50367a..6a05a8c5599 100644
--- a/sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDaoTest.java
@@ -103,6 +103,14 @@ public class CharacteristicDaoTest extends AbstractDaoTestCase {
}
@Test
+ public void select_sub_characteristics_by_parent_id() {
+ setupData("select_sub_characteristics_by_parent_id");
+
+ assertThat(dao.selectCharacteristicsByParentId(1)).hasSize(2);
+ assertThat(dao.selectCharacteristicsByParentId(55)).isEmpty();
+ }
+
+ @Test
public void select_characteristic_by_key() {
setupData("shared");
@@ -189,6 +197,7 @@ public class CharacteristicDaoTest extends AbstractDaoTestCase {
.setOrder(2)
// Created date should not changed
.setCreatedAt(DateUtils.parseDate("2013-11-22"))
+ .setUpdatedAt(DateUtils.parseDate("2014-03-19"))
.setEnabled(false);
dao.update(dto);
@@ -196,13 +205,4 @@ public class CharacteristicDaoTest extends AbstractDaoTestCase {
checkTables("update_characteristic", EXCLUDED_COLUMNS, "characteristics");
}
- @Test
- public void disable() throws Exception {
- setupData("disable");
-
- dao.disable(1);
-
- checkTables("disable", EXCLUDED_COLUMNS, "characteristics");
- }
-
}
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/insert-result.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/insert-result.xml
index 41f7ed10707..ff959688dc4 100644
--- a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/insert-result.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/insert-result.xml
@@ -27,7 +27,7 @@
remediation_function="linear" default_remediation_function="linear_offset"
remediation_factor="1h" default_remediation_factor="5d"
remediation_offset="5min" default_remediation_offset="10h"
- effort_to_fix_l10n_key="squid.S115.effortToFix"
+ effort_to_fix_description="squid.S115.effortToFix"
/>
</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/insert_all-result.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/insert_all-result.xml
index c4df8a49e92..dce46d3845d 100644
--- a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/insert_all-result.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/insert_all-result.xml
@@ -27,7 +27,7 @@
remediation_function="linear" default_remediation_function="linear_offset"
remediation_factor="1h" default_remediation_factor="5d"
remediation_offset="5min" default_remediation_offset="10h"
- effort_to_fix_l10n_key="squid.S115.effortToFix"
+ effort_to_fix_description="squid.S115.effortToFix"
/>
<rules id="2" plugin_rule_key="NewRuleKey2" plugin_name="plugin2" name="new name2" description="new description2" status="BETA"
@@ -37,7 +37,7 @@
remediation_function="linear_offset" default_remediation_function="linear"
remediation_factor="5d" default_remediation_factor="1h"
remediation_offset="10h" default_remediation_offset="5min"
- effort_to_fix_l10n_key="squid.S115.effortToFix2"
+ effort_to_fix_description="squid.S115.effortToFix2"
/>
</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/selectAll.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/selectAll.xml
index 2f26ad3f588..1511b2e67f9 100644
--- a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/selectAll.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/selectAll.xml
@@ -7,7 +7,7 @@
remediation_function="linear" default_remediation_function="linear_offset"
remediation_factor="1h" default_remediation_factor="5d"
remediation_offset="5min" default_remediation_offset="10h"
- effort_to_fix_l10n_key="squid.S115.effortToFix"
+ effort_to_fix_description="squid.S115.effortToFix"
/>
</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_by_characteristic_or_sub_characteristic_id.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_by_characteristic_or_sub_characteristic_id.xml
new file mode 100644
index 00000000000..db7d5b3a6c5
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_by_characteristic_or_sub_characteristic_id.xml
@@ -0,0 +1,61 @@
+<dataset>
+
+ <!-- Root characteristic -->
+ <characteristics id="1" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="1"
+ enabled="[true]"
+ created_at="2013-11-20" updated_at="2013-11-22"/>
+
+ <!-- Sub characteristics of root characteristic -->
+ <characteristics id="2" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="1" rcharacteristic_order="[null]"
+ enabled="[true]"
+ created_at="2013-11-20" updated_at="2013-11-22"/>
+ <characteristics id="3" kee="HARDWARE_RELATED_PORTABILITY" name="Hardware related portability " parent_id="1" rcharacteristic_order="[null]"
+ enabled="[true]"
+ created_at="2013-11-20" updated_at="2013-11-22"/>
+
+ <!-- Disabled root characteristic -->
+ <characteristics id="10" kee="DISABLED_ROOT_CHARACTERISTIC" name="Disabled root characteristic" parent_id="[null]" characteristic_order="2"
+ enabled="[false]"
+ created_at="2013-11-20" updated_at="2013-11-22"/>
+
+ <!-- Disabled characteristic -->
+ <characteristics id="11" kee="DISABLED_CHARACTERISTIC" name="Disabled characteristic" parent_id="10" characteristic_order="[null]"
+ enabled="[false]"
+ created_at="2013-11-20" updated_at="2013-11-22"/>
+
+ <!-- Rule linked to a sub characteristic -->
+ <rules id="1" plugin_rule_key="UselessImportCheck" plugin_name="squid" name="UselessImportCheck" description="Useless imports should be removed" status="READY"
+ characteristic_id="2" default_characteristic_id="50"
+ remediation_function="LINEAR_OFFSET" default_remediation_function="LINEAR_OFFSET"
+ remediation_factor="5d" default_remediation_factor="5d"
+ remediation_offset="10h" default_remediation_offset="10h" updated_at="2014-02-19"/>
+
+ <!-- Rule linked to a sub characteristic -->
+ <rules id="2" plugin_rule_key="LeftCurlyBraceStartLineCheck" plugin_name="squid" name="LeftCurlyBraceStartLineCheck" description="Left curly braces should be located at the beginning of lines of code" status="READY"
+ characteristic_id="3" default_characteristic_id="50"
+ remediation_function="LINEAR_OFFSET" default_remediation_function="LINEAR_OFFSET"
+ remediation_factor="5d" default_remediation_factor="5d"
+ remediation_offset="10h" default_remediation_offset="10h" updated_at="2014-02-19"/>
+
+ <!-- Rule linked to a disabled sub characteristic -> should never be returned -->
+ <rules id="3" plugin_rule_key="CallToFileDeleteOnExitMethod" plugin_name="squid" name="CallToFileDeleteOnExitMethod" description="CallToFileDeleteOnExitMethod" status="READY"
+ characteristic_id="11" default_characteristic_id="50"
+ remediation_function="LINEAR" default_remediation_function="LINEAR_OFFSET"
+ remediation_factor="5d" default_remediation_factor="5d"
+ remediation_offset="[null]" default_remediation_offset="10h" updated_at="2014-02-19"/>
+
+ <!-- Removed rule linked to one enable sub characteristic -> should never be returned -->
+ <rules id="4" plugin_rule_key="ObjectFinalizeOverridenCallsSuperFinalizeCheck" plugin_name="squid" name="ObjectFinalizeOverridenCallsSuperFinalizeCheck" description="super.finalize() should be called at the end of Object.finalize() implementations" status="REMOVED"
+ characteristic_id="3" default_characteristic_id="50"
+ remediation_function="LINEAR" default_remediation_function="LINEAR_OFFSET"
+ remediation_factor="5d" default_remediation_factor="5min"
+ remediation_offset="[null]" default_remediation_offset="10h" updated_at="2014-02-19"/>
+
+ <!-- Rule linked to a sub characteristic, but only default characteristic is linked -> should never be returned -->
+ <rules id="5" plugin_rule_key="RightCurlyBraceStartLineCheck" plugin_name="squid" name="RightCurlyBraceStartLineCheck" description="Right curly braces should be located at the beginning of lines of code" status="READY"
+ characteristic_id="[null]" default_characteristic_id="3"
+ remediation_function="[null]" default_remediation_function="LINEAR"
+ remediation_factor="[null]" default_remediation_factor="5d"
+ remediation_offset="[null]" default_remediation_offset="[null]" updated_at="2014-02-19"/>
+
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_enables_and_non_manual.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_enables_and_non_manual.xml
index 8b3f8abf0a5..971e58bead8 100644
--- a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_enables_and_non_manual.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_enables_and_non_manual.xml
@@ -1,23 +1,3 @@
-<!--
- ~ SonarQube, open source software quality management tool.
- ~ Copyright (C) 2008-2014 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.
- -->
-
<dataset>
<rules id="1" plugin_rule_key="AvoidNull" plugin_name="checkstyle" name="Avoid Null" description="Should avoid NULL" status="READY"
@@ -26,7 +6,7 @@
remediation_function="LINEAR" default_remediation_function="LINEAR_OFFSET"
remediation_factor="1h" default_remediation_factor="5d"
remediation_offset="5min" default_remediation_offset="10h"
- effort_to_fix_l10n_key="squid.S115.effortToFix"/>
+ effort_to_fix_description="squid.S115.effortToFix"/>
<rules id="2" plugin_rule_key="AvoidNull" plugin_name="squid" name="Avoid Null" description="Should avoid NULL" status="REMOVED"
note_data="[null]" note_user_login="[null]" note_created_at="[null]"
@@ -34,7 +14,7 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
<rules id="3" plugin_rule_key="AvoidNull" plugin_name="manual" name="Manual Rule" description="Should not appear" status="READY"
note_data="[null]" note_user_login="[null]" note_created_at="[null]"
@@ -42,6 +22,6 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/update-result.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/update-result.xml
index 206ac65e85c..d54cff88519 100644
--- a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/update-result.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/update-result.xml
@@ -7,7 +7,7 @@
remediation_function="linear" default_remediation_function="linear_offset"
remediation_factor="1h" default_remediation_factor="5d"
remediation_offset="5min" default_remediation_offset="10h"
- effort_to_fix_l10n_key="squid.S115.effortToFix"
+ effort_to_fix_description="squid.S115.effortToFix"
/>
<rules id="2" plugin_rule_key="Parent1" plugin_name="checkstyle" name="Parent Rule 1" description="Parent Rule 1" status="READY"
diff --git a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable-result.xml b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable-result.xml
deleted file mode 100644
index 04d1f65ac3e..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable-result.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<dataset>
-
- <characteristics id="1" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="[null]" characteristic_order="1" enabled="[false]"
- created_at="2013-11-20" updated_at="[null]"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable.xml b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable.xml
deleted file mode 100644
index dd69c61296d..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<dataset>
-
- <characteristics id="1" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="[null]" characteristic_order="1" enabled="[true]"
- created_at="2013-11-20" updated_at="2013-11-22"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/select_sub_characteristics_by_parent_id.xml b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/select_sub_characteristics_by_parent_id.xml
new file mode 100644
index 00000000000..e64655a3a59
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/select_sub_characteristics_by_parent_id.xml
@@ -0,0 +1,31 @@
+<dataset>
+
+ <!-- Root characteristic -->
+ <characteristics id="1" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="1"
+ enabled="[true]"
+ created_at="2013-11-20" updated_at="2013-11-22"/>
+
+ <!-- Sub characteristics of root characteristic -->
+ <characteristics id="2" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="1" rcharacteristic_order="[null]"
+ enabled="[true]"
+ created_at="2013-11-20" updated_at="2013-11-22"/>
+ <characteristics id="3" kee="HARDWARE_RELATED_PORTABILITY" name="Hardware related portability " parent_id="1" rcharacteristic_order="[null]"
+ enabled="[true]"
+ created_at="2013-11-20" updated_at="2013-11-22"/>
+
+ <!-- Other sub characteristic -->
+ <characteristics id="4" kee="READABILITY" name="Readability" parent_id="5" rcharacteristic_order="[null]"
+ enabled="[true]"
+ created_at="2013-11-20" updated_at="2013-11-22"/>
+
+ <!-- Disabled root characteristic -->
+ <characteristics id="10" kee="DISABLED_ROOT_CHARACTERISTIC" name="Disabled root characteristic" parent_id="[null]" characteristic_order="2"
+ enabled="[false]"
+ created_at="2013-11-20" updated_at="2013-11-22"/>
+
+ <!-- Disabled characteristic -->
+ <characteristics id="11" kee="DISABLED_CHARACTERISTIC" name="Disabled characteristic" parent_id="10" characteristic_order="[null]"
+ enabled="[false]"
+ created_at="2013-11-20" updated_at="2013-11-22"/>
+
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_characteristic-result.xml b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_characteristic-result.xml
index 1ecd594caba..0a409171a52 100644
--- a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_characteristic-result.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_characteristic-result.xml
@@ -1,6 +1,6 @@
<dataset>
<characteristics id="1" kee="COMPILER_RELATED_PORTABILITY" name="New name" parent_id="[null]" characteristic_order="2" enabled="[false]"
- created_at="2013-11-20" updated_at="2013-11-22"/>
+ created_at="2013-11-20" updated_at="2014-03-19"/>
</dataset>
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java
index 662841909d3..68b4d17d9ff 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java
@@ -19,6 +19,7 @@
*/
package org.sonar.api.server.rule;
+import com.google.common.base.Strings;
import com.google.common.collect.*;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
@@ -313,7 +314,7 @@ public interface RulesDefinition extends ServerExtension {
private RuleStatus status = RuleStatus.defaultStatus();
private String debtCharacteristic;
private DebtRemediationFunction debtRemediationFunction;
- private String effortToFixL10nKey;
+ private String effortToFixDescription;
private final Set<String> tags = Sets.newTreeSet();
private final Map<String, NewParam> paramsByKey = Maps.newHashMap();
@@ -383,8 +384,8 @@ public interface RulesDefinition extends ServerExtension {
return this;
}
- public NewRule setEffortToFixL10nKey(@Nullable String effortToFixL10nKey) {
- this.effortToFixL10nKey = effortToFixL10nKey;
+ public NewRule setEffortToFixDescription(@Nullable String effortToFixDescription) {
+ this.effortToFixDescription = effortToFixDescription;
return this;
}
@@ -433,13 +434,13 @@ public interface RulesDefinition extends ServerExtension {
}
private void validate() {
- if (StringUtils.isBlank(name)) {
+ if (Strings.isNullOrEmpty(name)) {
throw new IllegalStateException(String.format("Name of rule %s is empty", this));
}
- if (StringUtils.isBlank(htmlDescription)) {
+ if (Strings.isNullOrEmpty(htmlDescription)) {
throw new IllegalStateException(String.format("HTML description of rule %s is empty", this));
}
- if ((StringUtils.isBlank(debtCharacteristic) && debtRemediationFunction != null) || (!StringUtils.isBlank(debtCharacteristic) && debtRemediationFunction == null)) {
+ if ((Strings.isNullOrEmpty(debtCharacteristic) && debtRemediationFunction != null) || (!Strings.isNullOrEmpty(debtCharacteristic) && debtRemediationFunction == null)) {
throw new IllegalStateException(String.format("Both debt characteristic and debt remediation function should be defined on rule '%s'", this));
}
}
@@ -457,7 +458,7 @@ public interface RulesDefinition extends ServerExtension {
private final boolean template;
private final String debtCharacteristic;
private final DebtRemediationFunction debtRemediationFunction;
- private final String effortToFixL10nKey;
+ private final String effortToFixDescription;
private final Set<String> tags;
private final Map<String, Param> params;
private final RuleStatus status;
@@ -474,7 +475,7 @@ public interface RulesDefinition extends ServerExtension {
this.status = newRule.status;
this.debtCharacteristic = newRule.debtCharacteristic;
this.debtRemediationFunction = newRule.debtRemediationFunction;
- this.effortToFixL10nKey = newRule.effortToFixL10nKey;
+ this.effortToFixDescription = newRule.effortToFixDescription;
this.tags = ImmutableSortedSet.copyOf(newRule.tags);
ImmutableMap.Builder<String, Param> paramsBuilder = ImmutableMap.builder();
for (NewParam newParam : newRule.paramsByKey.values()) {
@@ -523,8 +524,8 @@ public interface RulesDefinition extends ServerExtension {
}
@CheckForNull
- public String effortToFixL10nKey() {
- return effortToFixL10nKey;
+ public String effortToFixDescription() {
+ return effortToFixDescription;
}
@CheckForNull
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java
index 594a14e450d..2cc13c0abc8 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java
@@ -72,7 +72,7 @@ public class RulesDefinitionTest {
.setStatus(RuleStatus.BETA)
.setDebtCharacteristic("COMPILER")
.setDebtRemediationFunction(DebtRemediationFunction.create(DebtRemediationFunction.Type.LINEAR_OFFSET, "1h", "10min"))
- .setEffortToFixL10nKey("squid.S115.effortToFix")
+ .setEffortToFixDescription("squid.S115.effortToFix")
.setTags("one", "two")
.addTags("two", "three", "four");
newFindbugs.createRule("ABC").setName("ABC").setHtmlDescription("ABC");
@@ -93,7 +93,7 @@ public class RulesDefinitionTest {
assertThat(npeRule.status()).isEqualTo(RuleStatus.BETA);
assertThat(npeRule.debtCharacteristic()).isEqualTo("COMPILER");
assertThat(npeRule.debtRemediationFunction()).isEqualTo(DebtRemediationFunction.create(DebtRemediationFunction.Type.LINEAR_OFFSET, "1h", "10min"));
- assertThat(npeRule.effortToFixL10nKey()).isEqualTo("squid.S115.effortToFix");
+ assertThat(npeRule.effortToFixDescription()).isEqualTo("squid.S115.effortToFix");
assertThat(npeRule.toString()).isEqualTo("[repository=findbugs, key=NPE]");
assertThat(npeRule.repository()).isSameAs(findbugs);
diff --git a/sonar-server/src/main/java/org/sonar/server/debt/DebtCharacteristicsXMLImporter.java b/sonar-server/src/main/java/org/sonar/server/debt/DebtCharacteristicsXMLImporter.java
index d10c8056add..1c47ffbc6a0 100644
--- a/sonar-server/src/main/java/org/sonar/server/debt/DebtCharacteristicsXMLImporter.java
+++ b/sonar-server/src/main/java/org/sonar/server/debt/DebtCharacteristicsXMLImporter.java
@@ -20,38 +20,40 @@
package org.sonar.server.debt;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
import org.apache.commons.lang.StringUtils;
import org.codehaus.stax2.XMLInputFactory2;
import org.codehaus.staxmate.SMInputFactory;
import org.codehaus.staxmate.in.SMHierarchicCursor;
import org.codehaus.staxmate.in.SMInputCursor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.ServerExtension;
import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic;
-import org.sonar.api.utils.ValidationMessages;
-import org.sonar.core.technicaldebt.DefaultTechnicalDebtModel;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import java.io.Reader;
import java.io.StringReader;
+import java.util.Collection;
+import java.util.List;
-public class DebtCharacteristicsXMLImporter implements ServerExtension {
+import static com.google.common.collect.Lists.newArrayList;
- private static final Logger LOG = LoggerFactory.getLogger(DebtCharacteristicsXMLImporter.class);
+public class DebtCharacteristicsXMLImporter implements ServerExtension {
public static final String CHARACTERISTIC = "chc";
public static final String CHARACTERISTIC_KEY = "key";
public static final String CHARACTERISTIC_NAME = "name";
- public DefaultTechnicalDebtModel importXML(String xml, ValidationMessages messages) {
- return importXML(new StringReader(xml), messages);
+ public DebtModel importXML(String xml) {
+ return importXML(new StringReader(xml));
}
- public DefaultTechnicalDebtModel importXML(Reader xml, ValidationMessages messages) {
- DefaultTechnicalDebtModel model = new DefaultTechnicalDebtModel();
+ public DebtModel importXML(Reader xml) {
+ DebtModel model = new DebtModel();
try {
SMInputFactory inputFactory = initStax();
SMHierarchicCursor cursor = inputFactory.rootElementCursor(xml);
@@ -61,14 +63,13 @@ public class DebtCharacteristicsXMLImporter implements ServerExtension {
SMInputCursor chcCursor = cursor.childElementCursor(CHARACTERISTIC);
while (chcCursor.getNext() != null) {
- processCharacteristic(model, null, chcCursor, messages);
+ processCharacteristic(model, null, chcCursor);
}
cursor.getStreamReader().closeCompletely();
} catch (XMLStreamException e) {
- LOG.error("XML is not valid", e);
- messages.addErrorText("XML is not valid: " + e.getMessage());
+ throw new IllegalStateException("XML is not valid", e);
}
return model;
}
@@ -82,8 +83,8 @@ public class DebtCharacteristicsXMLImporter implements ServerExtension {
return new SMInputFactory(xmlFactory);
}
- private DefaultCharacteristic processCharacteristic(DefaultTechnicalDebtModel model, DefaultCharacteristic parent, SMInputCursor chcCursor,
- ValidationMessages messages) throws XMLStreamException {
+ @CheckForNull
+ private DefaultCharacteristic processCharacteristic(DebtModel model, @Nullable DefaultCharacteristic parent, SMInputCursor chcCursor) throws XMLStreamException {
DefaultCharacteristic characteristic = new DefaultCharacteristic();
SMInputCursor cursor = chcCursor.childElementCursor();
while (cursor.getNext() != null) {
@@ -98,7 +99,7 @@ public class DebtCharacteristicsXMLImporter implements ServerExtension {
// <chc> can contain characteristics or requirements
} else if (StringUtils.equals(node, CHARACTERISTIC)) {
- processCharacteristic(model, characteristic, cursor, messages);
+ processCharacteristic(model, characteristic, cursor);
}
}
@@ -110,4 +111,53 @@ public class DebtCharacteristicsXMLImporter implements ServerExtension {
return null;
}
+ static class DebtModel {
+
+ private Collection<DefaultCharacteristic> rootCharacteristics;
+
+ public DebtModel() {
+ rootCharacteristics = newArrayList();
+ }
+
+ public DebtModel addRootCharacteristic(DefaultCharacteristic characteristic) {
+ rootCharacteristics.add(characteristic);
+ return this;
+ }
+
+ public List<DefaultCharacteristic> rootCharacteristics() {
+ return newArrayList(Iterables.filter(rootCharacteristics, new Predicate<DefaultCharacteristic>() {
+ @Override
+ public boolean apply(DefaultCharacteristic input) {
+ return input.isRoot();
+ }
+ }));
+ }
+
+ @CheckForNull
+ public DefaultCharacteristic characteristicByKey(final String key) {
+ return Iterables.find(characteristics(), new Predicate<DefaultCharacteristic>() {
+ @Override
+ public boolean apply(DefaultCharacteristic input) {
+ return input.key().equals(key);
+ }
+ }, null);
+ }
+
+ public List<DefaultCharacteristic> characteristics() {
+ List<DefaultCharacteristic> flatCharacteristics = newArrayList();
+ for (DefaultCharacteristic rootCharacteristic : rootCharacteristics) {
+ flatCharacteristics.add(rootCharacteristic);
+ for (DefaultCharacteristic characteristic : rootCharacteristic.children()) {
+ flatCharacteristics.add(characteristic);
+ }
+ }
+ return flatCharacteristics;
+ }
+
+ public boolean isEmpty() {
+ return rootCharacteristics.isEmpty();
+ }
+
+ }
+
}
diff --git a/sonar-server/src/main/java/org/sonar/server/debt/DebtModelService.java b/sonar-server/src/main/java/org/sonar/server/debt/DebtModelService.java
index 367f3bd1052..a17b23fdb17 100644
--- a/sonar-server/src/main/java/org/sonar/server/debt/DebtModelService.java
+++ b/sonar-server/src/main/java/org/sonar/server/debt/DebtModelService.java
@@ -20,14 +20,18 @@
package org.sonar.server.debt;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import org.apache.ibatis.session.SqlSession;
import org.sonar.api.server.debt.DebtCharacteristic;
import org.sonar.api.server.debt.DebtModel;
import org.sonar.api.server.debt.internal.DefaultDebtCharacteristic;
+import org.sonar.api.utils.System2;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.core.persistence.MyBatis;
+import org.sonar.core.rule.RuleDao;
+import org.sonar.core.rule.RuleDto;
import org.sonar.core.technicaldebt.db.CharacteristicDao;
import org.sonar.core.technicaldebt.db.CharacteristicDto;
import org.sonar.server.exceptions.BadRequestException;
@@ -39,6 +43,7 @@ import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.util.Collection;
+import java.util.Date;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
@@ -51,10 +56,19 @@ public class DebtModelService implements DebtModel {
private final MyBatis mybatis;
private final CharacteristicDao dao;
+ private final RuleDao ruleDao;
+ private final System2 system2;
- public DebtModelService(MyBatis mybatis, CharacteristicDao dao) {
+ public DebtModelService(MyBatis mybatis, CharacteristicDao dao, RuleDao ruleDao) {
+ this(mybatis, dao, ruleDao, System2.INSTANCE);
+ }
+
+ @VisibleForTesting
+ DebtModelService(MyBatis mybatis, CharacteristicDao dao, RuleDao ruleDao, System2 system2) {
this.mybatis = mybatis;
this.dao = dao;
+ this.ruleDao = ruleDao;
+ this.system2 = system2;
}
public List<DebtCharacteristic> rootCharacteristics() {
@@ -156,6 +170,48 @@ public class DebtModelService implements DebtModel {
}
}
+ /**
+ * Disable characteristic and sub characteristic or only sub characteristic.
+ * Will also update every rules linked to sub characteristics by setting characteristic id to -1 and remove function, factor and offset.
+ */
+ public void delete(int characteristicOrSubCharactteristicId) {
+ checkPermission();
+
+ SqlSession session = mybatis.openBatchSession();
+ try {
+ Date now = new Date(system2.now());
+
+ CharacteristicDto characteristicOrSubCharacteristicDto = findCharacteristic(characteristicOrSubCharactteristicId, session);
+ List<RuleDto> ruleDtos = ruleDao.selectByCharacteristicOrSubCharacteristicId(characteristicOrSubCharacteristicDto.getId(), session);
+ for (RuleDto ruleDto : ruleDtos) {
+ ruleDto.setCharacteristicId(RuleDto.DISABLED_CHARACTERISTIC_ID);
+ ruleDto.setRemediationFunction(null);
+ ruleDto.setRemediationFactor(null);
+ ruleDto.setRemediationOffset(null);
+ ruleDto.setUpdatedAt(now);
+ ruleDao.update(ruleDto, session);
+
+ // TODO update rules from E/S
+ }
+
+ if (characteristicOrSubCharacteristicDto.getParentId() == null) {
+ List<CharacteristicDto> dtos = dao.selectCharacteristicsByParentId(characteristicOrSubCharacteristicDto.getId(), session);
+ for (CharacteristicDto subCharacteristicDto : dtos) {
+ subCharacteristicDto.setEnabled(false);
+ subCharacteristicDto.setUpdatedAt(now);
+ dao.update(subCharacteristicDto, session);
+ }
+ }
+ characteristicOrSubCharacteristicDto.setEnabled(false);
+ characteristicOrSubCharacteristicDto.setUpdatedAt(now);
+ dao.update(characteristicOrSubCharacteristicDto, session);
+
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
private CharacteristicDto findCharacteristic(Integer id, SqlSession session) {
CharacteristicDto dto = dao.selectById(id, session);
if (dto == null) {
diff --git a/sonar-server/src/main/java/org/sonar/server/debt/DebtModelSynchronizer.java b/sonar-server/src/main/java/org/sonar/server/debt/DebtModelSynchronizer.java
index 9ef036dc864..5fa4ff5bd68 100644
--- a/sonar-server/src/main/java/org/sonar/server/debt/DebtModelSynchronizer.java
+++ b/sonar-server/src/main/java/org/sonar/server/debt/DebtModelSynchronizer.java
@@ -26,9 +26,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.ServerExtension;
import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic;
-import org.sonar.api.utils.ValidationMessages;
import org.sonar.core.persistence.MyBatis;
-import org.sonar.core.technicaldebt.DefaultTechnicalDebtModel;
import org.sonar.core.technicaldebt.TechnicalDebtModelRepository;
import org.sonar.core.technicaldebt.db.CharacteristicDao;
import org.sonar.core.technicaldebt.db.CharacteristicDto;
@@ -54,12 +52,12 @@ public class DebtModelSynchronizer implements ServerExtension {
this.importer = importer;
}
- public List<CharacteristicDto> synchronize(ValidationMessages messages) {
+ public List<CharacteristicDto> synchronize() {
SqlSession session = mybatis.openSession();
List<CharacteristicDto> model = newArrayList();
try {
- model = synchronize(messages, session);
+ model = synchronize(session);
session.commit();
} finally {
MyBatis.closeQuietly(session);
@@ -67,14 +65,13 @@ public class DebtModelSynchronizer implements ServerExtension {
return model;
}
- public List<CharacteristicDto> synchronize(ValidationMessages messages, SqlSession session) {
- DefaultTechnicalDebtModel defaultModel = loadModelFromXml(TechnicalDebtModelRepository.DEFAULT_MODEL, messages);
+ public List<CharacteristicDto> synchronize(SqlSession session) {
+ DebtCharacteristicsXMLImporter.DebtModel defaultModel = loadModelFromXml(TechnicalDebtModelRepository.DEFAULT_MODEL);
List<CharacteristicDto> model = loadOrCreateModelFromDb(defaultModel, session);
- messages.log(LOG);
return model;
}
- private List<CharacteristicDto> loadOrCreateModelFromDb(DefaultTechnicalDebtModel defaultModel, SqlSession session) {
+ private List<CharacteristicDto> loadOrCreateModelFromDb(DebtCharacteristicsXMLImporter.DebtModel defaultModel, SqlSession session) {
List<CharacteristicDto> characteristicDtos = loadModel();
if (characteristicDtos.isEmpty()) {
return createTechnicalDebtModel(defaultModel, session);
@@ -86,7 +83,7 @@ public class DebtModelSynchronizer implements ServerExtension {
return dao.selectEnabledCharacteristics();
}
- private List<CharacteristicDto> createTechnicalDebtModel(DefaultTechnicalDebtModel defaultModel, SqlSession session) {
+ private List<CharacteristicDto> createTechnicalDebtModel(DebtCharacteristicsXMLImporter.DebtModel defaultModel, SqlSession session) {
List<CharacteristicDto> characteristics = newArrayList();
for (DefaultCharacteristic rootCharacteristic : defaultModel.rootCharacteristics()) {
CharacteristicDto rootCharacteristicDto = CharacteristicDto.toDto(rootCharacteristic, null);
@@ -101,11 +98,11 @@ public class DebtModelSynchronizer implements ServerExtension {
return characteristics;
}
- public DefaultTechnicalDebtModel loadModelFromXml(String pluginKey, ValidationMessages messages) {
+ public DebtCharacteristicsXMLImporter.DebtModel loadModelFromXml(String pluginKey) {
Reader xmlFileReader = null;
try {
xmlFileReader = languageModelFinder.createReaderForXMLFile(pluginKey);
- return importer.importXML(xmlFileReader, messages);
+ return importer.importXML(xmlFileReader);
} finally {
IOUtils.closeQuietly(xmlFileReader);
}
diff --git a/sonar-server/src/main/java/org/sonar/server/debt/DebtRulesXMLImporter.java b/sonar-server/src/main/java/org/sonar/server/debt/DebtRulesXMLImporter.java
index 3beb4daa1e4..5f76c882bb9 100644
--- a/sonar-server/src/main/java/org/sonar/server/debt/DebtRulesXMLImporter.java
+++ b/sonar-server/src/main/java/org/sonar/server/debt/DebtRulesXMLImporter.java
@@ -81,14 +81,13 @@ public class DebtRulesXMLImporter implements ServerExtension {
cursor.advance();
SMInputCursor rootCursor = cursor.childElementCursor(CHARACTERISTIC);
while (rootCursor.getNext() != null) {
- processCharacteristic(ruleDebts, null, null, rootCursor);
+ process(ruleDebts, null, null, rootCursor);
}
cursor.getStreamReader().closeCompletely();
} catch (XMLStreamException e) {
- LOG.error("XML is not valid", e);
+ throw new IllegalStateException("XML is not valid", e);
}
-
return ruleDebts;
}
@@ -101,7 +100,7 @@ public class DebtRulesXMLImporter implements ServerExtension {
return new SMInputFactory(xmlFactory);
}
- private void processCharacteristic(List<RuleDebt> ruleDebts, @Nullable String rootKey, @Nullable String parentKey, SMInputCursor chcCursor) throws XMLStreamException {
+ private void process(List<RuleDebt> ruleDebts, @Nullable String rootKey, @Nullable String parentKey, SMInputCursor chcCursor) throws XMLStreamException {
String currentCharacteristicKey = null;
SMInputCursor cursor = chcCursor.childElementCursor();
while (cursor.getNext() != null) {
@@ -109,7 +108,7 @@ public class DebtRulesXMLImporter implements ServerExtension {
if (StringUtils.equals(node, CHARACTERISTIC_KEY)) {
currentCharacteristicKey = cursor.collectDescendantText().trim();
} else if (StringUtils.equals(node, CHARACTERISTIC)) {
- processCharacteristic(ruleDebts, parentKey, currentCharacteristicKey, cursor);
+ process(ruleDebts, parentKey, currentCharacteristicKey, cursor);
} else if (StringUtils.equals(node, REPOSITORY_KEY)) {
RuleDebt ruleDebt = processRule(cursor);
if (ruleDebt != null) {
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
index 87e242e4ae2..95754a60b42 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
@@ -103,6 +103,7 @@ import org.sonar.server.platform.ws.RestartHandler;
import org.sonar.server.plugins.*;
import org.sonar.server.qualitygate.QgateProjectFinder;
import org.sonar.server.qualitygate.QualityGates;
+import org.sonar.server.qualitygate.RegisterBuiltinQualityGate;
import org.sonar.server.qualitygate.ws.QgateAppHandler;
import org.sonar.server.qualitygate.ws.QualityGatesWs;
import org.sonar.server.qualityprofile.*;
@@ -397,6 +398,7 @@ class ServerComponents {
ComponentContainer startupContainer = pico.createChild();
startupContainer.addSingleton(GwtPublisher.class);
startupContainer.addSingleton(RegisterMetrics.class);
+ startupContainer.addSingleton(RegisterBuiltinQualityGate.class);
startupContainer.addSingleton(DeprecatedRulesDefinition.class);
startupContainer.addSingleton(RuleDefinitionsLoader.class);
startupContainer.addSingleton(RuleRegistration.class);
@@ -413,14 +415,18 @@ class ServerComponents {
startupContainer.addSingleton(RegisterServletFilters.class);
startupContainer.addSingleton(CleanPreviewAnalysisCache.class);
startupContainer.addSingleton(CopyRequirementsFromCharacteristicsToRules.class);
+
+ DoPrivileged.start();
startupContainer.startComponents();
startupContainer.getComponentByType(ServerLifecycleNotifier.class).notifyStart();
+ DoPrivileged.stop();
// Do not put the following statements in a finally block.
// It would hide the possible exception raised during startup
// See SONAR-3107
startupContainer.stopComponents();
+
pico.getComponentByType(DatabaseSessionFactory.class).clear();
}
}
diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginJarsInstaller.java b/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginJarsInstaller.java
index e681b0a47ef..1a903de8ae5 100644
--- a/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginJarsInstaller.java
+++ b/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginJarsInstaller.java
@@ -128,7 +128,7 @@ public class ServerPluginJarsInstaller {
File destFile = new File(destDir, jar.getName());
if (destFile.exists()) {
// plugin with same filename already installed
- FileUtils.deleteQuietly(jar);
+ FileUtils.deleteQuietly(destFile);
}
try {
if (deleteSource) {
diff --git a/sonar-server/src/main/java/org/sonar/server/qualitygate/RegisterBuiltinQualityGate.java b/sonar-server/src/main/java/org/sonar/server/qualitygate/RegisterBuiltinQualityGate.java
new file mode 100644
index 00000000000..8d3be51d139
--- /dev/null
+++ b/sonar-server/src/main/java/org/sonar/server/qualitygate/RegisterBuiltinQualityGate.java
@@ -0,0 +1,67 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.qualitygate;
+
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.core.qualitygate.db.QualityGateConditionDto;
+import org.sonar.core.qualitygate.db.QualityGateDto;
+import org.sonar.core.template.LoadedTemplateDao;
+import org.sonar.core.template.LoadedTemplateDto;
+
+
+public final class RegisterBuiltinQualityGate {
+
+ private static final String BUILTIN_QUALITY_GATE = "SonarQube way";
+
+ private final QualityGates qualityGates;
+ private final LoadedTemplateDao loadedTemplateDao;
+
+ public RegisterBuiltinQualityGate(QualityGates qualityGates, LoadedTemplateDao loadedTemplateDao) {
+ this.qualityGates = qualityGates;
+ this.loadedTemplateDao = loadedTemplateDao;
+ }
+
+ public void start() {
+ if (shouldRegisterBuiltinQualityGate()) {
+ createBuiltinQualityGate();
+ registerBuiltinQualityGate();
+ }
+ }
+
+ private boolean shouldRegisterBuiltinQualityGate() {
+ return loadedTemplateDao.countByTypeAndKey(LoadedTemplateDto.QUALITY_GATE_TYPE, BUILTIN_QUALITY_GATE) == 0;
+ }
+
+ private void createBuiltinQualityGate() {
+ QualityGateDto builtin = qualityGates.create(BUILTIN_QUALITY_GATE);
+ qualityGates.createCondition(builtin.getId(), CoreMetrics.BLOCKER_VIOLATIONS_KEY, QualityGateConditionDto.OPERATOR_GREATER_THAN, null, "0", null);
+ qualityGates.createCondition(builtin.getId(), CoreMetrics.CRITICAL_VIOLATIONS_KEY, QualityGateConditionDto.OPERATOR_GREATER_THAN, null, "0", null);
+ qualityGates.createCondition(builtin.getId(), CoreMetrics.TEST_ERRORS_KEY, QualityGateConditionDto.OPERATOR_GREATER_THAN, null, "0", null);
+ qualityGates.createCondition(builtin.getId(), CoreMetrics.TEST_FAILURES_KEY, QualityGateConditionDto.OPERATOR_GREATER_THAN, null, "0", null);
+ qualityGates.createCondition(builtin.getId(), CoreMetrics.NEW_COVERAGE_KEY, QualityGateConditionDto.OPERATOR_LESS_THAN, null, "80", 3);
+ qualityGates.createCondition(builtin.getId(), CoreMetrics.OPEN_ISSUES_KEY, QualityGateConditionDto.OPERATOR_GREATER_THAN, "0", null, null);
+ qualityGates.createCondition(builtin.getId(), CoreMetrics.REOPENED_ISSUES_KEY, QualityGateConditionDto.OPERATOR_GREATER_THAN, "0", null, null);
+ qualityGates.createCondition(builtin.getId(), CoreMetrics.SKIPPED_TESTS_KEY, QualityGateConditionDto.OPERATOR_GREATER_THAN, "0", null, null);
+ }
+
+ private void registerBuiltinQualityGate() {
+ loadedTemplateDao.insert(new LoadedTemplateDto(BUILTIN_QUALITY_GATE, LoadedTemplateDto.QUALITY_GATE_TYPE));
+ }
+}
diff --git a/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java b/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java
index 294dea34686..47f39e88dbd 100644
--- a/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java
+++ b/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QgateAppHandler.java
@@ -71,6 +71,9 @@ public class QgateAppHandler implements RequestHandler {
"quality_gates.projects_for_default",
"quality_gates.projects_for_default.edit",
"quality_gates.rename",
+ "quality_gates.delete.confirm.message",
+ "quality_gates.delete.confirm.default",
+ "quality_gates.delete_condition.confirm.message",
"rename",
"save",
"set_as_default",
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java b/sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java
index 6b82426ebaa..ee747ed4ba9 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java
@@ -195,7 +195,7 @@ public class RuleRegistration implements Startable {
.setDefaultRemediationFunction(remediationFunction.type().name())
.setDefaultRemediationFactor(remediationFunction.factor())
.setDefaultRemediationOffset(remediationFunction.offset())
- .setEffortToFixL10nKey(ruleDef.effortToFixL10nKey());
+ .setEffortToFixDescription(ruleDef.effortToFixDescription());
}
ruleDao.insert(ruleDto, sqlSession);
@@ -274,7 +274,7 @@ public class RuleRegistration implements Startable {
Integer characteristicId = characteristic != null ? characteristic.getId() : null;
String remediationFactor = hasCharacteristic ? debtRemediationFunction.factor() : null;
String remediationOffset = hasCharacteristic ? debtRemediationFunction.offset() : null;
- String effortToFixL10nKey = hasCharacteristic ? def.effortToFixL10nKey() : null;
+ String effortToFixDescription = hasCharacteristic ? def.effortToFixDescription() : null;
if (!ObjectUtils.equals(dto.getDefaultCharacteristicId(), characteristicId)) {
dto.setDefaultCharacteristicId(characteristicId);
@@ -293,8 +293,8 @@ public class RuleRegistration implements Startable {
dto.setDefaultRemediationOffset(remediationOffset);
changed = true;
}
- if (!StringUtils.equals(dto.getEffortToFixL10nKey(), effortToFixL10nKey)) {
- dto.setEffortToFixL10nKey(effortToFixL10nKey);
+ if (!StringUtils.equals(dto.getEffortToFixDescription(), effortToFixDescription)) {
+ dto.setEffortToFixDescription(effortToFixDescription);
changed = true;
}
return changed;
@@ -420,7 +420,7 @@ public class RuleRegistration implements Startable {
ruleDto.setDefaultRemediationFunction(parent.getDefaultRemediationFunction());
ruleDto.setDefaultRemediationFactor(parent.getDefaultRemediationFactor());
ruleDto.setDefaultRemediationOffset(parent.getDefaultRemediationOffset());
- ruleDto.setEffortToFixL10nKey(parent.getEffortToFixL10nKey());
+ ruleDto.setEffortToFixDescription(parent.getEffortToFixDescription());
ruleDto.setUpdatedAt(buffer.now());
ruleDao.update(ruleDto, sqlSession);
toBeRemoved = false;
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RuleRepositories.java b/sonar-server/src/main/java/org/sonar/server/rule/RuleRepositories.java
index 91153922bab..6eb28b6b0d2 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule/RuleRepositories.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule/RuleRepositories.java
@@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.SetMultimap;
+import org.apache.commons.lang.builder.CompareToBuilder;
import org.sonar.api.ServerComponent;
import org.sonar.api.server.rule.RulesDefinition;
@@ -110,7 +111,19 @@ public class RuleRepositories implements ServerComponent {
@Override
public int compareTo(Repository o) {
- return name.toLowerCase().compareTo(o.name.toLowerCase());
+ return new CompareToBuilder()
+ .append(name.toLowerCase(), o.name.toLowerCase())
+ .append(key, o.key)
+ .toComparison();
+ }
+
+ @Override
+ public String toString() {
+ return "Repository{" +
+ "key='" + key + '\'' +
+ ", name='" + name + '\'' +
+ ", language='" + language + '\'' +
+ '}';
}
}
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRules.java b/sonar-server/src/main/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRules.java
index 54232217ae2..51fcac7192f 100644
--- a/sonar-server/src/main/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRules.java
+++ b/sonar-server/src/main/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRules.java
@@ -34,7 +34,7 @@ import org.sonar.api.rules.Rule;
import org.sonar.api.utils.Duration;
import org.sonar.api.utils.System2;
import org.sonar.core.persistence.Database;
-import org.sonar.core.technicaldebt.db.CharacteristicDto;
+import org.sonar.core.rule.RuleDto;
import org.sonar.core.technicaldebt.db.RequirementDao;
import org.sonar.core.technicaldebt.db.RequirementDto;
import org.sonar.server.db.migrations.MassUpdater;
@@ -174,7 +174,7 @@ public class CopyRequirementsFromCharacteristicsToRules {
if (enabledRequirement == null && !Rule.STATUS_REMOVED.equals(ruleRow.getStatus())) {
// If no requirements are enable, it means that the requirement has been disabled for this rule
- updateStatement.setInt(1, CharacteristicDto.DISABLED_CHARACTERISTIC_ID);
+ updateStatement.setInt(1, RuleDto.DISABLED_CHARACTERISTIC_ID);
updateStatement.setNull(2, Types.VARCHAR);
updateStatement.setNull(3, Types.VARCHAR);
updateStatement.setNull(4, Types.VARCHAR);
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterDebtModel.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterDebtModel.java
index f0baaf7fdf5..59a4ecdf035 100644
--- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterDebtModel.java
+++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterDebtModel.java
@@ -23,7 +23,6 @@ package org.sonar.server.startup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.utils.TimeProfiler;
-import org.sonar.api.utils.ValidationMessages;
import org.sonar.server.debt.DebtModelSynchronizer;
public class RegisterDebtModel {
@@ -38,7 +37,7 @@ public class RegisterDebtModel {
public void start() {
TimeProfiler profiler = new TimeProfiler(LOGGER).start("Register technical debt model");
- manager.synchronize(ValidationMessages.create());
+ manager.synchronize();
profiler.stop();
}
diff --git a/sonar-server/src/main/java/org/sonar/server/user/DoPrivileged.java b/sonar-server/src/main/java/org/sonar/server/user/DoPrivileged.java
new file mode 100644
index 00000000000..0cf872702ad
--- /dev/null
+++ b/sonar-server/src/main/java/org/sonar/server/user/DoPrivileged.java
@@ -0,0 +1,45 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.user;
+
+import java.util.Locale;
+
+public final class DoPrivileged {
+
+ private static final String SYSTEM_LOGIN = "<system>";
+ private static final String SYSTEM_NAME = "Internal System Account";
+
+ public static void start() {
+ UserSession.set(new UserSession() {
+ @Override
+ public boolean hasGlobalPermission(String globalPermission) {
+ return true;
+ }
+ @Override
+ public boolean hasProjectPermission(String permission, String projectKey) {
+ return true;
+ }
+ }.setLocale(Locale.getDefault()).setLogin(SYSTEM_LOGIN).setName(SYSTEM_NAME));
+ }
+
+ public static void stop() {
+ UserSession.remove();
+ }
+}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb
index 9381e4bbb22..586698c4ea2 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb
@@ -81,11 +81,105 @@
</div>
<% end %>
- <% unless category_help(@category).blank? -%>
+ <% if @category.key() == 'exclusions' -%>
+ <div class="help marginbottom10" style="margin-left: -1px">
+ <h2>Wildcards</h2>
+ <p>Following rules are applied:</p>
+ <table class="data">
+ <thead><tr><th colspan="2"></th></tr></thead>
+ <tr>
+ <td>*</td>
+ <td>Match zero or more characters</td>
+ </tr>
+ <tr>
+ <td>**</td>
+ <td>Match zero or more directories</td>
+ </tr>
+ <tr>
+ <td>?</td>
+ <td>Match a single character</td>
+ </tr>
+ </table>
+ <br>
+ <table class="data">
+ <thead><tr><th>Example</th><th>Matches</th><th>Does not match</th></tr></thead>
+ <tbody>
+ <tr>
+ <td>**/foo/*.js</td>
+ <td>
+ <ul>
+ <li>src/foo/bar.js</li>
+ <li>lib/ui/foo/bar.js</li>
+ </ul>
+ </td>
+ <td>
+ <ul>
+ <li>src/bar.js</li>
+ <li>src/foo2/bar.js</li>
+ </ul>
+ </td>
+ </tr>
+ <tr>
+ <td>src/foo/*bar*.js</td>
+ <td>
+ <ul>
+ <li>src/foo/bar.js</li>
+ <li>src/foo/bar1.js</li>
+ <li>src/foo/bar123.js</li>
+ <li>src/foo/123bar123.js</li>
+ </ul>
+ </td>
+ <td>
+ <ul>
+ <li>src/foo/ui/bar.js</li>
+ <li>src/bar.js</li>
+ </ul>
+ </td>
+ </tr>
+ <tr>
+ <td>src/foo/**</td>
+ <td>
+ <ul>
+ <li>src/foo/bar.js</li>
+ <li>src/foo/ui/bar.js</li>
+ </ul>
+ </td>
+ <td>
+ <ul>
+ <li>src/bar/foo/bar.js</li>
+ <li>src/bar.js</li>
+ </ul>
+ </td>
+ </tr>
+ <tr>
+ <td>**/foo?.js</td>
+ <td>
+ <ul>
+ <li>src/foo1.js</li>
+ <li>src/bar/foo1.js</li>
+ </ul>
+ </td>
+ <td>
+ <ul>
+ <li>src/foo.js</li>
+ <li>src/foo12.js</li>
+ <li>src/12foo3.js</li>
+ </ul>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <% else
+ help = category_help(@category)
+ unless help.blank?
+ -%>
<div class="help marginbottom10" style="margin-left: -1px">
- <%= category_help(@category) -%>
+ <%= help -%>
</div>
- <% end -%>
+ <% end
+ end
+ -%>
<% end %>
</form>
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/520_add_debt_columns_to_rules.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/520_add_debt_columns_to_rules.rb
index 059f3a88b37..5af0233dd8c 100644
--- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/520_add_debt_columns_to_rules.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/520_add_debt_columns_to_rules.rb
@@ -33,7 +33,7 @@ class AddDebtColumnsToRules < ActiveRecord::Migration
add_column 'rules', :default_remediation_factor, :string, :null => true, :limit => 20
add_column 'rules', :remediation_offset, :string, :null => true, :limit => 20
add_column 'rules', :default_remediation_offset, :string, :null => true, :limit => 20
- add_column 'rules', :effort_to_fix_l10n_key, :string, :null => true, :limit => 100
+ add_column 'rules', :effort_to_fix_description, :string, :null => true, :limit => 4000
end
end
diff --git a/sonar-server/src/main/webapp/coffee/quality-gate/views/quality-gate-detail-condition-view.coffee b/sonar-server/src/main/webapp/coffee/quality-gate/views/quality-gate-detail-condition-view.coffee
index 1bebd6f6cb3..4182198ff25 100644
--- a/sonar-server/src/main/webapp/coffee/quality-gate/views/quality-gate-detail-condition-view.coffee
+++ b/sonar-server/src/main/webapp/coffee/quality-gate/views/quality-gate-detail-condition-view.coffee
@@ -90,9 +90,10 @@ define [
deleteCondition: ->
- if confirm t('are_you_sure')
+ if confirm t('quality_gates.delete_condition.confirm.message')
@showSpinner()
@model.delete().done =>
+ @options.collectionView.collection.remove @model
@options.collectionView.updateConditions()
@close()
diff --git a/sonar-server/src/main/webapp/coffee/quality-gate/views/quality-gate-detail-header-view.coffee b/sonar-server/src/main/webapp/coffee/quality-gate/views/quality-gate-detail-header-view.coffee
index 8111616458a..acf593f149f 100644
--- a/sonar-server/src/main/webapp/coffee/quality-gate/views/quality-gate-detail-header-view.coffee
+++ b/sonar-server/src/main/webapp/coffee/quality-gate/views/quality-gate-detail-header-view.coffee
@@ -40,7 +40,8 @@ define [
deleteQualityGate: ->
- if confirm t('are_you_sure')
+ message = if @model.get 'default' then 'quality_gates.delete.confirm.default' else 'quality_gates.delete.confirm.message'
+ if confirm t(message).replace('{0}', @model.get 'name')
@showSpinner()
jQuery.ajax
type: 'POST'
diff --git a/sonar-server/src/main/webapp/js/templates/quality-gates.js b/sonar-server/src/main/webapp/js/templates/quality-gates.js
index 3a3bf93216c..00e75e93448 100644
--- a/sonar-server/src/main/webapp/js/templates/quality-gates.js
+++ b/sonar-server/src/main/webapp/js/templates/quality-gates.js
@@ -250,14 +250,14 @@ function program1(depth0,data) {
function program2(depth0,data) {
var buffer = "", stack1, helper;
- buffer += "\n <optgroup label=\"";
+ buffer += "\n <optgroup label=\"";
if (helper = helpers.domain) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.domain); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
buffer += escapeExpression(stack1)
- + "\">\n ";
+ + "\">\n ";
stack1 = helpers.each.call(depth0, (depth0 && depth0.metrics), {hash:{},inverse:self.noop,fn:self.program(3, program3, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
- buffer += "\n </optgroup>\n ";
+ buffer += "\n </optgroup>\n ";
return buffer;
}
function program3(depth0,data) {
@@ -281,15 +281,15 @@ function program3(depth0,data) {
+ escapeExpression((helper = helpers.t || (depth0 && depth0.t),options={hash:{},data:data},helper ? helper.call(depth0, "quality_gates.introduction", options) : helperMissing.call(depth0, "t", "quality_gates.introduction", options)))
+ "\n <a class=\"link-action quality-gate-introduction-show-more\">"
+ escapeExpression((helper = helpers.t || (depth0 && depth0.t),options={hash:{},data:data},helper ? helper.call(depth0, "more", options) : helperMissing.call(depth0, "t", "more", options)))
- + "</a>\n </p>\n <div class=\"quality-gate-introduction-more\">\n "
+ + "</a>\n </p>\n <div class=\"quality-gate-introduction-more inline-help\">\n "
+ escapeExpression((helper = helpers.t || (depth0 && depth0.t),options={hash:{},data:data},helper ? helper.call(depth0, "quality_gates.health_icons", options) : helperMissing.call(depth0, "t", "quality_gates.health_icons", options)))
- + "\n <table class=\"data\">\n <thead>\n <tr>\n <th colspan=\"3\"></th>\n </tr>\n </thead>\n <tbody>\n <tr class=\"even\">\n <td><i class=\"icon-alert-ok\"></i></td>\n <td>"
+ + "\n <ul>\n <li>\n <i class=\"icon-alert-ok\"></i>\n "
+ escapeExpression((helper = helpers.t || (depth0 && depth0.t),options={hash:{},data:data},helper ? helper.call(depth0, "alerts.notes.ok", options) : helperMissing.call(depth0, "t", "alerts.notes.ok", options)))
- + "</td>\n </tr>\n <tr class=\"odd\">\n <td><i class=\"icon-alert-warn\"></i></td>\n <td>"
+ + "\n </li>\n <li>\n <i class=\"icon-alert-warn\"></i>\n "
+ escapeExpression((helper = helpers.t || (depth0 && depth0.t),options={hash:{},data:data},helper ? helper.call(depth0, "alerts.notes.warn", options) : helperMissing.call(depth0, "t", "alerts.notes.warn", options)))
- + "</td>\n </tr>\n <tr class=\"even\">\n <td><i class=\"icon-alert-error\"></i></td>\n <td>"
+ + "\n </li>\n <li>\n <i class=\"icon-alert-error\"></i>\n "
+ escapeExpression((helper = helpers.t || (depth0 && depth0.t),options={hash:{},data:data},helper ? helper.call(depth0, "alerts.notes.error", options) : helperMissing.call(depth0, "t", "alerts.notes.error", options)))
- + "</td>\n </tr>\n </tbody>\n </table>\n </div>\n</div>\n\n";
+ + "\n </li>\n </ul>\n </div>\n</div>\n\n";
stack1 = helpers['if'].call(depth0, (depth0 && depth0.canEdit), {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n\n<table class=\"data zebra width100 marginbottom10 spaced quality-gate-conditions\">\n <thead><tr></tr></thead>\n <tbody></tbody>\n</table>";
diff --git a/sonar-server/src/main/webapp/less/style.less b/sonar-server/src/main/webapp/less/style.less
index 925cf6777e6..6c1aec34cd8 100644
--- a/sonar-server/src/main/webapp/less/style.less
+++ b/sonar-server/src/main/webapp/less/style.less
@@ -1611,6 +1611,13 @@ option.sev_BLOCKER, span.sev_BLOCKER {
padding: 5px 0;
}
+.inline-help {
+ padding: 5px;
+ margin: 5px;
+ background-color: #FFF6BF;
+ border: 1px solid #FFD324;
+}
+
/* ------------------- FORMS ------------------- */
.admintable {
border: solid 1px #FFD324;
diff --git a/sonar-server/src/main/webapp/templates/quality-gates/quality-gate-detail-conditions.hbs b/sonar-server/src/main/webapp/templates/quality-gates/quality-gate-detail-conditions.hbs
index ef2980720ce..343994fd780 100644
--- a/sonar-server/src/main/webapp/templates/quality-gates/quality-gate-detail-conditions.hbs
+++ b/sonar-server/src/main/webapp/templates/quality-gates/quality-gate-detail-conditions.hbs
@@ -4,29 +4,22 @@
<p>{{t 'quality_gates.introduction'}}
<a class="link-action quality-gate-introduction-show-more">{{t 'more'}}</a>
</p>
- <div class="quality-gate-introduction-more">
+ <div class="quality-gate-introduction-more inline-help">
{{t 'quality_gates.health_icons'}}
- <table class="data">
- <thead>
- <tr>
- <th colspan="3"></th>
- </tr>
- </thead>
- <tbody>
- <tr class="even">
- <td><i class="icon-alert-ok"></i></td>
- <td>{{t 'alerts.notes.ok'}}</td>
- </tr>
- <tr class="odd">
- <td><i class="icon-alert-warn"></i></td>
- <td>{{t 'alerts.notes.warn'}}</td>
- </tr>
- <tr class="even">
- <td><i class="icon-alert-error"></i></td>
- <td>{{t 'alerts.notes.error'}}</td>
- </tr>
- </tbody>
- </table>
+ <ul>
+ <li>
+ <i class="icon-alert-ok"></i>
+ {{t 'alerts.notes.ok'}}
+ </li>
+ <li>
+ <i class="icon-alert-warn"></i>
+ {{t 'alerts.notes.warn'}}
+ </li>
+ <li>
+ <i class="icon-alert-error"></i>
+ {{t 'alerts.notes.error'}}
+ </li>
+ </ul>
</div>
</div>
@@ -36,9 +29,9 @@
<select id="quality-gate-new-condition-metric">
<option></option>
{{#each metricGroups}}
- <optgroup label="{{domain}}">
- {{#each metrics}}<option value="{{key}}">{{name}}</option>{{/each}}
- </optgroup>
+ <optgroup label="{{domain}}">
+ {{#each metrics}}<option value="{{key}}">{{name}}</option>{{/each}}
+ </optgroup>
{{/each}}
</select>
</div>
diff --git a/sonar-server/src/test/java/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest.java b/sonar-server/src/test/java/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest.java
index 4a6b947c03d..1180215e3a2 100644
--- a/sonar-server/src/test/java/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest.java
@@ -24,12 +24,11 @@ import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import org.junit.Test;
import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic;
-import org.sonar.api.utils.ValidationMessages;
-import org.sonar.core.technicaldebt.DefaultTechnicalDebtModel;
import java.io.IOException;
import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
public class DebtCharacteristicsXMLImporterTest {
@@ -37,8 +36,7 @@ public class DebtCharacteristicsXMLImporterTest {
public void import_characteristics() {
String xml = getFileContent("import_characteristics.xml");
- ValidationMessages messages = ValidationMessages.create();
- DefaultTechnicalDebtModel debtModel = new DebtCharacteristicsXMLImporter().importXML(xml, messages);
+ DebtCharacteristicsXMLImporter.DebtModel debtModel = new DebtCharacteristicsXMLImporter().importXML(xml);
assertThat(debtModel.rootCharacteristics()).hasSize(2);
assertThat(debtModel.rootCharacteristics().get(0).key()).isEqualTo("PORTABILITY");
@@ -63,26 +61,31 @@ public class DebtCharacteristicsXMLImporterTest {
public void import_badly_formatted_xml() {
String xml = getFileContent("import_badly_formatted_xml.xml");
- ValidationMessages messages = ValidationMessages.create();
- DefaultTechnicalDebtModel debtModel = new DebtCharacteristicsXMLImporter().importXML(xml, messages);
-
- checkXmlCorrectlyImported(debtModel, messages);
- }
-
- private void checkXmlCorrectlyImported(DefaultTechnicalDebtModel sqale, ValidationMessages messages) {
- assertThat(messages.getErrors()).isEmpty();
+ DebtCharacteristicsXMLImporter.DebtModel debtModel = new DebtCharacteristicsXMLImporter().importXML(xml);
// characteristics
- assertThat(sqale.rootCharacteristics()).hasSize(2);
- DefaultCharacteristic efficiency = sqale.characteristicByKey("EFFICIENCY");
+ assertThat(debtModel.rootCharacteristics()).hasSize(2);
+ DefaultCharacteristic efficiency = debtModel.characteristicByKey("EFFICIENCY");
assertThat(efficiency.name()).isEqualTo("Efficiency");
// sub-characteristics
assertThat(efficiency.children()).hasSize(1);
- DefaultCharacteristic memoryEfficiency = sqale.characteristicByKey("MEMORY_EFFICIENCY");
+ DefaultCharacteristic memoryEfficiency = debtModel.characteristicByKey("MEMORY_EFFICIENCY");
assertThat(memoryEfficiency.name()).isEqualTo("Memory use");
}
+ @Test
+ public void fail_on_bad_xml() {
+ String xml = getFileContent("fail_on_bad_xml.xml");
+
+ try {
+ new DebtCharacteristicsXMLImporter().importXML(xml);
+ fail();
+ } catch (Exception e){
+ assertThat(e).isInstanceOf(IllegalStateException.class);
+ }
+ }
+
private String getFileContent(String file) {
try {
return Resources.toString(Resources.getResource(DebtCharacteristicsXMLImporterTest.class, "DebtCharacteristicsXMLImporterTest/" + file), Charsets.UTF_8);
diff --git a/sonar-server/src/test/java/org/sonar/server/debt/DebtModelServiceTest.java b/sonar-server/src/test/java/org/sonar/server/debt/DebtModelServiceTest.java
index 61a58305daf..708a9a4165a 100644
--- a/sonar-server/src/test/java/org/sonar/server/debt/DebtModelServiceTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/debt/DebtModelServiceTest.java
@@ -29,8 +29,13 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import org.sonar.api.server.debt.DebtCharacteristic;
+import org.sonar.api.utils.DateUtils;
+import org.sonar.api.utils.System2;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.core.persistence.BatchSession;
import org.sonar.core.persistence.MyBatis;
+import org.sonar.core.rule.RuleDao;
+import org.sonar.core.rule.RuleDto;
import org.sonar.core.technicaldebt.db.CharacteristicDao;
import org.sonar.core.technicaldebt.db.CharacteristicDto;
import org.sonar.server.exceptions.BadRequestException;
@@ -38,6 +43,8 @@ import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.MockUserSession;
+import java.util.Date;
+
import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
@@ -51,22 +58,32 @@ public class DebtModelServiceTest {
CharacteristicDao dao;
@Mock
+ RuleDao ruleDao;
+
+ @Mock
MyBatis mybatis;
@Mock
SqlSession session;
- CharacteristicDto rootCharacteristicDto = new CharacteristicDto()
+ @Mock
+ System2 system2;
+
+ Date now = DateUtils.parseDate("2014-03-19");
+
+ CharacteristicDto characteristicDto = new CharacteristicDto()
.setId(1)
.setKey("MEMORY_EFFICIENCY")
.setName("Memory use")
- .setOrder(2);
+ .setOrder(2)
+ .setEnabled(true);
- CharacteristicDto characteristicDto = new CharacteristicDto()
+ CharacteristicDto subCharacteristicDto = new CharacteristicDto()
.setId(2)
.setKey("EFFICIENCY")
.setName("Efficiency")
- .setParentId(1);
+ .setParentId(1)
+ .setEnabled(true);
int currentId;
@@ -74,6 +91,8 @@ public class DebtModelServiceTest {
@Before
public void setUp() throws Exception {
+ when(system2.now()).thenReturn(now.getTime());
+
MockUserSession.set().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
currentId = 10;
@@ -88,24 +107,24 @@ public class DebtModelServiceTest {
}).when(dao).insert(any(CharacteristicDto.class), any(SqlSession.class));
when(mybatis.openSession()).thenReturn(session);
- service = new DebtModelService(mybatis, dao);
+ service = new DebtModelService(mybatis, dao, ruleDao,system2);
}
@Test
public void find_root_characteristics() {
- when(dao.selectEnabledRootCharacteristics()).thenReturn(newArrayList(rootCharacteristicDto));
+ when(dao.selectEnabledRootCharacteristics()).thenReturn(newArrayList(characteristicDto));
assertThat(service.rootCharacteristics()).hasSize(1);
}
@Test
public void find_characteristics() {
- when(dao.selectEnabledCharacteristics()).thenReturn(newArrayList(rootCharacteristicDto));
+ when(dao.selectEnabledCharacteristics()).thenReturn(newArrayList(characteristicDto));
assertThat(service.characteristics()).hasSize(1);
}
@Test
public void find_characteristic_by_id() {
- when(dao.selectById(1)).thenReturn(rootCharacteristicDto);
+ when(dao.selectById(1)).thenReturn(characteristicDto);
DebtCharacteristic characteristic = service.characteristicById(1);
assertThat(characteristic.id()).isEqualTo(1);
@@ -119,7 +138,7 @@ public class DebtModelServiceTest {
@Test
public void create_sub_characteristic() {
- when(dao.selectById(1, session)).thenReturn(rootCharacteristicDto);
+ when(dao.selectById(1, session)).thenReturn(characteristicDto);
DebtCharacteristic result = service.create("Compilation name", 1);
@@ -131,7 +150,7 @@ public class DebtModelServiceTest {
@Test
public void fail_to_create_sub_characteristic_when_parent_id_is_not_a_root_characteristic() {
- when(dao.selectById(1, session)).thenReturn(characteristicDto);
+ when(dao.selectById(1, session)).thenReturn(subCharacteristicDto);
try {
service.create("Compilation", 1);
@@ -156,7 +175,7 @@ public class DebtModelServiceTest {
@Test
public void fail_to_create_sub_characteristic_when_name_already_used() {
when(dao.selectByName("Compilation", session)).thenReturn(new CharacteristicDto());
- when(dao.selectById(1, session)).thenReturn(rootCharacteristicDto);
+ when(dao.selectById(1, session)).thenReturn(characteristicDto);
try {
service.create("Compilation", 1);
@@ -205,7 +224,7 @@ public class DebtModelServiceTest {
@Test
public void rename_characteristic() {
- when(dao.selectById(10, session)).thenReturn(characteristicDto);
+ when(dao.selectById(10, session)).thenReturn(subCharacteristicDto);
DebtCharacteristic result = service.rename(10, "New Efficiency");
@@ -215,7 +234,7 @@ public class DebtModelServiceTest {
@Test
public void not_rename_characteristic_when_renaming_with_same_name() {
- when(dao.selectById(10, session)).thenReturn(characteristicDto);
+ when(dao.selectById(10, session)).thenReturn(subCharacteristicDto);
service.rename(10, "Efficiency");
@@ -286,4 +305,78 @@ public class DebtModelServiceTest {
verify(dao, never()).update(any(CharacteristicDto.class), eq(session));
}
+ @Test
+ public void delete_sub_characteristic() {
+ BatchSession batchSession = mock(BatchSession.class);
+ when(mybatis.openBatchSession()).thenReturn(batchSession);
+
+ when(ruleDao.selectByCharacteristicOrSubCharacteristicId(2, batchSession)).thenReturn(newArrayList(
+ new RuleDto()
+ .setCharacteristicId(2).setRemediationFunction("LINEAR_OFFSET").setRemediationFactor("2h").setRemediationOffset("5min")
+ .setDefaultCharacteristicId(10).setDefaultRemediationFunction("LINEAR_OFFSET").setDefaultRemediationFactor("4h").setDefaultRemediationOffset("15min")
+ ));
+ when(dao.selectById(2, batchSession)).thenReturn(subCharacteristicDto);
+
+ service.delete(2);
+
+ ArgumentCaptor<RuleDto> ruleArgument = ArgumentCaptor.forClass(RuleDto.class);
+ verify(ruleDao).update(ruleArgument.capture(), eq(batchSession));
+ RuleDto ruleDto = ruleArgument.getValue();
+
+ // Overridden debt data are disabled
+ assertThat(ruleDto.getCharacteristicId()).isEqualTo(-1);
+ assertThat(ruleDto.getRemediationFunction()).isNull();
+ assertThat(ruleDto.getRemediationFactor()).isNull();
+ assertThat(ruleDto.getRemediationOffset()).isNull();
+ assertThat(ruleDto.getUpdatedAt()).isEqualTo(now);
+
+ // Default debt data should not be touched
+ assertThat(ruleDto.getDefaultCharacteristicId()).isEqualTo(10);
+ assertThat(ruleDto.getDefaultRemediationFunction()).isEqualTo("LINEAR_OFFSET");
+ assertThat(ruleDto.getDefaultRemediationFactor()).isEqualTo("4h");
+ assertThat(ruleDto.getDefaultRemediationOffset()).isEqualTo("15min");
+
+ ArgumentCaptor<CharacteristicDto> characteristicArgument = ArgumentCaptor.forClass(CharacteristicDto.class);
+ verify(dao).update(characteristicArgument.capture(), eq(batchSession));
+ CharacteristicDto characteristicDto = characteristicArgument.getValue();
+
+ // Sub characteristic is disable
+ assertThat(characteristicDto.getId()).isEqualTo(2);
+ assertThat(characteristicDto.isEnabled()).isFalse();
+ assertThat(characteristicDto.getUpdatedAt()).isEqualTo(now);
+ }
+
+ @Test
+ public void delete_characteristic() {
+ BatchSession batchSession = mock(BatchSession.class);
+ when(mybatis.openBatchSession()).thenReturn(batchSession);
+
+ when(ruleDao.selectByCharacteristicOrSubCharacteristicId(1, batchSession)).thenReturn(newArrayList(
+ new RuleDto().setCharacteristicId(2).setRemediationFunction("LINEAR_OFFSET").setRemediationFactor("2h").setRemediationOffset("5min")
+ ));
+ when(dao.selectCharacteristicsByParentId(1, batchSession)).thenReturn(newArrayList(
+ subCharacteristicDto
+ ));
+ when(dao.selectById(1, batchSession)).thenReturn(characteristicDto);
+
+ service.delete(1);
+
+ verify(ruleDao).update(any(RuleDto.class), eq(batchSession));
+
+ ArgumentCaptor<CharacteristicDto> characteristicArgument = ArgumentCaptor.forClass(CharacteristicDto.class);
+ verify(dao, times(2)).update(characteristicArgument.capture(), eq(batchSession));
+ CharacteristicDto subCharacteristicDto = characteristicArgument.getAllValues().get(0);
+ CharacteristicDto characteristicDto = characteristicArgument.getAllValues().get(1);
+
+ // Sub characteristic is disable
+ assertThat(subCharacteristicDto.getId()).isEqualTo(2);
+ assertThat(subCharacteristicDto.isEnabled()).isFalse();
+ assertThat(subCharacteristicDto.getUpdatedAt()).isEqualTo(now);
+
+ // Characteristic is disable
+ assertThat(characteristicDto.getId()).isEqualTo(1);
+ assertThat(characteristicDto.isEnabled()).isFalse();
+ assertThat(characteristicDto.getUpdatedAt()).isEqualTo(now);
+ }
+
}
diff --git a/sonar-server/src/test/java/org/sonar/server/debt/DebtModelSynchronizerTest.java b/sonar-server/src/test/java/org/sonar/server/debt/DebtModelSynchronizerTest.java
index 9b7accc80b2..0ab0f351732 100644
--- a/sonar-server/src/test/java/org/sonar/server/debt/DebtModelSynchronizerTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/debt/DebtModelSynchronizerTest.java
@@ -31,9 +31,7 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic;
-import org.sonar.api.utils.ValidationMessages;
import org.sonar.core.persistence.MyBatis;
-import org.sonar.core.technicaldebt.DefaultTechnicalDebtModel;
import org.sonar.core.technicaldebt.TechnicalDebtModelRepository;
import org.sonar.core.technicaldebt.db.CharacteristicDao;
import org.sonar.core.technicaldebt.db.CharacteristicDto;
@@ -67,7 +65,7 @@ public class DebtModelSynchronizerTest {
Integer currentId = 1;
- private DefaultTechnicalDebtModel defaultModel;
+ private DebtCharacteristicsXMLImporter.DebtModel defaultModel;
private DebtModelSynchronizer manager;
@@ -75,10 +73,10 @@ public class DebtModelSynchronizerTest {
public void initAndMerge() throws Exception {
when(myBatis.openSession()).thenReturn(session);
- defaultModel = new DefaultTechnicalDebtModel();
+ defaultModel = new DebtCharacteristicsXMLImporter.DebtModel();
Reader defaultModelReader = mock(Reader.class);
when(technicalDebtModelRepository.createReaderForXMLFile("technical-debt")).thenReturn(defaultModelReader);
- when(xmlImporter.importXML(eq(defaultModelReader), any(ValidationMessages.class))).thenReturn(defaultModel);
+ when(xmlImporter.importXML(eq(defaultModelReader))).thenReturn(defaultModel);
doAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) {
@@ -102,7 +100,7 @@ public class DebtModelSynchronizerTest {
when(technicalDebtModelRepository.getContributingPluginList()).thenReturn(Collections.<String>emptyList());
when(dao.selectEnabledCharacteristics()).thenReturn(Lists.<CharacteristicDto>newArrayList());
- manager.synchronize(ValidationMessages.create());
+ manager.synchronize();
verify(dao).selectEnabledCharacteristics();
ArgumentCaptor<CharacteristicDto> characteristicCaptor = ArgumentCaptor.forClass(CharacteristicDto.class);
@@ -123,7 +121,7 @@ public class DebtModelSynchronizerTest {
when(technicalDebtModelRepository.getContributingPluginList()).thenReturn(Collections.<String>emptyList());
when(dao.selectEnabledCharacteristics()).thenReturn(Lists.newArrayList(new CharacteristicDto()));
- manager.synchronize(ValidationMessages.create());
+ manager.synchronize();
verify(dao, never()).insert(any(CharacteristicDto.class), eq(session));
}
diff --git a/sonar-server/src/test/java/org/sonar/server/debt/DebtRulesXMLImporterTest.java b/sonar-server/src/test/java/org/sonar/server/debt/DebtRulesXMLImporterTest.java
index 08ed971be0d..9fdaefb428f 100644
--- a/sonar-server/src/test/java/org/sonar/server/debt/DebtRulesXMLImporterTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/debt/DebtRulesXMLImporterTest.java
@@ -190,6 +190,18 @@ public class DebtRulesXMLImporterTest {
}
}
+ @Test
+ public void fail_on_bad_xml() {
+ String xml = getFileContent("fail_on_bad_xml.xml");
+
+ try {
+ new DebtCharacteristicsXMLImporter().importXML(xml);
+ fail();
+ } catch (Exception e){
+ assertThat(e).isInstanceOf(IllegalStateException.class);
+ }
+ }
+
private String getFileContent(String file) {
try {
return Resources.toString(Resources.getResource(DebtRulesXMLImporterTest.class, "DebtRulesXMLImporterTest/" + file), Charsets.UTF_8);
diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarsInstallerTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarsInstallerTest.java
index 6ceb0107900..1e58b7dbdb3 100644
--- a/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarsInstallerTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarsInstallerTest.java
@@ -113,7 +113,7 @@ public class ServerPluginJarsInstallerTest {
}
@Test
- public void should_fail_on_plugin_depending_on_more_recent_sonar() {
+ public void fail_if_require_greater_SQ_version() {
when(server.getVersion()).thenReturn("2.0");
exception.expect(IllegalStateException.class);
diff --git a/sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterBuiltinQualityGateTest.java b/sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterBuiltinQualityGateTest.java
new file mode 100644
index 00000000000..3f94bfd4e6d
--- /dev/null
+++ b/sonar-server/src/test/java/org/sonar/server/qualitygate/RegisterBuiltinQualityGateTest.java
@@ -0,0 +1,85 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.qualitygate;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.sonar.core.qualitygate.db.QualityGateDto;
+import org.sonar.core.template.LoadedTemplateDao;
+import org.sonar.core.template.LoadedTemplateDto;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.*;
+
+@RunWith(MockitoJUnitRunner.class)
+public class RegisterBuiltinQualityGateTest {
+
+ @Mock
+ private QualityGates qualityGates;
+
+ @Mock
+ private LoadedTemplateDao templateDao;
+
+ private RegisterBuiltinQualityGate task;
+
+ @Before
+ public void setUp() {
+ task = new RegisterBuiltinQualityGate(qualityGates, templateDao);
+ }
+
+ @Test
+ public void should_register_builtin() {
+ String templateType = "QUALITY_GATE";
+ String templateName = "SonarQube way";
+ when(templateDao.countByTypeAndKey(templateType, templateName)).thenReturn(0);
+ when(qualityGates.create(templateName)).thenReturn(new QualityGateDto().setId(42L));
+
+ task.start();
+
+ verify(templateDao).countByTypeAndKey(templateType, templateName);
+ verify(qualityGates).create(templateName);
+ verify(qualityGates, times(8)).createCondition(anyLong(), anyString(), anyString(), anyString(), anyString(), anyInt());
+ ArgumentCaptor<LoadedTemplateDto> templateArg = ArgumentCaptor.forClass(LoadedTemplateDto.class);
+ verify(templateDao).insert(templateArg.capture());
+ LoadedTemplateDto template = templateArg.getValue();
+ assertThat(template.getType()).isEqualTo(templateType);
+ assertThat(template.getKey()).isEqualTo(templateName);
+ }
+
+ @Test
+ public void should_not_register_builtin() {
+ String templateType = "QUALITY_GATE";
+ String templateName = "SonarQube way";
+ when(templateDao.countByTypeAndKey(templateType, templateName)).thenReturn(1);
+
+ task.start();
+
+ verify(templateDao).countByTypeAndKey(templateType, templateName);
+ verifyZeroInteractions(qualityGates);
+ verifyNoMoreInteractions(templateDao);
+ }
+}
diff --git a/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java
index 40b55c17c79..dd5c8645817 100644
--- a/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QgateAppHandlerTest.java
@@ -35,15 +35,14 @@ import org.sonar.api.server.ws.WsTester;
import org.sonar.core.timemachine.Periods;
import org.sonar.server.qualitygate.QualityGates;
-import java.util.Collection;
-import java.util.Locale;
-import java.util.Map;
+import java.util.*;
import java.util.Map.Entry;
-import java.util.Set;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class QgateAppHandlerTest {
@@ -89,7 +88,7 @@ public class QgateAppHandlerTest {
Collection<Map> periods = (Collection<Map>) responseJson.get("periods");
assertThat(periods).hasSize(3);
Map messages = (Map) responseJson.get("messages");
- assertThat(messages).isNotNull().isNotEmpty().hasSize(47);
+ assertThat(messages).isNotNull().isNotEmpty().hasSize(50);
for (Entry message: (Set<Entry>) messages.entrySet()) {
assertThat(message.getKey()).isEqualTo(message.getValue());
}
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistrationTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistrationTest.java
index 40afa74f928..c0a4a97bdad 100644
--- a/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistrationTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistrationTest.java
@@ -50,7 +50,7 @@ public class RuleRegistrationTest extends AbstractDaoTestCase {
private static final String[] EXCLUDED_COLUMN_NAMES_INCLUDING_DEBT = {"created_at", "updated_at", "note_data", "note_user_login", "note_created_at", "note_updated_at",
"characteristic_id", "default_characteristic_id",
"remediation_function", "default_remediation_function", "remediation_factor", "default_remediation_factor", "remediation_offset", "default_remediation_offset",
- "effort_to_fix_l10n_key"};
+ "effort_to_fix_description"};
RuleRegistration task;
ProfilesManager profilesManager = mock(ProfilesManager.class);
@@ -287,7 +287,7 @@ public class RuleRegistrationTest extends AbstractDaoTestCase {
.setSeverity(Severity.BLOCKER)
.setDebtCharacteristic("MEMORY_EFFICIENCY")
.setDebtRemediationFunction(DebtRemediationFunction.createLinearWithOffset("5d", "10h"))
- .setEffortToFixL10nKey("squid.S115.effortToFix")
+ .setEffortToFixDescription("squid.S115.effortToFix")
.setInternalKey("config1")
.setTags("tag1", "tag3", "tag5");
rule1.createParam("param1").setDescription("parameter one").setDefaultValue("default value one");
diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RuleRepositoriesTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RuleRepositoriesTest.java
index 03d3d093c38..5ec62083e5c 100644
--- a/sonar-server/src/test/java/org/sonar/server/rule/RuleRepositoriesTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rule/RuleRepositoriesTest.java
@@ -25,6 +25,7 @@ import org.sonar.api.server.rule.RulesDefinition;
import static org.fest.assertions.Assertions.assertThat;
public class RuleRepositoriesTest {
+
@Test
public void should_register_repositories() {
RulesDefinition.Context context = new RulesDefinition.Context();
@@ -60,6 +61,30 @@ public class RuleRepositoriesTest {
assertThat(findbugs).isEqualTo(findbugs).isNotEqualTo(squid).isNotEqualTo("findbugs").isNotEqualTo(null);
}
+ @Test
+ public void register_repositories_having_same_name() {
+ RulesDefinition.Context context = new RulesDefinition.Context();
+ new RulesDefinition() {
+ @Override
+ public void define(Context context) {
+ context.createRepository("squid", "java").setName("SonarQube").done();
+ }
+ }.define(context);
+
+ // Repository with same name
+ new RulesDefinition() {
+ @Override
+ public void define(Context context) {
+ context.createRepository("javascript", "js").setName("SonarQube").done();
+ }
+ }.define(context);
+
+ RuleRepositories repositories = new RuleRepositories();
+ repositories.register(context);
+
+ assertThat(repositories.repositories()).hasSize(2);
+ }
+
static class FindbugsDefinitions implements RulesDefinition {
@Override
public void define(Context context) {
diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterDebtModelTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterDebtModelTest.java
index 5014226a950..b6d24cbcc94 100644
--- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterDebtModelTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterDebtModelTest.java
@@ -21,10 +21,8 @@
package org.sonar.server.startup;
import org.junit.Test;
-import org.sonar.api.utils.ValidationMessages;
import org.sonar.server.debt.DebtModelSynchronizer;
-import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
public class RegisterDebtModelTest {
@@ -36,6 +34,6 @@ public class RegisterDebtModelTest {
sqaleDefinition.start();
- verify(synchronizer, times(1)).synchronize(any(ValidationMessages.class));
+ verify(synchronizer, times(1)).synchronize();
}
}
diff --git a/sonar-server/src/test/java/org/sonar/server/user/DoPrivilegedTest.java b/sonar-server/src/test/java/org/sonar/server/user/DoPrivilegedTest.java
new file mode 100644
index 00000000000..410fcb612cb
--- /dev/null
+++ b/sonar-server/src/test/java/org/sonar/server/user/DoPrivilegedTest.java
@@ -0,0 +1,40 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.user;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DoPrivilegedTest {
+
+ @Test
+ public void should_allow_everything_in_privileged_mode_only() {
+ DoPrivileged.start();
+ UserSession userSession = UserSession.get();
+ assertThat(userSession.isLoggedIn()).isTrue();
+ assertThat(userSession.hasGlobalPermission("any permission")).isTrue();
+ assertThat(userSession.hasProjectPermission("any permission", "any project")).isTrue();
+
+ DoPrivileged.stop();
+ userSession = UserSession.get();
+ assertThat(userSession.isLoggedIn()).isFalse();
+ }
+}
diff --git a/sonar-server/src/test/resources/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest/fail_on_bad_xml.xml b/sonar-server/src/test/resources/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest/fail_on_bad_xml.xml
new file mode 100644
index 00000000000..3b15eae11d6
--- /dev/null
+++ b/sonar-server/src/test/resources/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest/fail_on_bad_xml.xml
@@ -0,0 +1 @@
+Not a valid xml
diff --git a/sonar-server/src/test/resources/org/sonar/server/debt/DebtRulesXMLImporterTest/fail_on_bad_xml.xml b/sonar-server/src/test/resources/org/sonar/server/debt/DebtRulesXMLImporterTest/fail_on_bad_xml.xml
new file mode 100644
index 00000000000..3b15eae11d6
--- /dev/null
+++ b/sonar-server/src/test/resources/org/sonar/server/debt/DebtRulesXMLImporterTest/fail_on_bad_xml.xml
@@ -0,0 +1 @@
+Not a valid xml
diff --git a/sonar-server/src/test/resources/org/sonar/server/plugins/ServerPluginJarsInstallerTest/should_fail_on_plugin_depending_on_more_recent_sonar/extensions/plugins/sonar-switch-off-violations-plugin-1.1.jar b/sonar-server/src/test/resources/org/sonar/server/plugins/ServerPluginJarsInstallerTest/fail_if_require_greater_SQ_version/extensions/plugins/sonar-switch-off-violations-plugin-1.1.jar
index 8044dff8988..8044dff8988 100644
--- a/sonar-server/src/test/resources/org/sonar/server/plugins/ServerPluginJarsInstallerTest/should_fail_on_plugin_depending_on_more_recent_sonar/extensions/plugins/sonar-switch-off-violations-plugin-1.1.jar
+++ b/sonar-server/src/test/resources/org/sonar/server/plugins/ServerPluginJarsInstallerTest/fail_if_require_greater_SQ_version/extensions/plugins/sonar-switch-off-violations-plugin-1.1.jar
Binary files differ
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/ignore_rule_debt_definitions_if_rule_is_linked_on_root_characteristic.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/ignore_rule_debt_definitions_if_rule_is_linked_on_root_characteristic.xml
index 3a010942f21..2c69463ae43 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/ignore_rule_debt_definitions_if_rule_is_linked_on_root_characteristic.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/ignore_rule_debt_definitions_if_rule_is_linked_on_root_characteristic.xml
@@ -8,7 +8,7 @@
remediation_function="[null]" default_remediation_function="LINEAR"
remediation_factor="[null]" default_remediation_factor="14min"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="squid.S1115.effortTotFix"/>
+ effort_to_fix_description="squid.S1115.effortTotFix"/>
<rules id="2" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="old_config_key2" name="old name2" description="old description2"
status="READY" priority="1" cardinality="SINGLE" parent_id="[null]"/>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/insert_new_rules-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/insert_new_rules-result.xml
index 489e2108e85..21cc3f9dab4 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/insert_new_rules-result.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/insert_new_rules-result.xml
@@ -6,7 +6,7 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
<rules id="2" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="config1" name="One" description="Description of One"
status="READY" priority="4" cardinality="SINGLE" parent_id="[null]" language="java"
@@ -14,7 +14,7 @@
remediation_function="[null]" default_remediation_function="LINEAR_OFFSET"
remediation_factor="[null]" default_remediation_factor="5d"
remediation_offset="[null]" default_remediation_offset="10h"
- effort_to_fix_l10n_key="squid.S115.effortToFix"/>
+ effort_to_fix_description="squid.S115.effortToFix"/>
<rules_parameters id="1" rule_id="2" default_value="default value one" description="parameter one" name="param1" param_type="STRING"/>
<rules_parameters id="2" rule_id="2" default_value="default value two" description="parameter two" name="param2" param_type="STRING"/>
@@ -33,6 +33,6 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/not_disable_already_disabled_rules-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/not_disable_already_disabled_rules-result.xml
index a5faaa73c51..c4b64d12430 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/not_disable_already_disabled_rules-result.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/not_disable_already_disabled_rules-result.xml
@@ -6,7 +6,7 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"
+ effort_to_fix_description="[null]"
updated_at="2014-03-16"/>
<rules id="2" plugin_rule_key="deprecated" plugin_name="fake" plugin_config_key="[null]" name="Deprecated fake" description="[null]"
@@ -15,7 +15,7 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"
+ effort_to_fix_description="[null]"
updated_at="2014-03-16"/>
<!-- New rules -->
@@ -25,7 +25,7 @@
remediation_function="[null]" default_remediation_function="LINEAR_OFFSET"
remediation_factor="[null]" default_remediation_factor="5d"
remediation_offset="[null]" default_remediation_offset="10h"
- effort_to_fix_l10n_key="squid.S115.effortToFix"
+ effort_to_fix_description="squid.S115.effortToFix"
updated_at="2014-03-17 19:10:03.0"/>
<rules id="4" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="[null]" name="Two" description="Description of Two"
@@ -34,7 +34,7 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"
+ effort_to_fix_description="[null]"
updated_at="2014-03-17 19:10:03.0"/>
</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/not_disable_already_disabled_rules.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/not_disable_already_disabled_rules.xml
index 8b0604e2036..27a03f91411 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/not_disable_already_disabled_rules.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/not_disable_already_disabled_rules.xml
@@ -8,7 +8,7 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"
+ effort_to_fix_description="[null]"
updated_at="2014-03-16"/>
<rules id="2" plugin_rule_key="deprecated" plugin_name="fake" plugin_config_key="[null]" name="Deprecated fake" description="[null]"
@@ -17,7 +17,7 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"
+ effort_to_fix_description="[null]"
updated_at="2014-03-16"/>
</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_characteristic_not_found-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_characteristic_not_found-result.xml
index a773983725f..89e5191d7fd 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_characteristic_not_found-result.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_characteristic_not_found-result.xml
@@ -6,7 +6,7 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
<rules id="2" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="[null]" name="Two" description="Description of Two"
status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"
@@ -14,6 +14,6 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_characteristic_not_found.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_characteristic_not_found.xml
index 6de51e77092..14495983726 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_characteristic_not_found.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_characteristic_not_found.xml
@@ -8,7 +8,7 @@
remediation_function="[null]" default_remediation_function="LINEAR"
remediation_factor="[null]" default_remediation_factor="14min"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
<rules id="2" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="old_config_key2" name="old name2" description="old description2"
status="READY" priority="1" cardinality="SINGLE" parent_id="[null]"/>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_default_characteristic_not_found_and_overriding_characteristic_disabled-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_default_characteristic_not_found_and_overriding_characteristic_disabled-result.xml
index df6e0278b99..fcb2b867045 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_default_characteristic_not_found_and_overriding_characteristic_disabled-result.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_default_characteristic_not_found_and_overriding_characteristic_disabled-result.xml
@@ -6,7 +6,7 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
<rules id="2" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="[null]" name="Two" description="Description of Two"
status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"
@@ -14,6 +14,6 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_default_characteristic_not_found_and_overriding_characteristic_disabled.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_default_characteristic_not_found_and_overriding_characteristic_disabled.xml
index 69426df342f..fd2c3d8e489 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_default_characteristic_not_found_and_overriding_characteristic_disabled.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_characteristic_when_default_characteristic_not_found_and_overriding_characteristic_disabled.xml
@@ -8,7 +8,7 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
<rules id="2" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="old_config_key2" name="old name2" description="old description2"
status="READY" priority="1" cardinality="SINGLE" parent_id="[null]"
@@ -16,6 +16,6 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_default_characteristic_when_default_characteristic_not_found_but_characteristic_has_been_overridden-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_default_characteristic_when_default_characteristic_not_found_but_characteristic_has_been_overridden-result.xml
index aa889da419b..9fcf2872bb9 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_default_characteristic_when_default_characteristic_not_found_but_characteristic_has_been_overridden-result.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_default_characteristic_when_default_characteristic_not_found_but_characteristic_has_been_overridden-result.xml
@@ -6,7 +6,7 @@
remediation_function="LINEAR_OFFSET" default_remediation_function="[null]"
remediation_factor="5d" default_remediation_factor="[null]"
remediation_offset="10h" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
<rules id="2" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="[null]" name="Two" description="Description of Two"
status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"
@@ -14,6 +14,6 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_default_characteristic_when_default_characteristic_not_found_but_characteristic_has_been_overridden.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_default_characteristic_when_default_characteristic_not_found_but_characteristic_has_been_overridden.xml
index cac7ab78521..66458e67ee3 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_default_characteristic_when_default_characteristic_not_found_but_characteristic_has_been_overridden.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/set_no_default_characteristic_when_default_characteristic_not_found_but_characteristic_has_been_overridden.xml
@@ -10,7 +10,7 @@
remediation_function="LINEAR_OFFSET" default_remediation_function="[null]"
remediation_factor="5d" default_remediation_factor="[null]"
remediation_offset="10h" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
<rules id="2" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="old_config_key2" name="old name2" description="old description2"
status="READY" priority="1" cardinality="SINGLE" parent_id="[null]"
@@ -18,6 +18,6 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_rule_fields-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_rule_fields-result.xml
index f630e3adbd9..4c832441dd4 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_rule_fields-result.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_rule_fields-result.xml
@@ -6,7 +6,7 @@
remediation_function="[null]" default_remediation_function="LINEAR_OFFSET"
remediation_factor="[null]" default_remediation_factor="5d"
remediation_offset="[null]" default_remediation_offset="10h"
- effort_to_fix_l10n_key="squid.S115.effortToFix"/>
+ effort_to_fix_description="squid.S115.effortToFix"/>
<rules_parameters id="1" rule_id="1" default_value="default value one" description="parameter one" name="param1" param_type="STRING"/>
<rules_parameters id="2" rule_id="1" default_value="default value two" description="parameter two" name="param2" param_type="STRING"/>
@@ -27,6 +27,6 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_rule_fields.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_rule_fields.xml
index 6ab04c32b61..5a04a1672f5 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_rule_fields.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_rule_fields.xml
@@ -8,7 +8,7 @@
remediation_function="[null]" default_remediation_function="LINEAR"
remediation_factor="[null]" default_remediation_factor="14min"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]"/>
+ effort_to_fix_description="[null]"/>
<rules_parameters id="1" rule_id="1" name="param1" description="[null]" param_type="STRING"/>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language-result.xml
index 7821240a5c7..0fc47887777 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language-result.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language-result.xml
@@ -6,7 +6,7 @@
remediation_function="[null]" default_remediation_function="LINEAR_OFFSET"
remediation_factor="[null]" default_remediation_factor="5d"
remediation_offset="[null]" default_remediation_offset="10h"
- effort_to_fix_l10n_key="squid.S115.effortToFix" />
+ effort_to_fix_description="squid.S115.effortToFix" />
<!-- Instance of old rule 1 :/ -->
<rules id="2" plugin_rule_key="template_rule1" plugin_name="fake" plugin_config_key="[null]" name="User rule" description="[null]"
@@ -15,7 +15,7 @@
remediation_function="[null]" default_remediation_function="LINEAR_OFFSET"
remediation_factor="[null]" default_remediation_factor="5d"
remediation_offset="[null]" default_remediation_offset="10h"
- effort_to_fix_l10n_key="squid.S115.effortToFix" />
+ effort_to_fix_description="squid.S115.effortToFix" />
<rules id="3" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="[null]" name="Two" description="Description of Two"
status="DEPRECATED" priority="0" cardinality="SINGLE" parent_id="[null]" language="java"
@@ -23,7 +23,7 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]" />
+ effort_to_fix_description="[null]" />
<!-- Template of old rule 3 :/ -->
<rules id="4" plugin_rule_key="template_rule2" plugin_name="fake" plugin_config_key="[null]" name="User rule" description="[null]"
@@ -32,6 +32,6 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]" />
+ effort_to_fix_description="[null]" />
</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language.xml
index 51e70c311d4..2813575401e 100644
--- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language.xml
@@ -8,7 +8,7 @@
remediation_function="[null]" default_remediation_function="LINEAR_OFFSET"
remediation_factor="[null]" default_remediation_factor="5d"
remediation_offset="[null]" default_remediation_offset="10h"
- effort_to_fix_l10n_key="squid.S115.effortToFix" />
+ effort_to_fix_description="squid.S115.effortToFix" />
<!-- Instance of rule 1 -->
<rules id="2" plugin_rule_key="template_rule1" plugin_name="fake" plugin_config_key="[null]" name="User rule" description="[null]"
@@ -17,7 +17,7 @@
remediation_function="[null]" default_remediation_function="LINEAR"
remediation_factor="[null]" default_remediation_factor="1h"
remediation_offset="[null]" default_remediation_offset="15min"
- effort_to_fix_l10n_key="squid.S115.effortToFix2" />
+ effort_to_fix_description="squid.S115.effortToFix2" />
<rules id="3" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="old_config_key2" name="old name2" description="old description2"
status="DEPRECATED" priority="1" cardinality="MULTIPLE" parent_id="[null]"
@@ -25,7 +25,7 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]" />
+ effort_to_fix_description="[null]" />
<!-- Instance of rule 3 -->
<rules id="4" plugin_rule_key="template_rule2" plugin_name="fake" plugin_config_key="[null]" name="User rule" description="[null]"
@@ -34,6 +34,6 @@
remediation_function="[null]" default_remediation_function="[null]"
remediation_factor="[null]" default_remediation_factor="[null]"
remediation_offset="[null]" default_remediation_offset="[null]"
- effort_to_fix_l10n_key="[null]" />
+ effort_to_fix_description="[null]" />
</dataset>