Search in sources :

Example 1 with ExportRuleParamDto

use of org.sonar.db.qualityprofile.ExportRuleParamDto in project sonarqube by SonarSource.

the class QProfileBackuperImpl method toImportedQProfile.

private static ImportedQProfile toImportedQProfile(List<ExportRuleDto> exportRules, String profileName, String profileLang) {
    List<ImportedRule> importedRules = new ArrayList<>(exportRules.size());
    for (ExportRuleDto exportRuleDto : exportRules) {
        ImportedRule importedRule = new ImportedRule();
        importedRule.setName(exportRuleDto.getName());
        importedRule.setDescription(exportRuleDto.getDescription());
        importedRule.setRuleKey(exportRuleDto.getRuleKey());
        importedRule.setSeverity(exportRuleDto.getSeverityString());
        if (importedRule.isCustomRule()) {
            importedRule.setTemplateKey(exportRuleDto.getTemplateRuleKey());
        }
        importedRule.setType(exportRuleDto.getRuleType().name());
        importedRule.setParameters(exportRuleDto.getParams().stream().collect(Collectors.toMap(ExportRuleParamDto::getKey, ExportRuleParamDto::getValue)));
        importedRules.add(importedRule);
    }
    return new ImportedQProfile(profileName, profileLang, importedRules);
}
Also used : ArrayList(java.util.ArrayList) ExportRuleDto(org.sonar.db.qualityprofile.ExportRuleDto) ExportRuleParamDto(org.sonar.db.qualityprofile.ExportRuleParamDto)

Example 2 with ExportRuleParamDto

use of org.sonar.db.qualityprofile.ExportRuleParamDto in project sonarqube by SonarSource.

the class QProfileParser method writeXml.

public void writeXml(Writer writer, QProfileDto profile, Iterator<ExportRuleDto> rulesToExport) {
    XmlWriter xml = XmlWriter.of(writer).declaration();
    xml.begin(ATTRIBUTE_PROFILE);
    xml.prop(ATTRIBUTE_NAME, profile.getName());
    xml.prop(ATTRIBUTE_LANGUAGE, profile.getLanguage());
    xml.begin(ATTRIBUTE_RULES);
    while (rulesToExport.hasNext()) {
        ExportRuleDto ruleToExport = rulesToExport.next();
        xml.begin(ATTRIBUTE_RULE);
        xml.prop(ATTRIBUTE_REPOSITORY_KEY, ruleToExport.getRuleKey().repository());
        xml.prop(ATTRIBUTE_KEY, ruleToExport.getRuleKey().rule());
        xml.prop(ATTRIBUTE_TYPE, ruleToExport.getRuleType().name());
        xml.prop(ATTRIBUTE_PRIORITY, ruleToExport.getSeverityString());
        if (ruleToExport.isCustomRule()) {
            xml.prop(ATTRIBUTE_NAME, ruleToExport.getName());
            xml.prop(ATTRIBUTE_TEMPLATE_KEY, ruleToExport.getTemplateRuleKey().rule());
            xml.prop(ATTRIBUTE_DESCRIPTION, ruleToExport.getDescription());
        }
        xml.begin(ATTRIBUTE_PARAMETERS);
        for (ExportRuleParamDto param : ruleToExport.getParams()) {
            xml.begin(ATTRIBUTE_PARAMETER).prop(ATTRIBUTE_PARAMETER_KEY, param.getKey()).prop(ATTRIBUTE_PARAMETER_VALUE, param.getValue()).end();
        }
        xml.end(ATTRIBUTE_PARAMETERS);
        xml.end(ATTRIBUTE_RULE);
    }
    xml.end(ATTRIBUTE_RULES).end(ATTRIBUTE_PROFILE).close();
}
Also used : ExportRuleDto(org.sonar.db.qualityprofile.ExportRuleDto) XmlWriter(org.sonar.api.utils.text.XmlWriter) ExportRuleParamDto(org.sonar.db.qualityprofile.ExportRuleParamDto)

Aggregations

ExportRuleDto (org.sonar.db.qualityprofile.ExportRuleDto)2 ExportRuleParamDto (org.sonar.db.qualityprofile.ExportRuleParamDto)2 ArrayList (java.util.ArrayList)1 XmlWriter (org.sonar.api.utils.text.XmlWriter)1