Search in sources :

Example 71 with QualityProfileDto

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

the class QProfileCopier method prepareTarget.

private QualityProfileDto prepareTarget(String fromProfileKey, String toName) {
    DbSession dbSession = db.openSession(false);
    try {
        QualityProfileDto fromProfile = db.qualityProfileDao().selectOrFailByKey(dbSession, fromProfileKey);
        QProfileName toProfileName = new QProfileName(fromProfile.getLanguage(), toName);
        verify(fromProfile, toProfileName);
        QualityProfileDto toProfile = db.qualityProfileDao().selectByNameAndLanguage(toProfileName.getName(), toProfileName.getLanguage(), dbSession);
        if (toProfile == null) {
            // Do not delegate creation to QProfileBackuper because we need to keep
            // the parent-child association, if exists.
            toProfile = factory.create(dbSession, toProfileName);
            toProfile.setParentKee(fromProfile.getParentKee());
            db.qualityProfileDao().update(dbSession, toProfile);
            dbSession.commit();
        }
        return toProfile;
    } finally {
        dbSession.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 72 with QualityProfileDto

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

the class QProfileCopier method copyToName.

public QualityProfileDto copyToName(String fromProfileKey, String toName) {
    QualityProfileDto to = prepareTarget(fromProfileKey, toName);
    File backupFile = temp.newFile();
    try {
        backup(fromProfileKey, backupFile);
        restore(backupFile, QProfileName.createFor(to.getLanguage(), to.getName()));
        return to;
    } finally {
        org.sonar.core.util.FileUtils.deleteQuietly(backupFile);
    }
}
Also used : File(java.io.File) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 73 with QualityProfileDto

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

the class QProfileFactory method setDefault.

private void setDefault(DbSession session, QualityProfileDto profile) {
    QualityProfileDto previousDefault = db.qualityProfileDao().selectDefaultProfile(session, profile.getLanguage());
    if (previousDefault != null) {
        db.qualityProfileDao().update(session, previousDefault.setDefault(false));
    }
    db.qualityProfileDao().update(session, profile.setDefault(true));
}
Also used : QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 74 with QualityProfileDto

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

the class QProfileFactory method delete.

// ------------- DELETION
/**
   * Session is NOT committed. Profiles marked as "default" for a language can't be deleted,
   * except if the parameter <code>force</code> is true.
   */
public List<ActiveRuleChange> delete(DbSession session, String key, boolean force) {
    QualityProfileDto profile = db.qualityProfileDao().selectOrFailByKey(session, key);
    List<QualityProfileDto> descendants = db.qualityProfileDao().selectDescendants(session, key);
    if (!force) {
        checkNotDefault(profile);
        for (QualityProfileDto descendant : descendants) {
            checkNotDefault(descendant);
        }
    }
    // delete bottom-up
    List<ActiveRuleChange> changes = new ArrayList<>();
    for (QualityProfileDto descendant : Lists.reverse(descendants)) {
        changes.addAll(doDelete(session, descendant));
    }
    changes.addAll(doDelete(session, profile));
    return changes;
}
Also used : ArrayList(java.util.ArrayList) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 75 with QualityProfileDto

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

the class QProfileFactory method findByName.

private QualityProfileDto findByName(DbSession dbSession, String language, String profileName) {
    QualityProfileDto profile;
    profile = db.qualityProfileDao().selectByNameAndLanguage(profileName, language, dbSession);
    return checkFound(profile, "Unable to find a profile for language '%s' with name '%s'", language, profileName);
}
Also used : QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Aggregations

QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)126 Test (org.junit.Test)76 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)37 RuleDto (org.sonar.db.rule.RuleDto)29 WsTester (org.sonar.server.ws.WsTester)21 RuleQuery (org.sonar.server.rule.index.RuleQuery)14 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)13 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)12 DbSession (org.sonar.db.DbSession)11 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)9 SearchOptions (org.sonar.server.es.SearchOptions)9 ComponentDto (org.sonar.db.component.ComponentDto)8 OrganizationDto (org.sonar.db.organization.OrganizationDto)7 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)6 Date (java.util.Date)5 QualityProfileTesting.newQualityProfileDto (org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto)5 RuleParamDto (org.sonar.db.rule.RuleParamDto)5 RulesProfile (org.sonar.api.profiles.RulesProfile)4 Language (org.sonar.api.resources.Language)4 RuleKey (org.sonar.api.rule.RuleKey)4