packagesGraph.addVertex(sonarDir);
directoryFiles.put(sonarDir, sonarFile);
//Build the dependency graph
for (CxxPreprocessor.Include include : includedFiles) {
File includedFile = File.fromIOFile(new java.io.File(include.getPath()), project);
if (includedFile == null) {
CxxUtils.LOG.warn("Unable to find resource '" + include.getPath() + "' to create a dependency with '" + sonarFile.getKey() + "'");
}
else if (filesGraph.hasEdge(sonarFile, includedFile)) {
FileEdge fileEdge = filesGraph.getEdge(sonarFile, includedFile);
Issuable issuable = perspectives.as(Issuable.class, sonarFile);
if ((issuable != null) && (duplicateIncludeRule != null)) {
Issue issue = issuable.newIssueBuilder()
.ruleKey(duplicateIncludeRule.getRule().ruleKey())
.line(include.getLine())
.message("Remove duplicated include, \"" + includedFile.getLongName() + "\" is already included at line " + fileEdge.getLine() + ".")
.build();
if (issuable.addIssue(issue))
violationsCount++;
}
else {
CxxUtils.LOG.warn("Already created edge from '" + sonarFile.getKey() + "' (line " + include.getLine() + ") to '" + includedFile.getKey() + "'" +
", previous edge from line " + fileEdge.getLine());
}
}
else {
//Add the dependency in the files graph
FileEdge fileEdge = new FileEdge(sonarFile, includedFile, include.getLine());
filesGraph.addEdge(fileEdge);
//Add the dependency in the packages graph, if the directories are different
Directory includedDir = includedFile.getParent();
if (!sonarDir.equals(includedDir)) {
DirectoryEdge edge = packagesGraph.getEdge(sonarDir, includedDir);
if (edge == null) {
edge = new DirectoryEdge(sonarDir, includedDir);
packagesGraph.addEdge(edge);