Exemplo n.º 1
0
  public void renameProfile(int profileId, String newName, UserSession userSession) {
    checkPermission(userSession);
    DbSession session = myBatis.openSession(false);
    try {
      QualityProfileDto profileDto = findNotNull(profileId, session);
      String oldName = profileDto.getName();

      QProfile profile = QProfile.from(profileDto);
      if (!oldName.equals(newName)) {
        checkNotAlreadyExists(newName, profile.language(), session);
      }
      profileDto.setName(newName);
      dao.update(session, profileDto);

      List<QProfile> children = profileLookup.children(profile, session);
      for (QProfile child : children) {
        dao.update(session, child.setParent(newName).toDto());
      }
      propertiesDao.updateProperties(
          PROFILE_PROPERTY_PREFIX + profile.language(), oldName, newName, session);

      session.commit();
    } finally {
      MyBatis.closeQuietly(session);
    }
  }
 public QProfile get(String language, String name) {
   QualityProfileDto dto = qualityProfileDao.getByNameAndLanguage(name, language);
   if (dto == null) {
     return null;
   }
   return new org.sonar.batch.protocol.input.QProfile(
       dto.getKey(),
       dto.getName(),
       dto.getLanguage(),
       UtcDateUtils.parseDateTime(dto.getRulesUpdatedAt()));
 }
Exemplo n.º 3
0
 public QProfile newProfile(
     String name,
     String language,
     @Nullable String parent,
     boolean failIfAlreadyExists,
     UserSession userSession,
     DbSession session) {
   checkPermission(userSession);
   if (failIfAlreadyExists) {
     checkNotAlreadyExists(name, language, session);
   }
   QualityProfileDto dto =
       new QualityProfileDto()
           .setName(name)
           .setLanguage(language)
           .setParent(parent)
           .setVersion(1)
           .setUsed(false);
   dao.insert(session, dto);
   return QProfile.from(dto);
 }
Exemplo n.º 4
0
  public void analyse(Project project, SensorContext context) {
    List<QProfileWithId> profiles = Lists.newArrayList();
    for (String language : fs.languages()) {
      QProfileWithId qProfile = (QProfileWithId) moduleQProfiles.findByLanguage(language);
      if (qProfile != null) {
        dao.updateUsedColumn(qProfile.id(), true);
        profiles.add(qProfile);
      }
    }
    UsedQProfiles used = UsedQProfiles.fromProfiles(profiles);
    Measure detailsMeasure = new Measure(CoreMetrics.QUALITY_PROFILES, used.toJSON());
    context.saveMeasure(detailsMeasure);

    // For backward compatibility
    if (profiles.size() == 1) {
      QProfileWithId qProfile = profiles.get(0);
      Measure measure =
          new Measure(CoreMetrics.PROFILE, qProfile.name()).setValue((double) qProfile.id());
      Measure measureVersion =
          new Measure(CoreMetrics.PROFILE_VERSION, qProfile.version().doubleValue());
      context.saveMeasure(measure);
      context.saveMeasure(measureVersion);
    }
  }
Exemplo n.º 5
0
 private void checkNotAlreadyExists(String name, String language, DbSession session) {
   if (dao.selectByNameAndLanguage(name, language, session) != null) {
     throw new BadRequestException("quality_profiles.profile_x_already_exists", name);
   }
 }
Exemplo n.º 6
0
 private QualityProfileDto findNotNull(int profileId, DbSession session) {
   QualityProfileDto profile = dao.selectById(profileId, session);
   QProfileValidations.checkProfileIsNotNull(profile);
   return profile;
 }