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();
}
}
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);
}
}
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));
}
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;
}
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);
}
Aggregations