private void loadFromDirectory(@NotNull Path dir, @NotNull Executor executor) {
    myProject.setName(JpsProjectConfigurationLoading.getDirectoryBaseProjectName(dir));
    Path defaultConfigFile = dir.resolve("misc.xml");
    JpsSdkType<?> projectSdkType = loadProjectRoot(myComponentLoader.loadRootElement(defaultConfigFile));
    for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
      for (JpsProjectExtensionSerializer serializer : extension.getProjectExtensionSerializers()) {
        myComponentLoader.loadComponents(dir, defaultConfigFile, serializer, myProject);
      }
    }

    Path externalConfigDir;
    if (myExternalConfigurationDirectory != null) {
      externalConfigDir = myExternalConfigurationDirectory.resolve("project");
      LOG.info("External project config dir is used: " + externalConfigDir);
    }
    else {
      externalConfigDir = null;
    }

    Element moduleData = myComponentLoader.loadComponent(dir.resolve("modules.xml"), MODULE_MANAGER_COMPONENT);
    Element externalModuleData;
    if (externalConfigDir == null) {
      externalModuleData = null;
    }
    else {
      Element rootElement = myComponentLoader.loadRootElement(externalConfigDir.resolve("modules.xml"));
      if (rootElement == null) {
        externalModuleData = null;
      }
      else {
        externalModuleData = JDomSerializationUtil.findComponent(rootElement, "ExternalProjectModuleManager");
        if (externalModuleData == null) {
          externalModuleData = JDomSerializationUtil.findComponent(rootElement, "ExternalModuleListStorage");
        }
        // old format (root tag is "component")
        if (externalModuleData == null && rootElement.getName().equals(JDomSerializationUtil.COMPONENT_ELEMENT)) {
          externalModuleData = rootElement;
        }
      }
    }
    if (externalModuleData != null) {
      String componentName = externalModuleData.getAttributeValue("name");
      LOG.assertTrue(componentName != null && componentName.startsWith("External"));
      externalModuleData.setAttribute("name", componentName.substring("External".length()));
      if (moduleData == null) {
        moduleData = externalModuleData;
      }
      else {
        JDOMUtil.deepMerge(moduleData, externalModuleData);
      }
    }

    Path workspaceFile = dir.resolve("workspace.xml");
    loadModules(moduleData, projectSdkType, workspaceFile, executor);

    Runnable timingLog = TimingLog.startActivity("loading project libraries");
    for (Path libraryFile : JpsProjectConfigurationLoading.listXmlFiles(dir.resolve("libraries"))) {
      loadProjectLibraries(myComponentLoader.loadRootElement(libraryFile));
    }

    if (externalConfigDir != null) {
      loadProjectLibraries(myComponentLoader.loadRootElement(externalConfigDir.resolve("libraries.xml")));
    }
    timingLog.run();

    JpsProjectConfigurationLoading.loadArtifactsFromDirectory(myProject, myComponentLoader, dir, externalConfigDir);
    JpsProjectConfigurationLoading.loadRunConfigurationsFromDirectory(myProject, myComponentLoader, dir, workspaceFile);
  }
private void loadFromDirectory(@NotNull Path dir, @NotNull Executor executor)