String dsmJson = serializeDsm(files, feedbackEdges);
context.saveMeasure(dir, new Measure(CoreMetrics.DEPENDENCY_MATRIX, dsmJson));
}
private void saveViolations(Set<Edge> feedbackEdges, DirectedGraph<Directory, DirectoryEdge> packagesGraph) {
ActiveRule cycleBetweenPackagesRule = CycleBetweenPackagesCheck.getActiveRule(checkFactory);
if (cycleBetweenPackagesRule != null) {
for (Edge feedbackEdge : feedbackEdges) {
Directory fromPackage = (Directory) feedbackEdge.getFrom();
Directory toPackage = (Directory) feedbackEdge.getTo();
DirectoryEdge edge = packagesGraph.getEdge(fromPackage, toPackage);
for (FileEdge subEdge : edge.getRootEdges()) {
Resource fromFile = subEdge.getFrom();
Resource toFile = subEdge.getTo();
Issuable issuable = perspectives.as(Issuable.class, fromFile);
// If resource cannot be obtained, then silently ignore, because anyway warning will be printed by method addFile
if ((issuable != null) && (fromFile != null) && (toFile != null)) {
Issue issue = issuable.newIssueBuilder()
.ruleKey(cycleBetweenPackagesRule.getRule().ruleKey())
.line(subEdge.getLine())
.message("Remove the dependency from file \"" + fromFile.getLongName()
+ "\" to file \"" + toFile.getLongName() + "\" to break a package cycle.")
.effortToFix((double) subEdge.getWeight())
.build();