private static boolean updateDependencyGraph(CompileContext context, Delta delta, ModuleChunk chunk, final CompilationRound markDirtyRound, @Nullable FileFilter skipMarkDirtyFilter) throws IOException {
    boolean performIntegrate = true;
    boolean additionalPassRequired = false;
    final boolean errorsDetected = Utils.errorsDetected(context);
    BuildDataManager dataManager = context.getProjectDescriptor().dataManager;
    GraphConfiguration graphConfig = Objects.requireNonNull(dataManager.getDependencyGraph());
    DependencyGraph dependencyGraph = graphConfig.getGraph();
    NodeSourcePathMapper pathMapper = graphConfig.getPathMapper();
    
    final ModulesBasedFileFilter moduleBasedFilter = new ModulesBasedFileFilter(context, chunk);
    DifferentiateParametersBuilder params = DifferentiateParametersBuilder.create(chunk.getPresentableShortName())
      .calculateAffected(context.shouldDifferentiate(chunk) && !isForcedRecompilationAllJavaModules(context))
      .processConstantsIncrementally(dataManager.isProcessConstantsIncrementally())
      .withAffectionFilter(s -> moduleBasedFilter.accept(pathMapper.toPath(s).toFile()))
      .withChunkStructureFilter(s -> moduleBasedFilter.belongsToCurrentTargetChunk(pathMapper.toPath(s).toFile()));
    DifferentiateParameters differentiateParams = params.get();
    DifferentiateResult diffResult = dependencyGraph.differentiate(delta, differentiateParams);

    final boolean compilingIncrementally = isCompileJavaIncrementally(context);

    if (diffResult.isIncremental()) {
      final Set<File> affectedFiles = Iterators.collect(
        Iterators.filter(Iterators.map(diffResult.getAffectedSources(), src -> pathMapper.toPath(src).toFile()), f -> skipMarkDirtyFilter == null || !skipMarkDirtyFilter.accept(f)),
        new HashSet<>()
      );

      if (differentiateParams.isCalculateAffected()) {
        final String infoMessage = JpsBuildBundle.message("progress.message.dependency.analysis.found.0.affected.files", affectedFiles.size());
        LOG.info(infoMessage);
        context.processMessage(new ProgressMessage(infoMessage));
      }

      if (!affectedFiles.isEmpty()) {
        
        if (LOG.isDebugEnabled()) {
          for (File file : affectedFiles) {
            LOG.debug("affected file: " + file.getPath());
          }
          final List<Pair<File, JpsModule>> wrongFiles =
            checkAffectedFilesInCorrectModules(context, affectedFiles, moduleBasedFilter);
          if (!wrongFiles.isEmpty()) {
            LOG.debug("Wrong affected files for module chunk " + chunk.getName() + ": ");
            for (Pair<File, JpsModule> pair : wrongFiles) {
              final String name = pair.second != null ? pair.second.getName() : "null";
              LOG.debug("\t[" + name + "] " + pair.first.getPath());
            }
          }
        }

        Set<ModuleBuildTarget> targetsToMark = null;
        final JavaModuleIndex moduleIndex = getJavaModuleIndex(context);
        for (File file : affectedFiles) {
          if (MODULE_INFO_FILE.equals(file.getName())) {
            final JavaSourceRootDescriptor rootDescr = context.getProjectDescriptor().getBuildRootIndex().findJavaRootDescriptor(context, file);
            if (rootDescr != null) {
              final ModuleBuildTarget target = rootDescr.getTarget();
              final File targetModuleInfo = moduleIndex.getModuleInfoFile(target.getModule(), target.isTests());
              if (FileUtil.filesEqual(targetModuleInfo, file)) {
                if (targetsToMark == null) {
                  targetsToMark = new HashSet<>(); // lazy init
                }
                targetsToMark.add(target);
              }
            }
          }
          else {
            FSOperations.markDirtyIfNotDeleted(context, markDirtyRound, file);
          }
        }

        boolean currentChunkAfected = false;
        if (targetsToMark != null) {
          for (ModuleBuildTarget target : targetsToMark) {
            if (chunk.getTargets().contains(target)) {
              currentChunkAfected = true;
            }
            else {
              FSOperations.markDirty(context, markDirtyRound, target, null);
            }
          }
          if (currentChunkAfected) {
            if (compilingIncrementally) {
              // turn on non-incremental mode for targets from the current chunk, if at least one of them was affected.
              for (ModuleBuildTarget target : chunk.getTargets()) {
                context.markNonIncremental(target);
              }
            }
            FSOperations.markDirty(context, markDirtyRound, chunk, null);
          }
        }
        additionalPassRequired = compilingIncrementally && (currentChunkAfected || moduleBasedFilter.containsFilesFromCurrentTargetChunk(affectedFiles));
      }
    }
    else {
      // non-incremental mode
      final String messageText = JpsBuildBundle.message("progress.message.marking.0.and.direct.dependants.for.recompilation", chunk.getPresentableShortName());
      LOG.info("Non-incremental mode: " + messageText);
      context.processMessage(new ProgressMessage(messageText));

      final boolean alreadyMarkedDirty = FSOperations.isMarkedDirty(context, chunk);
      additionalPassRequired = compilingIncrementally && !alreadyMarkedDirty;

      if (!alreadyMarkedDirty) {
        performIntegrate = false;
      }

      FileFilter toBeMarkedFilter = skipMarkDirtyFilter == null? null : new NegationFileFilter(skipMarkDirtyFilter);
      FSOperations.markDirtyRecursively(context, markDirtyRound, chunk, toBeMarkedFilter);
    }

    if (errorsDetected) {
      return false;
    }

    if (performIntegrate) {
      dependencyGraph.integrate(diffResult);
    }

    return additionalPassRequired;
  }
private static boolean updateDependencyGraph(CompileContext context, Delta delta, ModuleChunk chunk, final CompilationRound markDirtyRound, @Nullable FileFilter skipMarkDirtyFilter)