Пример #1
0
 private void validateRule(DefaultIssue issue, Rule rule) {
   RuleKey ruleKey = issue.ruleKey();
   if (rule == null) {
     throw MessageException.of(String.format("The rule '%s' does not exist.", ruleKey));
   }
   if (Strings.isNullOrEmpty(rule.name()) && Strings.isNullOrEmpty(issue.message())) {
     throw MessageException.of(
         String.format(
             "The rule '%s' has no name and the related issue has no message.", ruleKey));
   }
 }
Пример #2
0
 @Override
 protected void doOnGetProperties(String key) {
   if (mode.isPreview() && key.endsWith(".secured") && !key.contains(".license")) {
     throw MessageException.of(
         "Access to the secured property '"
             + key
             + "' is not possible in preview mode. The SonarQube plugin which requires this property must be deactivated in preview mode.");
   }
 }
  private void checkUtf8(Connection connection) throws SQLException {
    // Character set is defined globally and can be overridden on each column.
    // This request returns all VARCHAR columns. Collation may be empty.
    // Examples:
    // issues | key | ''
    // projects | name | utf8
    List<String[]> rows =
        select(
            connection,
            "select table_name, column_name, collation_name "
                + "from information_schema.columns "
                + "where table_schema='public' "
                + "and udt_name='varchar' "
                + "order by table_name, column_name",
            new SqlExecutor.StringsConverter(3 /* columns returned by SELECT */));
    boolean mustCheckGlobalCollation = false;
    Set<String> errors = new LinkedHashSet<>();
    for (String[] row : rows) {
      if (StringUtils.isBlank(row[2])) {
        mustCheckGlobalCollation = true;
      } else if (!containsIgnoreCase(row[2], UTF8)) {
        errors.add(format("%s.%s", row[0], row[1]));
      }
    }

    if (mustCheckGlobalCollation) {
      String charset =
          selectSingleString(
              connection,
              "SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = current_database()");
      if (!containsIgnoreCase(charset, UTF8)) {
        throw MessageException.of(
            format("Database collation is %s. It must support UTF8.", charset));
      }
    }
    if (!errors.isEmpty()) {
      throw MessageException.of(
          format(
              "Database columns [%s] must support UTF8 collation.", Joiner.on(", ").join(errors)));
    }
  }
 @CheckForNull
 private QProfile loadQProfile(Settings settings, String language) {
   String profileName = settings.getString("sonar.profile." + language);
   if (profileName != null) {
     QProfile dto = get(language, profileName);
     if (dto == null) {
       throw MessageException.of(
           String.format(
               "Quality profile not found : '%s' on language '%s'", profileName, language));
     }
     return dto;
   }
   return null;
 }
Пример #5
0
  @Override
  public void doAfterStart() {
    // default value is declared in CorePlugin
    String taskKey =
        StringUtils.defaultIfEmpty(
            taskProperties.get(CoreProperties.TASK), CoreProperties.SCAN_TASK);

    TaskDefinition def = getComponentByType(Tasks.class).definition(taskKey);
    if (def == null) {
      throw MessageException.of("Task " + taskKey + " does not exist");
    }
    Task task = getComponentByType(def.taskClass());
    if (task != null) {
      task.execute();
    } else {
      throw new IllegalStateException("Task " + taskKey + " is badly defined");
    }
  }
 /**
  * Report file, null if the property is not set.
  *
  * @throws org.sonar.api.utils.MessageException if the property relates to a directory or a
  *     non-existing file.
  */
 @CheckForNull
 private File getReportFromProperty() {
   String path = this.configuration.getReportPath();
   if (StringUtils.isNotBlank(path)) {
     File report = new File(path);
     if (!report.isAbsolute()) {
       report = new File(this.fileSystem.baseDir(), path);
     }
     if (report.exists() && report.isFile()) {
       return report;
     }
     throw MessageException.of(
         "Fortify report does not exist. Please check property "
             + FortifyConstants.REPORT_PATH_PROPERTY
             + ": "
             + path);
   }
   return null;
 }
Пример #7
0
 /** @param optionalSeverity if null, then the default rule severity is used */
 public ActiveRule activateRule(final Rule rule, @Nullable RulePriority optionalSeverity) {
   if (Iterables.any(
       activeRules,
       new Predicate<ActiveRule>() {
         @Override
         public boolean apply(ActiveRule input) {
           return input.getRule().equals(rule);
         }
       })) {
     throw MessageException.of(
         String.format(
             "The definition of the profile '%s' (language '%s') contains multiple occurrences of the '%s:%s' rule. The plugin which declares this profile should fix this.",
             getName(), getLanguage(), rule.getRepositoryKey(), rule.getKey()));
   }
   ActiveRule activeRule = new ActiveRule();
   activeRule.setRule(rule);
   activeRule.setRulesProfile(this);
   activeRule.setSeverity(optionalSeverity == null ? rule.getSeverity() : optionalSeverity);
   activeRules.add(activeRule);
   return activeRule;
 }
Пример #8
0
 private static MessageException processError(Exception e) {
   String message = String.format("Fail to migrate data, error is : %s", e.getMessage());
   LOGGER.error(message, e);
   throw MessageException.of(message);
 }