Package org.sonar.api.utils

Examples of org.sonar.api.utils.SonarException


  @Override
  public DecoratorContext saveMeasure(Measure measure) {
    checkReadOnly(SAVE_MEASURE_METHOD);
    Metric metric = metricFinder.findByKey(measure.getMetricKey());
    if (metric == null) {
      throw new SonarException("Unknown metric: " + measure.getMetricKey());
    }
    measure.setMetric(metric);
    if (measurementFilters.accept(resource, measure)) {
      List<Measure> metricMeasures = measuresByMetric.get(measure.getMetricKey());

      boolean add = true;
      if (metricMeasures != null) {
        int index = metricMeasures.indexOf(measure);
        if (index > -1) {
          if (metricMeasures.get(index) == measure) {
            add = false;
          } else {
            throw new SonarException("Can not add twice the same measure on " + resource + ": " + measure);
          }
        }
      }
      if (add) {
        measuresByMetric.put(measure.getMetricKey(), measure);
View Full Code Here


  @Override
  public String getLanguage() {
    if (singleLanguageProfile == null) {
      // Multi-languages module
      // This is a hack for CommonChecksDecorator that call this method in its constructor
      LOG.debug(DEPRECATED_USAGE_MESSAGE, new SonarException(DEPRECATED_USAGE_MESSAGE));
      return "";
    }
    return singleLanguageProfile.getLanguage();
  }
View Full Code Here

  private void initDeprecatedLanguage(Project project) {
    String languageKey = settings.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY);
    if (languageKey != null) {
      Language language = languages.get(languageKey);
      if (language == null) {
        throw new SonarException("Language with key '" + languageKey + "' not found");
      }
      project.setLanguage(language);
    } else {
      project.setLanguage(Project.NONE_LANGUAGE);
    }
View Full Code Here

      TimeProfiler profiler = new TimeProfiler().start("Execute " + goal);
      ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
      try {
        concreteExecute(project.getPom(), goal);
      } catch (Exception e) {
        throw new SonarException("Unable to execute maven plugin", e);
      } finally {
        // Reset original ClassLoader that may have been changed during Maven Execution (see SONAR-1800)
        Thread.currentThread().setContextClassLoader(currentClassLoader);
        profiler.stop();
      }
View Full Code Here

        executeMethod = m;
        break;
      }
    }
    if (executeMethod == null) {
      throw new SonarException("Unable to find execute method on Maven LifecycleExecutor. Please check your Maven version.");
    }
    if (executeMethod.getParameterTypes().length == 1) {
      concreteExecuteMaven3(pom, goal);
    } else if (executeMethod.getParameterTypes().length == 3) {
      concreteExecuteMaven2(executeMethod, pom, goal);
    } else {
      throw new SonarException("Unexpected parameter count on Maven LifecycleExecutor#execute method. Please check your Maven version.");
    }
  }
View Full Code Here

    projectSession.getRequest().setPom(pom.getFile());
    projectSession.getRequest().setGoals(Arrays.asList(goal));
    projectSession.getRequest().setInteractiveMode(false);
    lifecycleExecutor.execute(projectSession);
    if (projectSession.getResult().hasExceptions()) {
      throw new SonarException("Exception during execution of " + goal);
    }
  }
View Full Code Here

        mavenSession.getExecutionRootDirectory(),
        mavenSession.getExecutionProperties(),
        mavenSession.getStartTime());
      executeMethod.invoke(lifecycleExecutor, clonedSession, reactor, clonedSession.getEventDispatcher());
    } catch (Exception e) {
      throw new SonarException("Unable to execute Maven 2 plugin", e);
    }
  }
View Full Code Here

    ResourceModel model;
    try {
      model = session.getSingleResult(ResourceModel.class, "key", resource.getEffectiveKey());
      if (model == null) {
        if (StringUtils.isBlank(resource.getEffectiveKey())) {
          throw new SonarException("Unable to persist resource " + resource.toString() + ". Resource effective key is blank. This may be caused by an outdated plugin.");
        }
        model = createModel(resource, parentResource);

      } else {
        mergeModel(model, resource);
      }
      updateUuids(resource, parentResource, model);
      return model;

    } catch (NonUniqueResultException e) {
      throw new SonarException("The resource '" + resource.getEffectiveKey() + "' is duplicated in database.", e);
    }
  }
View Full Code Here

  public Tasks(TaskDefinition[] definitions) {
    SortedMap<String, TaskDefinition> map = Maps.newTreeMap();
    for (TaskDefinition definition : definitions) {
      if (map.containsKey(definition.key())) {
        throw new SonarException("Task '" + definition.key() + "' is declared twice");
      }
      map.put(definition.key(), definition);
    }
    this.byKey = ImmutableSortedMap.copyOf(map);
  }
View Full Code Here

    for (TaskDefinition def : definitions()) {
      TaskDefinition other = byClass.get(def.taskClass());
      if (other == null) {
        byClass.put(def.taskClass(), def);
      } else {
        throw new SonarException("Task '" + def.taskClass().getName() + "' is defined twice: first by '" + other.key() + "' and then by '" + def.key() + "'");
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.sonar.api.utils.SonarException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.