public void saveDesign(Project sonarProject) {
    Collection<Resource> directories = resourceMapping.directories();
    TimeProfiler profiler = new TimeProfiler(LOG).start("Package design analysis");
    LOG.debug("{} packages to analyze", directories.size());

    IncrementalCyclesAndFESSolver<Resource> cyclesAndFESSolver =
        new IncrementalCyclesAndFESSolver<>(graph, directories);
    LOG.debug("{} cycles", cyclesAndFESSolver.getCycles().size());

    Set<Edge> feedbackEdges = cyclesAndFESSolver.getFeedbackEdgeSet();
    LOG.debug("{} feedback edges", feedbackEdges.size());
    int tangles = cyclesAndFESSolver.getWeightOfFeedbackEdgeSet();

    saveIssues(feedbackEdges);
    saveDependencies();
    savePositiveMeasure(
        sonarProject, CoreMetrics.PACKAGE_CYCLES, cyclesAndFESSolver.getCycles().size());
    savePositiveMeasure(sonarProject, CoreMetrics.PACKAGE_FEEDBACK_EDGES, feedbackEdges.size());
    savePositiveMeasure(sonarProject, CoreMetrics.PACKAGE_TANGLES, tangles);
    savePositiveMeasure(
        sonarProject, CoreMetrics.PACKAGE_EDGES_WEIGHT, getEdgesWeight(directories));

    String dsmJson = serializeDsm(graph, directories, feedbackEdges);
    Measure dsmMeasure =
        new Measure(CoreMetrics.DEPENDENCY_MATRIX, dsmJson)
            .setPersistenceMode(PersistenceMode.DATABASE);
    context.saveMeasure(sonarProject, dsmMeasure);

    profiler.stop();

    for (Resource sonarPackage : directories) {
      onPackage(sonarPackage);
    }
  }
 private Collection<Resource> getResourcesForDirectory(Resource sonarPackage) {
   List<Resource> result = Lists.newArrayList();
   for (Resource resource : resourceMapping.files((Directory) sonarPackage)) {
     result.add(context.getResource(resource));
   }
   return result;
 }
 private void saveIssues(Set<Edge> feedbackEdges) {
   for (Edge feedbackEdge : feedbackEdges) {
     for (Dependency subDependency :
         resourceMapping.getSubDependencies((Dependency) feedbackEdge)) {
       Resource fromFile = subDependency.getFrom();
       Resource toFile = subDependency.getTo();
       Issuable issuable = resourcePerspectives.as(Issuable.class, fromFile);
       if (issuable != null) {
         issuable.addIssue(
             issuable
                 .newIssueBuilder()
                 .ruleKey(CycleBetweenPackagesCheck.RULE_KEY)
                 .message(
                     "Remove the dependency on the source file \""
                         + toFile.getLongName()
                         + "\" to break a package cycle.")
                 .build());
       }
     }
   }
 }