ActiveRule activeRule = new ActiveRule(null, new Rule(valuesRule.get("plugin"), valuesRule.get("key")), RulePriority
.valueOf(valuesRule.get("level")));
activeRule.setActiveRuleParams(params);
- activeRule.setInheritanceStatus(ActiveRuleInheritanceStatus.valueOf(valuesRule.get("inherited")));
+ if (valuesRule.containsKey("inherited")) {
+ activeRule.setInheritanceStatus(ActiveRuleInheritanceStatus.valueOf(valuesRule.get("inherited")));
+ }
return activeRule;
}
*/
package org.sonar.server.configuration;
-import org.sonar.api.rules.ActiveRuleInheritanceStatus;
-
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
assertThat(param.getDefaultValue(), is("test param value"));
}
+ @Test
+ public void shouldImportXmlWithoutInheritanceInformation() {
+ Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null),
+ new RulesBackup((DatabaseSession) null), new ProfilesBackup((DatabaseSession) null)));
+
+ String xml = getFileFromClasspath("backup-restore-without-inheritance.xml");
+ SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml);
+
+ Collection<RulesProfile> profiles = sonarConfig.getProfiles();
+ assertThat(profiles.size(), is(1));
+ RulesProfile testProfile = profiles.iterator().next();
+ assertThat(testProfile.getActiveRules().size(), is(1));
+ ActiveRule activeRule = testProfile.getActiveRules().get(0);
+ assertThat(activeRule.getInheritanceStatus(), is(ActiveRuleInheritanceStatus.NO));
+ }
+
@Test
public void shouldImportXmlWithXmlIlliciteCharacters() {
Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null)));
--- /dev/null
+<sonar-config>
+ <version><![CDATA[54]]></version>
+ <date><![CDATA[2008-11-18]]></date>
+ <profiles>
+ <profile>
+ <name><![CDATA[test name]]></name>
+ <default-profile><![CDATA[true]]></default-profile>
+ <provided><![CDATA[true]]></provided>
+ <language><![CDATA[test language]]></language>
+ <active-rules>
+ <active-rule>
+ <key><![CDATA[test key]]></key>
+ <plugin><![CDATA[test plugin]]></plugin>
+ <level><![CDATA[ERROR]]></level>
+ <params>
+ <param>
+ <key><![CDATA[test param key]]></key>
+ <value><![CDATA[test value]]></value>
+ </param>
+ </params>
+ </active-rule>
+ </active-rules>
+ </profile>
+ </profiles>
+</sonar-config>