Package org.sonar.api.resources

Examples of org.sonar.api.resources.Resource


    if (StringUtils.isBlank(resource.getKey())) {
      LOG.warn("Unable to index a resource without key " + resource);
      return null;
    }

    Resource parent = null;
    if (!ResourceUtils.isLibrary(resource)) {
      // a library has no parent
      parent = (Resource) ObjectUtils.defaultIfNull(parentReference, currentProject);
    }

    Bucket parentBucket = getBucket(parent);
    if (parentBucket == null && parent != null) {
      LOG.warn("Resource ignored, parent is not indexed: " + resource);
      return null;
    }

    resource.setEffectiveKey(ComponentKeys.createEffectiveKey(currentProject, resource));
    bucket = new Bucket(resource).setParent(parentBucket);
    addBucket(resource, bucket);

    Resource parentResource = parentBucket != null ? parentBucket.getResource() : null;
    Snapshot snapshot = persistence.saveResource(currentProject, resource, parentResource);
    if (ResourceUtils.isPersistable(resource) && !Qualifiers.LIBRARY.equals(resource.getQualifier())) {
      graph.addComponent(resource, snapshot);
    }
View Full Code Here


      boolean unitTest = InputFile.Type.TEST == inputFile.type();
      String pathFromSourceDir = ((DeprecatedDefaultInputFile) inputFile).pathRelativeToSourceDir();
      if (pathFromSourceDir == null) {
        pathFromSourceDir = inputFile.relativePath();
      }
      Resource sonarFile = File.create(inputFile.relativePath(), pathFromSourceDir, languages.get(languageKey), unitTest);
      if ("java".equals(languageKey)) {
        sonarFile.setDeprecatedKey(DeprecatedKeyUtils.getJavaFileDeprecatedKey(pathFromSourceDir));
      } else {
        sonarFile.setDeprecatedKey(pathFromSourceDir);
      }
      sonarIndex.index(sonarFile);

      importSources(fs, inputFile, sonarFile);
    }
View Full Code Here

      InputFile matchedFile = findInputFile(deprecatedFileKeyMapper, deprecatedTestKeyMapper, oldEffectiveKey, isTest);
      if (matchedFile != null) {
        String newEffectiveKey = ((DeprecatedDefaultInputFile) matchedFile).key();
        // Now compute migration of the parent dir
        String oldKey = StringUtils.substringAfterLast(oldEffectiveKey, ":");
        Resource sonarFile;
        String parentOldKey;
        if ("java".equals(resourceModel.getLanguageKey())) {
          parentOldKey = String.format("%s:%s", module.getEffectiveKey(), DeprecatedKeyUtils.getJavaFileParentDeprecatedKey(oldKey));
        } else {
          sonarFile = new File(oldKey);
          parentOldKey = String.format("%s:%s", module.getEffectiveKey(), sonarFile.getParent().getDeprecatedKey());
        }
        String parentNewKey = String.format("%s:%s", module.getEffectiveKey(), getParentKey(matchedFile));
        if (!deprecatedDirectoryKeyMapper.containsKey(parentOldKey)) {
          deprecatedDirectoryKeyMapper.put(parentOldKey, parentNewKey);
        } else if (!parentNewKey.equals(deprecatedDirectoryKeyMapper.get(parentOldKey))) {
View Full Code Here

public class ResourceCacheTest {
  @Test
  public void should_cache_resource() throws Exception {
    ResourceCache cache = new ResourceCache();
    String componentKey = "struts:src/org/struts/Action.java";
    Resource resource = new File("org/struts/Action.java").setEffectiveKey(componentKey);
    cache.add(resource);

    assertThat(cache.get(componentKey)).isSameAs(resource);
    assertThat(cache.get("other")).isNull();
  }
View Full Code Here

  }

  @Test
  public void should_fail_if_missing_component_key() throws Exception {
    ResourceCache cache = new ResourceCache();
    Resource resource = new File("org/struts/Action.java").setEffectiveKey(null);
    try {
      cache.add(resource);
      fail();
    } catch (IllegalStateException e) {
      // success
View Full Code Here

    assertThat(index.getParent(fileRef)).isNull();
  }

  @Test
  public void shouldNotIndexResourceWhenAddingMeasure() {
    Resource dir = Directory.create("src/org/foo", "org/foo");
    index.addMeasure(dir, new Measure("ncloc").setValue(50.0));

    assertThat(index.isIndexed(dir, true)).isFalse();
    assertThat(index.getMeasures(dir, MeasuresFilters.metric("ncloc"))).isNull();
  }
View Full Code Here

  ComponentDataCache cache = mock(ComponentDataCache.class);

  @Test
  public void should_load_default_perspective() throws Exception {
    Resource file = new File("foo.c").setEffectiveKey("myproject:path/to/foo.c");
    Component component = new ResourceComponent(file);

    HighlightableBuilder builder = new HighlightableBuilder(cache);
    Highlightable perspective = builder.loadPerspective(Highlightable.class, component);
View Full Code Here

    ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
    activeRulesBuilder.create(SQUID_RULE_KEY).setSeverity(Severity.INFO).activate();
    initModuleIssues();

    org.sonar.api.rules.Rule rule = org.sonar.api.rules.Rule.create("squid", "AvoidCycle", "Avoid Cycle");
    Resource resource = new File("org/struts/Action.java").setEffectiveKey("struts:src/org/struts/Action.java");
    Violation violation = new Violation(rule, resource);
    violation.setLineId(42);
    violation.setSeverity(RulePriority.CRITICAL);
    violation.setMessage("the message");
View Full Code Here

    assertThat(DsmSerializer.serialize(dsm), is("[]"));
  }

  @Test
  public void serialize() throws IOException {
    Resource foo = Directory.create("src/org/foo", "org/foo").setId(7);
    Resource bar = Directory.create("src/org/bar", "org/bar").setId(8);
    Dependency dep = new Dependency(foo, bar).setId(30l).setWeight(1);

    DirectedGraph<Resource, Dependency> graph = new DirectedGraph<Resource, Dependency>();
    graph.addVertex(foo);
    graph.addVertex(bar);
View Full Code Here

    ResourcePersister persister = new DefaultResourcePersister(getSession(), mock(ResourcePermissions.class), snapshotCache, resourceCache);
    persister.saveProject(multiModuleProject, null);
    persister.saveProject(moduleA, multiModuleProject);
    persister.saveProject(moduleB, multiModuleProject);
    persister.saveProject(moduleB1, moduleB);
    Resource file = File.create("src/main/java/org/Foo.java").setEffectiveKey("b1:src/main/java/org/Foo.java");
    file.getParent().setEffectiveKey("b1:src/main/java/org");
    persister.saveResource(moduleB1, file.getParent());
    persister.saveResource(moduleB1, file, file.getParent());

    checkTables("shouldSaveNewMultiModulesProject",
      new String[] {"build_date", "created_at", "authorization_updated_at", "uuid", "project_uuid", "module_uuid", "module_uuid_path"}, "projects", "snapshots");

    // Need to enable snapshot to make resource visible using ComponentMapper
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.