コード例 #1
0
ファイル: DefaultIndexTest.java プロジェクト: vpiyanov/sonar
  @Before
  public void createIndex() {
    lock = new DefaultResourceCreationLock(new Settings());
    MetricFinder metricFinder = mock(MetricFinder.class);
    when(metricFinder.findByKey("ncloc")).thenReturn(CoreMetrics.NCLOC);
    ruleFinder = mock(RuleFinder.class);

    index =
        new DefaultIndex(
            mock(PersistenceManager.class),
            lock,
            mock(ProjectTree.class),
            metricFinder,
            ruleFinder,
            mock(ScanGraph.class));
    Project project = new Project("project");

    ResourceFilter filter =
        new ResourceFilter() {

          public boolean isIgnored(Resource resource) {
            return StringUtils.containsIgnoreCase(resource.getKey(), "excluded");
          }
        };
    RulesProfile rulesProfile = RulesProfile.create();
    rule = Rule.create("repoKey", "ruleKey", "Rule");
    rule.setId(1);
    rulesProfile.activateRule(rule, null);
    index.setCurrentProject(
        project,
        new ResourceFilters(new ResourceFilter[] {filter}),
        new ViolationFilters(),
        rulesProfile);
    index.doStart(project);
  }
コード例 #2
0
ファイル: VariationDecorator.java プロジェクト: fuxji/sonar
  void compareWithPastMeasures(DecoratorContext context, int index, List<Object[]> pastMeasures) {
    Map<MeasureKey, Object[]> pastMeasuresByKey = Maps.newHashMap();
    for (Object[] pastMeasure : pastMeasures) {
      pastMeasuresByKey.put(new MeasureKey(pastMeasure), pastMeasure);
    }

    // for each measure, search equivalent past measure
    for (Measure measure : context.getMeasures(MeasuresFilters.all())) {
      // compare with past measure
      Integer metricId =
          (measure.getMetric().getId() != null
              ? measure.getMetric().getId()
              : metricFinder.findByKey(measure.getMetric().getKey()).getId());
      Integer characteristicId =
          (measure.getCharacteristic() != null ? measure.getCharacteristic().getId() : null);
      Integer ruleId =
          (measure instanceof RuleMeasure ? ((RuleMeasure) measure).getRule().getId() : null);

      Object[] pastMeasure =
          pastMeasuresByKey.get(new MeasureKey(metricId, characteristicId, ruleId));
      if (updateVariation(measure, pastMeasure, index)) {
        context.saveMeasure(measure);
      }
    }
  }
コード例 #3
0
  @Before
  public void mockResourcePersister() {
    duplicationCache = mock(DuplicationCache.class);

    ResourceCache resourceCache = mock(ResourceCache.class);
    BatchResource batchResource = mock(BatchResource.class);
    when(batchResource.resource()).thenReturn(aFile);
    when(batchResource.snapshotId()).thenReturn(FILE_SNAPSHOT_ID);
    when(resourceCache.get("foo:org/foo/Bar.java")).thenReturn(batchResource);

    MetricFinder metricFinder = mock(MetricFinder.class);
    when(metricFinder.findByKey(CoreMetrics.DUPLICATIONS_DATA_KEY))
        .thenReturn(CoreMetrics.DUPLICATIONS_DATA.setId(2));

    duplicationPersister =
        new DuplicationPersister(
            getMyBatis(), ruleFinder, resourceCache, duplicationCache, metricFinder);
  }
コード例 #4
0
  @Test
  public void initQuery() throws ParseException {
    Project project = mock(Project.class);
    when(project.getAnalysisDate()).thenReturn(date("2009-12-25"));

    MetricFinder metricFinder = mock(MetricFinder.class);
    when(metricFinder.findAll())
        .thenReturn(
            Arrays.asList(
                CoreMetrics.LINES,
                CoreMetrics.COVERAGE,
                CoreMetrics.COVERAGE_LINE_HITS_DATA,
                CoreMetrics.PROFILE));

    TendencyDecorator decorator = new TendencyDecorator(null, metricFinder, newConf());

    TimeMachineQuery query = decorator.initQuery(project);
    assertThat(query.getMetrics().size(), is(2));
    assertThat(query.getMetrics(), hasItems(CoreMetrics.LINES, CoreMetrics.COVERAGE));
    assertThat(query.getFrom(), is(date("2009-11-25")));
    assertThat(query.isToCurrentAnalysis(), is(true));
  }
コード例 #5
0
ファイル: DefaultIndex.java プロジェクト: ratlsun/view_sonar
  /** the measure is updated if it's already registered. */
  @Override
  public Measure addMeasure(Resource resource, Measure measure) {
    Bucket bucket = checkIndexed(resource);
    if (bucket != null && !bucket.isExcluded()) {
      Metric metric = metricFinder.findByKey(measure.getMetricKey());
      if (metric == null) {
        throw new SonarException("Unknown metric: " + measure.getMetricKey());
      }
      measure.setMetric(metric);
      bucket.addMeasure(measure);

      if (measure.getPersistenceMode().useDatabase()) {
        persistence.saveMeasure(resource, measure);
      }
    }
    return measure;
  }