public void addResource(File resource, String fileKey) { directories.put(resource.getParent(), resource); fileKeyByResource.put(resource, fileKey); }
public void addResource(File resource, String fileKey) { directories.put(resource.getParent(), resource); fileKeyByResource.put(resource, fileKey); }
@Override public void store(org.sonar.api.batch.sensor.dependency.Dependency dep) { BatchResource fromBatchResource = resourceCache.get(dep.fromKey()); BatchResource toBatchResource = resourceCache.get(dep.toKey()); Preconditions.checkNotNull(fromBatchResource, "Unable to find origin resource " + dep.fromKey()); Preconditions.checkNotNull(toBatchResource, "Unable to find destination resource " + dep.toKey()); File fromResource = (File) fromBatchResource.resource(); File toResource = (File) toBatchResource.resource(); if (sonarIndex.getEdge(fromResource, toResource) != null) { throw new IllegalStateException("Dependency between " + dep.fromKey() + " and " + dep.toKey() + " was already saved."); } Directory fromParent = fromResource.getParent(); Directory toParent = toResource.getParent(); Dependency parentDep = null; if (!fromParent.equals(toParent)) { parentDep = sonarIndex.getEdge(fromParent, toParent); if (parentDep != null) { parentDep.setWeight(parentDep.getWeight() + 1); } else { parentDep = new Dependency(fromParent, toParent).setUsage(USES).setWeight(1); parentDep = sonarIndex.addDependency(parentDep); } } sonarIndex.addDependency(new Dependency(fromResource, toResource) .setUsage(USES) .setWeight(dep.weight()) .setParent(parentDep)); }
@Override public void analyse(Project module, org.sonar.api.batch.SensorContext context) { createIssueOnDir(new Directory("")); File src = module.getFileSystem().getSourceDirs().get(0); for (File f : fileSystem.files(FileQuery.onMain().onLanguage(Xoo.KEY))) { String relativePathFromSourceDir = new PathResolver().relativePath(src, f); org.sonar.api.resources.File sonarFile = new org.sonar.api.resources.File(relativePathFromSourceDir); Issuable issuable = perspectives.as(Issuable.class, sonarFile); issuable.addIssue(issuable.newIssueBuilder() .ruleKey(RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY)) .message("Issue created using deprecated API") .line(1) .build()); sonarFile = context.getResource(sonarFile); Directory parent = sonarFile.getParent(); createIssueOnDir(parent); } }