Package org.sonar.api.resources

Examples of org.sonar.api.resources.Resource


public class DirectoriesDecoratorTest {

  @Test
  public void doNotInsertZeroOnFiles() {
    DirectoriesDecorator decorator = new DirectoriesDecorator();
    Resource file = new File("foo.php");
    DecoratorContext context = mock(DecoratorContext.class);

    decorator.decorate(file, context);

    verify(context, never()).saveMeasure(eq(CoreMetrics.DIRECTORIES), anyDouble());
View Full Code Here


  }

  @Test
  public void directoryCountsForOne() {
    DirectoriesDecorator decorator = new DirectoriesDecorator();
    Resource directory = new Directory("org/foo");
    DecoratorContext context = mock(DecoratorContext.class);
    decorator.decorate(directory, context);
    verify(context).saveMeasure(CoreMetrics.DIRECTORIES, 1.0);
  }
View Full Code Here

  }

  @Test
  public void countProjectDirectories() {
    DirectoriesDecorator decorator = new DirectoriesDecorator();
    Resource project = new Project("project");
    DecoratorContext context = mock(DecoratorContext.class);

    when(context.getChildrenMeasures(CoreMetrics.DIRECTORIES)).thenReturn(Arrays.<Measure>asList(
      new Measure(CoreMetrics.DIRECTORIES, 1.0),
      new Measure(CoreMetrics.DIRECTORIES, 1.0),
View Full Code Here

  }

  @Test
  public void noProjectValueWhenOnlyPackages() {
    DirectoriesDecorator decorator = new DirectoriesDecorator();
    Resource project = new Project("project");
    DecoratorContext context = mock(DecoratorContext.class);
    when(context.getChildrenMeasures(CoreMetrics.DIRECTORIES)).thenReturn(Collections.<Measure>emptyList());
    when(context.getChildrenMeasures(CoreMetrics.PACKAGES)).thenReturn(Arrays.<Measure>asList(
      new Measure(CoreMetrics.PACKAGES, 1.0),
      new Measure(CoreMetrics.PACKAGES, 1.0)
View Full Code Here

  @Test
  public void should_get_measures() throws Exception {
    MeasureCache cache = new MeasureCache(caches, metricFinder, techDebtModel);
    Project p = new Project("struts");
    Resource dir = new Directory("foo/bar").setEffectiveKey("struts:foo/bar");
    Resource file1 = new File("foo/bar/File1.txt").setEffectiveKey("struts:foo/bar/File1.txt");
    Resource file2 = new File("foo/bar/File2.txt").setEffectiveKey("struts:foo/bar/File2.txt");

    assertThat(cache.entries()).hasSize(0);

    assertThat(cache.byResource(p)).hasSize(0);
    assertThat(cache.byResource(dir)).hasSize(0);
View Full Code Here

  }

  @Test
  public void test_measure_coder() throws Exception {
    MeasureCache cache = new MeasureCache(caches, metricFinder, techDebtModel);
    Resource file1 = new File("foo/bar/File1.txt").setEffectiveKey("struts:foo/bar/File1.txt");

    Measure measure = new Measure(CoreMetrics.NCLOC, 1.786, 5);
    cache.put(file1, measure);

    Measure savedMeasure = cache.byResource(file1).iterator().next();
View Full Code Here

    this.key = key;
  }

  @Override
  public boolean matches(Object o) {
    Resource r = (Resource) o;
    boolean keyMatch = (key != null) ? StringUtils.equals(r.getKey() != null ? r.getKey() : r.getDeprecatedKey(), key) : true;
    return ObjectUtils.equals(r.getScope(), scope) && ObjectUtils.equals(r.getQualifier(), qualifier) && keyMatch;
  }
View Full Code Here

      MeasureMapper mapper = session.getMapper(MeasureMapper.class);

      for (Entry<Measure> entry : measureCache.entries()) {
        String effectiveKey = entry.key()[0].toString();
        Measure measure = entry.value();
        Resource resource = resourceCache.get(effectiveKey);

        if (shouldPersistMeasure(resource, measure)) {
          Snapshot snapshot = snapshotCache.get(effectiveKey);
          MeasureModel measureModel = model(measure, ruleFinder).setSnapshotId(snapshot.getId());
          mapper.insert(measureModel);
View Full Code Here

      MeasureMapper mapper = session.getMapper(MeasureMapper.class);
      org.sonar.api.measures.Metric duplicationMetricWithId = metricFinder.findByKey(CoreMetrics.DUPLICATIONS_DATA_KEY);
      for (Entry<List<DuplicationGroup>> entry : duplicationCache.entries()) {
        String effectiveKey = entry.key()[0].toString();
        Measure measure = new Measure(duplicationMetricWithId, DuplicationUtils.toXml(entry.value())).setPersistenceMode(PersistenceMode.DATABASE);
        Resource resource = resourceCache.get(effectiveKey);

        if (MeasurePersister.shouldPersistMeasure(resource, measure)) {
          Snapshot snapshot = snapshotCache.get(effectiveKey);
          MeasureModel measureModel = MeasurePersister.model(measure, ruleFinder).setSnapshotId(snapshot.getId());
          mapper.insert(measureModel);
View Full Code Here

    return mode == ViolationQuery.SwitchMode.ON && !violation.isSwitchedOff();
  }

  @Override
  public void addViolation(Violation violation, boolean force) {
    Resource resource = violation.getResource();
    if (resource == null) {
      violation.setResource(currentProject);
    } else if (!Scopes.isHigherThanOrEquals(resource, Scopes.FILE)) {
      throw new IllegalArgumentException("Violations are only supported on files, directories and project");
    }
View Full Code Here

TOP

Related Classes of org.sonar.api.resources.Resource

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.