[jps model] refactoring: extract and reuse JpsComponentLoader.loadComponent method

GitOrigin-RevId: 907421fa095075d727feb207538340cf41e4dcd6
This commit is contained in:
Nikolay Chashnikov
2024-06-28 17:05:00 +00:00
committed by intellij-monorepo-bot
parent 2e8cb4a8e1
commit 55fb09873d
4 changed files with 9 additions and 7 deletions
@@ -41,6 +41,10 @@ public class JpsComponentLoader {
return loadRootElement(file, myMacroExpander);
}
public @Nullable Element loadComponent(@NotNull Path file, @NotNull String componentName) {
return JDomSerializationUtil.findComponent(loadRootElement(file), componentName);
}
public <E extends JpsElement> void loadComponents(@NotNull Path dir,
@NotNull Path defaultConfigFile,
JpsElementExtensionSerializerBase<E> serializer,
@@ -60,7 +64,7 @@ public class JpsComponentLoader {
private @Nullable <E extends JpsElement> Element loadComponentData(@NotNull JpsElementExtensionSerializerBase<E> serializer, @NotNull Path configFile) {
String componentName = serializer.getComponentName();
Element component = JDomSerializationUtil.findComponent(loadRootElement(configFile), componentName);
Element component = loadComponent(configFile, componentName);
if (!(serializer instanceof JpsProjectExtensionWithExternalDataSerializer) || myExternalConfigurationDirectory == null) {
return component;
}
@@ -61,8 +61,7 @@ public final class JpsProjectConfigurationLoading {
for (Path configurationFile : listXmlFiles(dir.resolve("runConfigurations"))) {
JpsRunConfigurationSerializer.loadRunConfigurations(project, componentLoader.loadRootElement(configurationFile));
}
JpsRunConfigurationSerializer.loadRunConfigurations(project, JDomSerializationUtil.findComponent(
componentLoader.loadRootElement(workspaceFile), "RunManager"));
JpsRunConfigurationSerializer.loadRunConfigurations(project, componentLoader.loadComponent(workspaceFile, "RunManager"));
runConfTimingLog.run();
}
}
@@ -155,7 +154,7 @@ public final class JpsProjectConfigurationLoading {
public static @NotNull Set<String> readNamesOfUnloadedModules(@NotNull Path workspaceFile, @NotNull JpsComponentLoader componentLoader) {
Set<String> unloadedModules = new HashSet<>();
if (workspaceFile.toFile().exists()) {
Element unloadedModulesList = JDomSerializationUtil.findComponent(componentLoader.loadRootElement(workspaceFile), "UnloadedModulesList");
Element unloadedModulesList = componentLoader.loadComponent(workspaceFile, "UnloadedModulesList");
for (Element element : JDOMUtil.getChildren(unloadedModulesList, "module")) {
unloadedModules.add(element.getAttributeValue("name"));
}
@@ -158,7 +158,7 @@ public final class JpsProjectLoader {
externalConfigDir = null;
}
Element moduleData = JDomSerializationUtil.findComponent(myComponentLoader.loadRootElement(dir.resolve("modules.xml")), MODULE_MANAGER_COMPONENT);
Element moduleData = myComponentLoader.loadComponent(dir.resolve("modules.xml"), MODULE_MANAGER_COMPONENT);
Element externalModuleData;
if (externalConfigDir == null) {
externalModuleData = null;
@@ -17,8 +17,7 @@ internal class GlobalDirectJpsFileContentReader(private val macroExpander: JpsMa
private val componentLoader = JpsComponentLoader(macroExpander, null)
override fun loadComponent(fileUrl: String, componentName: String, customModuleFilePath: String?): Element? {
val rootElement = componentLoader.loadRootElement(Path(JpsPathUtil.urlToPath(fileUrl))) ?: return null
return JDomSerializationUtil.findComponent(rootElement, componentName)
return componentLoader.loadComponent(Path(JpsPathUtil.urlToPath(fileUrl)), componentName)
}
override fun getExpandMacroMap(fileUrl: String): ExpandMacroToPathMap {