private synchronized void applyConfigFiles(@NotNull ProgressIndicator indicator, List<Pair<Element, String>> configFiles) {
    indicator.setIndeterminate(true);
    indicator.pushState();
    try {
      indicator.setText(AntBundle.message("progress.text.loading.ant.config"));
      myInitThread = Thread.currentThread();

      // first, remove existing files
      // then fill the configuration with the files configured in xml
      // updating properties separately to avoid unnecessary building of PSI after clearing caches
      runNonBlocking(() -> {
        for (AntBuildFile file : myBuildFiles) {
          removeBuildFileImpl(file);
        }
      });

      // then fill the configuration with the files configured in xml
      final VirtualFileManager vfManager = VirtualFileManager.getInstance();
      List<Pair<Element, AntBuildFileBase>> buildFiles = new ArrayList<>(configFiles.size());
      for (Pair<Element, String> elemUrl : configFiles) {
        Pair<Element, AntBuildFileBase> bf = runNonBlocking(() -> {
          final Element element = elemUrl.getFirst();
          final VirtualFile file = vfManager.findFileByUrl(elemUrl.getSecond());
          if (file != null) {
            try {
              return Pair.create(element, addBuildFileImpl(file, element));
            }
            catch (AntNoFileException ignored) {
            }
            catch (InvalidDataException e) {
              LOG.error(e);
            }
          }
          return null;
        }, null);
        if (bf != null) {
          buildFiles.add(bf);
        }
      }

      // updating properties separately to avoid unnecessary building of PSI after clearing caches
      for (Pair<Element, AntBuildFileBase> elemBuildFile : buildFiles) {
        runNonBlocking(() -> {
          final AntBuildFileBase buildFile = elemBuildFile.getSecond();
          buildFile.updateProperties();
          for (Element e : elemBuildFile.getFirst().getChildren(EXECUTE_ON_ELEMENT)) {
            final String eventId = e.getAttributeValue(EVENT_ELEMENT);
            ExecutionEvent event = null;
            final String targetName = e.getAttributeValue(TARGET_ELEMENT);
            if (ExecuteBeforeCompilationEvent.TYPE_ID.equals(eventId)) {
              event = ExecuteBeforeCompilationEvent.getInstance();
            }
            else if (ExecuteAfterCompilationEvent.TYPE_ID.equals(eventId)) {
              event = ExecuteAfterCompilationEvent.getInstance();
            }
            else if (ExecuteCompositeTargetEvent.TYPE_ID.equals(eventId)) {
              try {
                event = new ExecuteCompositeTargetEvent(targetName);
              }
              catch (WrongNameFormatException e1) {
                LOG.info(e1);
                event = null;
              }
            }
            if (event != null) {
              try {
                event.readExternal(e, getProject());
                setTargetForEvent(buildFile, targetName, event);
              }
              catch (InvalidDataException readFailed) {
                LOG.info(readFailed.getMessage());
              }
            }
          }
        });
      }
      ReadAction.run(() -> {
        try {
          AntWorkspaceConfiguration.getInstance(getProject()).loadFileProperties();
        }
        catch (InvalidDataException e) {
          LOG.error(e);
        }
        finally {
          incModificationCount();
          updateRegisteredActions();
        }
      });
    }
    finally {
      myInitThread = null;
      LOG.info("AntConfiguration: initialized");
      myInitialized = true;
      ApplicationManager.getApplication().invokeLater(
        () -> myEventDispatcher.getMulticaster().configurationLoaded(),
        ModalityState.any()
      );
      indicator.popState();
    }
  }
private synchronized void applyConfigFiles(@NotNull ProgressIndicator indicator, List<Pair<Element, String>> configFiles)